Refactor more power and infiltration stuff. Create new power sabotage ability for spies in ra and ts.

This commit is contained in:
ScottNZ
2014-08-07 00:52:23 +12:00
parent 4fa199fb10
commit b70395e27c
31 changed files with 292 additions and 109 deletions

View File

@@ -171,6 +171,7 @@ namespace OpenRA.Traits
public interface ISpeedModifier { int GetSpeedModifier(); } public interface ISpeedModifier { int GetSpeedModifier(); }
public interface IFirepowerModifier { int GetFirepowerModifier(); } public interface IFirepowerModifier { int GetFirepowerModifier(); }
public interface IReloadModifier { int GetReloadModifier(); } public interface IReloadModifier { int GetReloadModifier(); }
public interface IPowerModifier { int GetPowerModifier(); }
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); } public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); } public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); } public interface IPips { IEnumerable<PipType> GetPips(Actor self); }

View File

@@ -16,8 +16,8 @@ using OpenRA.Graphics;
using OpenRA.Mods.RA; using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Orders; using OpenRA.Mods.RA.Orders;
using OpenRA.Mods.RA.Power;
using OpenRA.Mods.RA.Render; using OpenRA.Mods.RA.Render;
using OpenRA.Mods.RA.Widgets;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -12,7 +12,7 @@ using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA; using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
using OpenRA.Mods.RA.Widgets; using OpenRA.Mods.RA.Widgets;
using OpenRA.Mods.RA.Widgets.Logic; using OpenRA.Mods.RA.Widgets.Logic;
using OpenRA.Mods.D2k.Widgets; using OpenRA.Mods.D2k.Widgets;

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Power;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.AI namespace OpenRA.Mods.RA.AI

View File

@@ -15,6 +15,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Air; using OpenRA.Mods.RA.Air;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Move; using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Power;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Support; using OpenRA.Support;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -11,7 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
namespace OpenRA.Mods.RA.Effects namespace OpenRA.Mods.RA.Effects
{ {

View File

@@ -12,7 +12,7 @@ using System;
using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Effects;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA.Infiltration
{ {
[Desc("This structure can be infiltrated causing funds to be stolen.")] [Desc("This structure can be infiltrated causing funds to be stolen.")]
class InfiltrateForCashInfo : ITraitInfo class InfiltrateForCashInfo : ITraitInfo

View File

@@ -10,7 +10,7 @@
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA.Infiltration
{ {
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { } class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }

View File

@@ -0,0 +1,45 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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.Linq;
using OpenRA.Mods.RA.Power;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Infiltration
{
class InfiltrateForPowerOutageInfo : ITraitInfo
{
public readonly int Duration = 25 * 30;
public object Create(ActorInitializer init) { return new InfiltrateForPowerOutage(init.self, this); }
}
class InfiltrateForPowerOutage : INotifyCapture, INotifyInfiltrated
{
readonly InfiltrateForPowerOutageInfo info;
PowerManager playerPower;
public InfiltrateForPowerOutage(Actor self, InfiltrateForPowerOutageInfo info)
{
this.info = info;
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
public void Infiltrated(Actor self, Actor infiltrator)
{
playerPower.TriggerPowerOutage(info.Duration);
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
}
}

View File

@@ -11,7 +11,7 @@
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA.Infiltration
{ {
class InfiltrateForSupportPowerInfo : ITraitInfo class InfiltrateForSupportPowerInfo : ITraitInfo
{ {

View File

@@ -15,7 +15,7 @@ using OpenRA.Mods.RA.Activities;
using OpenRA.Mods.RA.Orders; using OpenRA.Mods.RA.Orders;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA.Infiltration
{ {
class InfiltratesInfo : ITraitInfo class InfiltratesInfo : ITraitInfo
{ {

View File

@@ -119,7 +119,9 @@
<Compile Include="Air\AttackPlane.cs" /> <Compile Include="Air\AttackPlane.cs" />
<Compile Include="AI\SupportPowerDecision.cs" /> <Compile Include="AI\SupportPowerDecision.cs" />
<Compile Include="Crates\DuplicateUnitCrateAction.cs" /> <Compile Include="Crates\DuplicateUnitCrateAction.cs" />
<Compile Include="Power.cs" /> <Compile Include="Infiltration\InfiltrateForPowerOutage.cs" />
<Compile Include="Power\AffectedByPowerOutage.cs" />
<Compile Include="Power\Power.cs" />
<Compile Include="Effects\Beacon.cs" /> <Compile Include="Effects\Beacon.cs" />
<Compile Include="Player\PlaceBeacon.cs" /> <Compile Include="Player\PlaceBeacon.cs" />
<Compile Include="MenuPaletteEffect.cs" /> <Compile Include="MenuPaletteEffect.cs" />
@@ -166,15 +168,15 @@
<Compile Include="CaptureNotification.cs" /> <Compile Include="CaptureNotification.cs" />
<Compile Include="Buildings\Building.cs" /> <Compile Include="Buildings\Building.cs" />
<Compile Include="Buildings\BuildingInfluence.cs" /> <Compile Include="Buildings\BuildingInfluence.cs" />
<Compile Include="CanPowerDown.cs" /> <Compile Include="Power\CanPowerDown.cs" />
<Compile Include="Buildings\CustomSellValue.cs" /> <Compile Include="Buildings\CustomSellValue.cs" />
<Compile Include="Buildings\CustomBuildTimeValue.cs" /> <Compile Include="Buildings\CustomBuildTimeValue.cs" />
<Compile Include="Buildings\DeadBuildingState.cs" /> <Compile Include="Buildings\DeadBuildingState.cs" />
<Compile Include="Buildings\FootprintUtils.cs" /> <Compile Include="Buildings\FootprintUtils.cs" />
<Compile Include="Buildings\LineBuild.cs" /> <Compile Include="Buildings\LineBuild.cs" />
<Compile Include="Buildings\PowerManager.cs" /> <Compile Include="Power\Player\PowerManager.cs" />
<Compile Include="Buildings\RepairableBuilding.cs" /> <Compile Include="Buildings\RepairableBuilding.cs" />
<Compile Include="Buildings\RequiresPower.cs" /> <Compile Include="Power\RequiresPower.cs" />
<Compile Include="Buildings\ShakeOnDeath.cs" /> <Compile Include="Buildings\ShakeOnDeath.cs" />
<Compile Include="Buildings\SoundOnDamageTransition.cs" /> <Compile Include="Buildings\SoundOnDamageTransition.cs" />
<Compile Include="Buildings\Util.cs" /> <Compile Include="Buildings\Util.cs" />
@@ -240,7 +242,7 @@
<Compile Include="Harvester.cs" /> <Compile Include="Harvester.cs" />
<Compile Include="HarvesterHuskModifier.cs" /> <Compile Include="HarvesterHuskModifier.cs" />
<Compile Include="Husk.cs" /> <Compile Include="Husk.cs" />
<Compile Include="InfiltrateForSupportPower.cs" /> <Compile Include="Infiltration\InfiltrateForSupportPower.cs" />
<Compile Include="Invulnerable.cs" /> <Compile Include="Invulnerable.cs" />
<Compile Include="IronCurtainable.cs" /> <Compile Include="IronCurtainable.cs" />
<Compile Include="JamsMissiles.cs" /> <Compile Include="JamsMissiles.cs" />
@@ -289,6 +291,7 @@
<Compile Include="PortableChrono.cs" /> <Compile Include="PortableChrono.cs" />
<Compile Include="Scripting\Properties\GuardProperties.cs" /> <Compile Include="Scripting\Properties\GuardProperties.cs" />
<Compile Include="Scripting\Properties\PlayerProperties.cs" /> <Compile Include="Scripting\Properties\PlayerProperties.cs" />
<Compile Include="Power\ScalePowerWithHealth.cs" />
<Compile Include="Warheads\DestroyResourceWarhead.cs" /> <Compile Include="Warheads\DestroyResourceWarhead.cs" />
<Compile Include="Warheads\CreateEffectWarhead.cs" /> <Compile Include="Warheads\CreateEffectWarhead.cs" />
<Compile Include="Warheads\CreateResourceWarhead.cs" /> <Compile Include="Warheads\CreateResourceWarhead.cs" />
@@ -413,12 +416,12 @@
<Compile Include="World\SmudgeLayer.cs" /> <Compile Include="World\SmudgeLayer.cs" />
<Compile Include="Player\BaseAttackNotifier.cs" /> <Compile Include="Player\BaseAttackNotifier.cs" />
<Compile Include="Player\HarvesterAttackNotifier.cs" /> <Compile Include="Player\HarvesterAttackNotifier.cs" />
<Compile Include="InfiltrateForExploration.cs" /> <Compile Include="Infiltration\InfiltrateForExploration.cs" />
<Compile Include="InfiltrateForCash.cs" /> <Compile Include="Infiltration\InfiltrateForCash.cs" />
<Compile Include="RenderShroudCircle.cs" /> <Compile Include="RenderShroudCircle.cs" />
<Compile Include="CloakPaletteEffect.cs" /> <Compile Include="CloakPaletteEffect.cs" />
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" /> <Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
<Compile Include="Infiltrates.cs" /> <Compile Include="Infiltration\Infiltrates.cs" />
<Compile Include="Armament.cs" /> <Compile Include="Armament.cs" />
<Compile Include="Buildings\BaseProvider.cs" /> <Compile Include="Buildings\BaseProvider.cs" />
<Compile Include="Widgets\Logic\ObserverShroudSelectorLogic.cs" /> <Compile Include="Widgets\Logic\ObserverShroudSelectorLogic.cs" />

View File

@@ -11,7 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
namespace OpenRA.Mods.RA.Orders namespace OpenRA.Mods.RA.Orders
{ {

View File

@@ -11,6 +11,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Power;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
using OpenRA.Mods.RA.Power;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA

View File

@@ -0,0 +1,58 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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.Drawing;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Power
{
public class AffectedByPowerOutageInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new AffectedByPowerOutage(init.self); }
}
public class AffectedByPowerOutage : INotifyCapture, ISelectionBar, IPowerModifier, IDisable
{
PowerManager playerPower;
public AffectedByPowerOutage(Actor self)
{
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
}
public float GetValue()
{
if (playerPower.PowerOutageRemainingTicks <= 0)
return 0;
return (float)playerPower.PowerOutageRemainingTicks / playerPower.PowerOutageTotalTicks;
}
public Color GetColor()
{
return Color.Yellow;
}
public int GetPowerModifier()
{
return playerPower.PowerOutageRemainingTicks > 0 ? 0 : 100;
}
public bool Disabled
{
get { return playerPower.PowerOutageRemainingTicks > 0; }
}
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{
playerPower = newOwner.PlayerActor.Trait<PowerManager>();
}
}
}

View File

@@ -11,24 +11,22 @@
using OpenRA.Mods.RA.Effects; using OpenRA.Mods.RA.Effects;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings namespace OpenRA.Mods.RA.Power
{ {
[Desc("The player can disable the power individually on this actor.")] [Desc("The player can disable the power individually on this actor.")]
public class CanPowerDownInfo : ITraitInfo, Requires<PowerInfo> public class CanPowerDownInfo : ITraitInfo, Requires<PowerInfo>
{ {
public object Create(ActorInitializer init) { return new CanPowerDown(init); } public object Create(ActorInitializer init) { return new CanPowerDown(init.self); }
} }
public class CanPowerDown : IResolveOrder, IDisable, INotifyCapture, ISync public class CanPowerDown : IPowerModifier, IResolveOrder, IDisable, ISync
{ {
[Sync] bool disabled = false; [Sync] bool disabled = false;
int normalPower = 0; readonly Power power;
PowerManager PowerManager;
public CanPowerDown(ActorInitializer init) public CanPowerDown(Actor self)
{ {
PowerManager = init.self.Owner.PlayerActor.Trait<PowerManager>(); power = self.Trait<Power>();
normalPower = init.self.Info.Traits.Get<PowerInfo>().Amount;
} }
public bool Disabled { get { return disabled; } } public bool Disabled { get { return disabled; } }
@@ -38,18 +36,17 @@ namespace OpenRA.Mods.RA.Buildings
if (order.OrderString == "PowerDown") if (order.OrderString == "PowerDown")
{ {
disabled = !disabled; disabled = !disabled;
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", (disabled ? "EnablePower" : "DisablePower"), self.Owner.Country.Race); Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", disabled ? "EnablePower" : "DisablePower", self.Owner.Country.Race);
PowerManager.UpdateActor(self, disabled ? 0 : normalPower); power.PlayerPower.UpdateActor(self);
if (disabled) if (disabled)
self.World.AddFrameEndTask( self.World.AddFrameEndTask(w => w.Add(new PowerdownIndicator(self)));
w => w.Add(new PowerdownIndicator(self)));
} }
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) public int GetPowerModifier()
{ {
PowerManager = newOwner.PlayerActor.Trait<PowerManager>(); return disabled ? 0 : 100;
} }
} }
} }

View File

@@ -9,20 +9,21 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings namespace OpenRA.Mods.RA.Power
{ {
public class PowerManagerInfo : ITraitInfo, Requires<DeveloperModeInfo> public class PowerManagerInfo : ITraitInfo, Requires<DeveloperModeInfo>
{ {
public readonly int AdviceInterval = 250; public readonly int AdviceInterval = 250;
public object Create(ActorInitializer init) { return new PowerManager(init, this); } public object Create(ActorInitializer init) { return new PowerManager(init.self, this); }
} }
public class PowerManager : ITick, ISync public class PowerManager : ITick, ISync
{ {
readonly Actor self;
readonly PowerManagerInfo info; readonly PowerManagerInfo info;
readonly Player player;
readonly DeveloperMode devMode; readonly DeveloperMode devMode;
readonly Dictionary<Actor, int> powerDrain = new Dictionary<Actor, int>(); readonly Dictionary<Actor, int> powerDrain = new Dictionary<Actor, int>();
@@ -34,43 +35,56 @@ namespace OpenRA.Mods.RA.Buildings
public int ExcessPower { get { return totalProvided - totalDrained; } } public int ExcessPower { get { return totalProvided - totalDrained; } }
public PowerManager(ActorInitializer init, PowerManagerInfo info) public int PowerOutageRemainingTicks { get; private set; }
public int PowerOutageTotalTicks { get; private set; }
public PowerManager(Actor self, PowerManagerInfo info)
{ {
this.self = self;
this.info = info; this.info = info;
player = init.self.Owner;
init.world.ActorAdded += ActorAdded; self.World.ActorAdded += UpdateActor;
init.world.ActorRemoved += ActorRemoved; self.World.ActorRemoved += RemoveActor;
devMode = init.self.Trait<DeveloperMode>(); devMode = self.Trait<DeveloperMode>();
wasHackEnabled = devMode.UnlimitedPower; wasHackEnabled = devMode.UnlimitedPower;
} }
void ActorAdded(Actor a) public void UpdateActor(Actor a)
{ {
if (a.Owner != player) UpdateActors(new[] { a });
return; }
var power = a.TraitOrDefault<Power>(); public void UpdateActors(IEnumerable<Actor> actors)
if (power == null) {
return; foreach (var a in actors)
{
if (a.Owner != self.Owner)
return;
powerDrain.Add(a, power.CurrentPower); var power = a.TraitOrDefault<Power>();
if (power == null)
return;
powerDrain[a] = power.GetCurrentPower();
}
UpdateTotals(); UpdateTotals();
} }
void ActorRemoved(Actor a) void RemoveActor(Actor a)
{ {
if (a.Owner != player || !a.HasTrait<Power>()) if (a.Owner != self.Owner || !a.HasTrait<Power>())
return; return;
powerDrain.Remove(a); powerDrain.Remove(a);
UpdateTotals(); UpdateTotals();
} }
void UpdateTotals() public void UpdateTotals()
{ {
totalProvided = 0; totalProvided = 0;
totalDrained = 0; totalDrained = 0;
foreach (var kv in powerDrain) foreach (var kv in powerDrain)
{ {
var p = kv.Value; var p = kv.Value;
@@ -84,15 +98,6 @@ namespace OpenRA.Mods.RA.Buildings
totalProvided = 1000000; totalProvided = 1000000;
} }
public void UpdateActor(Actor a, int newPower)
{
if (a.Owner != player || !a.HasTrait<Power>())
return;
powerDrain[a] = newPower;
UpdateTotals();
}
int nextPowerAdviceTime = 0; int nextPowerAdviceTime = 0;
bool wasLowPower = false; bool wasLowPower = false;
bool wasHackEnabled; bool wasHackEnabled;
@@ -116,15 +121,34 @@ namespace OpenRA.Mods.RA.Buildings
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "LowPower", self.Owner.Country.Race); Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", "LowPower", self.Owner.Country.Race);
nextPowerAdviceTime = info.AdviceInterval; nextPowerAdviceTime = info.AdviceInterval;
} }
if (PowerOutageRemainingTicks > 0 && --PowerOutageRemainingTicks == 0)
UpdatePowerOutageActors();
} }
public PowerState PowerState public PowerState PowerState
{ {
get { get
{
if (PowerProvided >= PowerDrained) return PowerState.Normal; if (PowerProvided >= PowerDrained) return PowerState.Normal;
if (PowerProvided > PowerDrained / 2) return PowerState.Low; if (PowerProvided > PowerDrained / 2) return PowerState.Low;
return PowerState.Critical; return PowerState.Critical;
} }
} }
public void TriggerPowerOutage(int totalTicks)
{
PowerOutageTotalTicks = PowerOutageRemainingTicks = totalTicks;
UpdatePowerOutageActors();
}
void UpdatePowerOutageActors()
{
var actors = self.World.ActorsWithTrait<AffectedByPowerOutage>()
.Select(tp => tp.Actor)
.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == self.Owner);
UpdateActors(actors);
}
} }
} }

View File

@@ -9,55 +9,41 @@
#endregion #endregion
using System; using System;
using OpenRA.Mods.RA.Buildings; using System.Linq;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA.Power
{ {
public class PowerInfo : ITraitInfo public class PowerInfo : ITraitInfo
{ {
[Desc("If negative, it will drain power. If positive, it will provide power.")] [Desc("If negative, it will drain power. If positive, it will provide power.")]
public readonly int Amount = 0; public readonly int Amount = 0;
[Desc("Scale power amount with the current health.")]
public readonly bool ScaleWithHealth = false;
public object Create(ActorInitializer init) { return new Power(init.self, this); } public object Create(ActorInitializer init) { return new Power(init.self, this); }
} }
public class Power : INotifyDamage, INotifyCapture public class Power : INotifyCapture
{ {
readonly PowerInfo info; readonly PowerInfo info;
readonly Lazy<Health> health; readonly Lazy<IPowerModifier[]> powerModifiers;
PowerManager playerPower;
public int CurrentPower public PowerManager PlayerPower { get; private set; }
public int GetCurrentPower()
{ {
get return Util.ApplyPercentageModifiers(info.Amount, powerModifiers.Value.Select(m => m.GetPowerModifier()));
{
if (info.Amount <= 0 || health == null || !info.ScaleWithHealth)
return info.Amount;
return info.Amount * health.Value.HP / health.Value.MaxHP;
}
} }
public Power(Actor self, PowerInfo info) public Power(Actor self, PowerInfo info)
{ {
this.info = info; this.info = info;
health = Exts.Lazy(self.TraitOrDefault<Health>); PlayerPower = self.Owner.PlayerActor.Trait<PowerManager>();
playerPower = self.Owner.PlayerActor.Trait<PowerManager>(); powerModifiers = Exts.Lazy(() => self.TraitsImplementing<IPowerModifier>().ToArray());
}
public void Damaged(Actor self, AttackInfo e)
{
if (info.ScaleWithHealth)
playerPower.UpdateActor(self, CurrentPower);
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{ {
playerPower = newOwner.PlayerActor.Trait<PowerManager>(); PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
} }
} }
} }

View File

@@ -10,7 +10,7 @@
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Buildings namespace OpenRA.Mods.RA.Power
{ {
class RequiresPowerInfo : ITraitInfo class RequiresPowerInfo : ITraitInfo
{ {
@@ -19,21 +19,21 @@ namespace OpenRA.Mods.RA.Buildings
class RequiresPower : IDisable, INotifyCapture class RequiresPower : IDisable, INotifyCapture
{ {
PowerManager power; PowerManager playerPower;
public RequiresPower( Actor self ) public RequiresPower(Actor self)
{ {
power = self.Owner.PlayerActor.Trait<PowerManager>(); playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
} }
public bool Disabled public bool Disabled
{ {
get { return power.PowerProvided < power.PowerDrained; } get { return playerPower.PowerProvided < playerPower.PowerDrained; }
} }
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
{ {
power = newOwner.PlayerActor.Trait<PowerManager>(); playerPower = newOwner.PlayerActor.Trait<PowerManager>();
} }
} }
} }

View File

@@ -0,0 +1,42 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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 OpenRA.Traits;
namespace OpenRA.Mods.RA.Power
{
[Desc("Scale power amount with the current health.")]
public class ScalePowerWithHealthInfo : ITraitInfo, Requires<PowerInfo>, Requires<HealthInfo>
{
public object Create(ActorInitializer init) { return new ScalePowerWithHealth(init.self); }
}
public class ScalePowerWithHealth : IPowerModifier, INotifyDamage
{
readonly Power power;
readonly Health health;
public ScalePowerWithHealth(Actor self)
{
power = self.Trait<Power>();
health = self.Trait<Health>();
}
public int GetPowerModifier()
{
return 100 * health.HP / health.MaxHP;
}
public void Damaged(Actor self, AttackInfo e)
{
power.PlayerPower.UpdateActor(self);
}
}
}

View File

@@ -9,7 +9,7 @@
#endregion #endregion
using System.Drawing; using System.Drawing;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic

View File

@@ -8,7 +8,7 @@
*/ */
#endregion #endregion
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
using OpenRA.Widgets; using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic namespace OpenRA.Mods.RA.Widgets.Logic

View File

@@ -13,7 +13,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Power;
using OpenRA.Network; using OpenRA.Network;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;

View File

@@ -11,8 +11,7 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.Mods.RA; using OpenRA.Mods.RA.Power;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Widgets; using OpenRA.Widgets;

View File

@@ -334,8 +334,8 @@ namespace OpenRA.Utility
node.Key = "Units"; node.Key = "Units";
} }
// Power from Building was moved out into its own trait // Power from Building was moved out into Power and ScalePowerWithHealth traits
if (engineVersion < 20140802) if (engineVersion < 20140823)
{ {
if (depth == 0) if (depth == 0)
{ {
@@ -350,11 +350,10 @@ namespace OpenRA.Utility
buildingFields.Remove(power); buildingFields.Remove(power);
var powerFields = new List<MiniYamlNode> { new MiniYamlNode("Amount", power.Value) }; var powerFields = new List<MiniYamlNode> { new MiniYamlNode("Amount", power.Value) };
if (FieldLoader.GetValue<int>("Power", power.Value.Value) > 0)
powerFields.Add(new MiniYamlNode("ScaleWithHealth", "True"));
actorTraits.Add(new MiniYamlNode("Power", new MiniYaml("", powerFields))); actorTraits.Add(new MiniYamlNode("Power", new MiniYaml("", powerFields)));
if (FieldLoader.GetValue<int>("Power", power.Value.Value) > 0)
actorTraits.Add(new MiniYamlNode("ScaleWithHealth", ""));
} }
} }
} }

View File

@@ -100,7 +100,7 @@ NUKE:
Bib: Bib:
Power: Power:
Amount: 100 Amount: 100
ScaleWithHealth: True ScalePowerWithHealth:
NUK2: NUK2:
Inherits: ^BaseBuilding Inherits: ^BaseBuilding
@@ -125,7 +125,7 @@ NUK2:
Bib: Bib:
Power: Power:
Amount: 200 Amount: 200
ScaleWithHealth: True ScalePowerWithHealth:
PROC: PROC:
Inherits: ^BaseBuilding Inherits: ^BaseBuilding

View File

@@ -106,7 +106,7 @@ CONCRETEB:
Sequence: idle-zaps Sequence: idle-zaps
Power: Power:
Amount: 100 Amount: 100
ScaleWithHealth: True ScalePowerWithHealth:
^BARRACKS: ^BARRACKS:
Inherits: ^Building Inherits: ^Building

View File

@@ -199,7 +199,7 @@ SPY:
Cost: 500 Cost: 500
DisguiseToolTip: DisguiseToolTip:
Name: Spy Name: Spy
Description: Infiltrates enemy structures to gather \nintelligence. Exact effect depends on the \nbuilding infiltrated.\n Strong vs Nothing\n Weak vs Everything\n Special Ability: Disguised Description: Infiltrates enemy structures for intel or\nsabotage. Exact effect depends on the\nbuilding infiltrated.\n Strong vs Nothing\n Weak vs Everything\n Special Ability: Disguised
Selectable: Selectable:
Voice: SpyVoice Voice: SpyVoice
Bounds: 12,17,0,-9 Bounds: 12,17,0,-9

View File

@@ -949,7 +949,12 @@ POWR:
DeadBuildingState: DeadBuildingState:
Power: Power:
Amount: 100 Amount: 100
ScaleWithHealth: True InfiltrateForPowerOutage:
AffectedByPowerOutage:
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
ScalePowerWithHealth:
DisabledOverlay:
APWR: APWR:
Inherits: ^Building Inherits: ^Building
@@ -978,7 +983,12 @@ APWR:
DeadBuildingState: DeadBuildingState:
Power: Power:
Amount: 200 Amount: 200
ScaleWithHealth: True InfiltrateForPowerOutage:
AffectedByPowerOutage:
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
ScalePowerWithHealth:
DisabledOverlay:
STEK: STEK:
Inherits: ^Building Inherits: ^Building

View File

@@ -71,7 +71,12 @@ GAPOWR:
Sequence: idle-plug Sequence: idle-plug
Power: Power:
Amount: 100 Amount: 100
ScaleWithHealth: True InfiltrateForPowerOutage:
AffectedByPowerOutage:
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
ScalePowerWithHealth:
DisabledOverlay:
GAPILE: GAPILE:
Inherits: ^Building Inherits: ^Building
@@ -222,7 +227,12 @@ NAPOWR:
Sequence: idle-lights Sequence: idle-lights
Power: Power:
Amount: 100 Amount: 100
ScaleWithHealth: True InfiltrateForPowerOutage:
AffectedByPowerOutage:
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
ScalePowerWithHealth:
DisabledOverlay:
NAAPWR: NAAPWR:
Inherits: ^Building Inherits: ^Building
@@ -251,7 +261,12 @@ NAAPWR:
Sequence: idle-lights Sequence: idle-lights
Power: Power:
Amount: 200 Amount: 200
ScaleWithHealth: True InfiltrateForPowerOutage:
AffectedByPowerOutage:
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
ScalePowerWithHealth:
DisabledOverlay:
NAHAND: NAHAND:
Inherits: ^Building Inherits: ^Building