Beispiel #1
0
 public void resetMovementPoints(WorldPowerName power) {
   for (Territory t : w.getTerritories().values()) {
     StationedGroup group = t.getUnitsStationed(power);
     for (UnitConcrete unit : group.getUnits()) {
       unit.setMovementPoints(unit.getProfile().getMove());
     }
   }
 }
Beispiel #2
0
  // TODO
  public boolean requestMoveUnit(UnitConcrete unit, Territory source, Territory destination) {
    // First do some validation to ensure that the unit can physically make the move.
    if (!source.getNeighbors().contains(destination)) {
      return false;
    }
    if (unit.getMovementPoints() <= 0) {
      return false;
    }

    // LandUnit -> Land or SeaUnit -> Sea
    if (unit.getProfile() instanceof LandUnit && !destination.isSeaZone()
        || unit.getProfile() instanceof SeaUnit && destination.isSeaZone()) {
      source.removeUnit(activePower, unit);
      destination.addUnit(activePower, unit);
      unit.setTerritorySource(destination);
      unit.setMovementPoints(unit.getMovementPoints() - 1);
      if (unit.getProfile() instanceof Transport || unit.getProfile() instanceof AircraftCarrier) {
        for (UnitConcrete cargo : unit.getCargo()) {
          source.removeUnit(activePower, cargo);
          destination.addUnit(activePower, cargo);
          cargo.setTerritorySource(destination);
        }
      }
      return true;
    }
    // LandUnit -> Sea (transport)
    else if (unit.getProfile() instanceof LandUnit
        && destination.isSeaZone()
        && !source.isSeaZone()) {
      ArrayList<UnitConcrete> transports =
          destination.getUnitsStationed(activePower).getUnitsByName(UnitName.TRANSPORT);
      for (UnitConcrete t : transports) {
        if (t.tryAddCargo(unit)) {
          source.removeUnit(activePower, unit);
          destination.addUnit(activePower, unit);
          unit.setTerritorySource(destination);
          unit.setMovementPoints(1); // All transported units can load-unload in same turn.
          return true;
        }
      }
    }
    // AirUnit
    else if (unit.getProfile() instanceof AirUnit) {
      if (checkAirUnitHasReturnPath(unit, destination)) {
        source.removeUnit(activePower, unit);
        destination.addUnit(activePower, unit);
        unit.setTerritorySource(destination);
        unit.setMovementPoints(unit.getMovementPoints() - 1);
        return true;
      }
    }
    // SeaUnit -> Land (impossible)
    else if (unit.getProfile() instanceof SeaUnit && !destination.isSeaZone()) {
      return false; // Boats can never go on land.
    }
    return true;
  }