public void testAssignDefendSettlementMission() {
    Game game = ServerTestHelper.startServerGame(getTestMap());
    Map map = game.getMap();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();

    // Create player and unit
    ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");

    Tile tile1 = map.getTile(2, 2);
    Unit soldier = new ServerUnit(game, tile1, dutch, veteranType);

    AIUnit aiUnit = aiMain.getAIUnit(soldier);
    assertNotNull(aiUnit);

    // Add nearby colony in need of defense
    Tile colonyTile = map.getTile(2, 3);
    assertTrue(colonyTile != null);
    colonyTile.setExplored(dutch, true);
    Colony colony =
        FreeColTestUtils.getColonyBuilder().player(dutch).colonyTile(colonyTile).build();

    assertTrue(colonyTile.getSettlement() == colony);
    assertTrue(colony.getOwner() == dutch);
    assertTrue(colony.getUnitCount() == 1);
    aiUnit.setMission(null);
    assertEquals(
        "DefendSettlementMission should be possible",
        null,
        DefendSettlementMission.invalidReason(aiUnit));
    assertEquals(
        "DefendSettlementMission should work with colony",
        null,
        DefendSettlementMission.invalidReason(aiUnit, colony));
  }
Ejemplo n.º 2
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));
  }
Ejemplo n.º 3
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());
  }