/**
  * Add a key of a map location to the processor that contains a location on the map that was yet
  * unchecked.
  *
  * @param key the key of the location that needs to be checked
  */
 public void reportUnchecked(final long key) {
   synchronized (unchecked) {
     if (unchecked.contains(key)) {
       unchecked.add(key);
     }
     unchecked.notify();
   }
   fullCheckNeeded = true;
 }
  /**
   * Add all tiles surrounding this location and the tile above to the list of unchecked tiles.
   *
   * @param searchLoc the location of the start of the search.
   */
  private void addAllNeighbours(final Location searchLoc) {
    for (int x = -1; x < 2; x++) {
      for (int y = -1; y < 2; y++) {
        if ((x == 0) && (y == 0)) {
          continue;
        }
        final long foundKey =
            Location.getKey(searchLoc.getScX() + x, searchLoc.getScY() + y, searchLoc.getScZ());
        synchronized (unchecked) {
          if (!unchecked.contains(foundKey)) {
            unchecked.add(foundKey);
          }
        }
      }
    }

    final long foundKey =
        Location.getKey(searchLoc.getScX(), searchLoc.getScY(), searchLoc.getScZ() + 1);
    synchronized (unchecked) {
      if (!unchecked.contains(foundKey)) {
        unchecked.add(foundKey);
      }
    }
  }
  /**
   * Add all tiles in the visible perspective below one location to the list of unchecked tiles
   * again.
   *
   * @param searchLoc the location the search starts add. This location is not added to the list of
   *     unchecked tiles
   * @param limit the limit the Z coordinate is not going below
   */
  private void addAllBelow(final Location searchLoc, final int limit) {
    int currX = searchLoc.getScX();
    int currY = searchLoc.getScY();
    int currZ = searchLoc.getScZ();

    while (currZ >= limit) {
      currX += MapDisplayManager.TILE_PERSPECTIVE_OFFSET;
      currY -= MapDisplayManager.TILE_PERSPECTIVE_OFFSET;
      currZ--;
      final long foundKey = Location.getKey(currX, currY, currZ);
      synchronized (unchecked) {
        if (!unchecked.contains(foundKey)) {
          unchecked.add(foundKey);
        }
      }
    }
  }
  /**
   * Perform a check if the player character is inside a building. In case the inside status differs
   * for any level from the state before the check, all tiles are added to the list of tiles that
   * need to be checked once more.
   */
  private void performInsideCheck() {
    if (!checkInside) {
      return;
    }

    checkInside = false;

    final Location playerLoc = World.getPlayer().getLocation();
    final int currX = playerLoc.getScX();
    final int currY = playerLoc.getScY();
    int currZ = playerLoc.getScZ();
    boolean nowOutside = false;
    boolean isInside = false;

    for (int i = 0; i < 2; ++i) {
      currZ++;
      if (isInside || (parent.isMapAt(currX, currY, currZ))) {
        if (!insideStates[i]) {
          insideStates[i] = true;
          synchronized (unchecked) {
            unchecked.add(Location.getKey(currX, currY, currZ));
          }
        }
        isInside = true;
      } else {
        if (insideStates[i]) {
          insideStates[i] = false;
          nowOutside = true;
        }
      }
    }

    /*
     * If one of the values turned from inside to outside, all tiles are
     * added to the list to be checked again.
     */
    if (nowOutside) {
      synchronized (unchecked) {
        unchecked.clear();
        parent.processTiles(this);
      }
    }

    World.getWeather().setOutside(!isInside);
  }
 private void readRouteTreeData(
     RouteSubregion routeTree,
     TLongArrayList idTables,
     TLongObjectHashMap<TLongArrayList> restrictions)
     throws IOException {
   routeTree.dataObjects = new ArrayList<RouteDataObject>();
   idTables.clear();
   restrictions.clear();
   List<String> stringTable = null;
   while (true) {
     int t = codedIS.readTag();
     int tag = WireFormat.getTagFieldNumber(t);
     switch (tag) {
       case 0:
         TLongObjectIterator<TLongArrayList> it = restrictions.iterator();
         while (it.hasNext()) {
           it.advance();
           int from = (int) it.key();
           RouteDataObject fromr = routeTree.dataObjects.get(from);
           fromr.restrictions = new long[it.value().size()];
           for (int k = 0; k < fromr.restrictions.length; k++) {
             int to = (int) (it.value().get(k) >> RouteDataObject.RESTRICTION_SHIFT);
             long valto =
                 (idTables.get(to) << RouteDataObject.RESTRICTION_SHIFT)
                     | ((long) it.value().get(k) & RouteDataObject.RESTRICTION_MASK);
             fromr.restrictions[k] = valto;
           }
         }
         for (RouteDataObject o : routeTree.dataObjects) {
           if (o != null) {
             if (o.id < idTables.size()) {
               o.id = idTables.get((int) o.id);
             }
             if (o.names != null && stringTable != null) {
               int[] keys = o.names.keys();
               for (int j = 0; j < keys.length; j++) {
                 o.names.put(keys[j], stringTable.get(o.names.get(keys[j]).charAt(0)));
               }
             }
           }
         }
         return;
       case RouteDataBlock.DATAOBJECTS_FIELD_NUMBER:
         int length = codedIS.readRawVarint32();
         int oldLimit = codedIS.pushLimit(length);
         RouteDataObject obj =
             readRouteDataObject(routeTree.routeReg, routeTree.left, routeTree.top);
         while (obj.id >= routeTree.dataObjects.size()) {
           routeTree.dataObjects.add(null);
         }
         routeTree.dataObjects.set((int) obj.id, obj);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.IDTABLE_FIELD_NUMBER:
         long routeId = 0;
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case IdTable.ROUTEID_FIELD_NUMBER:
               routeId += codedIS.readSInt64();
               idTables.add(routeId);
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.RESTRICTIONS_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         long from = 0;
         long to = 0;
         long type = 0;
         idLoop:
         while (true) {
           int ts = codedIS.readTag();
           int tags = WireFormat.getTagFieldNumber(ts);
           switch (tags) {
             case 0:
               break idLoop;
             case RestrictionData.FROM_FIELD_NUMBER:
               from = codedIS.readInt32();
               break;
             case RestrictionData.TO_FIELD_NUMBER:
               to = codedIS.readInt32();
               break;
             case RestrictionData.TYPE_FIELD_NUMBER:
               type = codedIS.readInt32();
               break;
             default:
               skipUnknownField(ts);
               break;
           }
         }
         if (!restrictions.containsKey(from)) {
           restrictions.put(from, new TLongArrayList());
         }
         restrictions.get(from).add((to << RouteDataObject.RESTRICTION_SHIFT) + type);
         codedIS.popLimit(oldLimit);
         break;
       case RouteDataBlock.STRINGTABLE_FIELD_NUMBER:
         length = codedIS.readRawVarint32();
         oldLimit = codedIS.pushLimit(length);
         stringTable = map.readStringTable();
         //				codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
         codedIS.popLimit(oldLimit);
         break;
       default:
         skipUnknownField(t);
         break;
     }
   }
 }
  /**
   * Procedure function that is used to collect data from the map of the game.
   *
   * <p>Do not call this function from any other class.
   */
  @Override
  public boolean execute(final long key, final MapTile tile) {
    unchecked.add(key);

    return true;
  }