Merge pull request #3574 from ScottNZ/superweapons

Add atom bomb and gps public superweapon timers to RA
This commit is contained in:
Matthias Mailänder
2013-07-17 08:25:25 -07:00
10 changed files with 156 additions and 72 deletions

View File

@@ -410,6 +410,7 @@
<Compile Include="Widgets\OrderButtonWidget.cs" />
<Compile Include="Widgets\RadarWidget.cs" />
<Compile Include="Widgets\StrategicProgressWidget.cs" />
<Compile Include="Widgets\SupportPowerTimerWidget.cs" />
<Compile Include="Widgets\SupportPowerBinWidget.cs" />
<Compile Include="Widgets\WorldCommandWidget.cs" />
<Compile Include="Widgets\WorldTooltipWidget.cs" />

View File

@@ -28,6 +28,8 @@ namespace OpenRA.Mods.RA
public readonly string SelectTargetSound = null;
public readonly string LaunchSound = null;
public readonly bool DisplayTimer = false;
public readonly string OrderName;
public abstract object Create(ActorInitializer init);

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA
public void Tick(Actor self)
{
foreach(var power in Powers.Values)
foreach (var power in Powers.Values)
power.Tick();
}
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA
Powers[key].Target();
}
static readonly SupportPowerInstance[] NoInstances = {};
static readonly SupportPowerInstance[] NoInstances = { };
public IEnumerable<SupportPowerInstance> GetPowersForActor(Actor a)
{
@@ -110,85 +110,85 @@ namespace OpenRA.Mods.RA
return a.TraitsImplementing<SupportPower>()
.Select(t => Powers[MakeKey(t)]);
}
}
public class SupportPowerInstance
public class SupportPowerInstance
{
readonly SupportPowerManager Manager;
readonly string Key;
public List<SupportPower> Instances;
public int RemainingTime;
public int TotalTime;
public bool Active { get; private set; }
public bool Disabled { get; private set; }
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
public bool Ready { get { return Active && RemainingTime == 0; } }
public SupportPowerInstance(string key, SupportPowerManager manager)
{
readonly SupportPowerManager Manager;
readonly string Key;
Manager = manager;
Key = key;
}
public List<SupportPower> Instances;
public int RemainingTime;
public int TotalTime;
public bool Active { get; private set; }
public bool Disabled { get; private set; }
static bool InstanceDisabled(SupportPower sp)
{
return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
public SupportPowerInfo Info { get { return Instances.Select(i => i.Info).FirstOrDefault(); } }
public bool Ready { get { return Active && RemainingTime == 0; } }
bool notifiedCharging;
bool notifiedReady;
public void Tick()
{
Active = !Disabled && Instances.Any(i => !i.self.IsDisabled());
if (!Active)
return;
public SupportPowerInstance(string key, SupportPowerManager manager)
if (Active)
{
Manager = manager;
Key = key;
}
var power = Instances.First();
if (Manager.devMode.FastCharge && RemainingTime > 25)
RemainingTime = 25;
static bool InstanceDisabled(SupportPower sp)
{
return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
bool notifiedCharging;
bool notifiedReady;
public void Tick()
{
Active = !Disabled && Instances.Any(i => !i.self.IsDisabled());
if (!Active)
return;
if (Active)
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
var power = Instances.First();
if (Manager.devMode.FastCharge && RemainingTime > 25)
RemainingTime = 25;
power.Charging(power.self, Key);
notifiedCharging = true;
}
if (RemainingTime > 0) --RemainingTime;
if (!notifiedCharging)
{
power.Charging(power.self, Key);
notifiedCharging = true;
}
if (RemainingTime == 0
&& !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
if (RemainingTime == 0
&& !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
}
}
public void Target()
{
if (!Ready)
return;
public void Target()
{
if (!Ready)
return;
Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager);
}
Manager.self.World.OrderGenerator = Instances.First().OrderGenerator(Key, Manager);
}
public void Activate(Order order)
{
if (!Ready)
return;
public void Activate(Order order)
{
if (!Ready)
return;
var power = Instances.First(i => !InstanceDisabled(i));
var power = Instances.First(i => !InstanceDisabled(i));
// Note: order.Subject is the *player* actor
power.Activate(power.self, order);
RemainingTime = TotalTime;
notifiedCharging = notifiedReady = false;
// Note: order.Subject is the *player* actor
power.Activate(power.self, order);
RemainingTime = TotalTime;
notifiedCharging = notifiedReady = false;
if (Info.OneShot)
Disabled = true;
}
if (Info.OneShot)
Disabled = true;
}
}

View File

@@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Widgets
}
}
static string GetOverlayForItem(SupportPowerManager.SupportPowerInstance item)
static string GetOverlayForItem(SupportPowerInstance item)
{
if (item.Disabled) return "ON HOLD";
if (item.Ready) return "READY";

View File

@@ -0,0 +1,65 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets
{
public class SupportPowerTimerWidget : Widget
{
public readonly string Font = "Bold";
public readonly string Format = "{0}: {1}";
public readonly TimerOrder Order = TimerOrder.Descending;
readonly IEnumerable<SupportPowerInstance> powers;
Pair<string, Color>[] texts;
[ObjectCreator.UseCtor]
public SupportPowerTimerWidget(World world)
{
powers = world.ActorsWithTrait<SupportPowerManager>()
.Where(p => !p.Actor.IsDead() && !p.Actor.Owner.NonCombatant)
.SelectMany(s => s.Trait.Powers.Values)
.Where(p => p.Instances.Any() && p.Info.DisplayTimer && !p.Disabled);
}
public override void Tick()
{
texts = powers.Select(p =>
{
var time = WidgetUtils.FormatTime(p.RemainingTime, false);
var text = Format.F(p.Info.Description, time);
var color = !p.Ready || Game.LocalTick % 50 < 25 ? p.Instances[0].self.Owner.Color.RGB : Color.White;
return Pair.New(text, color);
}).ToArray();
}
public override void Draw()
{
if (!IsVisible() || texts == null)
return;
var y = 0;
foreach (var t in texts)
{
var font = Game.Renderer.Fonts[Font];
font.DrawTextWithContrast(t.First, new float2(Bounds.Location) + new float2(0, y), t.Second, Color.Black, 1);
y += (font.Measure(t.First).Y + 5) * (int)Order;
}
}
public enum TimerOrder { Ascending = -1, Descending = 1 }
}
}