This commit is contained in:
Chris Forbes
2010-01-09 11:05:00 +13:00
13 changed files with 107 additions and 20 deletions

View File

@@ -13,6 +13,5 @@ namespace OpenRa.Game.GameRules
public readonly int TechLevel = -1;
public readonly bool GivenAuto = true;
public readonly string Impl = null;
public readonly bool AutoActivate = false;
}
}

View File

@@ -124,7 +124,7 @@
<Compile Include="SupportPower.cs" />
<Compile Include="SupportPowers\Chronoshift.cs" />
<Compile Include="SupportPowers\GpsSatellite.cs" />
<Compile Include="SupportPowers\IronCurtain.cs" />
<Compile Include="SupportPowers\IronCurtainPower.cs" />
<Compile Include="SupportPowers\ISupportPowerImpl.cs" />
<Compile Include="SupportPowers\NullPower.cs" />
<Compile Include="Support\Stopwatch.cs" />

View File

@@ -4,11 +4,17 @@ using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
using OpenRa.Game.SupportPowers;
namespace OpenRa.Game.Orders
{
class IronCurtainOrderGenerator : IOrderGenerator
{
ISupportPowerImpl power;
public IronCurtainOrderGenerator(ISupportPowerImpl power)
{
this.power = power;
}
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Right)
@@ -31,7 +37,8 @@ namespace OpenRa.Game.Orders
if (unit != null)
{
yield return new Order("IronCurtain", underCursor, null, int2.Zero, null);
yield return new Order("IronCurtain", underCursor, this.power);
//yield return new Order("IronCurtain", underCursor, null, int2.Zero, null);
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using OpenRa.Game.SupportPowers;
namespace OpenRa.Game
{
@@ -31,6 +32,19 @@ namespace OpenRa.Game
this.TargetLocation = targetLocation;
this.TargetString = targetString;
}
// This is a hack - fix me
public readonly ISupportPowerImpl Power;
public Order(string orderString, Actor subject, ISupportPowerImpl power)
{
this.OrderString = orderString;
this.SubjectId = UIntFromActor( subject );
this.Power = power;
this.TargetActorId = UIntFromActor(null);
this.TargetLocation = int2.Zero;
this.TargetString = null;
}
public bool Validate()
{

View File

@@ -34,6 +34,8 @@ namespace OpenRa.Game
public bool IsDone { get { return RemainingTime == 0; } }
public int RemainingTime { get; private set; }
public int TotalTime { get; private set; }
bool notifiedReady = false;
bool notifiedCharging = false;
public void Tick()
{
@@ -56,10 +58,20 @@ namespace OpenRa.Game
if (IsAvailable && (!Info.Powered || Owner.GetPowerState() == PowerState.Normal))
{
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
Impl.IsChargingNotification(this);
notifiedCharging = true;
}
}
if (RemainingTime == 0 && Info.AutoActivate)
Activate();
if (RemainingTime == 0
&& Impl != null
&& !notifiedReady)
{
Impl.IsReadyNotification(this);
notifiedReady = true;
}
}
public void Activate()
@@ -76,6 +88,8 @@ namespace OpenRa.Game
IsAvailable = false;
}
RemainingTime = TotalTime;
notifiedReady = false;
notifiedCharging = false;
}
public void Give(bool requireCharge) // called by crate/spy/etc code

View File

@@ -11,5 +11,9 @@ namespace OpenRa.Game.SupportPowers
if (Game.controller.ToggleInputMode<ChronosphereSelectOrderGenerator>())
Sound.Play("slcttgt1.aud");
}
public void OnFireNotification(Actor target, int2 xy) {}
public void IsChargingNotification(SupportPower p) {}
public void IsReadyNotification(SupportPower p) {}
}
}

View File

@@ -6,7 +6,15 @@ namespace OpenRa.Game.SupportPowers
{
class GpsSatellite : ISupportPowerImpl
{
const int revealDelay = 30 * 25;
const int revealDelay = 15 * 25;
public void OnFireNotification(Actor a, int2 xy) { }
public void IsChargingNotification(SupportPower p) { }
public void IsReadyNotification(SupportPower p)
{
// Power is auto-activated
Activate(p);
}
public void Activate(SupportPower p)
{

View File

@@ -8,5 +8,8 @@ namespace OpenRa.Game.SupportPowers
interface ISupportPowerImpl
{
void Activate(SupportPower p);
void OnFireNotification(Actor target, int2 xy);
void IsChargingNotification(SupportPower p);
void IsReadyNotification(SupportPower p);
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Orders;
using OpenRa.Game.Traits;
namespace OpenRa.Game.SupportPowers
{
class IronCurtainPower : ISupportPowerImpl
{
public void IsReadyNotification(SupportPower p)
{
Sound.Play("ironrdy1.aud");
}
public void IsChargingNotification(SupportPower p)
{
Sound.Play("ironchg1.aud");
}
public void OnFireNotification(Actor target, int2 xy)
{
p.FinishActivate();
Game.controller.CancelInputMode();
Sound.Play("ironcur9.aud");
// Play active anim
var ironCurtain = Game.world.Actors
.Where(a => a.Owner == p.Owner && a.traits.Contains<IronCurtain>())
.FirstOrDefault();
if (ironCurtain != null)
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
}
SupportPower p;
public void Activate(SupportPower p)
{
this.p = p;
// Pick a building to use
Game.controller.orderGenerator = new IronCurtainOrderGenerator(this);
Sound.Play("slcttgt1.aud");
}
}
}

View File

@@ -7,6 +7,9 @@ namespace OpenRa.Game.SupportPowers
{
class NullPower : ISupportPowerImpl
{
public void OnFireNotification(Actor a, int2 xy) { }
public void IsReadyNotification(SupportPower p) { }
public void IsChargingNotification(SupportPower p) { }
public void Activate(SupportPower p)
{
// if this was a real power, i'd do something here!

View File

@@ -28,16 +28,9 @@ namespace OpenRa.Game.Traits
{
if (order.OrderString == "IronCurtain")
{
Game.controller.CancelInputMode();
order.Power.OnFireNotification(self, self.Location);
Game.world.AddFrameEndTask(w => w.Add(new InvulnEffect(self)));
RemainingTicks = (int)(Rules.General.IronCurtain * 60 * 25);
Sound.Play("ironcur9.aud");
// Play active anim
var ironCurtain = Game.world.Actors
.Where(a => a.Owner == order.Subject.Owner && a.traits.Contains<IronCurtain>())
.FirstOrDefault();
if (ironCurtain != null)
ironCurtain.traits.Get<RenderBuilding>().PlayCustomAnim(ironCurtain, "active");
}
}
}

View File

@@ -890,7 +890,6 @@ Prerequisite=ATEK
Image=gpssicon
TechLevel=12
Impl=GpsSatellite
AutoActivate=yes
[InvulnerabilityPower] ; the point of IRON
ChargeTime=11
@@ -899,4 +898,4 @@ LongDesc=Makes a single unit invulnerable for a \nshort time.
Image=infxicon
Prerequisite=IRON
TechLevel=12
Impl=IronCurtain
Impl=IronCurtainPower