support power impl pretty much done

This commit is contained in:
Chris Forbes
2010-01-08 21:50:27 +13:00
parent 6ff0f82c02
commit 28746d0bcd
7 changed files with 84 additions and 3 deletions

View File

@@ -729,15 +729,18 @@ namespace OpenRa.Game
buildPaletteRenderer.DrawSprite(clock.Image, drawPos, PaletteType.Chrome); buildPaletteRenderer.DrawSprite(clock.Image, drawPos, PaletteType.Chrome);
var rect = new Rectangle(5, y, 64, 48);
if (sp.Value.IsDone) if (sp.Value.IsDone)
{ {
ready.Play("ready"); ready.Play("ready");
buildPaletteRenderer.DrawSprite(ready.Image, buildPaletteRenderer.DrawSprite(ready.Image,
drawPos + new float2((64 - ready.Image.size.X) / 2, 2), drawPos + new float2((64 - ready.Image.size.X) / 2, 2),
PaletteType.Chrome); PaletteType.Chrome);
AddButton(rect, HandleSupportPower( sp.Value ));
} }
var rect = new Rectangle(5, y, 64, 48);
if (rect.Contains(lastMousePos.ToPoint())) if (rect.Contains(lastMousePos.ToPoint()))
{ {
tooltipItem = sp.Key; tooltipItem = sp.Key;
@@ -754,6 +757,11 @@ namespace OpenRa.Game
DrawSupportPowerTooltip(tooltipItem, tooltipPos); DrawSupportPowerTooltip(tooltipItem, tooltipPos);
} }
Action<bool> HandleSupportPower(SupportPower sp)
{
return b => { if (b) sp.Activate(); };
}
string FormatTime(int ticks) string FormatTime(int ticks)
{ {
var seconds = ticks / 25; var seconds = ticks / 25;

View File

@@ -16,5 +16,6 @@ namespace OpenRa.Game.GameRules
public readonly string[] Prerequisite = { }; public readonly string[] Prerequisite = { };
public readonly int TechLevel = -1; public readonly int TechLevel = -1;
public readonly bool GivenAuto = true; public readonly bool GivenAuto = true;
public readonly string Impl = null;
} }
} }

View File

@@ -120,6 +120,8 @@
<Compile Include="Smudge.cs" /> <Compile Include="Smudge.cs" />
<Compile Include="Sound.cs" /> <Compile Include="Sound.cs" />
<Compile Include="SupportPower.cs" /> <Compile Include="SupportPower.cs" />
<Compile Include="SupportPowers\ISupportPowerImpl.cs" />
<Compile Include="SupportPowers\NullPower.cs" />
<Compile Include="Support\Stopwatch.cs" /> <Compile Include="Support\Stopwatch.cs" />
<Compile Include="Support\PerfHistory.cs" /> <Compile Include="Support\PerfHistory.cs" />
<Compile Include="Traits\AcceptsOre.cs" /> <Compile Include="Traits\AcceptsOre.cs" />

View File

@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using OpenRa.Game.Traits;
using OpenRa.Game.SupportPowers;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -10,15 +12,25 @@ namespace OpenRa.Game
{ {
public readonly SupportPowerInfo Info; public readonly SupportPowerInfo Info;
public readonly Player Owner; public readonly Player Owner;
readonly ISupportPowerImpl Impl;
static ISupportPowerImpl ConstructPowerImpl(string implName)
{
var type = typeof(ISupportPowerImpl).Assembly.GetType(
typeof(ISupportPowerImpl).Namespace + "." + implName, true, false);
var ctor = type.GetConstructor(Type.EmptyTypes);
return (ISupportPowerImpl)ctor.Invoke(new object[] { });
}
public SupportPower(SupportPowerInfo info, Player owner) public SupportPower(SupportPowerInfo info, Player owner)
{ {
Info = info; Info = info;
Owner = owner; Owner = owner;
RemainingTime = TotalTime = (int)info.ChargeTime * 60 * 25; RemainingTime = TotalTime = (int)info.ChargeTime * 60 * 25;
Impl = ConstructPowerImpl(info.Impl);
} }
public bool IsUsed;
public bool IsAvailable { get; private set; } public bool IsAvailable { get; private set; }
public bool IsDone { get { return RemainingTime == 0; } } public bool IsDone { get { return RemainingTime == 0; } }
public int RemainingTime { get; private set; } public int RemainingTime { get; private set; }
@@ -26,6 +38,9 @@ namespace OpenRa.Game
public void Tick() public void Tick()
{ {
if (Info.OneShot && IsUsed)
return;
if (Info.GivenAuto) if (Info.GivenAuto)
{ {
var buildings = Rules.TechTree.GatherBuildings(Owner); var buildings = Rules.TechTree.GatherBuildings(Owner);
@@ -47,6 +62,25 @@ namespace OpenRa.Game
public void Activate() public void Activate()
{ {
if (Impl != null)
Impl.Activate(this);
}
public void FinishActivate()
{
if (Info.OneShot)
{
IsUsed = true;
IsAvailable = false;
}
RemainingTime = TotalTime;
}
public void Give(bool requireCharge) // called by crate/spy/etc code
{
IsAvailable = true;
IsUsed = false;
RemainingTime = requireCharge ? TotalTime : 0;
} }
} }
} }

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.SupportPowers
{
interface ISupportPowerImpl
{
void Activate(SupportPower p);
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.SupportPowers
{
class NullPower : ISupportPowerImpl
{
public void Activate(SupportPower p)
{
// if this was a real power, i'd do something here!
throw new NotImplementedException();
}
}
}

View File

@@ -830,6 +830,7 @@ LongDesc=A Badger drops a squad of Riflemen \nanywhere on the map
Prerequisite=AFLD Prerequisite=AFLD
TechLevel=5 TechLevel=5
Image=pinficon Image=pinficon
Impl=NullPower
[ParabombPower] ; picked up in a crate [ParabombPower] ; picked up in a crate
ChargeTime=14 ChargeTime=14
@@ -840,6 +841,7 @@ Powered=no
Image=pbmbicon Image=pbmbicon
TechLevel=8 TechLevel=8
GivenAuto=no GivenAuto=no
Impl=NullPower
[SonarPulsePower] ; picked up in a crate, or by spy -> spen/syrd [SonarPulsePower] ; picked up in a crate, or by spy -> spen/syrd
ChargeTime=10 ChargeTime=10
@@ -850,6 +852,7 @@ Powered=no
Image=sonricon Image=sonricon
TechLevel=5 TechLevel=5
GivenAuto=no GivenAuto=no
Impl=NullPower
[ChronoshiftPower] ; free with Chronosphere... sortof the point. [ChronoshiftPower] ; free with Chronosphere... sortof the point.
ChargeTime=7 ChargeTime=7
@@ -858,6 +861,7 @@ LongDesc=Temporarily teleports a vehicle across \nthe map.
Prerequisite=PDOX Prerequisite=PDOX
Image=warpicon Image=warpicon
TechLevel=12 TechLevel=12
Impl=NullPower
[SpyPlanePower] ; free with first AFLD [SpyPlanePower] ; free with first AFLD
ChargeTime=3 ChargeTime=3
@@ -866,6 +870,7 @@ Description=Spy Plane
LongDesc=Reveals an area of the map. LongDesc=Reveals an area of the map.
Prerequisite=AFLD Prerequisite=AFLD
Image=smigicon Image=smigicon
Impl=NullPower
[NukePower] ; the point of MSLO [NukePower] ; the point of MSLO
ChargeTime=13 ChargeTime=13
@@ -874,6 +879,7 @@ LongDesc=Launches a nuclear missile at your target
Prerequisite=MSLO Prerequisite=MSLO
Image=atomicon Image=atomicon
TechLevel=12 TechLevel=12
Impl=NullPower
[GpsSatellitePower] ; free with ATEK [GpsSatellitePower] ; free with ATEK
ChargeTime=8 ChargeTime=8
@@ -883,6 +889,7 @@ OneShot=yes
Prerequisite=ATEK Prerequisite=ATEK
Image=gpssicon Image=gpssicon
TechLevel=12 TechLevel=12
Impl=NullPower
[InvulnerabilityPower] ; the point of IRON [InvulnerabilityPower] ; the point of IRON
ChargeTime=11 ChargeTime=11
@@ -891,3 +898,4 @@ LongDesc=Makes a single unit invulnerable for a \nshort time.
Image=infxicon Image=infxicon
Prerequisite=IRON Prerequisite=IRON
TechLevel=12 TechLevel=12
Impl=NullPower