Exemplo n.º 1
0
  /**
   * @return the ObjectKey2 in the STATIONS table of the station owned by player p within the city
   *     radius, or -1 if there is no station
   */
  public ObjectKey2 hasStation(FreerailsPrincipal p) {
    int xmin = cityModel.getCityX() - cityModel.getCityRadius();
    int xmax = cityModel.getCityX() + cityModel.getCityRadius();
    int ymin = cityModel.getCityY() - cityModel.getCityRadius();
    int ymax = cityModel.getCityY() + cityModel.getCityRadius();

    xmin = xmin < 0 ? 0 : xmin;
    ymin = ymin < 0 ? 0 : ymin;
    xmax = xmax >= world.getMapWidth() ? world.getMapWidth() - 1 : xmax;
    ymax = ymax >= world.getMapHeight() ? world.getMapHeight() - 1 : ymax;

    Iterator i = world.getIterator(KEY.STATIONS, p);
    while (i.hasNext()) {
      StationModel sm = (StationModel) i.next();
      int x = sm.getStationX();
      int y = sm.getStationY();
      if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
        return new ObjectKey2(KEY.STATIONS, p, sm.getUUID());
      }
    }
    return null;
  }