Skip to content

Commit

Permalink
BR#3362 - Ships the AI builds in its colonies no longer wait one turn…
Browse files Browse the repository at this point in the history
… before being utilized.
  • Loading branch information
stiangre committed Jul 26, 2024
1 parent b776249 commit 274310a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
21 changes: 15 additions & 6 deletions src/net/sf/freecol/server/ai/mission/TransportMission.java
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,9 @@ private CargoResult tryCargo(Cargo cargo, LogBuilder lb) {
*/
private void doTransport(LogBuilder lb) {
final Unit unit = getUnit();
if (tSize() == 0) {
queueMoreCargo(lb, unit);
}
if (tSize() > 0) {
// Arrived at a target. Deliver what can be delivered.
// Check other deliveries, we might be in port so this is
Expand Down Expand Up @@ -1064,15 +1067,21 @@ private void doTransport(LogBuilder lb) {
}

queueEasilyTransportedCargo(unit);

queueMoreCargo(lb, unit);
}

private void queueMoreCargo(LogBuilder lb, final Unit unit) {
// Replenish cargoes up to available destination capacity
// and 50% above maximum cargoes (FIXME: longer?)
final EuropeanAIPlayer euaip = getEuropeanAIPlayer();
while (destinationCapacity() > 0
&& tSize() < unit.getCargoCapacity() * 3 / 2) {
Cargo cargo = getBestCargo(unit);
if (cargo == null) break;
if (!queueCargo(cargo, false, lb)) break;
while (destinationCapacity() > 0 && tSize() < unit.getCargoCapacity() * 3 / 2) {
final Cargo cargo = getBestCargo(unit);
if (cargo == null) {
break;
}
if (!queueCargo(cargo, false, lb)) {
break;
}
euaip.claimTransportable(cargo.getTransportable());
}

Expand Down
1 change: 1 addition & 0 deletions test/src/net/sf/freecol/server/ai/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static Test suite() {
suite.addTestSuite(REFTest.class);
suite.addTestSuite(StandardAIPlayerTest.class);
suite.addTestSuite(TensionTest.class);
suite.addTestSuite(EuropeanAIPlayerTest.class);
//$JUnit-END$
suite.addTest(net.sf.freecol.server.ai.mission.AllTests.suite());
return suite;
Expand Down
47 changes: 16 additions & 31 deletions test/src/net/sf/freecol/server/ai/EuropeanAIPlayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package net.sf.freecol.server.ai;

import net.sf.freecol.common.model.Colony;
import net.sf.freecol.common.model.Europe;
import net.sf.freecol.common.model.Game;
import net.sf.freecol.common.model.GoodsContainer;
import net.sf.freecol.common.model.GoodsType;
Expand All @@ -34,55 +33,41 @@
import net.sf.freecol.server.model.ServerPlayer;
import net.sf.freecol.server.model.ServerUnit;
import net.sf.freecol.util.test.FreeColTestCase;
import net.sf.freecol.util.test.FreeColTestUtils;


public class EuropeanAIPlayerTest extends FreeColTestCase {

private static final GoodsType fursType = spec().getGoodsType("model.goods.furs");
private static final TileType savannahType = spec().getTileType("model.tile.savannah");
private static final UnitType caravelType = spec().getUnitType("model.unit.caravel");

private static final GoodsType fursType
= spec().getGoodsType("model.goods.furs");

private static final TileType savannahType
= spec().getTileType("model.tile.savannah");

private static final UnitType caravelType
= spec().getUnitType("model.unit.caravel");

private LogBuilder lb = new LogBuilder(0); // dummy


@Override
public void tearDown() throws Exception {
ServerTestHelper.stopServerGame();
super.tearDown();
}


/**
* Tests _one_ case of export:
* If goods (e.g. furs) is over storage capacity - goods shall be exported
* Verifies that a ship exports goods on the same turn as it was added (provided there are
* no other transportation tasks).
*/
public void testExport() {

Game game = ServerTestHelper.startServerGame(getCoastTestMap(savannahType));
Map map = game.getMap();
AIMain aiMain = ServerTestHelper.getServer().getAIMain();
public void testGoodsTransportHappensTheSameTurn() {
final Game game = ServerTestHelper.startServerGame(getCoastTestMap(savannahType));
final Map map = game.getMap();
final AIMain aiMain = ServerTestHelper.getServer().getAIMain();

// setup player and Europe
final ServerPlayer player
= getServerPlayer(game, "model.nation.dutch");
final EuropeanAIPlayer aiPlayer
= (EuropeanAIPlayer)aiMain.getAIPlayer(player);
final ServerPlayer player = getServerPlayer(game, "model.nation.dutch");
final EuropeanAIPlayer aiPlayer = (EuropeanAIPlayer)aiMain.getAIPlayer(player);
player.exploreMap(true);
Europe europe = player.getEurope();
assertNotNull("Setup error, europe is null", europe);

// create a coastal colony
Tile colonyTile = map.getTile(9, 9);
final Tile colonyTile = map.getTile(9, 9);
final Colony colony = createStandardColony(1, colonyTile.getX(), colonyTile.getY());

// Create a unit that can transport the exported goods
Unit caravel = new ServerUnit(game, colony.getTile(), player, caravelType);
final Unit caravel = new ServerUnit(game, colony.getTile(), player, caravelType);

game.setCurrentPlayer(colony.getOwner());

Expand All @@ -92,8 +77,8 @@ public void testExport() {
aiPlayer.startWorking();

// Verify furs are exported and loaded onto caravel
GoodsContainer gc = caravel.getGoodsContainer();
int numberOfFurs = gc.getGoodsCount(fursType);
final GoodsContainer gc = caravel.getGoodsContainer();
final int numberOfFurs = gc.getGoodsCount(fursType);
assertEquals(110, numberOfFurs);
}
}

0 comments on commit 274310a

Please sign in to comment.