mirror of https://github.com/FreeCol/freecol.git
Owned unit removal still failing.
This commit is contained in:
parent
dd7d7415f1
commit
a4d0e2b6a4
|
@ -1184,7 +1184,7 @@ public class DebugUtils {
|
|||
lb.add("\n");
|
||||
}
|
||||
lb.add("\nUnits owned\n");
|
||||
for (Unit u : sis.getOwnedUnits()) {
|
||||
for (Unit u : sis.getOwnedUnitList()) {
|
||||
Mission m = aiMain.getAIUnit(u).getMission();
|
||||
lb.add(u, " at ", u.getLocation());
|
||||
if (m != null) {
|
||||
|
|
|
@ -191,10 +191,6 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
* @param unit The {@code Unit} to be added.
|
||||
*/
|
||||
public void addOwnedUnit(Unit unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Parameter 'unit' must not be 'null'.");
|
||||
}
|
||||
|
||||
synchronized (this.ownedUnits) {
|
||||
if (!this.ownedUnits.contains(unit)) {
|
||||
this.ownedUnits.add(unit);
|
||||
|
@ -207,7 +203,7 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
*
|
||||
* @return The list of units native to this settlement.
|
||||
*/
|
||||
public List<Unit> getOwnedUnits() {
|
||||
public List<Unit> getOwnedUnitList() {
|
||||
synchronized (this.ownedUnits) {
|
||||
return new ArrayList<>(this.ownedUnits);
|
||||
}
|
||||
|
@ -232,9 +228,6 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
* @return a {@code boolean} value
|
||||
*/
|
||||
public boolean removeOwnedUnit(Unit unit) {
|
||||
if (unit == null) {
|
||||
throw new IllegalArgumentException("Parameter 'unit' must not be 'null'.");
|
||||
}
|
||||
synchronized (this.ownedUnits) {
|
||||
return this.ownedUnits.remove(unit);
|
||||
}
|
||||
|
@ -828,7 +821,7 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
unitType, spec.getMilitaryRolesList());
|
||||
|
||||
if (type.getMilitary()) { // Retain enough goods to fully arm
|
||||
return sum(getOwnedUnits(),
|
||||
return sum(getOwnedUnitList(),
|
||||
u -> !militaryRoles.contains(u.getRole()),
|
||||
u -> AbstractGoods.getCount(type,
|
||||
u.getGoodsDifference(first(militaryRoles), 1)));
|
||||
|
@ -1134,7 +1127,7 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
public void disposeResources() {
|
||||
// Orphan the units whose home settlement this is.
|
||||
while (!ownedUnits.isEmpty()) {
|
||||
ownedUnits.remove(0).setHomeIndianSettlement(null);
|
||||
ownedUnits.remove(0).changeHomeIndianSettlement(null);
|
||||
}
|
||||
super.disposeResources();
|
||||
}
|
||||
|
@ -1173,7 +1166,7 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
Unit indian = (Unit)locatable;
|
||||
if (indian.getHomeIndianSettlement() == null) {
|
||||
// Adopt homeless Indians
|
||||
indian.setHomeIndianSettlement(this);
|
||||
indian.changeHomeIndianSettlement(this);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -1685,8 +1678,10 @@ public class IndianSettlement extends Settlement implements TradeLocation {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(64);
|
||||
sb.append(getName()).append(" at (").append(tile.getX())
|
||||
.append(',').append(tile.getY()).append(')');
|
||||
Tile tile = getTile();
|
||||
sb.append(getName());
|
||||
if (tile != null) sb.append(" at (").append(tile.getX())
|
||||
.append(',').append(tile.getY()).append(')');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1509,10 +1509,20 @@ public class Unit extends GoodsLocation
|
|||
/**
|
||||
* Sets the home {@code IndianSettlement} for this unit.
|
||||
*
|
||||
* @param indianSettlement The {@code IndianSettlement} that should
|
||||
* now own this {@code Unit}.
|
||||
* @param indianSettlement The {@code IndianSettlement} that this unit
|
||||
* considers to be its home.
|
||||
*/
|
||||
public void setHomeIndianSettlement(IndianSettlement indianSettlement) {
|
||||
this.indianSettlement = indianSettlement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the home {@code IndianSettlement} for this unit.
|
||||
*
|
||||
* @param indianSettlement The {@code IndianSettlement} that should
|
||||
* now own this {@code Unit} and be considered this unit's home.
|
||||
*/
|
||||
public void changeHomeIndianSettlement(IndianSettlement indianSettlement) {
|
||||
if (this.indianSettlement != null) {
|
||||
this.indianSettlement.removeOwnedUnit(this);
|
||||
}
|
||||
|
@ -3740,28 +3750,22 @@ public class Unit extends GoodsLocation
|
|||
* on a carrier.
|
||||
*
|
||||
* @param tile The {@code Tile} the unit appears at.
|
||||
* @param player The {@code Player} the copy is for.
|
||||
* @return This {@code Unit} with reduced visibility.
|
||||
*/
|
||||
public Unit reduceVisibility(Tile tile) {
|
||||
public Unit reduceVisibility(Tile tile, Player player) {
|
||||
final Game game = getGame();
|
||||
Unit ret = null;
|
||||
Unit ret = this.copy(game, player);
|
||||
if (isOnCarrier()) {
|
||||
Unit carrier = getCarrier().copy(game);
|
||||
for (Unit u : carrier.getUnitList()) {
|
||||
if (u.getId().equals(getId())) {
|
||||
ret = u;
|
||||
} else {
|
||||
carrier.remove(u);
|
||||
}
|
||||
}
|
||||
carrier.removeAll(); // Goods!
|
||||
Unit carrier = getCarrier().copy(game, player);
|
||||
carrier.removeAll();
|
||||
carrier.add(ret);
|
||||
carrier.setLocationNoUpdate(tile);
|
||||
ret.setLocationNoUpdate(carrier);
|
||||
} else {
|
||||
ret = this.copy(game);
|
||||
ret.setLocationNoUpdate(tile);
|
||||
ret.setWorkType(null);
|
||||
ret.setState(Unit.UnitState.ACTIVE);
|
||||
if (isOwnerHidden()) ret.setOwner(game.getUnknownEnemy());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -4126,7 +4130,7 @@ public class Unit extends GoodsLocation
|
|||
student = null;
|
||||
}
|
||||
|
||||
setHomeIndianSettlement(null);
|
||||
changeHomeIndianSettlement(null);
|
||||
|
||||
getOwner().removeUnit(this);
|
||||
|
||||
|
|
|
@ -345,7 +345,7 @@ public class ChangeSet {
|
|||
* Build a new AttackChange.
|
||||
*
|
||||
* Note that we must copy attackers and defenders because a
|
||||
* successful attacker can move, any an unsuccessful
|
||||
* successful attacker can move, and an unsuccessful
|
||||
* participant can die, and unsuccessful defenders can be
|
||||
* captured. Furthermore for defenders, insufficient
|
||||
* information is serialized when a unit is inside a
|
||||
|
@ -429,9 +429,9 @@ public class ChangeSet {
|
|||
public DOMMessage toMessage(ServerPlayer serverPlayer) {
|
||||
if (!isNotifiable(serverPlayer)) return null;
|
||||
Unit a = (serverPlayer.owns(attacker)) ? attacker
|
||||
: attacker.reduceVisibility(attacker.getTile());
|
||||
: attacker.reduceVisibility(attacker.getTile(), serverPlayer);
|
||||
Unit d = (serverPlayer.owns(defender)) ? defender
|
||||
: defender.reduceVisibility(defender.getTile());
|
||||
: defender.reduceVisibility(defender.getTile(), serverPlayer);
|
||||
return new AnimateAttackMessage(a, d, success,
|
||||
!attackerVisible(serverPlayer), !defenderVisible(serverPlayer));
|
||||
}
|
||||
|
@ -697,7 +697,7 @@ public class ChangeSet {
|
|||
public DOMMessage toMessage(ServerPlayer serverPlayer) {
|
||||
if (!isNotifiable(serverPlayer)) return null;
|
||||
Unit u = (serverPlayer.owns(unit)) ? unit
|
||||
: unit.reduceVisibility(oldLocation.getTile());
|
||||
: unit.reduceVisibility(oldLocation.getTile(), serverPlayer);
|
||||
return new AnimateMoveMessage(u, oldLocation.getTile(), newTile,
|
||||
!seeOld(serverPlayer));
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ public class NativeAIPlayer extends MissionAIPlayer {
|
|||
// Collect native units and defenders
|
||||
List<Unit> units = is.getAllUnitsList();
|
||||
List<Unit> defenders = new ArrayList<>();
|
||||
for (Unit u : is.getOwnedUnits()) {
|
||||
for (Unit u : is.getOwnedUnitList()) {
|
||||
if (!units.contains(u)) units.add(u);
|
||||
}
|
||||
|
||||
|
@ -479,7 +479,7 @@ public class NativeAIPlayer extends MissionAIPlayer {
|
|||
// enough missions in operation.
|
||||
List<Unit> availableUnits = new ArrayList<>();
|
||||
int alreadyAssignedUnits = 0;
|
||||
for (Unit ou : is.getOwnedUnits()) {
|
||||
for (Unit ou : is.getOwnedUnitList()) {
|
||||
AIUnit aiu = getAIUnit(ou);
|
||||
if (aiu == null) {
|
||||
continue;
|
||||
|
@ -575,7 +575,7 @@ public class NativeAIPlayer extends MissionAIPlayer {
|
|||
// enough missions in operation.
|
||||
List<Unit> availableUnits = new ArrayList<>();
|
||||
int alreadyAssignedUnits = 0;
|
||||
for (Unit ou : is.getOwnedUnits()) {
|
||||
for (Unit ou : is.getOwnedUnitList()) {
|
||||
AIUnit aiu = getAIUnit(ou);
|
||||
if (Mission.invalidNewMissionReason(aiu) == null) {
|
||||
if (aiu.hasMission(IndianDemandMission.class)) {
|
||||
|
|
|
@ -215,7 +215,7 @@ public class ServerIndianSettlement extends IndianSettlement
|
|||
for (int i = 0; i < count; i++) {
|
||||
Unit unit = new ServerUnit(game, this, getOwner(), brave,
|
||||
brave.getDefaultRole());
|
||||
unit.setHomeIndianSettlement(this);
|
||||
unit.changeHomeIndianSettlement(this);
|
||||
unit.setLocation(this);
|
||||
}
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ public class ServerIndianSettlement extends IndianSettlement
|
|||
consumeGoods(rumType, FOOD_PER_COLONIST/4);
|
||||
// New units quickly go out of their city and start annoying.
|
||||
addOwnedUnit(unit);
|
||||
unit.setHomeIndianSettlement(this);
|
||||
unit.changeHomeIndianSettlement(this);
|
||||
lb.add(" new ", unit);
|
||||
}
|
||||
// Consume the food anyway
|
||||
|
|
|
@ -3216,8 +3216,8 @@ outer: for (Effect effect : effects) {
|
|||
int plunder = is.getPlunder(attacker, random);
|
||||
|
||||
// Remaining units lose their home.
|
||||
for (Unit u : is.getOwnedUnits()) {
|
||||
u.setHomeIndianSettlement(null);
|
||||
for (Unit u : is.getOwnedUnitList()) {
|
||||
u.changeHomeIndianSettlement(null);
|
||||
cs.add(See.only(nativePlayer), u);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,7 +201,7 @@ public class MissionAssignmentTest extends FreeColTestCase {
|
|||
// so that he may defend the settlement
|
||||
Unit braveOutside = new ServerUnit(game, settlementTile, inca,
|
||||
braveType);
|
||||
braveOutside.setHomeIndianSettlement(camp);
|
||||
braveOutside.changeHomeIndianSettlement(camp);
|
||||
|
||||
// Setup enemy units
|
||||
int enemyUnits = camp.getUnitCount() + 1;
|
||||
|
@ -209,7 +209,7 @@ public class MissionAssignmentTest extends FreeColTestCase {
|
|||
new ServerUnit(game, adjacentTile, dutch, veteranType);
|
||||
}
|
||||
|
||||
for (Unit brave : camp.getOwnedUnits()) {
|
||||
for (Unit brave : camp.getOwnedUnitList()) {
|
||||
assertNotNull("Got null while getting the camps units", brave);
|
||||
AIUnit aiUnit = aiMain.getAIUnit(brave);
|
||||
assertNotNull("Couldnt get the ai object for the brave", aiUnit);
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TensionTest extends FreeColTestCase {
|
|||
for (int i = 0; i < unitCount; i++) {
|
||||
UnitType unitType = spec().getDefaultUnitType(indian);
|
||||
Unit unit = new ServerUnit(game, is, indian, unitType);
|
||||
unit.setHomeIndianSettlement(is);
|
||||
unit.changeHomeIndianSettlement(is);
|
||||
if (i == 0) {
|
||||
unit.setLocation(tile);
|
||||
} else {
|
||||
|
|
|
@ -1363,7 +1363,7 @@ public class InGameControllerTest extends FreeColTestCase {
|
|||
dragoonRole);
|
||||
Unit brave = new ServerUnit(game, tile2, inca, braveType,
|
||||
spec().getDefaultRole());
|
||||
brave.setHomeIndianSettlement(settlement1);
|
||||
brave.changeHomeIndianSettlement(settlement1);
|
||||
|
||||
// Dragoon loses and brave captures its horses
|
||||
List<CombatResult> crs
|
||||
|
|
Loading…
Reference in New Issue