Remove RearmBuildings from Aircraft and Minelayer
In favor of using Rearmable trait.
This commit is contained in:
@@ -36,9 +36,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("The speed at which the aircraft is repulsed from other aircraft. Specify -1 for normal movement speed.")]
|
||||
public readonly int RepulsionSpeed = -1;
|
||||
|
||||
[ActorReference]
|
||||
public readonly HashSet<string> RearmBuildings = new HashSet<string> { };
|
||||
|
||||
public readonly int InitialFacing = 0;
|
||||
|
||||
public readonly int TurnSpeed = 255;
|
||||
@@ -155,6 +152,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly Actor self;
|
||||
|
||||
RepairableInfo repairableInfo;
|
||||
RearmableInfo rearmableInfo;
|
||||
ConditionManager conditionManager;
|
||||
IDisposable reservation;
|
||||
IEnumerable<int> speedModifiers;
|
||||
@@ -211,6 +209,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
protected virtual void Created(Actor self)
|
||||
{
|
||||
repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>();
|
||||
rearmableInfo = self.Info.TraitInfoOrDefault<RearmableInfo>();
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
speedModifiers = self.TraitsImplementing<ISpeedModifier>().ToArray().Select(sm => sm.GetSpeedModifier());
|
||||
cachedPosition = self.CenterPosition;
|
||||
@@ -450,7 +449,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.AppearsHostileTo(a))
|
||||
return false;
|
||||
|
||||
return Info.RearmBuildings.Contains(a.Info.Name)
|
||||
return (rearmableInfo != null && rearmableInfo.RearmActors.Contains(a.Info.Name))
|
||||
|| (repairableInfo != null && repairableInfo.RepairBuildings.Contains(a.Info.Name));
|
||||
}
|
||||
|
||||
@@ -487,7 +486,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public virtual IEnumerable<Activity> GetResupplyActivities(Actor a)
|
||||
{
|
||||
var name = a.Info.Name;
|
||||
if (Info.RearmBuildings.Contains(name))
|
||||
if (rearmableInfo != null && rearmableInfo.RearmActors.Contains(name))
|
||||
yield return new Rearm(self, a, WDist.Zero);
|
||||
|
||||
// The ResupplyAircraft activity guarantees that we're on the helipad
|
||||
@@ -669,13 +668,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
Order IIssueDeployOrder.IssueDeployOrder(Actor self, bool queued)
|
||||
{
|
||||
if (!Info.RearmBuildings.Any())
|
||||
if (rearmableInfo == null || !rearmableInfo.RearmActors.Any())
|
||||
return null;
|
||||
|
||||
return new Order("ReturnToBase", self, queued);
|
||||
}
|
||||
|
||||
bool IIssueDeployOrder.CanIssueDeployOrder(Actor self) { return Info.RearmBuildings.Any(); }
|
||||
bool IIssueDeployOrder.CanIssueDeployOrder(Actor self) { return rearmableInfo != null && rearmableInfo.RearmActors.Any(); }
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
@@ -689,7 +688,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
case "Stop":
|
||||
return Info.Voice;
|
||||
case "ReturnToBase":
|
||||
return Info.RearmBuildings.Any() ? Info.Voice : null;
|
||||
return rearmableInfo != null && rearmableInfo.RearmActors.Any() ? Info.Voice : null;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
@@ -782,7 +781,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.QueueActivity(new HeliLand(self, true));
|
||||
}
|
||||
}
|
||||
else if (order.OrderString == "ReturnToBase" && Info.RearmBuildings.Any())
|
||||
else if (order.OrderString == "ReturnToBase" && rearmableInfo != null && rearmableInfo.RearmActors.Any())
|
||||
{
|
||||
UnReserve();
|
||||
self.CancelActivity();
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Return to a player owned RearmBuildings. If none available, head back to base and circle over it.")]
|
||||
[Desc("Return to a player owned RearmActor. If none available, head back to base and circle over it.")]
|
||||
public class ReturnOnIdleInfo : ITraitInfo, Requires<AircraftInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new ReturnOnIdle(init.Self, this); }
|
||||
|
||||
@@ -97,15 +97,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return true;
|
||||
}
|
||||
|
||||
// This mostly serves to avoid complicated ReloadAmmoPool look-ups in various other places.
|
||||
// TODO: Investigate removing this when the Rearm activity is replaced with a condition-based solution.
|
||||
public bool AutoReloads { get; private set; }
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
conditionManager = self.TraitOrDefault<ConditionManager>();
|
||||
AutoReloads = self.TraitsImplementing<ReloadAmmoPool>().Any(r => r.Info.AmmoPool == Info.Name && r.Info.RequiresCondition == null);
|
||||
|
||||
UpdateCondition(self);
|
||||
|
||||
// HACK: Temporarily needed until Rearm activity is gone for good
|
||||
|
||||
@@ -32,19 +32,23 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public virtual object Create(ActorInitializer init) { return new Repairable(init.Self, this); }
|
||||
}
|
||||
|
||||
class Repairable : IIssueOrder, IResolveOrder, IOrderVoice
|
||||
class Repairable : IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated
|
||||
{
|
||||
public readonly RepairableInfo Info;
|
||||
readonly IHealth health;
|
||||
readonly IMove movement;
|
||||
readonly AmmoPool[] ammoPools;
|
||||
Rearmable rearmable;
|
||||
|
||||
public Repairable(Actor self, RepairableInfo info)
|
||||
{
|
||||
Info = info;
|
||||
health = self.Trait<IHealth>();
|
||||
movement = self.Trait<IMove>();
|
||||
ammoPools = self.TraitsImplementing<AmmoPool>().ToArray();
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
rearmable = self.TraitOrDefault<Rearmable>();
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
@@ -70,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool CanRearmAt(Actor target)
|
||||
{
|
||||
return Info.RepairBuildings.Contains(target.Info.Name);
|
||||
return rearmable != null && rearmable.Info.RearmActors.Contains(target.Info.Name);
|
||||
}
|
||||
|
||||
bool CanRepair()
|
||||
@@ -80,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool CanRearm()
|
||||
{
|
||||
return ammoPools.Any(x => !x.AutoReloads && !x.FullAmmo());
|
||||
return rearmable != null && rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
|
||||
}
|
||||
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
|
||||
Reference in New Issue
Block a user