Esempio n. 1
0
 /**
  * Place rebels, fill hexes starting from closest available hex. Return true if all rebels placed,
  * false if we run out of planet hexes before all rebels are placed.
  *
  * @param rebels list of units to place
  * @return true iff all rebels placed
  */
 private boolean placeRebels(LinkedList<Unit> rebels, Util.FindHexesAround.Hextype type) {
   Hex center = null;
   Hex target = null;
   Hex prev_target = null;
   Util.FindHexesAround hex_finder = null;
   Point p = new Point(C.NEUTRAL, C.NEUTRAL);
   int p_idx = -1;
   int x = -1;
   int y = -1;
   while (!rebels.isEmpty()) {
     Unit unit = rebels.pop();
     if (unit.y != y || unit.x != x || unit.p_idx != p_idx) {
       y = unit.y;
       x = unit.x;
       p_idx = unit.p_idx;
       addMessage(
           new Message(
               "Rebellion on " + game.getPlanet(p_idx).name + " " + x + "," + y + "!",
               C.Msg.REBELLION,
               game.getYear(),
               game.getPlanet(p_idx)));
     }
     Hex hex_tmp = game.getHexFromPXY(unit.p_idx, unit.x, unit.y);
     if (!hex_tmp.equals(center)) {
       center = hex_tmp;
       hex_finder =
           new Util.FindHexesAround(center, C.NEUTRAL, type, game.getPlanet(p_idx).tile_set_type);
       prev_target = target;
       target = hex_finder.next();
     }
     while (target != null && Util.stackSize(target.getStack()) >= C.STACK_SIZE) {
       target = hex_finder.next();
     }
     prev_target = spot(prev_target, target);
     if (target == null) {
       return false;
     }
     if (unit.carrier == null) {
       if (unit.type_data.cargo > 0 && unit.cargo_list.size() > 0) {
         List<Unit> tmp = new LinkedList<>();
         tmp.addAll(unit.cargo_list);
         for (Unit u : tmp) {
           unit.disembark(u);
           center.addUnit(u);
         }
       }
     } else {
       Unit u = unit.carrier;
       u.disembark(unit);
     }
     center.getStack().remove(unit);
     game.changeOwnerOfUnit(p, unit);
     game.relocateUnit(false, unit.p_idx, target.getX(), target.getY(), unit);
     target.addUnit(unit);
     game.getUnits().add(unit);
     // Util.dP(" hex " + target.getX() + "," + target.getY());
   }
   spot(target, prev_target);
   return true;
 }
Esempio n. 2
0
 private Hex spot(Hex prev_target, Hex target) {
   if (prev_target != null && !prev_target.equals(target)) {
     List<Unit> tmp = prev_target.getStack();
     // Util.dP("spot " + prev_target.getX() + "," + prev_target.getY() + " " + tmp.size() + " " +
     // Util.getFactionName(tmp.get(0).owner));
     game.getHexProc().spotProc(prev_target, tmp);
     prev_target = target;
   }
   return prev_target;
 }