Upgrade(s) while loading cargo
This commit is contained in:
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
[Desc("This actor can transport Passenger actors.")]
|
[Desc("This actor can transport Passenger actors.")]
|
||||||
public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>
|
public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>, Requires<UpgradeManagerInfo>
|
||||||
{
|
{
|
||||||
[Desc("The maximum sum of Passenger.Weight that this actor can support.")]
|
[Desc("The maximum sum of Passenger.Weight that this actor can support.")]
|
||||||
public readonly int MaxWeight = 0;
|
public readonly int MaxWeight = 0;
|
||||||
@@ -51,6 +51,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Cursor to display when unable to unload the passengers.")]
|
[Desc("Cursor to display when unable to unload the passengers.")]
|
||||||
public readonly string UnloadBlockedCursor = "deploy-blocked";
|
public readonly string UnloadBlockedCursor = "deploy-blocked";
|
||||||
|
|
||||||
|
[UpgradeGrantedReference]
|
||||||
|
[Desc("The upgrades to grant to self while loading cargo.")]
|
||||||
|
public readonly string[] LoadingUpgrades = { };
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new Cargo(init, this); }
|
public object Create(ActorInitializer init) { return new Cargo(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public readonly CargoInfo Info;
|
public readonly CargoInfo Info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
readonly UpgradeManager upgradeManager;
|
||||||
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 Lazy<IFacing> facing;
|
readonly Lazy<IFacing> facing;
|
||||||
@@ -80,6 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Info = info;
|
Info = info;
|
||||||
Unloading = false;
|
Unloading = false;
|
||||||
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
|
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
|
||||||
|
upgradeManager = self.Trait<UpgradeManager>();
|
||||||
|
|
||||||
if (init.Contains<RuntimeCargoInit>())
|
if (init.Contains<RuntimeCargoInit>())
|
||||||
{
|
{
|
||||||
@@ -183,6 +189,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!HasSpace(w))
|
if (!HasSpace(w))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (reserves.Count == 0)
|
||||||
|
foreach (var u in Info.LoadingUpgrades)
|
||||||
|
upgradeManager.GrantUpgrade(self, u, this);
|
||||||
|
|
||||||
reserves.Add(a);
|
reserves.Add(a);
|
||||||
reservedWeight += w;
|
reservedWeight += w;
|
||||||
|
|
||||||
@@ -196,6 +206,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
reservedWeight -= GetWeight(a);
|
reservedWeight -= GetWeight(a);
|
||||||
reserves.Remove(a);
|
reserves.Remove(a);
|
||||||
|
|
||||||
|
if (reserves.Count == 0)
|
||||||
|
foreach (var u in Info.LoadingUpgrades)
|
||||||
|
upgradeManager.RevokeUpgrade(self, u, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string CursorForOrder(Actor self, Order order)
|
public string CursorForOrder(Actor self, Order order)
|
||||||
@@ -235,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
p.Transport = null;
|
p.Transport = null;
|
||||||
|
|
||||||
foreach (var u in p.Info.GrantUpgrades)
|
foreach (var u in p.Info.GrantUpgrades)
|
||||||
self.Trait<UpgradeManager>().RevokeUpgrade(self, u, p);
|
upgradeManager.RevokeUpgrade(self, u, p);
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
@@ -287,6 +301,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
reservedWeight -= w;
|
reservedWeight -= w;
|
||||||
reserves.Remove(a);
|
reserves.Remove(a);
|
||||||
|
|
||||||
|
if (reserves.Count == 0)
|
||||||
|
foreach (var u in Info.LoadingUpgrades)
|
||||||
|
upgradeManager.RevokeUpgrade(self, u, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||||
@@ -295,7 +313,7 @@ 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)
|
foreach (var u in p.Info.GrantUpgrades)
|
||||||
self.Trait<UpgradeManager>().GrantUpgrade(self, u, p);
|
upgradeManager.GrantUpgrade(self, u, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
|
|||||||
Reference in New Issue
Block a user