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";
[UpgradeGrantedReference]
[Desc("The upgrades to grant to self while loading cargo.")]
public readonly string[] LoadingUpgrades = { };
[Desc("The condition to grant to self while waiting for cargo to load.")]
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); }
}
@@ -69,6 +74,7 @@ namespace OpenRA.Mods.Common.Traits
readonly Actor self;
readonly Stack<Actor> cargo = new Stack<Actor>();
readonly HashSet<Actor> reserves = new HashSet<Actor>();
readonly Dictionary<string, Stack<int>> passengerTokens = new Dictionary<string, Stack<int>>();
readonly Lazy<IFacing> facing;
readonly bool checkTerrainType;
@@ -76,6 +82,7 @@ namespace OpenRA.Mods.Common.Traits
int reservedWeight = 0;
Aircraft aircraft;
UpgradeManager upgradeManager;
int loadingToken = UpgradeManager.InvalidConditionToken;
CPos currentCell;
public IEnumerable<CPos> CurrentAdjacentCells { get; private set; }
@@ -193,9 +200,8 @@ namespace OpenRA.Mods.Common.Traits
if (!HasSpace(w))
return false;
if (reserves.Count == 0)
foreach (var u in Info.LoadingUpgrades)
upgradeManager.GrantUpgrade(self, u, this);
if (upgradeManager != null && loadingToken == UpgradeManager.InvalidConditionToken && !string.IsNullOrEmpty(Info.LoadingCondition))
loadingToken = upgradeManager.GrantCondition(self, Info.LoadingCondition);
reserves.Add(a);
reservedWeight += w;
@@ -211,9 +217,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= GetWeight(a);
reserves.Remove(a);
if (reserves.Count == 0)
foreach (var u in Info.LoadingUpgrades)
upgradeManager.RevokeUpgrade(self, u, this);
if (loadingToken != UpgradeManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
}
public string CursorForOrder(Actor self, Order order)
@@ -251,8 +256,9 @@ namespace OpenRA.Mods.Common.Traits
var p = a.Trait<Passenger>();
p.Transport = null;
foreach (var u in p.Info.GrantUpgrades)
upgradeManager.RevokeUpgrade(self, u, p);
Stack<int> passengerToken;
if (passengerTokens.TryGetValue(a.Info.Name, out passengerToken) && passengerToken.Any())
upgradeManager.RevokeCondition(self, passengerToken.Pop());
return a;
}
@@ -304,9 +310,8 @@ namespace OpenRA.Mods.Common.Traits
reservedWeight -= w;
reserves.Remove(a);
if (reserves.Count == 0)
foreach (var u in Info.LoadingUpgrades)
upgradeManager.RevokeUpgrade(self, u, this);
if (loadingToken != UpgradeManager.InvalidConditionToken)
loadingToken = upgradeManager.RevokeCondition(self, loadingToken);
}
// 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>();
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)

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).")]
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";
public object Create(ActorInitializer init) { return new Passenger(this); }

View File

@@ -574,6 +574,16 @@ namespace OpenRA.Mods.Common.UtilityCommands
RenameNodeKey(node, "ProximityExternalCondition");
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);