New special powers mechanism. Only cnc Airstrike has been reimplemented so far. Special power crates, and spy bonuses have also been disabled.

This commit is contained in:
Paul Chote
2010-12-05 11:53:42 +13:00
parent c6fad7fe98
commit 76f792bfdf
17 changed files with 366 additions and 252 deletions

View File

@@ -14,136 +14,40 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public abstract class SupportPowerInfo : ITraitInfo, ITraitPrerequisite<TechTreeInfo>, ITraitPrerequisite<PowerManagerInfo>
public abstract class SupportPowerInfo : ITraitInfo
{
public readonly bool RequiresPower = true;
public readonly bool OneShot = false;
public readonly float ChargeTime = 0;
public readonly int ChargeTime = 0;
public readonly string Image = null;
public readonly string Description = "";
public readonly string LongDesc = "";
[ActorReference]
public readonly string[] Prerequisites = { };
public readonly bool GivenAuto = true;
public readonly string OrderName;
public readonly string BeginChargeSound = null;
public readonly string EndChargeSound = null;
public readonly string SelectTargetSound = null;
public readonly string LaunchSound = null;
public readonly bool AllowMultiple = false;
public abstract object Create(ActorInitializer init);
public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
}
public class SupportPower : ITick, ITechTreeElement
public class SupportPower
{
public readonly Actor self;
public readonly SupportPowerInfo Info;
public int RemainingTime { get; private set; }
public int TotalTime { get { return (int)(Info.ChargeTime * 60 * 25); } }
public bool IsUsed;
public bool IsAvailable;
public bool IsReady { get { return IsAvailable && RemainingTime == 0; } }
protected readonly Actor Self;
protected readonly Player Owner;
bool notifiedCharging;
bool notifiedReady;
readonly PowerManager PlayerPower;
public SupportPower(Actor self, SupportPowerInfo info)
{
Info = info;
RemainingTime = TotalTime;
Self = self;
Owner = self.Owner;
PlayerPower = self.Trait<PowerManager>();
self.Trait<TechTree>().Add( Info.OrderName, Info.Prerequisites.Select( a => a.ToLowerInvariant() ).ToList(), this );
this.self = self;
}
public void Tick(Actor self)
public virtual void Activate(Actor self, Order order) { }
public virtual IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{
if (Info.OneShot && IsUsed)
return;
if (Info.GivenAuto)
IsAvailable = hasPrerequisites;
if (IsAvailable && (!Info.RequiresPower || PlayerPower.PowerState == PowerState.Normal))
{
if (self.World.LobbyInfo.GlobalSettings.AllowCheats && self.Trait<DeveloperMode>().FastCharge) RemainingTime = 0;
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
Sound.PlayToPlayer(Owner, Info.BeginChargeSound);
OnBeginCharging();
notifiedCharging = true;
}
}
if (RemainingTime == 0
&& !notifiedReady)
{
Sound.PlayToPlayer(Owner, Info.EndChargeSound);
OnFinishCharging();
notifiedReady = true;
}
}
public void FinishActivate()
{
if (Info.OneShot)
{
IsUsed = true;
IsAvailable = false;
}
RemainingTime = TotalTime;
notifiedReady = false;
notifiedCharging = false;
}
public void Give(float charge)
{
IsAvailable = true;
IsUsed = false;
RemainingTime = (int)(charge * TotalTime);
}
protected virtual void OnBeginCharging() { }
protected virtual void OnFinishCharging() { }
protected virtual void OnActivate() { }
public void Activate()
{
if (!IsAvailable || !IsReady)
return;
if (Info.RequiresPower && PlayerPower.PowerState != PowerState.Normal)
{
var eva = Owner.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
Sound.Play(eva.AbilityInsufficientPower);
return;
}
Sound.PlayToPlayer(Owner, Info.SelectTargetSound);
OnActivate();
}
bool hasPrerequisites;
public void PrerequisitesAvailable(string key)
{
hasPrerequisites = true;
}
public void PrerequisitesUnavailable(string key)
{
hasPrerequisites = false;
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
return new SelectGenericPowerTarget(order, manager, "ability", MouseButton.Left);
}
}
}