Skip to content

Commit

Permalink
Allow capture or destruction of enemy infrastructure on unowned water…
Browse files Browse the repository at this point in the history
…. (redrum)

git-svn-id: https://svn.code.sf.net/p/triplea/code/trunk/triplea@4321 a4c711aa-641f-0410-879d-9b464e52b682
  • Loading branch information
veqryn committed Jun 1, 2015
1 parent a832280 commit 1d18e9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
@@ -1,4 +1,6 @@
Changes for 1.8.0.7
* Allow capture or destruction of enemy infrastructure on unowned water. (redrum)

* Fixed bug with movement validation for fighters launching from a carrier and flying into enemy land territory then returning. (veqryn)

* Bug fixes on unit casualty sorters, and switching approximate method in as the default. (veqryn)
Expand Down
63 changes: 33 additions & 30 deletions src/games/strategy/triplea/delegate/BattleTracker.java
Expand Up @@ -65,10 +65,10 @@
import java.util.Set;

/**
*
*
* @author Sean Bridges
* @version 1.0
*
*
* Used to keep track of where battles have occurred
*/
public class BattleTracker implements java.io.Serializable
Expand Down Expand Up @@ -355,7 +355,7 @@ private void markWasInCombat(final Collection<Unit> units, final IDelegateBridge
{
addBombingBattle(route, units, attacker, data, null);
}*/

private void addBombingBattle(final Route route, final Collection<Unit> units, final PlayerID attacker, final GameData data, final HashMap<Unit, HashSet<Unit>> targets)
{
IBattle battle = getPendingBattle(route.getEnd(), true, BattleType.BOMBING_RAID);
Expand Down Expand Up @@ -436,7 +436,8 @@ private void addEmptyBattle(final Route route, final Collection<Unit> units, fin
final CompositeMatch<Territory> conquerable = new CompositeMatchAnd<Territory>();
conquerable.add(Matches.territoryIsEmptyOfCombatUnits(data, id));
conquerable.add(new CompositeMatchOr<Territory>(Matches.territoryIsOwnedByPlayerWhosRelationshipTypeCanTakeOverOwnedTerritoryAndPassableAndNotWater(id),
Matches.isTerritoryEnemyAndNotUnownedWaterOrImpassibleOrRestricted(id, data)));
// Matches.isTerritoryEnemyAndNotUnownedWaterOrImpassibleOrRestricted(id, data),
new CompositeMatchAnd<Territory>(Matches.isTerritoryEnemy(id, data), Matches.TerritoryIsPassableAndNotRestricted(id, data))));
final Collection<Territory> conquered = new ArrayList<Territory>();
if (canConquerMiddleSteps)
{
Expand Down Expand Up @@ -545,9 +546,7 @@ private void addEmptyBattle(final Route route, final Collection<Unit> units, fin

public void takeOver(final Territory territory, final PlayerID id, final IDelegateBridge bridge, final UndoableMove changeTracker, final Collection<Unit> arrivingUnits)
{
final TerritoryAttachment ta = TerritoryAttachment.get(territory);
if (ta == null)
return;
final TerritoryAttachment ta = TerritoryAttachment.get(territory); // This could be NULL if unowned water
final GameData data = bridge.getData();
final Collection<Unit> arrivedUnits = (arrivingUnits == null ? null : new ArrayList<Unit>(arrivingUnits));
// final OriginalOwnerTracker origOwnerTracker = DelegateFinder.battleDelegate(data).getOriginalOwnerTracker();
Expand Down Expand Up @@ -575,7 +574,7 @@ public void takeOver(final Territory territory, final PlayerID id, final IDelega
return;
}
// If it was a Convoy Route- check ownership of the associated neighboring territory and set message
if (ta.getConvoyRoute())
if (ta != null && ta.getConvoyRoute())
{
// we could be part of a convoy route for another territory
final Collection<Territory> attachedConvoyTo = TerritoryAttachment.getWhatTerritoriesThisIsUsedInConvoysFor(territory, data);
Expand Down Expand Up @@ -624,7 +623,7 @@ else if (relationshipTracker.isAtWar(id, convoyOwner))
}
// if its a capital we take the money
// NOTE: this is not checking to see if it is an enemy. instead it is relying on the fact that the capital should be owned by the person it is attached to
if (isTerritoryOwnerAnEnemy && ta.getCapital() != null)
if (ta != null && isTerritoryOwnerAnEnemy && ta.getCapital() != null)
{
// if the capital is owned by the capitols player
// take the money
Expand Down Expand Up @@ -705,7 +704,7 @@ else if (whoseCapital.equals(territory.getOwner()))
}
}
// if we have specially set this territory to have whenCapturedByGoesTo, then we set that here (except we don't set it if we are liberating allied owned territory)
if (isTerritoryOwnerAnEnemy && newOwner.equals(id) && Matches.TerritoryHasWhenCapturedByGoesTo().match(territory))
if (ta != null && isTerritoryOwnerAnEnemy && newOwner.equals(id) && Matches.TerritoryHasWhenCapturedByGoesTo().match(territory))
{
for (final String value : ta.getWhenCapturedByGoesTo())
{
Expand All @@ -721,25 +720,25 @@ else if (whoseCapital.equals(territory.getOwner()))
}
}
}
if (isTerritoryOwnerAnEnemy)
if (isTerritoryOwnerAnEnemy && ta != null)
{
final Change takeOver = ChangeFactory.changeOwner(territory, newOwner);
bridge.getHistoryWriter().addChildToEvent(takeOver.toString());
bridge.addChange(takeOver);
if (changeTracker != null)
{
changeTracker.addChange(takeOver);
changeTracker.addToConquered(territory);
}
// play a sound
if (territory.isWater())
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_TERRITORY_CAPTURE_SEA, id.getName());
else if (ta.getCapital() != null)
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_TERRITORY_CAPTURE_SEA, id.getName()); // should probably see if there is something actually happening for water
else if (ta != null && ta.getCapital() != null)
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_TERRITORY_CAPTURE_CAPITAL, id.getName());
else if (m_blitzed.contains(territory) && Match.someMatch(arrivedUnits, Matches.UnitCanBlitz))
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_TERRITORY_CAPTURE_BLITZ, id.getName());
else
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_TERRITORY_CAPTURE_LAND, id.getName());
if (changeTracker != null)
{
changeTracker.addChange(takeOver);
changeTracker.addToConquered(territory);
}
}
// Remove any bombing raids against captured territory
// TODO: see if necessary
Expand All @@ -758,7 +757,8 @@ else if (m_blitzed.contains(territory) && Match.someMatch(arrivedUnits, Matches.
captureOrDestroyUnits(territory, id, newOwner, bridge, changeTracker, arrivedUnits);
// is this territory our capitol or a capitol of our ally
// Also check to make sure playerAttachment even HAS a capital to fix abend
if (isTerritoryOwnerAnEnemy && terrOrigOwner != null && ta.getCapital() != null && TerritoryAttachment.getAllCapitals(terrOrigOwner, data).contains(territory)
if (isTerritoryOwnerAnEnemy && terrOrigOwner != null && ta != null && ta.getCapital() != null
&& TerritoryAttachment.getAllCapitals(terrOrigOwner, data).contains(territory)
&& relationshipTracker.isAllied(terrOrigOwner, id))
{
// if it is give it back to the original owner
Expand Down Expand Up @@ -888,15 +888,18 @@ public static void captureOrDestroyUnits(final Territory territory, final Player
}
}
}
// FYI: a dummy delegate will not do anything with this change, meaning that the battle calculator will think this unit lived even though it died or was captured, etc!
final Change capture = ChangeFactory.changeOwner(nonCom, newOwner, territory);
bridge.addChange(capture);
if (changeTracker != null)
changeTracker.addChange(capture);
final Change noMovementChange = ChangeFactory.markNoMovementChange(nonCom);
bridge.addChange(noMovementChange);
if (changeTracker != null)
changeTracker.addChange(noMovementChange);
if (!nonCom.isEmpty())
{
// FYI: a dummy delegate will not do anything with this change, meaning that the battle calculator will think this unit lived even though it died or was captured, etc!
final Change capture = ChangeFactory.changeOwner(nonCom, newOwner, territory);
bridge.addChange(capture);
if (changeTracker != null)
changeTracker.addChange(capture);
final Change noMovementChange = ChangeFactory.markNoMovementChange(nonCom);
bridge.addChange(noMovementChange);
if (changeTracker != null)
changeTracker.addChange(noMovementChange);
}
}

private Change addMustFightBattleChange(final Route route, final Collection<Unit> units, final PlayerID id, final GameData data)
Expand Down Expand Up @@ -1092,7 +1095,7 @@ public void removeBattle(final IBattle battle)
/**
* Marks the set of territories as having been the source of a naval
* bombardment.
*
*
* @param territories
* a collection of territories
*/
Expand Down Expand Up @@ -1224,5 +1227,5 @@ private void addNeutralBattle(Route route, Collection<Unit> units, final PlayerI
}
}
}
*/
*/
}

0 comments on commit 1d18e9d

Please sign in to comment.