Пример #1
0
  public void testAvoidStarvation() {
    Game game = ServerTestHelper.startServerGame(getTestMap(marsh));

    int unitsBeforeNewTurn = 3;
    Colony colony = getStandardColony(unitsBeforeNewTurn);
    ServerPlayer player = (ServerPlayer) colony.getOwner();
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn, colony.getUnitCount());

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

    int consumption = colony.getFoodConsumption();
    int production = colony.getTile().getType().getPotentialProduction(grainType, null);
    assertEquals(6, consumption);
    assertEquals(3, production);
    assertEquals(-3, colony.getNetProductionOf(foodType));
    assertEquals(0, colony.getGoodsCount(foodType));
    assertEquals(0, colony.getTile().getUnitCount());

    colony.addGoods(foodType, 202);
    ServerTestHelper.newTurn();
    assertEquals(199, colony.getGoodsCount(foodType));
    assertEquals(0, colony.getTile().getUnitCount());
    assertEquals(3, colony.getUnitCount());

    colony.addGoods(foodType, 15);
    ServerTestHelper.newTurn();
    assertEquals(11, colony.getGoodsCount(foodType));
    assertEquals(1, colony.getTile().getUnitCount());
  }
Пример #2
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());
  }