Exemplo n.º 1
0
  /**
   * 最寄りの施設をさがす.<br>
   *
   * @author n-yuuta<br>
   * @param lan 経度<br>
   * @param lon 緯度<br>
   * @return building
   */
  public Building getNearestBuilding(double longitude, double latitude) {

    int minBuildId = 0;
    double minLan = 0.0;
    double minLon = 0.0;
    int minCount = 0;
    String minName = "";

    double minDistance = 0.0;
    double distance = 0.0;

    ArrayList<Building> buildingList = DBUtils.convertDBToBuildingList();

    for (int i = 0; i < buildingList.size(); i++) {

      distance =
          this.calcDistance(
              longitude,
              latitude,
              buildingList.get(i).getLongitude(),
              buildingList.get(i).getLatitude(),
              5);

      if (i == 0) {
        minDistance = distance;
        minBuildId = buildingList.get(i).getBuildId();
        minLan = buildingList.get(i).getLongitude();
        minLon = buildingList.get(i).getLatitude();
        minCount = buildingList.get(i).getCount();
        minName = buildingList.get(i).getName();

      } else {
        if (distance < minDistance) {
          minDistance = distance;
          minBuildId = buildingList.get(i).getBuildId();
          minLan = buildingList.get(i).getLongitude();
          minLon = buildingList.get(i).getLatitude();
          minCount = buildingList.get(i).getCount();
          minName = buildingList.get(i).getName();
        }
      }
    }

    Building building = new Building();
    building.setBuildId(minBuildId);
    building.setLongitude(minLan);
    building.setLatitude(minLon);
    building.setCount(minCount);
    building.setName(minName);

    return building;
  }
Exemplo n.º 2
0
  /**
   * 近くの施設をまとめて返す(おそらく正式に使うBuildingList版)
   *
   * @author 2015020 賀数
   * @param lon 緯度
   * @param lat 経度
   * @return 施設群
   */
  public BuildingList searchBuildings(double longitude, double latitude) {
    BuildingList buildingList = new BuildingList();

    List<Building> buildings = new ArrayList<Building>();

    DBCursor cursor = coll.find(new BasicDBObject());

    buildingList.setBuildNum(cursor.count());

    for (DBObject test : cursor) {
      Building bld = new Building();
      bld.setBuildId((int) test.get("buildId"));
      bld.setCount((int) test.get("count"));
      bld.setLatitude((double) test.get("latitude"));
      bld.setLongitude((double) test.get("longitude"));
      bld.setName((String) test.get("name"));

      buildings.add(bld);
    }

    buildingList.setBuildings(buildings);

    return buildingList;
  }
Exemplo n.º 3
0
 /**
  * Constructor which sets up a new City for a particular Player, with optional City name, Town
  * Center name, Brute name, Assigned Work. If any of these optional values are null, they will be
  * set to default values (e.g. "New City", etc.).
  *
  * @param playerId
  * @param cityName
  * @param townCenterName
  * @param bruteName
  * @param assignedWork
  * @throws DataSourceParseException
  * @throws UnitNotFoundException
  * @throws BuildingAtMaxGarrisonException
  * @throws InvalidBuildingProductionTypeException
  */
 public City(
     Integer playerId,
     String cityName,
     String townCenterName,
     String bruteName,
     ArrayList<Integer> assignedWork)
     throws DataSourceParseException, UnitNotFoundException, BuildingAtMaxGarrisonException,
         InvalidBuildingProductionTypeException {
   this.setId(0);
   if (cityName == null || cityName.equals(null) || cityName.isEmpty() || cityName.equals("")) {
     this.setName("New City");
   } else {
     this.setName(cityName);
   }
   //		this.setOwner(Player.getInstance(playerId));
   this.setOwner(playerId);
   // new Town Center
   ArrayList<Building> newBuildings = new ArrayList<Building>();
   Building b = new Building(1);
   if (townCenterName == null
       || townCenterName.equals(null)
       || townCenterName.isEmpty()
       || townCenterName.equals("")) {
     // keep default Town Center name
   } else {
     b.setName(townCenterName);
   }
   b.setCity(this.getId());
   // new Brute
   Unit u = new Unit(1);
   if (bruteName == null
       || bruteName.equals(null)
       || bruteName.isEmpty()
       || bruteName.equals("")) {
     // keep default Brute name
   } else {
     u.setName(bruteName);
   }
   b.addOccupant(u.getId());
   b.addGarrisonedUnit(u.getId());
   newBuildings.add(b);
   this.setBuildings(newBuildings);
   // calculate new City offense & defense
   Integer off = 0;
   Integer def = 0;
   Iterator<Building> it = newBuildings.iterator();
   while (it.hasNext()) {
     Building temp = it.next();
     off += temp.getOffense();
     def += temp.getDefense();
   }
   this.setOffense(off);
   this.setDefense(def);
   this.setPopulation(100);
   // default Resources
   this.addResource(1, 0);
   this.addResource(2, 0);
   this.addResource(3, 0);
   this.addResource(4, 0);
   this.addResource(5, 0);
   this.addResource(6, 0);
   this.addResource(7, 0);
   this.addResource(8, 100);
   this.addResource(9, 100);
   this.setValue(this.getResourceValue());
   this.setHappiness(this.getHappinessValue());
   this.setScore(this.getValue() + this.getHappiness() + this.getPopulation());
   this.setImage(null);
   ArrayList<Integer> work = new ArrayList<Integer>();
   if (assignedWork == null
       || assignedWork.equals(null)
       || assignedWork.isEmpty()
       || assignedWork.size() == 0) {
     work.add(0); // farmers
     work.add(0); // miners
     work.add(0); // lumberjacks
     work.add(0); // merchants
     work.add(0); // civil defense
     work.add(100); // unemployed
     this.setAssignedWork(work);
   } else {
     this.setAssignedWork(assignedWork);
   }
 }