Convert Cargo to conditions.

This commit is contained in:
Paul Chote
2016-12-03 15:34:15 +00:00
parent ea46199cab
commit 45af024b15
12 changed files with 47 additions and 32 deletions

View File

@@ -56,8 +56,13 @@ namespace OpenRA.Mods.Common.Traits
public readonly string UnloadBlockedCursor = "deploy-blocked"; public readonly string UnloadBlockedCursor = "deploy-blocked";
[UpgradeGrantedReference] [UpgradeGrantedReference]
[Desc("The upgrades to grant to self while loading cargo.")] [Desc("The condition to grant to self while waiting for cargo to load.")]
public readonly string[] LoadingUpgrades = { }; public readonly string LoadingCondition = null;
[UpgradeGrantedReference]
[Desc("Conditions to grant when specified actors are loaded inside the transport.",
"A dictionary of [actor id]: [condition].")]
public readonly Dictionary<string, string> PassengerConditions = new Dictionary<string, string>();
public object Create(ActorInitializer init) { return new Cargo(init, this); } public object Create(ActorInitializer init) { return new Cargo(init, this); }
} }
@@ -69,6 +74,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self; readonly Actor self;
readonly Stack<Actor> cargo = new Stack<Actor>(); readonly Stack<Actor> cargo = new Stack<Actor>();
readonly HashSet<Actor> reserves = new HashSet<Actor>(); readonly HashSet<Actor> reserves = new HashSet<Actor>();
readonly Dictionary<string, Stack<int>> passengerTokens = new Dictionary<string, Stack<int>>();
readonly Lazy<IFacing> facing; readonly Lazy<IFacing> facing;
readonly bool checkTerrainType; readonly bool checkTerrainType;
@@ -76,6 +82,7 @@ namespace OpenRA.Mods.Common.Traits
int reservedWeight = 0; int reservedWeight = 0;
Aircraft aircraft; Aircraft aircraft;
UpgradeManager upgradeManager; UpgradeManager upgradeManager;
int loadingToken = UpgradeManager.InvalidConditionToken;
CPos currentCell; CPos currentCell;
public IEnumerable<CPos> CurrentAdjacentCells { get; private set; } public IEnumerable<CPos> CurrentAdjacentCells { get; private set; }
@@ -193,9 +200,8 @@ namespace OpenRA.Mods.Common.Traits
if (!HasSpace(w)) if (!HasSpace(w))
return false; return false;
if (reserves.Count == 0) if (upgradeManager != null && loadingToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition))
foreach (var u in Info.LoadingUpgrades) loadingToken = upgradeManager.GrantCondition(self, Info.LoadingCondition);
upgradeManager.GrantUpgrade(self, u, this);
reserves.Add(a); reserves.Add(a);
reservedWeight += w; reservedWeight += w;
@@ -211,9 +217,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= GetWeight(a); reservedWeight -= GetWeight(a);
reserves.Remove(a); reserves.Remove(a);
if (reserves.Count == 0) if (loadingToken != UpgradeManager.InvalidConditionToken)
foreach (var u in Info.LoadingUpgrades) loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
upgradeManager.RevokeUpgrade(self, u, this);
} }
public string CursorForOrder(Actor self, Order order) public string CursorForOrder(Actor self, Order order)
@@ -251,8 +256,9 @@ namespace OpenRA.Mods.Common.Traits
var p = a.Trait<Passenger>(); var p = a.Trait<Passenger>();
p.Transport = null; p.Transport = null;
foreach (var u in p.Info.GrantUpgrades) Stack<int> passengerToken;
upgradeManager.RevokeUpgrade(self, u, p); if (passengerTokens.TryGetValue(a.Info.Name, out passengerToken) && passengerToken.Any())
upgradeManager.RevokeCondition(self, passengerToken.Pop());
return a; return a;
} }
@@ -304,9 +310,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= w; reservedWeight -= w;
reserves.Remove(a); reserves.Remove(a);
if (reserves.Count == 0) if (loadingToken != UpgradeManager.InvalidConditionToken)
foreach (var u in Info.LoadingUpgrades) loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
upgradeManager.RevokeUpgrade(self, u, this);
} }
// If not initialized then this will be notified in the first tick // If not initialized then this will be notified in the first tick
@@ -316,8 +321,10 @@ namespace OpenRA.Mods.Common.Traits
var p = a.Trait<Passenger>(); var p = a.Trait<Passenger>();
p.Transport = self; p.Transport = self;
foreach (var u in p.Info.GrantUpgrades)
upgradeManager.GrantUpgrade(self, u, p); string passengerCondition;
if (upgradeManager != null && Info.PassengerConditions.TryGetValue(a.Info.Name, out passengerCondition))
passengerTokens.GetOrAdd(a.Info.Name).Push(upgradeManager.GrantCondition(self, passengerCondition));
} }
void INotifyKilled.Killed(Actor self, AttackInfo e) void INotifyKilled.Killed(Actor self, AttackInfo e)

View File

@@ -38,9 +38,6 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Range from self for looking for an alternate transport (default: 5.5 cells).")] [Desc("Range from self for looking for an alternate transport (default: 5.5 cells).")]
public readonly WDist AlternateTransportScanRange = WDist.FromCells(11) / 2; public readonly WDist AlternateTransportScanRange = WDist.FromCells(11) / 2;
[Desc("Upgrade types to grant to transport.")]
[UpgradeGrantedReference] public readonly string[] GrantUpgrades = { };
[VoiceReference] public readonly string Voice = "Action"; [VoiceReference] public readonly string Voice = "Action";
public object Create(ActorInitializer init) { return new Passenger(this); } public object Create(ActorInitializer init) { return new Passenger(this); }

View File

@@ -574,6 +574,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
RenameNodeKey(node, "ProximityExternalCondition"); RenameNodeKey(node, "ProximityExternalCondition");
ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition"); ConvertUpgradesToCondition(parent, node, "Upgrades", "Condition");
} }
if (node.Key == "Cargo")
ConvertUpgradesToCondition(parent, node, "LoadingUpgrades", "LoadingCondition");
if (node.Key == "Passenger" && node.Value.Nodes.Any(n => n.Key == "GrantUpgrades"))
{
Console.WriteLine("Passenger.GrantUpgrades support has been removed.");
Console.WriteLine("Define passenger-conditions using Cargo.PassengerConditions on the transports instead.");
node.Value.Nodes.RemoveAll(n => n.Key == "GrantUpgrades");
}
} }
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -76,4 +76,4 @@ LST:
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
PassengerFacing: 0 PassengerFacing: 0
LoadingUpgrades: notmobile LoadingCondition: notmobile

View File

@@ -120,7 +120,7 @@ APC:
Types: Infantry Types: Infantry
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
LoadingUpgrades: notmobile LoadingCondition: notmobile
SpawnActorOnDeath: SpawnActorOnDeath:
Actor: APC.Husk Actor: APC.Husk

View File

@@ -55,7 +55,6 @@ SPY.Strong:
ExternalCaptures: ExternalCaptures:
CaptureTypes: MissionObjective CaptureTypes: MissionObjective
Passenger: Passenger:
GrantUpgrades: mobile
DOG.Patrol: DOG.Patrol:
Inherits: DOG Inherits: DOG
@@ -76,6 +75,8 @@ TRUK.Hijackable:
Types: Infantry Types: Infantry
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
PassengerConditions:
spy.strong: mobile
AutoTargetIgnore: AutoTargetIgnore:
-Huntable: -Huntable:
ExternalCapturable: ExternalCapturable:

View File

@@ -242,7 +242,7 @@ LST:
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
PassengerFacing: 0 PassengerFacing: 0
LoadingUpgrades: notmobile LoadingCondition: notmobile
-Chronoshiftable: -Chronoshiftable:
PT: PT:

View File

@@ -355,7 +355,7 @@ JEEP:
Types: Infantry Types: Infantry
MaxWeight: 1 MaxWeight: 1
PipCount: 1 PipCount: 1
LoadingUpgrades: notmobile LoadingCondition: notmobile
ProducibleWithLevel: ProducibleWithLevel:
Prerequisites: vehicles.upgraded Prerequisites: vehicles.upgraded
@@ -391,7 +391,7 @@ APC:
Types: Infantry Types: Infantry
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
LoadingUpgrades: notmobile LoadingCondition: notmobile
ProducibleWithLevel: ProducibleWithLevel:
Prerequisites: vehicles.upgraded Prerequisites: vehicles.upgraded
@@ -752,7 +752,7 @@ STNK:
Types: Infantry Types: Infantry
MaxWeight: 4 MaxWeight: 4
PipCount: 4 PipCount: 4
LoadingUpgrades: notmobile LoadingCondition: notmobile
Cloak: Cloak:
InitialDelay: 125 InitialDelay: 125
CloakDelay: 250 CloakDelay: 250

View File

@@ -102,7 +102,7 @@ BUS:
MaxWeight: 20 MaxWeight: 20
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
PICK: PICK:
@@ -126,7 +126,7 @@ PICK:
MaxWeight: 2 MaxWeight: 2
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
CAR: CAR:
@@ -150,7 +150,7 @@ CAR:
MaxWeight: 4 MaxWeight: 4
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
WINI: WINI:
@@ -174,7 +174,7 @@ WINI:
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
LOCOMOTIVE: LOCOMOTIVE:

View File

@@ -802,7 +802,7 @@
Cargo: Cargo:
Types: Infantry Types: Infantry
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
Health: Health:
HP: 100 HP: 100
Armor: Armor:

View File

@@ -28,7 +28,7 @@ APC:
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
UpgradeOnTerrain: UpgradeOnTerrain:
Upgrades: inwater Upgrades: inwater

View File

@@ -285,7 +285,7 @@ SAPC:
MaxWeight: 5 MaxWeight: 5
PipCount: 5 PipCount: 5
UnloadVoice: Unload UnloadVoice: Unload
LoadingUpgrades: loading LoadingCondition: loading
EjectOnDeath: true EjectOnDeath: true
SUBTANK: SUBTANK: