public void testProductionSoldier() {

    Game game = getStandardGame();
    Map map = getTestMap();
    game.setMap(map);
    Player dutch = game.getPlayer("model.nation.dutch");

    Tile tile = map.getTile(5, 8);
    Resource grain = new Resource(game, tile, spec().getResourceType("model.resource.grain"));
    tile.addResource(grain);

    UnitType veteran = spec().getUnitType("model.unit.veteranSoldier");
    Unit soldier = new ServerUnit(game, map.getTile(6, 8), dutch, veteran);

    Colony colony = new ServerColony(game, dutch, "New Amsterdam", soldier.getTile());
    dutch.addSettlement(colony);
    GoodsType foodType = grainType;
    soldier.setWorkType(foodType);
    nonServerBuildColony(soldier, colony);

    // Test the colony
    assertEquals(map.getTile(6, 8), colony.getTile());

    assertEquals("New Amsterdam", colony.getName());

    assertEquals(colony, colony.getTile().getSettlement());

    assertEquals(dutch, colony.getTile().getOwner());

    // Disabled.  Removal of equipment has moved to the server, so
    // nonServerBuildColony is not going to work.
    //// Should have 50 Muskets and nothing else
    // GoodsType muskets = spec().getGoodsType("model.goods.muskets");
    // assertNotNull(muskets);
    //
    // for (GoodsType type : spec().getGoodsTypeList()){
    //    if (type == muskets)
    //        assertEquals(50, colony.getGoodsCount(type));
    //    else
    //        assertEquals(type.toString(), 0, colony.getGoodsCount(type));
    // }

    // Test the state of the soldier
    // Soldier should be working on the field with the bonus

    assertEquals(foodType, soldier.getWorkType());

    assertEquals(colony.getColonyTile(tile).getTile(), soldier.getLocation().getTile());

    assertEquals(0, soldier.getMovesLeft());

    // assertEquals(false, soldier.isArmed());
  }
Esempio n. 2
0
 public String toString() {
   Tile tile = colony.getTile();
   String eqStr = "/";
   for (EquipmentType e : equipment.keySet()) {
     eqStr += e.toString().substring(16, 17);
   }
   String locStr =
       (loc == null)
           ? ""
           : (loc instanceof Building)
               ? Utils.lastPart(((Building) loc).getType().toString(), ".")
               : (loc instanceof ColonyTile)
                   ? tile.getDirection(((ColonyTile) loc).getWorkTile()).toString()
                   : (loc instanceof Tile) ? (loc.getId() + eqStr) : loc.getId();
   Location newLoc = unit.getLocation();
   String newEqStr = "/";
   for (EquipmentType e : unit.getEquipment().keySet()) {
     newEqStr += e.toString().substring(16, 17);
   }
   String newLocStr =
       (newLoc == null)
           ? ""
           : (newLoc instanceof Building)
               ? Utils.lastPart(((Building) newLoc).getType().toString(), ".")
               : (newLoc instanceof ColonyTile)
                   ? tile.getDirection(((ColonyTile) newLoc).getWorkTile()).toString()
                   : (newLoc instanceof Tile) ? (newLoc.getId() + newEqStr) : newLoc.getId();
   GoodsType newWork = unit.getWorkType();
   int newWorkAmount = (newWork == null) ? 0 : getAmount(newLoc, newWork);
   return String.format(
           "%-30s %-25s -> %-25s",
           unit.getId() + ":" + Utils.lastPart(unit.getType().toString(), "."),
           locStr
               + ((work == null || workAmount <= 0)
                   ? ""
                   : "("
                       + Integer.toString(workAmount)
                       + " "
                       + Utils.lastPart(work.toString(), ".")
                       + ")"),
           newLocStr
               + ((newWork == null || newWorkAmount <= 0)
                   ? ""
                   : "("
                       + Integer.toString(newWorkAmount)
                       + " "
                       + Utils.lastPart(newWork.toString(), ".")
                       + ")"))
       .trim();
 }
  public void testGetPotentialProduction() {
    Game game = getGame();
    game.setMap(getTestMap());

    Colony colony = getStandardColony(1);
    ColonyTile colonyTile = colony.getColonyTile(colony.getTile());
    assertNotNull(colonyTile);
    assertEquals(plainsType, colony.getTile().getType());
    Building townHall = colony.getBuilding(townHallType);
    assertNotNull(townHall);
    UnitType colonistType = spec().getDefaultUnitType();
    assertNotNull(colonistType);

    assertEquals(
        "Zero potential production of cotton in town hall",
        0,
        townHall.getPotentialProduction(cottonType, colonistType));
    assertEquals(
        "Basic potential production of bells in town hall",
        (int)
            FeatureContainer.applyModifiers(
                0f, game.getTurn(), townHall.getProductionModifiers(bellsType, colonistType)),
        townHall.getPotentialProduction(bellsType, colonistType));

    assertEquals(
        "Basic potential production of cotton on center tile" + " if not using a unit",
        plainsType.getProductionOf(cottonType, null),
        colonyTile.getPotentialProduction(cottonType, null));
    assertEquals(
        "Zero potential production of cotton on center tile" + " if using a unit",
        0,
        colonyTile.getPotentialProduction(cottonType, colonistType));
    assertEquals(
        "Zero potential production of cotton in town hall",
        0,
        townHall.getPotentialProduction(cottonType, colonistType));
  }
  public void testProduction() {
    Game game = getGame();
    game.setMap(getTestMap());

    Colony colony = getStandardColony(3);
    ColonyTile tile = colony.getColonyTile(colony.getTile());

    assertEquals(0, colony.getGoodsCount(foodType));

    assertEquals(grainType, tile.getProduction().get(0).getType());
    assertEquals(5, tile.getProduction().get(0).getAmount());
    assertEquals(cottonType, tile.getProduction().get(1).getType());
    assertEquals(2, tile.getProduction().get(1).getAmount());

    for (Unit unit : colony.getUnitList()) {
      ProductionInfo unitInfo = colony.getProductionInfo(unit);
      assertNotNull(unitInfo);
      assertEquals(2, unitInfo.getConsumption().size());
      assertEquals(2, unitInfo.getMaximumConsumption().size());
      ProductionInfo tileInfo = colony.getProductionInfo(unit.getLocation());
      assertEquals(1, tileInfo.getProduction().size());
      assertEquals(grainType, tileInfo.getProduction().get(0).getType());
      assertEquals(5, tileInfo.getProduction().get(0).getAmount());
    }

    /*
    TypeCountMap<GoodsType> grossProduction = new TypeCountMap<GoodsType>();
    TypeCountMap<GoodsType> netProduction = new TypeCountMap<GoodsType>();
    for (ProductionInfo productionInfo : info.values()) {
        for (AbstractGoods goods : productionInfo.getProduction()) {
            grossProduction.incrementCount(goods.getType(), goods.getAmount());
            netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount());
        }
        for (AbstractGoods goods : productionInfo.getStorage()) {
            grossProduction.incrementCount(goods.getType(), goods.getAmount());
            netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount());
        }
        for (AbstractGoods goods : productionInfo.getConsumption()) {
            netProduction.incrementCount(goods.getType().getStoredAs(), -goods.getAmount());
        }
    }

    assertEquals(2, grossProduction.getCount(cottonType));
    assertEquals(2, colony.getNetProductionOf(cottonType));

    assertEquals(20, grossProduction.getCount(grainType));
    assertEquals(0, colony.getNetProductionOf(grainType));

    assertEquals(3, grossProduction.getCount(bellsType));
    assertEquals(0, colony.getNetProductionOf(bellsType));

    assertEquals(1, grossProduction.getCount(crossesType));
    assertEquals(1, colony.getNetProductionOf(crossesType));

    // this is storage only
    assertEquals(7, grossProduction.getCount(foodType));
    // this includes implicit type change and consumption
    assertEquals(14, colony.getNetProductionOf(foodType));

    colony.addGoods(horsesType, 50);
    colony.getUnitList().get(0).setWorkType(cottonType);
    Building weaverHouse = colony.getBuilding(spec().getBuildingType("model.building.weaverHouse"));
    colony.getUnitList().get(1).setLocation(weaverHouse);

    info = colony.getProductionAndConsumption();

    assertEquals(grainType, tile.getProduction().get(0).getType());
    assertEquals(5, tile.getProduction().get(0).getAmount());
    assertEquals(cottonType, tile.getProduction().get(1).getType());
    assertEquals(2, tile.getProduction().get(1).getAmount());

    grossProduction = new TypeCountMap<GoodsType>();
    netProduction = new TypeCountMap<GoodsType>();
    for (ProductionInfo productionInfo : info.values()) {
        for (AbstractGoods goods : productionInfo.getProduction()) {
            grossProduction.incrementCount(goods.getType(), goods.getAmount());
            netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount());
        }
        for (AbstractGoods goods : productionInfo.getStorage()) {
            grossProduction.incrementCount(goods.getType(), goods.getAmount());
            netProduction.incrementCount(goods.getType().getStoredAs(), goods.getAmount());
        }
        for (AbstractGoods goods : productionInfo.getConsumption()) {
            netProduction.incrementCount(goods.getType().getStoredAs(), -goods.getAmount());
        }
    }

    assertEquals(4, grossProduction.getCount(cottonType));
    assertEquals(1, colony.getNetProductionOf(cottonType));

    assertEquals(3, grossProduction.getCount(clothType));
    assertEquals(3, colony.getNetProductionOf(clothType));

    assertEquals(10, grossProduction.getCount(grainType));
    assertEquals(0, colony.getNetProductionOf(grainType));

    assertEquals(2, grossProduction.getCount(horsesType));
    assertEquals(2, colony.getNetProductionOf(horsesType));

    assertEquals(3, grossProduction.getCount(bellsType));
    assertEquals(0, colony.getNetProductionOf(bellsType));

    assertEquals(1, grossProduction.getCount(crossesType));
    assertEquals(1, colony.getNetProductionOf(crossesType));

    // this is storage only
    assertEquals(2, grossProduction.getCount(foodType));
    // this includes implicit type change and consumption
    assertEquals(2, colony.getNetProductionOf(foodType));

    */
  }