mirror of https://github.com/FreeCol/freecol.git
This fixes unattended production so that it matches the original game on viceroy difficulty.
This commit is contained in:
parent
46e12489f4
commit
0fc1b6ebf6
|
@ -303,7 +303,7 @@
|
|||
temperature-minimum="0" temperature-maximum="15"
|
||||
altitude-minimum="1" altitude-maximum="2"/>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="5"/>
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.cotton" value="2"/>
|
||||
</production>
|
||||
<production>
|
||||
|
@ -359,7 +359,7 @@
|
|||
temperature-minimum="30" temperature-maximum="40"
|
||||
altitude-minimum="1" altitude-maximum="1"/>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="4"/>
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.sugar" value="3"/>
|
||||
</production>
|
||||
<production>
|
||||
|
@ -429,16 +429,16 @@
|
|||
temperature-minimum="10" temperature-maximum="40"
|
||||
altitude-minimum="1" altitude-maximum="2"/>
|
||||
<production unattended="true" production-level="veryHigh">
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.cotton" value="1"/>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.ore" value="2"/>
|
||||
</production>
|
||||
<production unattended="true" production-level="veryLow">
|
||||
<output goods-type="model.goods.grain" value="1"/>
|
||||
<output goods-type="model.goods.cotton" value="1"/>
|
||||
<output goods-type="model.goods.ore" value="2"/>
|
||||
</production>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.cotton" value="1"/>
|
||||
<output goods-type="model.goods.grain" value="1"/>
|
||||
<output goods-type="model.goods.ore" value="2"/>
|
||||
</production>
|
||||
<production>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
|
@ -484,7 +484,7 @@
|
|||
<modifier id="model.modifier.defence" index="50"
|
||||
type="percentage" value="50"/>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.furs" value="3"/>
|
||||
</production>
|
||||
<production>
|
||||
|
@ -566,7 +566,7 @@
|
|||
<modifier id="model.modifier.defence" index="50"
|
||||
type="percentage" value="50"/>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.furs" value="2"/>
|
||||
</production>
|
||||
<production>
|
||||
|
@ -628,7 +628,7 @@
|
|||
type="percentage" value="75"/>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.furs" value="1"/>
|
||||
<output goods-type="model.goods.sugar" value="1"/>
|
||||
</production>
|
||||
<production>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
|
@ -661,7 +661,7 @@
|
|||
<modifier id="model.modifier.defence" index="50"
|
||||
type="percentage" value="50"/>
|
||||
<production unattended="true" production-level="veryHigh">
|
||||
<output goods-type="model.goods.grain" value="3"/>
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.furs" value="2"/>
|
||||
</production>
|
||||
<production unattended="true" production-level="veryLow">
|
||||
|
@ -669,7 +669,7 @@
|
|||
<output goods-type="model.goods.furs" value="2"/>
|
||||
</production>
|
||||
<production unattended="true">
|
||||
<output goods-type="model.goods.grain" value="2"/>
|
||||
<output goods-type="model.goods.grain" value="1"/>
|
||||
<output goods-type="model.goods.furs" value="2"/>
|
||||
</production>
|
||||
<production>
|
||||
|
|
|
@ -587,8 +587,14 @@ public class TileImprovement extends TileItem {
|
|||
|
||||
final Specification spec = getSpecification();
|
||||
|
||||
if (!isNatural()
|
||||
&& unitType == null
|
||||
if (unitType == null
|
||||
&& isNatural()
|
||||
&& goodsType.isFoodType()) {
|
||||
return Stream.<Modifier>empty();
|
||||
}
|
||||
|
||||
if (unitType == null
|
||||
&& !isNatural()
|
||||
&& !goodsType.isFoodType()
|
||||
&& spec.getBoolean(GameOptions.ONLY_NATURAL_IMPROVEMENTS)) {
|
||||
return Stream.<Modifier>empty();
|
||||
|
|
|
@ -32,11 +32,7 @@ public final class ProductionUtils {
|
|||
}
|
||||
final float rebelFactor = (buildingType != null) ? buildingType.getRebelFactor() : 1.0F;
|
||||
final int bonus = (int) Math.floor(colonyProductionBonus * rebelFactor);
|
||||
Modifier mod = new Modifier(goodsType.getId(), bonus,
|
||||
Modifier.ModifierType.ADDITIVE,
|
||||
Specification.SOL_MODIFIER_SOURCE);
|
||||
mod.setModifierIndex(Modifier.COLONY_PRODUCTION_INDEX);
|
||||
return Stream.of(mod);
|
||||
return createRebelProductionModifierStream(Modifier.COLONY_PRODUCTION_INDEX, goodsType, bonus);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,6 +49,14 @@ public final class ProductionUtils {
|
|||
return Stream.<Modifier>empty();
|
||||
}
|
||||
|
||||
if (unitType == null && colonyProductionBonus < 0) { // unattended
|
||||
return Stream.<Modifier>empty();
|
||||
}
|
||||
|
||||
if (unitType == null) { // unattended
|
||||
return createRebelProductionModifierStream(Modifier.COLONYTILE_PRODUCTION_INDEX, goodsType, colonyProductionBonus);
|
||||
}
|
||||
|
||||
float rebelFactor = 1.0F;
|
||||
if (unitType != null
|
||||
&& unitType.getExpertProduction() != null
|
||||
|
@ -67,10 +71,15 @@ public final class ProductionUtils {
|
|||
}
|
||||
|
||||
int bonus = (int) Math.max(colonyProductionBonus, Math.floor(colonyProductionBonus * rebelFactor));
|
||||
return createRebelProductionModifierStream(Modifier.COLONYTILE_PRODUCTION_INDEX, goodsType, bonus);
|
||||
}
|
||||
|
||||
|
||||
private static Stream<Modifier> createRebelProductionModifierStream(int modifierIndex, GoodsType goodsType, int bonus) {
|
||||
Modifier mod = new Modifier(goodsType.getId(), bonus,
|
||||
Modifier.ModifierType.ADDITIVE,
|
||||
Specification.SOL_MODIFIER_SOURCE);
|
||||
mod.setModifierIndex(Modifier.COLONYTILE_PRODUCTION_INDEX);
|
||||
mod.setModifierIndex(modifierIndex);
|
||||
return Stream.of(mod);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import net.sf.freecol.common.model.ProductionType;
|
|||
import net.sf.freecol.common.model.Tile;
|
||||
import net.sf.freecol.common.model.Turn;
|
||||
import net.sf.freecol.common.model.UnitType;
|
||||
import net.sf.freecol.common.option.GameOptions;
|
||||
|
||||
/**
|
||||
* Calculates the production for a tile.
|
||||
|
@ -96,25 +95,18 @@ public class TileProductionCalculator {
|
|||
|
||||
if (colonyCenterTile) {
|
||||
forEach(workerAssignment.getProductionType().getOutputs(), output -> {
|
||||
boolean onlyNaturalImprovements = tile.getSpecification()
|
||||
.getBoolean(GameOptions.ONLY_NATURAL_IMPROVEMENTS)
|
||||
&& !output.getType().isFoodType();
|
||||
int potential = output.getAmount();
|
||||
if (tile.getTileItemContainer() != null) {
|
||||
potential = tile.getTileItemContainer()
|
||||
.getTotalBonusPotential(output.getType(), null,
|
||||
potential, onlyNaturalImprovements);
|
||||
int n = getCenterTileProduction(turn, tile, output.getType());
|
||||
if (n > 0) {
|
||||
pi.addProduction(new AbstractGoods(output.getType(), n));
|
||||
}
|
||||
potential += Math.max(0, colonyProductionBonus);
|
||||
AbstractGoods production
|
||||
= new AbstractGoods(output.getType(), potential);
|
||||
pi.addProduction(production);
|
||||
});
|
||||
} else {
|
||||
forEach(map(workerAssignment.getProductionType().getOutputs(), AbstractGoods::getType),
|
||||
gt -> {
|
||||
int n = getUnitProduction(turn, tile, workerAssignment, gt);
|
||||
if (n > 0) pi.addProduction(new AbstractGoods(gt, n));
|
||||
if (n > 0) {
|
||||
pi.addProduction(new AbstractGoods(gt, n));
|
||||
}
|
||||
});
|
||||
}
|
||||
return pi;
|
||||
|
@ -146,6 +138,14 @@ public class TileProductionCalculator {
|
|||
getProductionModifiers(turn, tile, goodsType, workerAssignment.getUnitType())));
|
||||
}
|
||||
|
||||
private int getCenterTileProduction(Turn turn, Tile tile, GoodsType goodsType) {
|
||||
final int production = tile.getBaseProduction(null, goodsType, null);
|
||||
return Math.max(0, (int) FeatureContainer.applyModifiers(
|
||||
production,
|
||||
turn,
|
||||
getCenterTileProductionModifiers(turn, tile, goodsType)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base production exclusive of any bonuses.
|
||||
*
|
||||
|
@ -198,11 +198,11 @@ public class TileProductionCalculator {
|
|||
return Stream.<Modifier>empty();
|
||||
}
|
||||
return concat(tile.getProductionModifiers(goodsType, null),
|
||||
ProductionUtils.getRebelProductionModifiersForTile(tile, colonyProductionBonus, goodsType, null),
|
||||
ProductionUtils.getRebelProductionModifiersForTile(tile, colonyProductionBonus, goodsType, null)
|
||||
// This does not seem to influence center tile production, but was present in the old code.
|
||||
//colony.getModifiers(id, null, turn),
|
||||
((owner == null) ? null
|
||||
: owner.getModifiers(goodsType.getId(), tile.getType(), turn)));
|
||||
//((owner == null) ? null : owner.getModifiers(goodsType.getId(), tile.getType(), turn))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -34,3 +34,82 @@ Production;Tile Type;Goods Type;Bonus Resource;Unit Type;River Magnitude;Road;Pl
|
|||
22;model.tile.prairie;model.goods.cotton;model.resource.cotton;model.unit.masterCottonPlanter;0;0;1;0;0;0;2
|
||||
12;model.tile.prairie;model.goods.cotton;model.resource.cotton;model.unit.freeColonist;1;0;1;0;0;0;2
|
||||
24;model.tile.prairie;model.goods.cotton;model.resource.cotton;model.unit.masterCottonPlanter;1;0;1;0;0;0;2
|
||||
3;model.tile.prairie;model.goods.grain;;unattended;0;0;0;0;0;0;-2
|
||||
3;model.tile.prairie;model.goods.grain;;unattended;0;0;0;0;0;0;-1
|
||||
3;model.tile.prairie;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.plains;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.prairie;model.goods.grain;;unattended;2;0;0;0;0;0;0
|
||||
4;model.tile.prairie;model.goods.grain;;unattended;0;0;0;0;0;0;1
|
||||
5;model.tile.plains;model.goods.grain;;unattended;0;0;0;0;0;0;2
|
||||
6;model.tile.plains;model.goods.grain;;unattended;0;0;1;0;0;0;2
|
||||
6;model.tile.prairie;model.goods.grain;model.resource.cotton;unattended;0;0;1;0;0;0;2
|
||||
6;model.tile.prairie;model.goods.grain;;unattended;1;1;1;0;0;0;2
|
||||
3;model.tile.prairie;model.goods.cotton;;unattended;0;0;0;0;0;0;-2
|
||||
3;model.tile.prairie;model.goods.cotton;;unattended;0;0;0;0;0;0;-1
|
||||
3;model.tile.prairie;model.goods.cotton;;unattended;0;0;0;0;0;0;0
|
||||
4;model.tile.prairie;model.goods.cotton;;unattended;0;0;0;0;0;0;1
|
||||
2;model.tile.plains;model.goods.cotton;;unattended;0;0;0;0;0;0;0
|
||||
4;model.tile.plains;model.goods.cotton;;unattended;0;0;0;0;0;0;2
|
||||
4;model.tile.plains;model.goods.cotton;;unattended;0;0;1;0;0;0;2
|
||||
6;model.tile.prairie;model.goods.cotton;;unattended;1;1;1;0;0;0;2
|
||||
8;model.tile.prairie;model.goods.cotton;model.resource.cotton;unattended;0;1;1;0;0;0;2
|
||||
8;model.tile.prairie;model.goods.cotton;model.resource.cotton;unattended;2;0;0;0;0;0;0
|
||||
# savannah
|
||||
3;model.tile.savannah;model.goods.grain;model.resource.sugar;unattended;0;0;0;0;0;0;0
|
||||
6;model.tile.savannah;model.goods.sugar;model.resource.sugar;unattended;0;0;0;0;0;0;0
|
||||
5;model.tile.savannah;model.goods.grain;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
3;model.tile.savannah;model.goods.sugar;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
4;model.tile.savannah;model.goods.sugar;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
# grassland
|
||||
3;model.tile.grassland;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.grassland;model.goods.tobacco;;unattended;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.cotton;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.furs;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.lumber;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.ore;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.silver;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.sugar;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.cotton;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.furs;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.lumber;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.ore;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.silver;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
0;model.tile.grassland;model.goods.sugar;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
3;model.tile.grassland;model.goods.grain;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
3;model.tile.grassland;model.goods.tobacco;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
4;model.tile.grassland;model.goods.grain;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
4;model.tile.grassland;model.goods.tobacco;;model.unit.freeColonist;1;0;0;0;0;0;0
|
||||
# desert
|
||||
1;model.tile.desert;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.desert;model.goods.ore;;unattended;0;0;0;0;0;0;0
|
||||
# tundra
|
||||
3;model.tile.tundra;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.tundra;model.goods.ore;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.tundra;model.goods.grain;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
2;model.tile.tundra;model.goods.ore;;model.unit.freeColonist;0;0;0;0;0;0;0
|
||||
# arctic
|
||||
0;model.tile.arctic;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
# broadleafForest
|
||||
2;model.tile.broadleafForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.broadleafForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# coniferForest
|
||||
2;model.tile.coniferForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.coniferForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# rainForest
|
||||
2;model.tile.rainForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
1;model.tile.rainForest;model.goods.sugar;;unattended;0;0;0;0;0;0;0
|
||||
# wetlandForest
|
||||
2;model.tile.wetlandForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.wetlandForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# mixedForest
|
||||
2;model.tile.mixedForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.mixedForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# scrubForest
|
||||
1;model.tile.scrubForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.scrubForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# borealForest
|
||||
2;model.tile.borealForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
3;model.tile.borealForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
# tropicalForest
|
||||
2;model.tile.tropicalForest;model.goods.grain;;unattended;0;0;0;0;0;0;0
|
||||
2;model.tile.tropicalForest;model.goods.furs;;unattended;0;0;0;0;0;0;0
|
||||
|
|
Can't render this file because it has a wrong number of fields in line 57.
|
|
@ -776,7 +776,7 @@ public class BuildingTest extends FreeColTestCase {
|
|||
assertEquals(grainType, unit.getWorkType());
|
||||
|
||||
// no horses yet
|
||||
assertEquals(8, colony.getNetProductionOf(foodType));
|
||||
assertEquals(6, colony.getNetProductionOf(foodType));
|
||||
assertEquals(0, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(0, colony.getNetProductionOf(horsesType));
|
||||
assertEquals(0, country.getMaximumProductionOf(horsesType));
|
||||
|
@ -791,9 +791,9 @@ public class BuildingTest extends FreeColTestCase {
|
|||
colony.addGoods(horsesType, 1);
|
||||
colony.invalidateCache();
|
||||
|
||||
assertEquals(4, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(3, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(4, country.getMaximumProductionOf(horsesType));
|
||||
assertEquals(4, colony.getNetProductionOf(horsesType));
|
||||
assertEquals(3, colony.getNetProductionOf(horsesType));
|
||||
|
||||
country.upgrade();
|
||||
colony.removeGoods(horsesType);
|
||||
|
@ -809,24 +809,24 @@ public class BuildingTest extends FreeColTestCase {
|
|||
colony.invalidateCache();
|
||||
|
||||
assertEquals(26, colony.getGoodsCount(horsesType));
|
||||
assertEquals(4, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(3, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(4, country.getMaximumProductionOf(horsesType));
|
||||
assertEquals(4, colony.getNetProductionOf(horsesType));
|
||||
assertEquals(3, colony.getNetProductionOf(horsesType));
|
||||
|
||||
colony.addGoods(horsesType, 24);
|
||||
colony.invalidateCache();
|
||||
|
||||
assertEquals(50, colony.getGoodsCount(horsesType));
|
||||
assertEquals(4, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(3, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(4, country.getMaximumProductionOf(horsesType));
|
||||
assertEquals(4, colony.getNetProductionOf(horsesType));
|
||||
assertEquals(3, colony.getNetProductionOf(horsesType));
|
||||
|
||||
colony.addGoods(horsesType, 1);
|
||||
colony.invalidateCache();
|
||||
|
||||
assertEquals(51, colony.getGoodsCount(horsesType));
|
||||
// no more than half the surplus production!
|
||||
assertEquals(4, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(3, country.getTotalProductionOf(horsesType));
|
||||
assertEquals(6, country.getMaximumProductionOf(horsesType));
|
||||
assertEquals("Horse production should equal food surplus.",
|
||||
colony.getNetProductionOf(foodType),
|
||||
|
|
|
@ -102,17 +102,17 @@ public class ClassicTileProductionTest extends FreeColTestCase {
|
|||
if (ptc.unitType == defaultUnitType) {
|
||||
final ProductionInfo piCriminal = tpc.getBasicProductionInfo(tile, new Turn(1), new WorkerAssignment(pettyCriminalUnitType, productionType), false);
|
||||
assertEquals("Petty criminals should have the same production as a Free Colonist on tiles.",
|
||||
getProductionAmount(pi),
|
||||
getProductionAmount(piCriminal));
|
||||
getProductionAmount(ptc.goodsType, pi),
|
||||
getProductionAmount(ptc.goodsType, piCriminal));
|
||||
|
||||
final ProductionInfo piIndentured = tpc.getBasicProductionInfo(tile, new Turn(1), new WorkerAssignment(indenturedServantUnitType, productionType), false);
|
||||
assertEquals("Indentured Servants should have the same production as a Free Colonist on tiles.",
|
||||
getProductionAmount(pi),
|
||||
getProductionAmount(piIndentured));
|
||||
getProductionAmount(ptc.goodsType, pi),
|
||||
getProductionAmount(ptc.goodsType, piIndentured));
|
||||
}
|
||||
|
||||
final List<Object> output = new ArrayList<>();
|
||||
output.add(getProductionAmount(pi));
|
||||
output.add(getProductionAmount(ptc.goodsType, pi));
|
||||
output.add(ptc.tileType.getId());
|
||||
output.add(ptc.goodsType.getId());
|
||||
output.add(ptc.resourceType != null ? ptc.resourceType.getId() : "");
|
||||
|
@ -204,8 +204,15 @@ public class ClassicTileProductionTest extends FreeColTestCase {
|
|||
return result;
|
||||
}
|
||||
|
||||
private int getProductionAmount(ProductionInfo pi) {
|
||||
return pi.getProduction().isEmpty() ? 0 : pi.getProduction().get(0).getAmount();
|
||||
private int getProductionAmount(GoodsType goodstype, ProductionInfo pi) {
|
||||
if (pi.getProduction().isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return pi.getProduction().stream()
|
||||
.filter(ag -> ag.getType().equals(goodstype))
|
||||
.map(AbstractGoods::getAmount)
|
||||
.findFirst()
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
private <T> List<T> nullAnd(List<T> input) {
|
||||
|
|
|
@ -247,7 +247,7 @@ public class ColonyProductionTest extends FreeColTestCase {
|
|||
Colony colony = getStandardColony(1);
|
||||
Building pasture = colony.getBuilding(countryType);
|
||||
Unit unit = colony.getFirstUnit();
|
||||
unit.setLocation(colony.getWorkLocationFor(unit, bellsType));
|
||||
unit.setLocation(colony.getWorkLocationFor(unit, foodType));
|
||||
|
||||
List<AbstractGoods> outputs = toList(pasture.getOutputs());
|
||||
assertEquals(1, outputs.size());
|
||||
|
@ -261,7 +261,7 @@ public class ColonyProductionTest extends FreeColTestCase {
|
|||
colony.invalidateCache();
|
||||
|
||||
assertEquals(99, colony.getGoodsCount(horsesType));
|
||||
assertTrue(colony.getNetProductionOf(foodType) > 0);
|
||||
assertTrue(colony.getNetProductionOf(foodType) > 1);
|
||||
assertEquals("Wrong horse production", 1,
|
||||
pasture.getTotalProductionOf(horsesType));
|
||||
assertEquals("Wrong maximum horse production", 1,
|
||||
|
@ -379,7 +379,7 @@ public class ColonyProductionTest extends FreeColTestCase {
|
|||
|
||||
assertEquals(0, colony.getGoodsCount(foodType));
|
||||
assertEquals(grainType, tile.getProduction().get(0).getType());
|
||||
assertEquals(5, tile.getProduction().get(0).getAmount());
|
||||
assertEquals(3, tile.getProduction().get(0).getAmount());
|
||||
assertEquals(cottonType, tile.getProduction().get(1).getType());
|
||||
assertEquals(2, tile.getProduction().get(1).getAmount());
|
||||
|
||||
|
|
|
@ -59,7 +59,13 @@ public class ColonyTest extends FreeColTestCase {
|
|||
= spec().getGoodsType("model.goods.hammers");
|
||||
private static final GoodsType lumberGoodsType
|
||||
= spec().getGoodsType("model.goods.lumber");
|
||||
|
||||
|
||||
private static final ResourceType cottonResourceType
|
||||
= spec().getResourceType("model.resource.cotton");
|
||||
|
||||
private static final TileImprovementType plowTileImprovementType
|
||||
= spec().getTileImprovementType("model.improvement.plow");
|
||||
|
||||
private static final Role soldierRole
|
||||
= spec().getRole("model.role.soldier");
|
||||
|
||||
|
@ -67,6 +73,8 @@ public class ColonyTest extends FreeColTestCase {
|
|||
= spec().getTileType("model.tile.arctic");
|
||||
private static final TileType plainsTileType
|
||||
= spec().getTileType("model.tile.plains");
|
||||
private static final TileType prairieTileType
|
||||
= spec().getTileType("model.tile.prairie");
|
||||
|
||||
private static final UnitType cottonPlanterType
|
||||
= spec().getUnitType("model.unit.masterCottonPlanter");
|
||||
|
@ -241,19 +249,30 @@ public class ColonyTest extends FreeColTestCase {
|
|||
// Add one plains tile
|
||||
Tile plainsTile = colony.getTile().getNeighbourOrNull(Direction.S);
|
||||
plainsTile.setType(plainsTileType);
|
||||
ColonyTile colonyTile = colony.getColonyTile(plainsTile);
|
||||
assertTrue(colonyTile.isEmpty());
|
||||
ColonyTile plainsColonyTile = colony.getColonyTile(plainsTile);
|
||||
assertTrue(plainsColonyTile.isEmpty());
|
||||
|
||||
// Add one prairie tile
|
||||
Tile prairieTile = colony.getTile().getNeighbourOrNull(Direction.N);
|
||||
prairieTile.setType(prairieTileType);
|
||||
prairieTile.addResource(new Resource(game, prairieTile, cottonResourceType));
|
||||
ColonyTile prairieColonyTile = colony.getColonyTile(prairieTile);
|
||||
assertTrue(prairieColonyTile.isEmpty());
|
||||
|
||||
// colonist experience might be cotton, but the colony needs food
|
||||
colonist.setLocation(colony.getTile());
|
||||
colonist.changeWorkType(cottonGoodsType);
|
||||
colonist.modifyExperience(100);
|
||||
nonServerJoinColony(colonist, colony);
|
||||
assertEquals(colonyTile, colonist.getLocation());
|
||||
assertEquals(plainsColonyTile, colonist.getLocation());
|
||||
assertEquals(grainGoodsType, colonist.getWorkType());
|
||||
|
||||
// Change the center tile to plains to improve the food situation
|
||||
// Change the center tile to plains and plow to improve the food situation
|
||||
colony.getTile().changeType(plainsTileType);
|
||||
final TileImprovement tileImprovement = new TileImprovement(game, colony.getTile(), plowTileImprovementType, null);
|
||||
tileImprovement.setTurnsToComplete(0);
|
||||
colony.getTile().add(tileImprovement);
|
||||
|
||||
colony.invalidateCache();
|
||||
assertTrue("colony should produce more food than it consumes",
|
||||
colony.getFoodProduction() >= colony.getFoodConsumption()
|
||||
|
@ -264,7 +283,7 @@ public class ColonyTest extends FreeColTestCase {
|
|||
colonist.changeWorkType(cottonGoodsType);
|
||||
colonist.modifyExperience(100);
|
||||
nonServerJoinColony(colonist, colony);
|
||||
assertEquals(colonyTile, colonist.getLocation());
|
||||
assertEquals(prairieColonyTile, colonist.getLocation());
|
||||
assertEquals(cottonGoodsType, colonist.getWorkType());
|
||||
|
||||
// colonist should still make cotton due to expertise
|
||||
|
@ -272,7 +291,7 @@ public class ColonyTest extends FreeColTestCase {
|
|||
colonist.changeWorkType(null);
|
||||
colonist.setType(cottonPlanterType);
|
||||
nonServerJoinColony(colonist, colony);
|
||||
assertEquals(colonyTile, colonist.getLocation());
|
||||
assertEquals(prairieColonyTile, colonist.getLocation());
|
||||
assertEquals(cottonGoodsType, colonist.getWorkType());
|
||||
|
||||
// colonist produces cloth, because there is cotton now
|
||||
|
|
|
@ -312,18 +312,18 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testDesert() {
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(cotton, 1);
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(ore, 2);
|
||||
testProduction(inputs, outputs,
|
||||
desert.getAvailableProductionTypes(true, "veryHigh"));
|
||||
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(cotton, 1);
|
||||
outputs.put(grain, 1);
|
||||
outputs.put(ore, 2);
|
||||
testProduction(inputs, outputs,
|
||||
desert.getAvailableProductionTypes(true));
|
||||
|
||||
outputs.put(grain, 1);
|
||||
outputs.put(cotton, 1);
|
||||
outputs.put(ore, 2);
|
||||
testProduction(inputs, outputs,
|
||||
desert.getAvailableProductionTypes(true, "veryLow"));
|
||||
|
||||
|
@ -333,7 +333,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
desert.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(2, desert.getPotentialProduction(grain, null));
|
||||
assertEquals(1, desert.getPotentialProduction(grain, null));
|
||||
assertEquals(2, getGenericPotential(desert, grain));
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testMixedForest() {
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(furs, 3);
|
||||
testProduction(inputs, outputs,
|
||||
mixedForest.getAvailableProductionTypes(true));
|
||||
|
@ -433,7 +433,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
mixedForest.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(3, mixedForest.getPotentialProduction(grain, null));
|
||||
assertEquals(2, mixedForest.getPotentialProduction(grain, null));
|
||||
assertEquals(3, getGenericPotential(mixedForest, grain));
|
||||
}
|
||||
|
||||
|
@ -463,7 +463,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testPlains() {
|
||||
outputs.put(grain, 5);
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(cotton, 2);
|
||||
testProduction(inputs, outputs,
|
||||
plains.getAvailableProductionTypes(true));
|
||||
|
@ -474,7 +474,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
plains.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(5, plains.getPotentialProduction(grain, null));
|
||||
assertEquals(3, plains.getPotentialProduction(grain, null));
|
||||
assertEquals(5, getGenericPotential(plains, grain));
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
|
||||
public void testRainForest() {
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(furs, 1);
|
||||
outputs.put(sugar, 1);
|
||||
testProduction(inputs, outputs,
|
||||
rainForest.getAvailableProductionTypes(true));
|
||||
|
||||
|
@ -513,7 +513,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testSavannah() {
|
||||
outputs.put(grain, 4);
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(sugar, 3);
|
||||
testProduction(inputs, outputs,
|
||||
savannah.getAvailableProductionTypes(true));
|
||||
|
@ -523,17 +523,17 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
savannah.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(4, savannah.getPotentialProduction(grain, null));
|
||||
assertEquals(3, savannah.getPotentialProduction(grain, null));
|
||||
assertEquals(4, getGenericPotential(savannah, grain));
|
||||
}
|
||||
|
||||
public void testScrubForest() {
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(furs, 2);
|
||||
testProduction(inputs, outputs,
|
||||
scrubForest.getAvailableProductionTypes(true, "veryHigh"));
|
||||
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(grain, 1);
|
||||
outputs.put(furs, 2);
|
||||
testProduction(inputs, outputs,
|
||||
scrubForest.getAvailableProductionTypes(true));
|
||||
|
@ -551,7 +551,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
scrubForest.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(2, scrubForest.getPotentialProduction(grain, null));
|
||||
assertEquals(1, scrubForest.getPotentialProduction(grain, null));
|
||||
assertEquals(2, getGenericPotential(scrubForest, grain));
|
||||
}
|
||||
|
||||
|
@ -573,7 +573,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testTropicalForest() {
|
||||
outputs.put(grain, 3);
|
||||
outputs.put(grain, 2);
|
||||
outputs.put(furs, 2);
|
||||
testProduction(inputs, outputs,
|
||||
tropicalForest.getAvailableProductionTypes(true));
|
||||
|
@ -585,7 +585,7 @@ public class ProductionTypeTest extends FreeColTestCase {
|
|||
testProduction(inputs, outputs,
|
||||
tropicalForest.getAvailableProductionTypes(false));
|
||||
|
||||
assertEquals(3, tropicalForest.getPotentialProduction(grain, null));
|
||||
assertEquals(2, tropicalForest.getPotentialProduction(grain, null));
|
||||
assertEquals(3, getGenericPotential(tropicalForest, grain));
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ public class TileTest extends FreeColTestCase {
|
|||
AbstractGoods primaryProduction = production.get(0);
|
||||
AbstractGoods secondaryProduction = production.get(1);
|
||||
assertEquals(grain, primaryProduction.getType());
|
||||
assertEquals(5, primaryProduction.getAmount());
|
||||
assertEquals(3, primaryProduction.getAmount());
|
||||
assertEquals(cotton, secondaryProduction.getType());
|
||||
assertEquals(2, secondaryProduction.getAmount());
|
||||
|
||||
|
@ -276,7 +276,7 @@ public class TileTest extends FreeColTestCase {
|
|||
primaryProduction = production.get(0);
|
||||
secondaryProduction = production.get(1);
|
||||
assertEquals(grain, primaryProduction.getType());
|
||||
assertEquals(6, primaryProduction.getAmount());
|
||||
assertEquals(4, primaryProduction.getAmount());
|
||||
assertEquals(cotton, secondaryProduction.getType());
|
||||
assertEquals(2, secondaryProduction.getAmount());
|
||||
|
||||
|
@ -288,7 +288,7 @@ public class TileTest extends FreeColTestCase {
|
|||
primaryProduction = production.get(0);
|
||||
secondaryProduction = production.get(1);
|
||||
assertEquals(grain, primaryProduction.getType());
|
||||
assertEquals(3, primaryProduction.getAmount());
|
||||
assertEquals(2, primaryProduction.getAmount());
|
||||
assertEquals(furs, secondaryProduction.getType());
|
||||
assertEquals(3, secondaryProduction.getAmount());
|
||||
}
|
||||
|
@ -327,9 +327,9 @@ public class TileTest extends FreeColTestCase {
|
|||
|
||||
// grain-max should equal grain-potential + 1 (ploughing improvement)
|
||||
Tile tile2 = new Tile(game, plains, 0, 1);
|
||||
assertEquals("Plains/grain", 5,
|
||||
assertEquals("Plains/grain", 3,
|
||||
tile2.getPotentialProduction(grain, null));
|
||||
assertEquals("Plains/grain max", 6,
|
||||
assertEquals("Plains/grain max", 4,
|
||||
tile2.getMaximumPotential(grain, null));
|
||||
assertEquals("Plains/grain/colonist", 5,
|
||||
tile2.getPotentialProduction(grain, colonistType));
|
||||
|
@ -338,9 +338,9 @@ public class TileTest extends FreeColTestCase {
|
|||
assertEquals("Plains/grain/expertFarmer", 7,
|
||||
tile2.getPotentialProduction(grain, expertFarmerType));
|
||||
tile2.addResource(new Resource(game, tile2, grainResource));
|
||||
assertEquals("Plains+Resource/grain", 7,
|
||||
assertEquals("Plains+Resource/grain", 5,
|
||||
tile2.getPotentialProduction(grain, null));
|
||||
assertEquals("Plains+Resource/grain max", 8,
|
||||
assertEquals("Plains+Resource/grain max", 6,
|
||||
tile2.getMaximumPotential(grain, null));
|
||||
assertEquals("Plains+Resource/grain/colonist", 7,
|
||||
tile2.getPotentialProduction(grain, colonistType));
|
||||
|
@ -352,9 +352,9 @@ public class TileTest extends FreeColTestCase {
|
|||
tile2.getMaximumPotential(grain, expertFarmerType));
|
||||
|
||||
Tile tile3 = new Tile(game, plainsForest, 1, 1);
|
||||
assertEquals("Forest/grain", 3,
|
||||
assertEquals("Forest/grain", 2,
|
||||
tile3.getPotentialProduction(grain, null));
|
||||
assertEquals("Forest/grain max", 6,
|
||||
assertEquals("Forest/grain max", 4,
|
||||
tile3.getMaximumPotential(grain, null));
|
||||
assertEquals("Forest/lumber/colonist", 6,
|
||||
tile3.getPotentialProduction(lumber, colonistType));
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import net.sf.freecol.common.model.Ability;
|
||||
import net.sf.freecol.common.model.AbstractGoods;
|
||||
import net.sf.freecol.common.model.Building;
|
||||
import net.sf.freecol.common.model.BuildingType;
|
||||
import net.sf.freecol.common.model.Colony;
|
||||
|
@ -1157,6 +1158,7 @@ public class ServerBuildingTest extends FreeColTestCase {
|
|||
Game game = ServerTestHelper.startServerGame(getTestMap(true));
|
||||
|
||||
Colony colony = getSchoolColony(2, SchoolLevel.SCHOOLHOUSE);
|
||||
colony.addGoods(new AbstractGoods(foodType, 100));
|
||||
Building school = colony.getBuilding(schoolType);
|
||||
Iterator<Unit> units = colony.getUnitList().iterator();
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ServerColonyTest extends FreeColTestCase {
|
|||
}
|
||||
|
||||
public void testEqualFoodProductionConsumptionCase() {
|
||||
Game game = ServerTestHelper.startServerGame(getTestMap(desert));
|
||||
Game game = ServerTestHelper.startServerGame(getTestMap(coniferForest));
|
||||
|
||||
// Setting test colony
|
||||
Tile colonyTile = game.getMap().getTile(5, 8);
|
||||
|
|
|
@ -215,7 +215,7 @@ public class ServerUnitTest extends FreeColTestCase {
|
|||
// Before
|
||||
assertEquals(0, colony.getGoodsCount(foodType));
|
||||
assertEquals(2, colony.getFoodConsumption());
|
||||
assertEquals(5 + 5, colony.getFoodProduction());
|
||||
assertEquals(4 + 4, colony.getFoodProduction());
|
||||
assertFalse(hasImprovement(plain58, plow));
|
||||
assertEquals(0, colony.getProductionBonus());
|
||||
assertEquals("" + soldier.getLocation(), colony.getColonyTile(map.getTile(5, 8)), soldier.getLocation());
|
||||
|
@ -224,10 +224,10 @@ public class ServerUnitTest extends FreeColTestCase {
|
|||
ServerTestHelper.newTurn();
|
||||
|
||||
assertFalse(hasImprovement(plain58, plow));
|
||||
assertEquals(8, colony.getGoodsCount(foodType));
|
||||
assertEquals(6, colony.getGoodsCount(foodType));
|
||||
assertEquals(2, colony.getFoodConsumption());
|
||||
assertEquals(0, colony.getProductionBonus());
|
||||
assertEquals(5 + 5, colony.getFoodProduction());
|
||||
assertEquals(4 + 4, colony.getFoodProduction());
|
||||
|
||||
// Start Plowing
|
||||
//TileImprovement plowImprovement
|
||||
|
@ -244,10 +244,10 @@ public class ServerUnitTest extends FreeColTestCase {
|
|||
|
||||
assertTrue(hasImprovement(plain58, plow));
|
||||
// Production for next turn is updated
|
||||
assertEquals(5 + 6, colony.getFoodProduction());
|
||||
assertEquals(4 + 5, colony.getFoodProduction());
|
||||
assertEquals(2, colony.getFoodConsumption());
|
||||
// But in only 10 - 2 == 8 are added from last turn
|
||||
assertEquals(8 + n * 8, colony.getGoodsCount(foodType));
|
||||
assertEquals(6 + n * 6, colony.getGoodsCount(foodType));
|
||||
|
||||
// In game, this should happen via a Tile update
|
||||
colony.invalidateCache();
|
||||
|
@ -255,9 +255,9 @@ public class ServerUnitTest extends FreeColTestCase {
|
|||
ServerTestHelper.newTurn();
|
||||
|
||||
assertTrue(hasImprovement(plain58, plow));
|
||||
assertEquals(5 + 6, colony.getFoodProduction());
|
||||
assertEquals(4 + 5, colony.getFoodProduction());
|
||||
assertEquals(2, colony.getFoodConsumption());
|
||||
assertEquals(8 + n * 8 + 9, colony.getGoodsCount(foodType));
|
||||
assertEquals(6 + n * 6 + 7, colony.getGoodsCount(foodType));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue