Exemple #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;
 }
Exemple #2
0
 /**
  * Adjust unit loyalty, create rebels, place rebels. Note: AFAIK in all mods Naval move units can
  * only move on oceans, and non-Naval units can move on land, so rebels are placed with this
  * feature in mind.
  */
 public void adjustUnitLoyalty() {
   List<Unit> units = game.getUnits();
   LinkedList<Unit> rebels = new LinkedList<>();
   for (Unit unit : units) {
     if (unit.owner == game.getTurn() && canRebel(unit)) {
       unit.loyalty = pay_rate * C.PAY_LOYALTY_HIT;
       if (!unit.in_space && unit.loyalty < C.LOYALTY_REBEL_LIMIT) {
         if (game.getRandom().nextFloat()
             < (1 - unit.loyalty / C.LOYALTY_REBEL_LIMIT) * C.LOYALTY_REBEL_HIGH_P) {
           rebels.add(unit);
         }
       }
     }
   }
   if (rebels.isEmpty()) {
     return;
   }
   rebels.sort(Comp.unit_xy);
   rebels.sort(Comp.unit_pidx);
   LinkedList<Unit> naval = new LinkedList<>();
   LinkedList<Unit> non_naval = new LinkedList<>();
   for (Unit rebel : rebels) {
     if (rebel.move_type == C.MoveType.NAVAL) {
       naval.add(rebel);
     } else {
       non_naval.add(rebel);
     }
   }
   placeRebels(naval, Util.FindHexesAround.Hextype.SEA);
   placeRebels(non_naval, Util.FindHexesAround.Hextype.LAND);
 }
Exemple #3
0
 public static void eliminateNoblelessFactions(Game game) {
   List<Unit> units = game.getUnits();
   List<Structure> cities = game.getStructures();
   // find out newly eliminated factions and set them to eliminated and
   // set their original assets to neutral/rebel faction
   boolean[] prev_no_nobles = new boolean[C.NR_HOUSES];
   for (int i = 0; i < prev_no_nobles.length; i++) {
     prev_no_nobles[i] = game.getFaction(i).isEliminated();
   }
   boolean[] no_nobles = {true, true, true, true, true};
   for (Unit unit : units) {
     if (unit.type == C.NOBLE_UNIT_TYPE
         && C.HOUSE1 <= unit.prev_owner
         && unit.prev_owner <= C.HOUSE5) {
       no_nobles[unit.prev_owner] = false;
     }
   }
   for (int i = 0; i < no_nobles.length; i++) {
     if (no_nobles[i] ^ prev_no_nobles[i]) {
       game.getFaction(i).setEliminated();
       for (Unit unit : units) {
         if (unit.prev_owner == i) {
           unit.prev_owner = C.NEUTRAL;
           unit.owner = C.NEUTRAL;
         }
       }
       for (Structure city : cities) {
         if (city.prev_owner == i) {
           city.prev_owner = C.NEUTRAL;
           city.owner = C.NEUTRAL;
         }
       }
     }
   }
 }
Exemple #4
0
 /**
  * Calculate base unit pay.
  *
  * @return
  */
 public int calculateUnitPay() {
   int pay = 0;
   List<Unit> all_units = game.getUnits();
   for (Unit u : all_units) {
     if (u.prev_owner == number) {
       pay += u.type_data.crd_trn;
     }
   }
   return pay;
 }