Try again, with less fail.
This commit is contained in:
@@ -38,7 +38,7 @@ namespace OpenRA.Traits
|
||||
public object Create(ActorInitializer init) { return new Building(init); }
|
||||
}
|
||||
|
||||
public class Building : INotifyDamage, IResolveOrder, IRenderModifier, IOccupySpace
|
||||
public class Building : INotifyDamage, IResolveOrder, IOccupySpace
|
||||
{
|
||||
readonly Actor self;
|
||||
public readonly BuildingInfo Info;
|
||||
@@ -47,11 +47,6 @@ namespace OpenRA.Traits
|
||||
|
||||
readonly PowerManager PlayerPower;
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get { return self.TraitsImplementing<IDisable>().Any(t => t.Disabled); }
|
||||
}
|
||||
|
||||
public Building(ActorInitializer init)
|
||||
{
|
||||
this.self = init.self;
|
||||
@@ -99,16 +94,6 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
foreach (var a in r)
|
||||
{
|
||||
yield return a;
|
||||
if (Disabled)
|
||||
yield return a.WithPalette("disabled");
|
||||
}
|
||||
}
|
||||
|
||||
public int2 TopLeft
|
||||
{
|
||||
get { return topLeft; }
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace OpenRA.Traits
|
||||
PowerManagerInfo Info;
|
||||
Player Player;
|
||||
|
||||
Dictionary<Actor, List<string>> Overrides = new Dictionary<Actor, List<string>>();
|
||||
Dictionary<Actor, int> PowerDrain = new Dictionary<Actor, int>();
|
||||
[Sync] int totalProvided;
|
||||
public int PowerProvided { get { return totalProvided; } }
|
||||
@@ -67,9 +66,6 @@ namespace OpenRA.Traits
|
||||
totalDrained = 0;
|
||||
foreach (var kv in PowerDrain)
|
||||
{
|
||||
if (Overrides.Keys.Contains(kv.Key))
|
||||
continue;
|
||||
|
||||
var p = kv.Value;
|
||||
if (p > 0)
|
||||
totalProvided += p;
|
||||
@@ -106,46 +102,6 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
// Force power down for power-down button, spy, emp, etc
|
||||
public void Disable(Actor a, string key)
|
||||
{
|
||||
Game.Debug("Disabled {0}.{1}",a.Info.Name,key);
|
||||
|
||||
if (Overrides.ContainsKey(a))
|
||||
{
|
||||
if (Overrides[a].Contains(key))
|
||||
return;
|
||||
|
||||
Overrides[a].Add(key);
|
||||
}
|
||||
else
|
||||
Overrides.Add(a, new List<string>() { key });
|
||||
|
||||
UpdateTotals();
|
||||
}
|
||||
|
||||
public void RemoveDisable(Actor a, string key)
|
||||
{
|
||||
Game.Debug("Enabled {0}.{1}",a.Info.Name, key);
|
||||
|
||||
if (!Overrides.ContainsKey(a) || !Overrides[a].Contains(key))
|
||||
return;
|
||||
|
||||
Overrides[a].Remove(key);
|
||||
if (Overrides[a].Count == 0)
|
||||
Overrides.Remove(a);
|
||||
|
||||
UpdateTotals();
|
||||
}
|
||||
|
||||
public bool IsPowered(Actor a)
|
||||
{
|
||||
if (Overrides.ContainsKey(a))
|
||||
return false;
|
||||
|
||||
return PowerProvided >= PowerDrained;
|
||||
}
|
||||
|
||||
public PowerState GetPowerState()
|
||||
{
|
||||
if (PowerProvided >= PowerDrained) return PowerState.Normal;
|
||||
|
||||
@@ -222,8 +222,7 @@ namespace OpenRA.Traits
|
||||
|
||||
protected static bool IsDisabledBuilding(Actor a)
|
||||
{
|
||||
var building = a.TraitOrDefault<Building>();
|
||||
return building != null && building.Disabled;
|
||||
return a.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
||||
}
|
||||
|
||||
protected virtual void BuildUnit( string name )
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace OpenRA.Traits
|
||||
bool UpdateActive(Actor self)
|
||||
{
|
||||
// Check if powered
|
||||
var b = self.Trait<Building>();
|
||||
if (b.Disabled) return false;
|
||||
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled))
|
||||
return false;
|
||||
|
||||
var isJammed = self.World.Queries.WithTrait<JamsRadar>().Any(a => self.Owner != a.Actor.Owner
|
||||
&& (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<JamsRadarInfo>().Range);
|
||||
|
||||
@@ -104,8 +104,7 @@ namespace OpenRA.Traits
|
||||
|
||||
// Takes 0.3ms on pchote's machine -- calling it every tick for every active special power is retarded
|
||||
var buildings = TechTree.GatherBuildings(Owner);
|
||||
|
||||
return effectivePrereq.All(a => buildings[a].Any(b => !b.Trait<Building>().Disabled));
|
||||
return effectivePrereq.All(a => buildings[a].Any(b => !b.TraitsImplementing<IDisable>().All(d => d.Disabled)));
|
||||
}
|
||||
|
||||
public void FinishActivate()
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Traits;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -45,7 +46,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
protected override void QueueAttack( Actor self, Order order )
|
||||
{
|
||||
if (self.HasTrait<Building>() && self.Trait<Building>().Disabled)
|
||||
if (self.TraitsImplementing<IDisable>().Any(d => d.Disabled))
|
||||
return;
|
||||
|
||||
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
||||
|
||||
@@ -17,15 +17,17 @@ namespace OpenRA.Mods.RA
|
||||
public object Create(ActorInitializer init) { return new CanPowerDown(init); }
|
||||
}
|
||||
|
||||
public class CanPowerDown : IResolveOrder
|
||||
public class CanPowerDown : IResolveOrder, IDisable
|
||||
{
|
||||
[Sync]
|
||||
bool disabled = false;
|
||||
|
||||
int normalPower = 0;
|
||||
readonly PowerManager PlayerPower;
|
||||
|
||||
public CanPowerDown(ActorInitializer init)
|
||||
{
|
||||
PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
normalPower = init.self.Info.Traits.Get<BuildingInfo>().Power;
|
||||
}
|
||||
public bool Disabled { get { return disabled; } }
|
||||
|
||||
@@ -37,10 +39,7 @@ namespace OpenRA.Mods.RA
|
||||
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
|
||||
Sound.PlayToPlayer(self.Owner, disabled ? eva.EnablePower : eva.DisablePower);
|
||||
|
||||
if (disabled)
|
||||
PlayerPower.Disable(self, "PowerDown");
|
||||
else
|
||||
PlayerPower.RemoveDisable(self, "PowerDown");
|
||||
PlayerPower.UpdateActor(self, disabled ? 0 : normalPower);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,14 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
return r.Select(a => a.WithPos(a.Pos - Origin));
|
||||
var disabled = self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
||||
foreach (var a in r)
|
||||
{
|
||||
var ret = a.WithPos(a.Pos - Origin);
|
||||
yield return ret;
|
||||
if (disabled)
|
||||
yield return ret.WithPalette("disabled").WithZOffset(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public RenderBuilding( ActorInitializer init, Func<int> baseFacing )
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
get { return power.IsPowered(self); }
|
||||
get { return power.PowerProvided < power.PowerDrained; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user