コード例 #1
0
 /*
   Place all motionless objects (fire stations, police offices, ambulance teams and refuges)
   @param fire An array to be filled with fire stations
   @param police An array to be filled with police offices
   @param ambulance An array to be filled with ambulance centres
   @param refuge An array to be filled with refuges
   @param allBuildings All buildings in the map
   @return All ordinary buildings
 */
 public static Building[] placeMotionlessObjects(
     FireStation[] fire,
     PoliceOffice[] police,
     AmbulanceCenter[] ambulance,
     Refuge[] refuge,
     Building[] allBuildings) {
   List remaining = new ArrayList();
   for (int i = 0; i < allBuildings.length; ++i) remaining.add(allBuildings[i]);
   Collections.shuffle(remaining);
   System.out.println("Placing " + ambulance.length + " ambulance centers");
   Iterator it = remaining.iterator();
   for (int i = 0; i < ambulance.length; ++i) {
     Building location = (Building) it.next();
     it.remove();
     AmbulanceCenter a = new AmbulanceCenter(location);
     a.setID(location.getID());
     ambulance[i] = a;
     //			writeFixedObjectData(out,TYPE_AMBULANCE_CENTER,i,location);
   }
   System.out.println("Placing " + fire.length + " fire stations");
   for (int i = 0; i < fire.length; ++i) {
     Building location = (Building) it.next();
     it.remove();
     FireStation a = new FireStation(location);
     a.setID(location.getID());
     fire[i] = a;
     //			writeFixedObjectData(out,TYPE_FIRE_STATION,i,location);
     //			System.out.print(".");
   }
   System.out.println("Placing " + police.length + " police stations");
   for (int i = 0; i < police.length; ++i) {
     Building location = (Building) it.next();
     it.remove();
     PoliceOffice a = new PoliceOffice(location);
     a.setID(location.getID());
     police[i] = a;
     //			writeFixedObjectData(out,TYPE_POLICE_OFFICE,i,location);
     //			System.out.print(".");
   }
   System.out.println("Placing " + refuge.length + " refuges");
   for (int i = 0; i < refuge.length; ++i) {
     Building location = (Building) it.next();
     it.remove();
     Refuge a = new Refuge(location);
     a.setID(location.getID());
     refuge[i] = a;
     //			writeFixedObjectData(out,TYPE_REFUGE,i,location);
     //			System.out.print(".");
   }
   //		System.out.println();
   return (Building[]) remaining.toArray(new Building[0]);
 }
コード例 #2
0
 public static Building[] placeNormalFires(int num, Building[] b) {
   List remaining = new ArrayList();
   for (int i = 0; i < b.length; ++i) remaining.add(b[i]);
   Collections.shuffle(remaining);
   Building[] result = new Building[num];
   System.out.println("Placing " + num + " fires");
   Iterator it = remaining.iterator();
   for (int i = 0; i < num; ++i) result[i] = (Building) it.next();
   return result;
 }
コード例 #3
0
 public static Building[] placeBigFires(int num, Building[] b, Limits radius) {
   List remaining = new ArrayList();
   for (int i = 0; i < b.length; ++i) remaining.add(b[i]);
   Collections.shuffle(remaining);
   Collection fires = new HashSet();
   System.out.print("Placing " + num + " big fires");
   Iterator it = remaining.iterator();
   for (int i = 0; i < num; ++i) {
     Building center = (Building) it.next();
     fires.add(center);
     long r = radius.getNumber();
     long distanceSquared = r * r;
     // Check for close buildings
     for (int j = 0; j < b.length; ++j) {
       long dx = center.getX() - b[j].getX();
       long dy = center.getY() - b[j].getY();
       long distance = (dx * dx) + (dy * dy);
       if (distance <= distanceSquared) fires.add(b[j]);
     }
   }
   return (Building[]) fires.toArray(new Building[0]);
 }