예제 #1
0
  public void testDeathByStarvation() {
    Game game = ServerTestHelper.startServerGame(getTestMap(marsh));

    int consumption, production, unitsBeforeNewTurn = 3;
    Colony colony = getStandardColony(unitsBeforeNewTurn);
    ServerPlayer player = (ServerPlayer) colony.getOwner();

    final Building townHall = colony.getBuilding(townHallType);
    for (Unit u : colony.getUnitList()) {
      u.setLocation(townHall);
    }
    colony.removeGoods(foodGoodsType);
    colony.invalidateCache();

    consumption = colony.getFoodConsumption();
    production = colony.getFoodProduction();
    assertTrue(
        "Food consumption ("
            + consumption
            + ") should be higher than production ("
            + production
            + ")",
        consumption > production);
    assertEquals("No food stored in colony", 0, colony.getGoodsCount(foodType));
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn, colony.getUnitCount());

    ServerTestHelper.newTurn();

    consumption = colony.getFoodConsumption();
    production = colony.getFoodProduction();
    assertTrue(
        "Food consumption ("
            + consumption
            + ") should be higher than production ("
            + production
            + ")",
        consumption > production);
    assertEquals("No food stored in colony", 0, colony.getGoodsCount(foodType));
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn - 1, colony.getUnitCount());
  }
예제 #2
0
  public void testEqualFoodProductionConsumptionCase() {
    Game game = ServerTestHelper.startServerGame(getTestMap(desert));

    // Setting test colony
    Tile colonyTile = game.getMap().getTile(5, 8);
    Colony colony =
        FreeColTestUtils.getColonyBuilder().colonyTile(colonyTile).initialColonists(1).build();

    // Set the food production of the center tile of the colony to 2
    // This will be the only food production of the colony
    List<AbstractGoods> colonyTileProduction = colonyTile.getType().getPossibleProduction(true);
    for (int i = 0; i < colonyTileProduction.size(); i++) {
      AbstractGoods production = colonyTileProduction.get(i);
      if (production.getType() == foodGoodsType) {
        production.setAmount(2);
        break;
      }
    }
    Unit unit = colony.getUnitList().get(0);
    unit.setLocation(colony.getWorkLocationFor(unit, bellsType));

    // Verify that there is enough food stored
    colony.addGoods(foodGoodsType, colony.getFoodConsumption() * 2);

    assertEquals(
        "Production not equal to consumption",
        colony.getFoodConsumption(),
        colony.getFoodProduction());

    int colonists = colony.getUnitCount();
    assertEquals("Unexpected change of colonists in colony", colonists, colony.getUnitCount());

    assertEquals(
        "Unexpected change of production/consumption ratio",
        colony.getFoodProduction(),
        colony.getFoodConsumption());
  }
예제 #3
0
  public void testFoodConsumption() {
    Game game = ServerTestHelper.startServerGame(getTestMap(plains));
    ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");
    // Setting test colony and colonist
    Colony colony =
        FreeColTestUtils.getColonyBuilder().colonyTile(game.getMap().getTile(5, 8)).build();
    new ServerUnit(game, colony.getWorkLocationForProducing(bellsType), dutch, colonistType);
    assertEquals(0, colony.getGoodsCount(foodType));

    int quantity = colony.getFoodConsumption() * 2;
    colony.addGoods(foodGoodsType, quantity);
    int foodStored = colony.getGoodsCount(foodGoodsType);
    assertEquals(quantity, foodStored);
    int foodExpected = foodStored - colony.getFoodConsumption() + colony.getFoodProduction();

    ServerTestHelper.newTurn();
    assertEquals(
        "Unexpected value for remaining food, ", foodExpected, colony.getGoodsCount(foodGoodsType));
  }