Example #1
0
  public void assignTargets(Simulator sim, Set<Unit> enemies) {

    GameState s = sim.getGameState();
    Unit ally = s.getUnit(getUnitID());
    Region region = sim.getState().getMap().getRegion(ally);

    // divide damage equally among enemies.
    //
    final int M = enemies.size();
    for (Unit enemy : enemies) {
      String msg =
          ally.getOwnerId()
              + ":"
              + ally.getUnitId()
              + " attacks "
              + enemy.getOwnerId()
              + ":"
              + enemy.getUnitId()
              + " "
              + enemy.getUnitTypeString()
              + " in region "
              + region.getId();
      simlog.info(s.getCycle() + "\t" + msg);
      int damage = Math.max(Math.round(Attack.getDamage(ally, enemy) / (float) M), 1);
      if (damage > 0) {
        sim.addChange(new AttributeDifference(enemy.getUnitId(), "hitPoints", -damage));
        simlog.info(
            s.getCycle()
                + "\t"
                + "damage -"
                + damage
                + " to enemy "
                + enemy.getOwnerId()
                + ":"
                + enemy.getUnitId()
                + " "
                + enemy.getUnitTypeString()
                + " in region "
                + region.getId());
      }
    }
  }
Example #2
0
 public ActionAttack(Unit u, Region r) {
   this(u.getOwnerId(), u.getUnitId(), r.getId());
 }
Example #3
0
 private boolean isInTargetRegion(Unit ally, GameState state) {
   Region region = state.getMap().getRegion(getRegionId());
   return region.contains(ally.getLocX(), ally.getLocY());
 }