コード例 #1
0
  /** Test that an petty criminal becomes an indentured servant */
  public void testTeachPettyCriminals() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);

    teacher.setLocation(university);
    assertEquals(teacher.getNeededTurnsOfTraining(), 4);
    assertTrue(criminal.canBeStudent(teacher));
    assertEquals(criminal, teacher.getStudent());

    // PETTY_CRIMINALS become INDENTURED_SERVANTS
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #2
0
  public void testIsTargetValidForSeekAndDestroy() {
    Game game = ServerTestHelper.startServerGame(getTestMap());
    Map map = game.getMap();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();

    // Create player and unit
    ServerPlayer incaPlayer = (ServerPlayer) game.getPlayerByNationId("model.nation.inca");
    NativeAIPlayer aiInca = (NativeAIPlayer) aiMain.getAIPlayer(incaPlayer);
    ServerPlayer dutchPlayer = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");

    Tile dutchUnitTile = map.getTile(9, 9);
    Tile braveUnitTile = map.getTile(9, 8);
    ;

    Unit brave = new ServerUnit(game, braveUnitTile, incaPlayer, braveType);
    Unit soldier = new ServerUnit(game, dutchUnitTile, dutchPlayer, veteranType);

    Player.makeContact(incaPlayer, dutchPlayer);

    assertFalse(
        "Target should NOT be valid for UnitSeekAndDestroyMission",
        aiInca.isTargetValidForSeekAndDestroy(brave, soldier.getTile()));

    incaPlayer.setTension(dutchPlayer, new Tension(Tension.Level.HATEFUL.getLimit()));
    assertTrue(
        "Target should be valid for UnitSeekAndDestroyMission",
        aiInca.isTargetValidForSeekAndDestroy(brave, soldier.getTile()));

    incaPlayer.setStance(dutchPlayer, Stance.WAR);
    dutchPlayer.setStance(incaPlayer, Stance.WAR);
    assertTrue(
        "Target should be valid for UnitSeekAndDestroyMission",
        aiInca.isTargetValidForSeekAndDestroy(brave, soldier.getTile()));
  }
コード例 #3
0
  /**
   * If there are two teachers of the same kind, but just one colonist to be taught, this should not
   * mean any speed up.
   */
  public void testTwoTeachersOfSameKind() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumberjack1 = units.next();
    lumberjack1.setType(expertLumberJackType);

    Unit lumberjack2 = units.next();
    lumberjack2.setType(expertLumberJackType);

    lumberjack1.setLocation(university);
    lumberjack2.setLocation(university);
    assertEquals(colonist, lumberjack1.getStudent());
    assertNull(lumberjack2.getStudent());

    for (int i = lumberjack1.getNeededTurnsOfTraining(); i > 0; i--) {
      assertEquals(1, getUnitList(colony, freeColonistType).size());
      trainForTurns(colony, 1);
    }

    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(3, getUnitList(colony, expertLumberJackType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #4
0
  /** Test that an indentured servant becomes a free colonist */
  public void testTeachIndenturedServants() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit indenturedServant = units.next();
    indenturedServant.setType(indenturedServantType);

    Unit teacher = units.next();
    teacher.setType(masterBlacksmithType);

    teacher.setLocation(university);
    assertEquals(teacher.getNeededTurnsOfTraining(), 4);
    assertEquals(indenturedServant, teacher.getStudent());

    // Train to become free colonist
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(freeColonistType, indenturedServant.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #5
0
  /** Sons of Liberty influences teaching. */
  public void testSonsOfLiberty() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();
    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumberjack = units.next();
    lumberjack.setType(expertLumberJackType);
    lumberjack.setLocation(university);

    assertEquals(4, lumberjack.getNeededTurnsOfTraining());

    colony.addGoods(bellsType, 100000);
    assertEquals(2, lumberjack.getNeededTurnsOfTraining());

    trainForTurns(colony, 2);
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertLumberJackType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #6
0
  /**
   * Progress in teaching is bound to the teacher and not the learner.
   *
   * <p>Moving students around does not slow education. This behavior is there to simplify gameplay.
   */
  public void testTeacherStoresProgress() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();
    Unit outsider = new ServerUnit(game, colony.getTile(), colony.getOwner(), freeColonistType);

    Building townHall = colony.getBuilding(townHallType);
    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(townHall);

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);
    teacher.setLocation(university);
    assertEquals(teacher.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), teacher);

    // Train to become free colonist then swap the colonist with
    // another one.
    trainForTurns(colony, teacher.getNeededTurnsOfTraining() - 1);
    colonist.setLocation(colony.getTile());
    outsider.setLocation(townHall);
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(teacher.getStudent(), outsider);

    ServerTestHelper.newTurn();
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(expertOreMinerType, outsider.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #7
0
  public void testCollege() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    // otherwise this test will crash and burn
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Colony colony = getSchoolColony(4, SchoolLevel.COLLEGE);
    Building college = colony.getBuilding(collegeType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit blackSmith = units.next();
    blackSmith.setType(masterBlacksmithType);

    blackSmith.setLocation(college);
    assertEquals(blackSmith.getStudent(), colonist);

    trainForTurns(colony, blackSmith.getNeededTurnsOfTraining());
    assertEquals(masterBlacksmithType, colonist.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #8
0
  public void testUniversity() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    // otherwise this test will crash and burn
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    assertEquals(4, colony.getUnitCount());
    Building university = colony.getBuilding(universityType);
    assertNotNull(university);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit elder = units.next();
    assertEquals(elder.getType(), elderStatesmanType);

    elder.setLocation(university);
    assertEquals(elder.getStudent(), colonist);

    trainForTurns(colony, elder.getNeededTurnsOfTraining());
    assertEquals(elderStatesmanType, colonist.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #9
0
  public void testProductionBonus() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(6, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);

    Iterator<Unit> units = colony.getUnitIterator();

    Unit carpenter = units.next();
    carpenter.setType(masterCarpenterType);

    Unit blacksmith = units.next();
    blacksmith.setType(masterBlacksmithType);

    Unit statesman = units.next();
    statesman.setType(elderStatesmanType);

    units.next().setType(freeColonistType);
    units.next().setType(freeColonistType);
    units.next().setType(freeColonistType);

    carpenter.setLocation(university);
    blacksmith.setLocation(university);
    statesman.setLocation(university);

    for (int bonus = -2; bonus < 3; bonus++) {
      setProductionBonus(colony, bonus);
      assertEquals(4 - bonus, carpenter.getNeededTurnsOfTraining());
      assertEquals(6 - bonus, blacksmith.getNeededTurnsOfTraining());
      assertEquals(8 - bonus, statesman.getNeededTurnsOfTraining());
    }

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #10
0
  /** Check that a free colonist can be taught something. */
  public void testExpertTeaching() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    // otherwise this test will crash and burn
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Colony colony = getSchoolColony(4, SchoolLevel.SCHOOLHOUSE);
    Building school = colony.getBuilding(schoolType);
    assertTrue(school.canTeach());
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumber = units.next();
    lumber.setType(expertLumberJackType);

    Unit black = units.next();
    black.setType(masterBlacksmithType);

    Unit ore = units.next();
    ore.setType(expertOreMinerType);

    assertTrue(colony.canTrain(ore));
    ore.setLocation(school);
    assertEquals(ore.getStudent(), colonist);

    trainForTurns(colony, ore.getNeededTurnsOfTraining());
    assertEquals(expertOreMinerType, colonist.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #11
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());
  }
コード例 #12
0
  /** Tests invalid completion of buildable, having enough resources */
  public void testInvalidCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony(2);
    Building carpenterHouse = colony.getBuilding(carpenterHouseType);
    assertEquals(
        "Colony should not have lumber mill", carpenterHouse, colony.getBuilding(lumberMillType));
    assertFalse("Colony should not be able to build lumber mill", colony.canBuild(lumberMillType));
    colony.setCurrentlyBuilding(lumberMillType);
    assertEquals(
        "Colony should be building lumber mill", lumberMillType, colony.getCurrentlyBuilding());
    // Add sufficient units and goods to build lumber mill.
    Unit unit = new ServerUnit(game, colony.getTile(), colony.getOwner(), colonistType);
    unit.setLocation(colony);
    for (AbstractGoods ag : lumberMillType.getRequiredGoods()) {
      GoodsType type = ag.getType();
      int amount = ag.getAmount() + 1;
      colony.addGoods(type, amount);
      assertEquals("Wrong quantity of " + type, amount, colony.getGoodsCount(type));
    }

    // Allow the building to finish
    ServerTestHelper.newTurn();

    assertEquals(
        "Colony should have lumber mill",
        lumberMillType,
        colony.getBuilding(lumberMillType).getType());
    assertFalse(
        "Colony should no longer be building lumber mill",
        colony.getCurrentlyBuilding() == lumberMillType);
  }
コード例 #13
0
  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));
  }
コード例 #14
0
  /**
   * The time to teach somebody does not depend on the one who is being taught, but on the teacher.
   */
  public void testTeachPettyCriminalsByMaster() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(masterBlacksmithType);

    teacher.setLocation(university);
    assertEquals(teacher.getNeededTurnsOfTraining(), 4);
    assertEquals(criminal, teacher.getStudent());

    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #15
0
  /**
   * Test that an indentured servant cannot be promoted to free colonist and learn a skill at the
   * same time.
   */
  public void testTeachingDoublePromotion() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit indenturedServant = units.next();
    indenturedServant.setType(indenturedServantType);
    indenturedServant.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher1 = units.next();
    teacher1.setType(expertOreMinerType);

    Unit teacher2 = units.next();
    teacher2.setType(expertLumberJackType);

    // set location only AFTER all types have been set!
    teacher1.setLocation(university);
    teacher2.setLocation(university);
    assertEquals(criminal, teacher1.getStudent());
    assertEquals(indenturedServant, teacher2.getStudent());

    // Training time
    trainForTurns(colony, teacher1.getNeededTurnsOfTraining());

    // indentured servant should have been promoted to free colonist
    // petty criminal should have been promoted to indentured servant
    assertEquals(freeColonistType, indenturedServant.getType());
    assertEquals(indenturedServantType, criminal.getType());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, indenturedServantType).size());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    criminal.setLocation(getGame().getMap().getTile(10, 8));
    assertNull(teacher1.getStudent());
    assertEquals(teacher2, indenturedServant.getTeacher());

    // Train again
    trainForTurns(colony, teacher2.getNeededTurnsOfTraining());
    assertEquals(expertLumberJackType, indenturedServant.getType());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(2, getUnitList(colony, expertLumberJackType).size());
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #16
0
  /**
   * When searching for threats to a settlement, the indian player should ignore naval threats, as
   * he does not have naval power
   */
  public void testSecureIndianSettlementMissionIgnoreNavalThreat() {
    Game game = ServerTestHelper.startServerGame(getCoastTestMap(plainsType));
    Map map = game.getMap();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();
    InGameController igc = ServerTestHelper.getInGameController();

    // Create player and unit
    ServerPlayer inca = (ServerPlayer) game.getPlayerByNationId("model.nation.inca");
    NativeAIPlayer aiInca = (NativeAIPlayer) aiMain.getAIPlayer(inca);
    ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");

    Tile settlementTile = map.getTile(9, 9);
    Tile seaTile = map.getTile(10, 9);
    assertTrue("Settlement tile should be land", settlementTile.isLand());
    assertFalse("Galleon tile should be ocean", seaTile.isLand());
    FreeColTestCase.IndianSettlementBuilder builder =
        new FreeColTestCase.IndianSettlementBuilder(game);
    IndianSettlement camp =
        builder.player(inca).settlementTile(settlementTile).initialBravesInCamp(10).build();
    ServerUnit galleon = new ServerUnit(game, seaTile, dutch, galleonType);
    int unitsInGalleon = 6;
    for (int i = 0; i < unitsInGalleon; i++) {
      ServerUnit artillery = new ServerUnit(game, settlementTile, dutch, artilleryType);
      igc.embarkUnit(dutch, artillery, galleon);
    }
    assertEquals("Wrong number of units onboard galleon", unitsInGalleon, galleon.getUnitCount());
    assertEquals("Galleon should be full", 0, galleon.getSpaceLeft());

    for (Unit brave : camp.getUnitList()) {
      AIUnit aiUnit = aiMain.getAIUnit(brave);
      assertNotNull(aiUnit);
      new UnitWanderHostileMission(aiMain, aiUnit);

      assertTrue("No enemy units present", aiUnit.hasMission(UnitWanderHostileMission.class));
    }

    inca.setStance(dutch, Stance.WAR);
    inca.setTension(dutch, new Tension(Tension.Level.HATEFUL.getLimit()));
    assertTrue("Indian player should be at war with dutch", inca.getStance(dutch) == Stance.WAR);
    assertEquals(
        "Wrong Indian player tension towards dutch",
        Tension.Level.HATEFUL.getLimit(),
        inca.getTension(dutch).getValue());

    aiInca.abortInvalidMissions();
    aiInca.secureIndianSettlement(camp, lb);
    boolean seeking = false;
    for (Unit brave : inca.getUnits()) {
      AIUnit aiUnit = aiMain.getAIUnit(brave);
      assertNotNull(aiUnit);
      if (aiUnit.hasMission(UnitSeekAndDestroyMission.class)) {
        seeking = true;
        break;
      }
    }
    assertFalse("Braves should not pursue naval units", seeking);
  }
コード例 #17
0
  /**
   * If there are two teachers with the same skill level, the first to be put in the school should
   * be used for teaching.
   */
  public void testSingleGuyTwoTeachers2() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumber = units.next();
    lumber.setType(expertLumberJackType);

    Unit ore = units.next();
    ore.setType(expertOreMinerType);

    // It should take 4 turns to train an expert lumber jack and
    // also 4 to train a ore miner.  First come first serve, the
    // lumber jack wins.
    lumber.setLocation(university);
    ore.setLocation(university);
    assertEquals(colonist.getTeacher(), lumber);
    assertNull(ore.getStudent());

    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #18
0
  public void testLibertyAndImmigration() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    final int population = 3;
    Colony colony = getStandardColony(population);

    ServerBuilding townHall = (ServerBuilding) colony.getBuilding(townHallType);
    Unit statesman = colony.getUnitList().get(0);
    townHall.setWorkFor(statesman);
    assertEquals(bellsType, statesman.getWorkType());

    ServerBuilding church = (ServerBuilding) colony.getBuilding(chapelType);
    church.upgrade();
    Unit preacher = colony.getUnitList().get(1);
    church.setWorkFor(preacher);
    assertEquals(crossesType, preacher.getWorkType());

    assertEquals(0, colony.getGoodsCount(bellsType));
    ServerTestHelper.newTurn();

    int bells = 3;
    assertEquals(population, colony.getUnitCount());
    assertEquals(bells, colony.getNetProductionOf(bellsType));
    assertEquals(bells, colony.getGoodsCount(bellsType));

    colony.addGoods(bellsType, 7);
    bells += 7;
    assertEquals(bells, colony.getGoodsCount(bellsType));
    assertEquals(bells, colony.getLiberty());

    colony.removeGoods(bellsType, 5);
    bells -= 5;
    assertEquals(bells, colony.getGoodsCount(bellsType));
    assertEquals(bells, colony.getLiberty());

    int crosses = colony.getTotalProductionOf(crossesType) - colony.getConsumptionOf(crossesType);
    assertEquals(crosses, colony.getNetProductionOf(crossesType));
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());

    colony.addGoods(crossesType, 7);
    crosses += 7;
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());

    colony.removeGoods(crossesType, 5);
    crosses -= 5;
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());
  }
コード例 #19
0
  public void testTwoTeachersSimple() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Game game = ServerTestHelper.startServerGame(getTestMap(true));
    Colony colony = getSchoolColony(5, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist1 = units.next();
    colonist1.setType(freeColonistType);
    colonist1.setLocation(colony.getBuilding(townHallType));

    Unit colonist2 = units.next();
    colonist2.setType(freeColonistType);
    colonist2.setLocation(colony.getBuilding(townHallType));

    Unit colonist3 = units.next();
    colonist3.setType(freeColonistType);
    colonist3.setLocation(colony.getBuilding(townHallType));

    Unit black = units.next();
    black.setType(masterBlacksmithType);

    Unit ore = units.next();
    ore.setType(expertOreMinerType);

    black.setLocation(university);
    ore.setLocation(university);

    assertEquals(3, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    trainForTurns(colony, ore.getNeededTurnsOfTraining());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertNotNull(ore.getStudent());
    assertNotNull(black.getStudent());

    trainForTurns(colony, black.getNeededTurnsOfTraining() - black.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #20
0
  public void testImpossibleConditionsForTargetSelection() {
    Game game = ServerTestHelper.startServerGame(getCoastTestMap(plainsType));
    Map map = game.getMap();
    AIMain aiMain = ServerTestHelper.getServer().getAIMain();

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

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

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

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

    Tile tile3 = map.getTile(1, 2);
    Unit enemyColonist = new ServerUnit(game, tile3, french, colonistType);

    Tile tile4 = map.getTile(12, 12); // in the water
    assertFalse("Tle should be water", tile4.isLand());

    Unit enemyGalleon = new ServerUnit(game, tile4, french, galleonType);
    // Make tests

    assertNotNull(
        "Cannot attack own unit",
        UnitSeekAndDestroyMission.invalidReason(aiUnit, friendlyColonist));
    assertNotNull(
        "Players are not at war", UnitSeekAndDestroyMission.invalidReason(aiUnit, enemyColonist));

    dutch.setStance(french, Stance.WAR);
    french.setStance(dutch, Stance.WAR);

    assertEquals(
        "Unit should be able to attack land unit",
        null,
        UnitSeekAndDestroyMission.invalidReason(aiUnit, enemyColonist));
    assertNotNull(
        "Land unit cannot attack naval unit",
        UnitSeekAndDestroyMission.invalidReason(aiUnit, enemyGalleon));
  }
コード例 #21
0
  /** Tests completion of buildable */
  public void testBuildingCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony();
    ServerBuilding initialWarehouse = new ServerBuilding(getGame(), colony, depotType);
    colony.addBuilding(initialWarehouse);
    assertTrue("Colony should be able to build warehouse", colony.canBuild(warehouseType));

    // Simulate that the build is done
    colony.setCurrentlyBuilding(warehouseType);
    colony.addGoods(hammerGoodsType, 90);
    assertFalse(
        "Colony should not have warehouse", colony.getWarehouse().getType() == warehouseType);

    ServerTestHelper.newTurn();

    assertTrue("Colony should have warehouse", colony.getWarehouse().getType() == warehouseType);
  }
コード例 #22
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));
  }
コード例 #23
0
  public void testCaseTwoTeachersWithDifferentExp() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit teacher1 = units.next();
    teacher1.setType(expertOreMinerType);

    Unit teacher2 = units.next();
    teacher2.setType(masterCarpenterType);

    // First we let the teacher1 train for 3 turns
    teacher1.setLocation(university);
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    assertEquals(3, teacher1.getTurnsOfTraining());

    // Then teacher2 for 1 turn
    teacher1.setLocation(colony.getWorkLocationFor(teacher1, grainType));
    teacher2.setLocation(university);
    ServerTestHelper.newTurn();
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(1, teacher2.getTurnsOfTraining());

    // If we now also add teacher1 to the university, but
    // teacher2 should still be the teacher in charge
    teacher1.setLocation(university);
    assertNull(teacher1.getStudent());
    ServerTestHelper.newTurn();

    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(2, teacher2.getTurnsOfTraining());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #24
0
  /**
   * Trains partly one colonist then put another teacher.
   *
   * <p>Should not save progress but start all over.
   */
  public void testPartTraining() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumberjack = units.next();
    lumberjack.setType(expertLumberJackType);

    Unit miner = units.next();
    miner.setType(expertOreMinerType);

    // Put Lumberjack in School
    lumberjack.setLocation(university);
    assertEquals(lumberjack.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), lumberjack);

    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();

    // After 2 turns replace by miner. Progress starts from scratch.
    lumberjack.setLocation(colony.getWorkLocationFor(lumberjack, grainType));
    assertNull(lumberjack.getStudent());
    assertNull(colonist.getTeacher());

    miner.setLocation(university);
    assertEquals(miner.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), miner);

    trainForTurns(colony, miner.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #25
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());
  }
コード例 #26
0
  /** If there are two teachers, but just one colonist to be taught. */
  public void testSingleGuyTwoTeachers() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumberJack = units.next();
    lumberJack.setType(expertLumberJackType);

    Unit blackSmith = units.next();
    blackSmith.setType(masterBlacksmithType);

    // It should take 4 turns to train an expert lumber jack and 6
    // to train a blacksmith, so the lumber jack chould be
    // finished teaching first.  The school works for now as
    // first come first serve.
    blackSmith.setLocation(university);
    lumberJack.setLocation(university);
    assertTrue(colonist.getTeacher() == blackSmith);
    assertNull(lumberJack.getStudent());

    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());

    trainForTurns(colony, blackSmith.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(2, getUnitList(colony, masterBlacksmithType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #27
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());
  }
コード例 #28
0
  public void testConcurrentUpgrade() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(2, SchoolLevel.SCHOOLHOUSE);
    Building school = colony.getBuilding(schoolType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit lumber = units.next();
    lumber.setType(expertLumberJackType);

    Unit student = units.next();
    student.setType(pettyCriminalType);
    student.setLocation(colony.getBuilding(townHallType));

    assertTrue(school.canTeach());
    assertTrue(colony.canTrain(lumber));
    lumber.setLocation(school);

    ServerTestHelper.newTurn();
    assertEquals(student, lumber.getStudent());

    // lumber jack can teach indentured servant
    student.changeType(indenturedServantType);
    assertEquals(student, lumber.getStudent());

    // lumber jack can teach free colonist
    student.changeType(freeColonistType);
    assertEquals(student, lumber.getStudent());

    // lumber jack can not teach expert
    student.changeType(masterCarpenterType);
    assertNull(lumber.getStudent());
    assertNull(student.getTeacher());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #29
0
  public void testColonialRegular() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    colony.getOwner().addAbility(new Ability(Ability.INDEPENDENCE_DECLARED));
    Iterator<Unit> units = colony.getUnitIterator();

    Unit regular = units.next();
    regular.setType(colonialRegularType);

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    regular.setLocation(university);
    assertEquals(colonist, regular.getStudent());
    trainForTurns(colony, freeColonistType.getEducationTurns(veteranSoldierType));

    assertEquals(veteranSoldierType, colonist.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
コード例 #30
0
  /**
   * Test that free colonists are trained before indentured servants, which are preferred to petty
   * criminals.
   */
  public void testTeachingOrder() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit indenturedServant = units.next();
    indenturedServant.setType(indenturedServantType);
    indenturedServant.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);
    teacher.setLocation(university);

    assertTrue(colonist.canBeStudent(teacher));
    assertTrue(indenturedServant.canBeStudent(teacher));
    assertTrue(criminal.canBeStudent(teacher));

    // Criminal training
    assertEquals(teacher, criminal.getTeacher());
    assertEquals(criminal, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());
    criminal.setLocation(getGame().getMap().getTile(10, 8));

    // Servant training
    assertNull(teacher.getStudent());
    ServerTestHelper.newTurn();
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(freeColonistType, indenturedServant.getType());

    // Colonist(former servant) training continues
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    assertEquals(colonist.getTeacher(), null);

    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertEquals(expertOreMinerType, indenturedServant.getType());
    assertEquals(indenturedServant.getTeacher(), null);

    FreeColTestUtils.setStudentSelection(selection);
  }