mirror of https://github.com/FreeCol/freecol.git
Uses changeMission instead of setMission since the former handles dispose and setting transportation priority.
This commit is contained in:
parent
146923ee2e
commit
18ec0e754a
|
@ -677,7 +677,7 @@ public final class NativeAIPlayer extends MissionAIPlayer {
|
||||||
for (AIUnit au : getAIUnits()) {
|
for (AIUnit au : getAIUnits()) {
|
||||||
Mission mission = au.getMission();
|
Mission mission = au.getMission();
|
||||||
String reason = (mission == null) ? null : mission.invalidReason();
|
String reason = (mission == null) ? null : mission.invalidReason();
|
||||||
if (reason != null) au.setMission(null);
|
if (reason != null) au.changeMission(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,11 +205,11 @@ public final class MilitaryCoordinator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
artillery.setMission(new UnitSeekAndDestroyMission(artillery.getAIMain(), artillery, possibleTarget));
|
artillery.changeMission(new UnitSeekAndDestroyMission(artillery.getAIMain(), artillery, possibleTarget));
|
||||||
artilleryUnits.remove(artillery);
|
artilleryUnits.remove(artillery);
|
||||||
unusedUnits.remove(artillery);
|
unusedUnits.remove(artillery);
|
||||||
|
|
||||||
escort.setMission(new EscortUnitMission(escort.getAIMain(), escort, artillery.getUnit()));
|
escort.changeMission(new EscortUnitMission(escort.getAIMain(), escort, artillery.getUnit()));
|
||||||
dragoonUnits.remove(escort);
|
dragoonUnits.remove(escort);
|
||||||
unusedUnits.remove(escort);
|
unusedUnits.remove(escort);
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ public final class MilitaryCoordinator {
|
||||||
|
|
||||||
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
||||||
if (path != null && path.getTurns() <= turns) {
|
if (path != null && path.getTurns() <= turns) {
|
||||||
dragoon.setMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
dragoon.changeMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
||||||
unusedUnits.remove(dragoon);
|
unusedUnits.remove(dragoon);
|
||||||
dragoonUnits.remove(dragoon);
|
dragoonUnits.remove(dragoon);
|
||||||
targetedEnemies.add(enemy);
|
targetedEnemies.add(enemy);
|
||||||
|
@ -268,7 +268,7 @@ public final class MilitaryCoordinator {
|
||||||
|
|
||||||
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
||||||
if (path != null && path.getTurns() <= turns) {
|
if (path != null && path.getTurns() <= turns) {
|
||||||
dragoon.setMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
dragoon.changeMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
||||||
unusedUnits.remove(dragoon);
|
unusedUnits.remove(dragoon);
|
||||||
dragoonUnits.remove(dragoon);
|
dragoonUnits.remove(dragoon);
|
||||||
targetedEnemies.add(enemy);
|
targetedEnemies.add(enemy);
|
||||||
|
@ -296,7 +296,7 @@ public final class MilitaryCoordinator {
|
||||||
|
|
||||||
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
final PathNode path = dragoon.getUnit().findPath(enemy.getTile()); // TODO: add max turns to the search.
|
||||||
if (path != null && path.getTurns() <= turns) {
|
if (path != null && path.getTurns() <= turns) {
|
||||||
dragoon.setMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
dragoon.changeMission(new UnitSeekAndDestroyMission(dragoon.getAIMain(), dragoon, enemy));
|
||||||
unusedUnits.remove(dragoon);
|
unusedUnits.remove(dragoon);
|
||||||
dragoonUnits.remove(dragoon);
|
dragoonUnits.remove(dragoon);
|
||||||
targetedEnemies.add(enemy);
|
targetedEnemies.add(enemy);
|
||||||
|
@ -311,7 +311,7 @@ public final class MilitaryCoordinator {
|
||||||
for (AIUnit unit : new HashSet<>(unusedUnits)) {
|
for (AIUnit unit : new HashSet<>(unusedUnits)) {
|
||||||
final Mission mission = player.getDefendSettlementMission(unit, true, true);
|
final Mission mission = player.getDefendSettlementMission(unit, true, true);
|
||||||
if (mission != null) {
|
if (mission != null) {
|
||||||
unit.setMission(mission);
|
unit.changeMission(mission);
|
||||||
unusedUnits.remove(unit);
|
unusedUnits.remove(unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,7 @@ public final class MilitaryCoordinator {
|
||||||
if (unit.getUnit().getTile() != null) {
|
if (unit.getUnit().getTile() != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
unit.setMission(new DefendSettlementMission(unit.getAIMain(), unit, destination.getColony()));
|
unit.changeMission(new DefendSettlementMission(unit.getAIMain(), unit, destination.getColony()));
|
||||||
unusedUnits.remove(unit);
|
unusedUnits.remove(unit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -357,15 +357,14 @@ public final class MilitaryCoordinator {
|
||||||
|
|
||||||
private void assignWanderHostile() {
|
private void assignWanderHostile() {
|
||||||
for (AIUnit unit : new HashSet<>(unusedUnits)) {
|
for (AIUnit unit : new HashSet<>(unusedUnits)) {
|
||||||
unit.setMission(new UnitWanderHostileMission(unit.getAIMain(), unit));
|
unit.changeMission(new UnitWanderHostileMission(unit.getAIMain(), unit));
|
||||||
unusedUnits.remove(unit);
|
unusedUnits.remove(unit);
|
||||||
}
|
}
|
||||||
assert unusedUnits.isEmpty();
|
assert unusedUnits.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void placeDefender(AIUnit unit, AIColony colony) {
|
private void placeDefender(AIUnit unit, AIColony colony) {
|
||||||
unit.setMission(null);
|
unit.changeMission(new DefendSettlementMission(unit.getAIMain(), unit, colony.getColony()));
|
||||||
unit.setMission(new DefendSettlementMission(unit.getAIMain(), unit, colony.getColony()));
|
|
||||||
final List<AIUnit> units = defenders.get(colony);
|
final List<AIUnit> units = defenders.get(colony);
|
||||||
units.add(unit);
|
units.add(unit);
|
||||||
unusedUnits.remove(unit);
|
unusedUnits.remove(unit);
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class MissionAssignmentTest extends FreeColTestCase {
|
||||||
assertTrue(colonyTile.getSettlement() == colony);
|
assertTrue(colonyTile.getSettlement() == colony);
|
||||||
assertTrue(colony.getOwner() == dutch);
|
assertTrue(colony.getOwner() == dutch);
|
||||||
assertTrue(colony.getUnitCount() == 1);
|
assertTrue(colony.getUnitCount() == 1);
|
||||||
aiUnit.setMission(null);
|
aiUnit.changeMission(null);
|
||||||
assertEquals("DefendSettlementMission should be possible", null,
|
assertEquals("DefendSettlementMission should be possible", null,
|
||||||
DefendSettlementMission.invalidMissionReason(aiUnit));
|
DefendSettlementMission.invalidMissionReason(aiUnit));
|
||||||
assertEquals("DefendSettlementMission should work with colony", null,
|
assertEquals("DefendSettlementMission should work with colony", null,
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class PioneeringMissionTest extends FreeColTestCase {
|
||||||
colonistType);
|
colonistType);
|
||||||
final AIUnit aiUnit = aiMain.getAIUnit(colonist);
|
final AIUnit aiUnit = aiMain.getAIUnit(colonist);
|
||||||
assertNotNull(aiUnit);
|
assertNotNull(aiUnit);
|
||||||
aiUnit.setMission(null);
|
aiUnit.changeMission(null);
|
||||||
|
|
||||||
// Check there are improvements to be made.
|
// Check there are improvements to be made.
|
||||||
aiColony.updateTileImprovementPlans(lb);
|
aiColony.updateTileImprovementPlans(lb);
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class PrivateerMissionTest extends FreeColTestCase {
|
||||||
AIUnit privateerAI = aiMain.getAIUnit(privateer);
|
AIUnit privateerAI = aiMain.getAIUnit(privateer);
|
||||||
assertNotNull("Setup error, could not get privateerAI", privateerAI);
|
assertNotNull("Setup error, could not get privateerAI", privateerAI);
|
||||||
|
|
||||||
privateerAI.setMission(null);
|
privateerAI.changeMission(null);
|
||||||
assertFalse("Privateer has no mission", privateerAI.hasMission());
|
assertFalse("Privateer has no mission", privateerAI.hasMission());
|
||||||
assertEquals("PrivateeringMission valid", null,
|
assertEquals("PrivateeringMission valid", null,
|
||||||
PrivateerMission.invalidMissionReason(privateerAI));
|
PrivateerMission.invalidMissionReason(privateerAI));
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class ScoutingMissionTest extends FreeColTestCase {
|
||||||
assertEquals(scoutRole, scout.getRole());
|
assertEquals(scoutRole, scout.getRole());
|
||||||
|
|
||||||
AIUnit aiUnit = aiMain.getAIUnit(scout);
|
AIUnit aiUnit = aiMain.getAIUnit(scout);
|
||||||
aiUnit.setMission(null);
|
aiUnit.changeMission(null);
|
||||||
assertNotNull("The scout should be an AI unit", aiUnit);
|
assertNotNull("The scout should be an AI unit", aiUnit);
|
||||||
assertEquals("Scout should have the scout role", scoutRole,
|
assertEquals("Scout should have the scout role", scoutRole,
|
||||||
scout.getRole());
|
scout.getRole());
|
||||||
|
|
|
@ -296,7 +296,7 @@ public class TransportMissionTest extends FreeColTestCase {
|
||||||
AIUnit wagon = aiMain.getAIUnit(wagonTrain);
|
AIUnit wagon = aiMain.getAIUnit(wagonTrain);
|
||||||
assertNotNull(wagon);
|
assertNotNull(wagon);
|
||||||
|
|
||||||
wagon.setMission(null);
|
wagon.changeMission(null);
|
||||||
assertNull("Transport mission should be valid.",
|
assertNull("Transport mission should be valid.",
|
||||||
TransportMission.invalidMissionReason(wagon));
|
TransportMission.invalidMissionReason(wagon));
|
||||||
TransportMission mission = new TransportMission(aiMain, wagon);
|
TransportMission mission = new TransportMission(aiMain, wagon);
|
||||||
|
|
Loading…
Reference in New Issue