Refactor more power and infiltration stuff. Create new power sabotage ability for spies in ra and ts.
This commit is contained in:
@@ -171,6 +171,7 @@ namespace OpenRA.Traits
|
||||
public interface ISpeedModifier { int GetSpeedModifier(); }
|
||||
public interface IFirepowerModifier { int GetFirepowerModifier(); }
|
||||
public interface IReloadModifier { int GetReloadModifier(); }
|
||||
public interface IPowerModifier { int GetPowerModifier(); }
|
||||
public interface ILoadsPalettes { void LoadPalettes(WorldRenderer wr); }
|
||||
public interface IPaletteModifier { void AdjustPalette(IReadOnlyDictionary<string, MutablePalette> b); }
|
||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||
|
||||
@@ -16,8 +16,8 @@ using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Mods.RA.Render;
|
||||
using OpenRA.Mods.RA.Widgets;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -12,7 +12,7 @@ using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Mods.RA.Widgets;
|
||||
using OpenRA.Mods.RA.Widgets.Logic;
|
||||
using OpenRA.Mods.D2k.Widgets;
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.AI
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Air;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Move;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
|
||||
namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ using System;
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
namespace OpenRA.Mods.RA.Infiltration
|
||||
{
|
||||
[Desc("This structure can be infiltrated causing funds to be stolen.")]
|
||||
class InfiltrateForCashInfo : ITraitInfo
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
namespace OpenRA.Mods.RA.Infiltration
|
||||
{
|
||||
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
|
||||
|
||||
45
OpenRA.Mods.RA/Infiltration/InfiltrateForPowerOutage.cs
Normal file
45
OpenRA.Mods.RA/Infiltration/InfiltrateForPowerOutage.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
namespace OpenRA.Mods.RA.Infiltration
|
||||
{
|
||||
class InfiltrateForSupportPowerInfo : ITraitInfo
|
||||
{
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Mods.RA.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
namespace OpenRA.Mods.RA.Infiltration
|
||||
{
|
||||
class InfiltratesInfo : ITraitInfo
|
||||
{
|
||||
@@ -119,7 +119,9 @@
|
||||
<Compile Include="Air\AttackPlane.cs" />
|
||||
<Compile Include="AI\SupportPowerDecision.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="Player\PlaceBeacon.cs" />
|
||||
<Compile Include="MenuPaletteEffect.cs" />
|
||||
@@ -166,15 +168,15 @@
|
||||
<Compile Include="CaptureNotification.cs" />
|
||||
<Compile Include="Buildings\Building.cs" />
|
||||
<Compile Include="Buildings\BuildingInfluence.cs" />
|
||||
<Compile Include="CanPowerDown.cs" />
|
||||
<Compile Include="Power\CanPowerDown.cs" />
|
||||
<Compile Include="Buildings\CustomSellValue.cs" />
|
||||
<Compile Include="Buildings\CustomBuildTimeValue.cs" />
|
||||
<Compile Include="Buildings\DeadBuildingState.cs" />
|
||||
<Compile Include="Buildings\FootprintUtils.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\RequiresPower.cs" />
|
||||
<Compile Include="Power\RequiresPower.cs" />
|
||||
<Compile Include="Buildings\ShakeOnDeath.cs" />
|
||||
<Compile Include="Buildings\SoundOnDamageTransition.cs" />
|
||||
<Compile Include="Buildings\Util.cs" />
|
||||
@@ -240,7 +242,7 @@
|
||||
<Compile Include="Harvester.cs" />
|
||||
<Compile Include="HarvesterHuskModifier.cs" />
|
||||
<Compile Include="Husk.cs" />
|
||||
<Compile Include="InfiltrateForSupportPower.cs" />
|
||||
<Compile Include="Infiltration\InfiltrateForSupportPower.cs" />
|
||||
<Compile Include="Invulnerable.cs" />
|
||||
<Compile Include="IronCurtainable.cs" />
|
||||
<Compile Include="JamsMissiles.cs" />
|
||||
@@ -289,6 +291,7 @@
|
||||
<Compile Include="PortableChrono.cs" />
|
||||
<Compile Include="Scripting\Properties\GuardProperties.cs" />
|
||||
<Compile Include="Scripting\Properties\PlayerProperties.cs" />
|
||||
<Compile Include="Power\ScalePowerWithHealth.cs" />
|
||||
<Compile Include="Warheads\DestroyResourceWarhead.cs" />
|
||||
<Compile Include="Warheads\CreateEffectWarhead.cs" />
|
||||
<Compile Include="Warheads\CreateResourceWarhead.cs" />
|
||||
@@ -413,12 +416,12 @@
|
||||
<Compile Include="World\SmudgeLayer.cs" />
|
||||
<Compile Include="Player\BaseAttackNotifier.cs" />
|
||||
<Compile Include="Player\HarvesterAttackNotifier.cs" />
|
||||
<Compile Include="InfiltrateForExploration.cs" />
|
||||
<Compile Include="InfiltrateForCash.cs" />
|
||||
<Compile Include="Infiltration\InfiltrateForExploration.cs" />
|
||||
<Compile Include="Infiltration\InfiltrateForCash.cs" />
|
||||
<Compile Include="RenderShroudCircle.cs" />
|
||||
<Compile Include="CloakPaletteEffect.cs" />
|
||||
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
|
||||
<Compile Include="Infiltrates.cs" />
|
||||
<Compile Include="Infiltration\Infiltrates.cs" />
|
||||
<Compile Include="Armament.cs" />
|
||||
<Compile Include="Buildings\BaseProvider.cs" />
|
||||
<Compile Include="Widgets\Logic\ObserverShroudSelectorLogic.cs" />
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
|
||||
namespace OpenRA.Mods.RA.Orders
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
|
||||
58
OpenRA.Mods.RA/Power/AffectedByPowerOutage.cs
Normal file
58
OpenRA.Mods.RA/Power/AffectedByPowerOutage.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,24 +11,22 @@
|
||||
using OpenRA.Mods.RA.Effects;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
namespace OpenRA.Mods.RA.Power
|
||||
{
|
||||
[Desc("The player can disable the power individually on this actor.")]
|
||||
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;
|
||||
int normalPower = 0;
|
||||
PowerManager PowerManager;
|
||||
readonly Power power;
|
||||
|
||||
public CanPowerDown(ActorInitializer init)
|
||||
public CanPowerDown(Actor self)
|
||||
{
|
||||
PowerManager = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
normalPower = init.self.Info.Traits.Get<PowerInfo>().Amount;
|
||||
power = self.Trait<Power>();
|
||||
}
|
||||
|
||||
public bool Disabled { get { return disabled; } }
|
||||
@@ -38,18 +36,17 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
if (order.OrderString == "PowerDown")
|
||||
{
|
||||
disabled = !disabled;
|
||||
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", (disabled ? "EnablePower" : "DisablePower"), self.Owner.Country.Race);
|
||||
PowerManager.UpdateActor(self, disabled ? 0 : normalPower);
|
||||
Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Sounds", disabled ? "EnablePower" : "DisablePower", self.Owner.Country.Race);
|
||||
power.PlayerPower.UpdateActor(self);
|
||||
|
||||
if (disabled)
|
||||
self.World.AddFrameEndTask(
|
||||
w => w.Add(new PowerdownIndicator(self)));
|
||||
self.World.AddFrameEndTask(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
OpenRA.Mods.RA/Buildings/PowerManager.cs → OpenRA.Mods.RA/Power/Player/PowerManager.cs
Executable file → Normal file
72
OpenRA.Mods.RA/Buildings/PowerManager.cs → OpenRA.Mods.RA/Power/Player/PowerManager.cs
Executable file → Normal file
@@ -9,20 +9,21 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
namespace OpenRA.Mods.RA.Power
|
||||
{
|
||||
public class PowerManagerInfo : ITraitInfo, Requires<DeveloperModeInfo>
|
||||
{
|
||||
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
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly PowerManagerInfo info;
|
||||
readonly Player player;
|
||||
readonly DeveloperMode devMode;
|
||||
|
||||
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 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;
|
||||
player = init.self.Owner;
|
||||
|
||||
init.world.ActorAdded += ActorAdded;
|
||||
init.world.ActorRemoved += ActorRemoved;
|
||||
self.World.ActorAdded += UpdateActor;
|
||||
self.World.ActorRemoved += RemoveActor;
|
||||
|
||||
devMode = init.self.Trait<DeveloperMode>();
|
||||
devMode = self.Trait<DeveloperMode>();
|
||||
wasHackEnabled = devMode.UnlimitedPower;
|
||||
}
|
||||
|
||||
void ActorAdded(Actor a)
|
||||
public void UpdateActor(Actor a)
|
||||
{
|
||||
if (a.Owner != player)
|
||||
UpdateActors(new[] { a });
|
||||
}
|
||||
|
||||
public void UpdateActors(IEnumerable<Actor> actors)
|
||||
{
|
||||
foreach (var a in actors)
|
||||
{
|
||||
if (a.Owner != self.Owner)
|
||||
return;
|
||||
|
||||
var power = a.TraitOrDefault<Power>();
|
||||
if (power == null)
|
||||
return;
|
||||
|
||||
powerDrain.Add(a, power.CurrentPower);
|
||||
powerDrain[a] = power.GetCurrentPower();
|
||||
}
|
||||
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;
|
||||
|
||||
powerDrain.Remove(a);
|
||||
UpdateTotals();
|
||||
}
|
||||
|
||||
void UpdateTotals()
|
||||
public void UpdateTotals()
|
||||
{
|
||||
totalProvided = 0;
|
||||
totalDrained = 0;
|
||||
|
||||
foreach (var kv in powerDrain)
|
||||
{
|
||||
var p = kv.Value;
|
||||
@@ -84,15 +98,6 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
totalProvided = 1000000;
|
||||
}
|
||||
|
||||
public void UpdateActor(Actor a, int newPower)
|
||||
{
|
||||
if (a.Owner != player || !a.HasTrait<Power>())
|
||||
return;
|
||||
|
||||
powerDrain[a] = newPower;
|
||||
UpdateTotals();
|
||||
}
|
||||
|
||||
int nextPowerAdviceTime = 0;
|
||||
bool wasLowPower = false;
|
||||
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);
|
||||
nextPowerAdviceTime = info.AdviceInterval;
|
||||
}
|
||||
|
||||
if (PowerOutageRemainingTicks > 0 && --PowerOutageRemainingTicks == 0)
|
||||
UpdatePowerOutageActors();
|
||||
}
|
||||
|
||||
public PowerState PowerState
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
if (PowerProvided >= PowerDrained) return PowerState.Normal;
|
||||
if (PowerProvided > PowerDrained / 2) return PowerState.Low;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,55 +9,41 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
namespace OpenRA.Mods.RA.Power
|
||||
{
|
||||
public class PowerInfo : ITraitInfo
|
||||
{
|
||||
[Desc("If negative, it will drain power. If positive, it will provide power.")]
|
||||
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 class Power : INotifyDamage, INotifyCapture
|
||||
public class Power : INotifyCapture
|
||||
{
|
||||
readonly PowerInfo info;
|
||||
readonly Lazy<Health> health;
|
||||
PowerManager playerPower;
|
||||
readonly Lazy<IPowerModifier[]> powerModifiers;
|
||||
|
||||
public int CurrentPower
|
||||
{
|
||||
get
|
||||
{
|
||||
if (info.Amount <= 0 || health == null || !info.ScaleWithHealth)
|
||||
return info.Amount;
|
||||
public PowerManager PlayerPower { get; private set; }
|
||||
|
||||
return info.Amount * health.Value.HP / health.Value.MaxHP;
|
||||
}
|
||||
public int GetCurrentPower()
|
||||
{
|
||||
return Util.ApplyPercentageModifiers(info.Amount, powerModifiers.Value.Select(m => m.GetPowerModifier()));
|
||||
}
|
||||
|
||||
public Power(Actor self, PowerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
health = Exts.Lazy(self.TraitOrDefault<Health>);
|
||||
playerPower = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
public void Damaged(Actor self, AttackInfo e)
|
||||
{
|
||||
if (info.ScaleWithHealth)
|
||||
playerPower.UpdateActor(self, CurrentPower);
|
||||
PlayerPower = self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
powerModifiers = Exts.Lazy(() => self.TraitsImplementing<IPowerModifier>().ToArray());
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
playerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
PlayerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
OpenRA.Mods.RA/Buildings/RequiresPower.cs → OpenRA.Mods.RA/Power/RequiresPower.cs
Executable file → Normal file
12
OpenRA.Mods.RA/Buildings/RequiresPower.cs → OpenRA.Mods.RA/Power/RequiresPower.cs
Executable file → Normal file
@@ -10,7 +10,7 @@
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Buildings
|
||||
namespace OpenRA.Mods.RA.Power
|
||||
{
|
||||
class RequiresPowerInfo : ITraitInfo
|
||||
{
|
||||
@@ -19,21 +19,21 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
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
|
||||
{
|
||||
get { return power.PowerProvided < power.PowerDrained; }
|
||||
get { return playerPower.PowerProvided < playerPower.PowerDrained; }
|
||||
}
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
power = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
playerPower = newOwner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
OpenRA.Mods.RA/Power/ScalePowerWithHealth.cs
Normal file
42
OpenRA.Mods.RA/Power/ScalePowerWithHealth.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Mods.RA.Power;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
|
||||
@@ -334,8 +334,8 @@ namespace OpenRA.Utility
|
||||
node.Key = "Units";
|
||||
}
|
||||
|
||||
// Power from Building was moved out into its own trait
|
||||
if (engineVersion < 20140802)
|
||||
// Power from Building was moved out into Power and ScalePowerWithHealth traits
|
||||
if (engineVersion < 20140823)
|
||||
{
|
||||
if (depth == 0)
|
||||
{
|
||||
@@ -350,11 +350,10 @@ namespace OpenRA.Utility
|
||||
buildingFields.Remove(power);
|
||||
|
||||
var powerFields = new List<MiniYamlNode> { new MiniYamlNode("Amount", power.Value) };
|
||||
actorTraits.Add(new MiniYamlNode("Power", new MiniYaml("", powerFields)));
|
||||
|
||||
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("ScaleWithHealth", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ NUKE:
|
||||
Bib:
|
||||
Power:
|
||||
Amount: 100
|
||||
ScaleWithHealth: True
|
||||
ScalePowerWithHealth:
|
||||
|
||||
NUK2:
|
||||
Inherits: ^BaseBuilding
|
||||
@@ -125,7 +125,7 @@ NUK2:
|
||||
Bib:
|
||||
Power:
|
||||
Amount: 200
|
||||
ScaleWithHealth: True
|
||||
ScalePowerWithHealth:
|
||||
|
||||
PROC:
|
||||
Inherits: ^BaseBuilding
|
||||
|
||||
@@ -106,7 +106,7 @@ CONCRETEB:
|
||||
Sequence: idle-zaps
|
||||
Power:
|
||||
Amount: 100
|
||||
ScaleWithHealth: True
|
||||
ScalePowerWithHealth:
|
||||
|
||||
^BARRACKS:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -199,7 +199,7 @@ SPY:
|
||||
Cost: 500
|
||||
DisguiseToolTip:
|
||||
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:
|
||||
Voice: SpyVoice
|
||||
Bounds: 12,17,0,-9
|
||||
|
||||
@@ -949,7 +949,12 @@ POWR:
|
||||
DeadBuildingState:
|
||||
Power:
|
||||
Amount: 100
|
||||
ScaleWithHealth: True
|
||||
InfiltrateForPowerOutage:
|
||||
AffectedByPowerOutage:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
|
||||
ScalePowerWithHealth:
|
||||
DisabledOverlay:
|
||||
|
||||
APWR:
|
||||
Inherits: ^Building
|
||||
@@ -978,7 +983,12 @@ APWR:
|
||||
DeadBuildingState:
|
||||
Power:
|
||||
Amount: 200
|
||||
ScaleWithHealth: True
|
||||
InfiltrateForPowerOutage:
|
||||
AffectedByPowerOutage:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
|
||||
ScalePowerWithHealth:
|
||||
DisabledOverlay:
|
||||
|
||||
STEK:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -71,7 +71,12 @@ GAPOWR:
|
||||
Sequence: idle-plug
|
||||
Power:
|
||||
Amount: 100
|
||||
ScaleWithHealth: True
|
||||
InfiltrateForPowerOutage:
|
||||
AffectedByPowerOutage:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
|
||||
ScalePowerWithHealth:
|
||||
DisabledOverlay:
|
||||
|
||||
GAPILE:
|
||||
Inherits: ^Building
|
||||
@@ -222,7 +227,12 @@ NAPOWR:
|
||||
Sequence: idle-lights
|
||||
Power:
|
||||
Amount: 100
|
||||
ScaleWithHealth: True
|
||||
InfiltrateForPowerOutage:
|
||||
AffectedByPowerOutage:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
|
||||
ScalePowerWithHealth:
|
||||
DisabledOverlay:
|
||||
|
||||
NAAPWR:
|
||||
Inherits: ^Building
|
||||
@@ -251,7 +261,12 @@ NAAPWR:
|
||||
Sequence: idle-lights
|
||||
Power:
|
||||
Amount: 200
|
||||
ScaleWithHealth: True
|
||||
InfiltrateForPowerOutage:
|
||||
AffectedByPowerOutage:
|
||||
TargetableBuilding:
|
||||
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
|
||||
ScalePowerWithHealth:
|
||||
DisabledOverlay:
|
||||
|
||||
NAHAND:
|
||||
Inherits: ^Building
|
||||
|
||||
Reference in New Issue
Block a user