From 97ce4766f3681a6ef77908a1adb3f5ccb3eb2659 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Thu, 16 Jul 2015 08:48:15 -0500 Subject: [PATCH] Grant upgrades while aircraft is airborne --- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 38 ++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index d5bbe680a2..57a146b5f3 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -46,22 +46,52 @@ namespace OpenRA.Mods.Common.Traits [VoiceReference] public readonly string Voice = "Action"; + [UpgradeGrantedReference] + [Desc("The upgrades to grant to self while airborne.")] + public readonly string[] AirborneUpgrades = { }; + public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary(); } bool IOccupySpaceInfo.SharesCell { get { return false; } } } - public class Aircraft : IFacing, IPositionable, ISync, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing + public class Aircraft : IFacing, IPositionable, ISync, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCreated, INotifyActorDisposing { static readonly Pair[] NoCells = { }; readonly AircraftInfo info; readonly Actor self; + UpgradeManager um; [Sync] public int Facing { get; set; } [Sync] public WPos CenterPosition { get; private set; } public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } } public IDisposable Reservation; public int ROT { get { return info.ROT; } } + bool IsAirborne + { + get + { + return airborne; + } + + set + { + if (airborne == value) + return; + airborne = value; + if (um != null) + { + if (airborne) + foreach (var u in info.AirborneUpgrades) + um.GrantUpgrade(self, u, this); + else + foreach (var u in info.AirborneUpgrades) + um.RevokeUpgrade(self, u, this); + } + } + } + + bool airborne = false; public Aircraft(ActorInitializer init, AircraftInfo info) { @@ -77,6 +107,8 @@ namespace OpenRA.Mods.Common.Traits Facing = init.Contains() ? init.Get() : info.InitialFacing; } + public void Created(Actor self) { um = self.TraitOrDefault(); } + bool firstTick = true; public virtual void Tick(Actor self) { @@ -197,6 +229,7 @@ namespace OpenRA.Mods.Common.Traits { self.World.ScreenMap.Update(self); self.World.ActorMap.UpdatePosition(self, this); + IsAirborne = self.World.Map.DistanceAboveTerrain(CenterPosition).Length > 0; } } @@ -213,6 +246,8 @@ namespace OpenRA.Mods.Common.Traits self.World.ActorMap.AddInfluence(self, this); self.World.ActorMap.AddPosition(self, this); self.World.ScreenMap.Add(self); + if (self.World.Map.DistanceAboveTerrain(CenterPosition).Length > 0) + IsAirborne = true; } public void RemovedFromWorld(Actor self) @@ -221,6 +256,7 @@ namespace OpenRA.Mods.Common.Traits self.World.ActorMap.RemoveInfluence(self, this); self.World.ActorMap.RemovePosition(self, this); self.World.ScreenMap.Remove(self); + IsAirborne = false; } public bool AircraftCanEnter(Actor a)