Add upgrade support to SupportPower.
This commit is contained in:
@@ -12,7 +12,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
public abstract class SupportPowerInfo : ITraitInfo
|
public abstract class SupportPowerInfo : UpgradableTraitInfo, ITraitInfo
|
||||||
{
|
{
|
||||||
[Desc("Measured in seconds.")]
|
[Desc("Measured in seconds.")]
|
||||||
public readonly int ChargeTime = 0;
|
public readonly int ChargeTime = 0;
|
||||||
@@ -53,15 +53,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
|
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SupportPower
|
public class SupportPower : UpgradableTrait<SupportPowerInfo>
|
||||||
{
|
{
|
||||||
public readonly Actor Self;
|
public readonly Actor Self;
|
||||||
public readonly SupportPowerInfo Info;
|
|
||||||
protected RadarPing ping;
|
protected RadarPing ping;
|
||||||
|
|
||||||
public SupportPower(Actor self, SupportPowerInfo info)
|
public SupportPower(Actor self, SupportPowerInfo info)
|
||||||
|
: base(info)
|
||||||
{
|
{
|
||||||
Info = info;
|
|
||||||
Self = self;
|
Self = self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!Powers.TryGetValue(key, out sp))
|
if (!Powers.TryGetValue(key, out sp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sp.Disabled = false;
|
sp.PrerequisitesAvailable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PrerequisitesUnavailable(string key)
|
public void PrerequisitesUnavailable(string key)
|
||||||
@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!Powers.TryGetValue(key, out sp))
|
if (!Powers.TryGetValue(key, out sp))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sp.Disabled = true;
|
sp.PrerequisitesAvailable(false);
|
||||||
sp.RemainingTime = sp.TotalTime;
|
sp.RemainingTime = sp.TotalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,17 +158,25 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public int RemainingTime;
|
public int RemainingTime;
|
||||||
public int TotalTime;
|
public int TotalTime;
|
||||||
public bool Active { get; private set; }
|
public bool Active { get; private set; }
|
||||||
public bool Disabled { get; set; }
|
public bool Disabled { get { return !prereqsAvailable || !upgradeAvailable; } }
|
||||||
|
|
||||||
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
|
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
|
||||||
public bool Ready { get { return Active && RemainingTime == 0; } }
|
public bool Ready { get { return Active && RemainingTime == 0; } }
|
||||||
|
|
||||||
|
bool upgradeAvailable;
|
||||||
|
bool prereqsAvailable = true;
|
||||||
|
|
||||||
public SupportPowerInstance(string key, SupportPowerManager manager)
|
public SupportPowerInstance(string key, SupportPowerManager manager)
|
||||||
{
|
{
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.key = key;
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PrerequisitesAvailable(bool available)
|
||||||
|
{
|
||||||
|
prereqsAvailable = available;
|
||||||
|
}
|
||||||
|
|
||||||
static bool InstanceDisabled(SupportPower sp)
|
static bool InstanceDisabled(SupportPower sp)
|
||||||
{
|
{
|
||||||
return sp.Self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
return sp.Self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
||||||
@@ -178,6 +186,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool notifiedReady;
|
bool notifiedReady;
|
||||||
public void Tick()
|
public void Tick()
|
||||||
{
|
{
|
||||||
|
upgradeAvailable = Instances.Any(i => !i.IsTraitDisabled);
|
||||||
|
if (!upgradeAvailable)
|
||||||
|
RemainingTime = TotalTime;
|
||||||
|
|
||||||
Active = !Disabled && Instances.Any(i => !i.Self.IsDisabled());
|
Active = !Disabled && Instances.Any(i => !i.Self.IsDisabled());
|
||||||
if (!Active)
|
if (!Active)
|
||||||
return;
|
return;
|
||||||
@@ -226,7 +238,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
notifiedCharging = notifiedReady = false;
|
notifiedCharging = notifiedReady = false;
|
||||||
|
|
||||||
if (Info.OneShot)
|
if (Info.OneShot)
|
||||||
Disabled = true;
|
PrerequisitesAvailable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user