Actor properties consistency improved
This commit is contained in:
@@ -23,20 +23,33 @@ namespace OpenRA
|
||||
{
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
||||
{
|
||||
public readonly ActorInfo Info;
|
||||
[Sync] public Player Owner;
|
||||
|
||||
public readonly ActorInfo Info;
|
||||
public readonly World World;
|
||||
public readonly uint ActorID;
|
||||
public Lazy<Rectangle> Bounds;
|
||||
|
||||
Lazy<IOccupySpace> occupySpace;
|
||||
public bool IsInWorld { get; internal set; }
|
||||
public bool Destroyed { get; private set; }
|
||||
|
||||
Activity currentActivity;
|
||||
|
||||
public Group Group;
|
||||
public int Generation;
|
||||
|
||||
Lazy<Rectangle> bounds;
|
||||
Lazy<IFacing> facing;
|
||||
Lazy<Health> health;
|
||||
Lazy<IOccupySpace> occupySpace;
|
||||
Lazy<IEffectiveOwner> effectiveOwner;
|
||||
|
||||
public Rectangle Bounds { get { return bounds.Value; } }
|
||||
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
|
||||
public IEffectiveOwner EffectiveOwner { get { return effectiveOwner.Value; } }
|
||||
|
||||
public bool IsIdle { get { return currentActivity == null; } }
|
||||
public bool IsDead { get { return Destroyed || (health.Value == null ? false : health.Value.IsDead); } }
|
||||
|
||||
public CPos Location { get { return occupySpace.Value.TopLeft; } }
|
||||
public WPos CenterPosition { get { return occupySpace.Value.CenterPosition; } }
|
||||
|
||||
@@ -50,12 +63,6 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
[Sync] public Player Owner;
|
||||
|
||||
Activity currentActivity;
|
||||
public Group Group;
|
||||
public int Generation;
|
||||
|
||||
internal Actor(World world, string name, TypeDictionary initDict)
|
||||
{
|
||||
var init = new ActorInitializer(this, initDict);
|
||||
@@ -69,10 +76,12 @@ namespace OpenRA
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
if (!world.Map.Rules.Actors.ContainsKey(name.ToLowerInvariant()))
|
||||
throw new NotImplementedException("No rules definition for unit {0}".F(name.ToLowerInvariant()));
|
||||
name = name.ToLowerInvariant();
|
||||
|
||||
Info = world.Map.Rules.Actors[name.ToLowerInvariant()];
|
||||
if (!world.Map.Rules.Actors.ContainsKey(name))
|
||||
throw new NotImplementedException("No rules definition for unit " + name);
|
||||
|
||||
Info = world.Map.Rules.Actors[name];
|
||||
foreach (var trait in Info.TraitsInConstructOrder())
|
||||
AddTrait(trait.Create(init));
|
||||
}
|
||||
@@ -81,7 +90,7 @@ namespace OpenRA
|
||||
health = Exts.Lazy(() => TraitOrDefault<Health>());
|
||||
effectiveOwner = Exts.Lazy(() => TraitOrDefault<IEffectiveOwner>());
|
||||
|
||||
Bounds = Exts.Lazy(() =>
|
||||
bounds = Exts.Lazy(() =>
|
||||
{
|
||||
var si = Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
var size = (si != null && si.Bounds != null) ? new int2(si.Bounds[0], si.Bounds[1]) :
|
||||
@@ -99,16 +108,12 @@ namespace OpenRA
|
||||
{
|
||||
var wasIdle = IsIdle;
|
||||
currentActivity = Traits.Util.RunActivity(this, currentActivity);
|
||||
|
||||
if (!wasIdle && IsIdle)
|
||||
foreach (var n in TraitsImplementing<INotifyBecomingIdle>())
|
||||
n.OnBecomingIdle(this);
|
||||
}
|
||||
|
||||
public bool IsIdle
|
||||
{
|
||||
get { return currentActivity == null; }
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||
{
|
||||
var renderables = Renderables(wr);
|
||||
@@ -124,8 +129,6 @@ namespace OpenRA
|
||||
yield return renderable;
|
||||
}
|
||||
|
||||
public bool IsInWorld { get; internal set; }
|
||||
|
||||
public void QueueActivity(bool queued, Activity nextActivity)
|
||||
{
|
||||
if (!queued)
|
||||
@@ -198,8 +201,6 @@ namespace OpenRA
|
||||
World.traitDict.AddTrait(this, trait);
|
||||
}
|
||||
|
||||
public bool Destroyed { get; private set; }
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
World.AddFrameEndTask(w =>
|
||||
@@ -239,19 +240,6 @@ namespace OpenRA
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsDead()
|
||||
{
|
||||
if (Destroyed)
|
||||
return true;
|
||||
|
||||
return (health.Value == null) ? false : health.Value.IsDead;
|
||||
}
|
||||
|
||||
public bool IsDisguised()
|
||||
{
|
||||
return effectiveOwner.Value != null && effectiveOwner.Value.Disguised;
|
||||
}
|
||||
|
||||
public void Kill(Actor attacker)
|
||||
{
|
||||
if (health.Value == null)
|
||||
|
||||
@@ -81,7 +81,8 @@ namespace OpenRA.Graphics
|
||||
if (Game.Settings.Game.TeamHealthColors)
|
||||
{
|
||||
var isAlly = actor.Owner.IsAlliedWith(actor.World.LocalPlayer)
|
||||
|| (actor.IsDisguised() && actor.World.LocalPlayer.IsAlliedWith(actor.EffectiveOwner.Owner));
|
||||
|| (actor.EffectiveOwner != null && actor.EffectiveOwner.Disguised
|
||||
&& actor.World.LocalPlayer.IsAlliedWith(actor.EffectiveOwner.Owner));
|
||||
return isAlly ? Color.LimeGreen : actor.Owner.NonCombatant ? Color.Tan : Color.Red;
|
||||
}
|
||||
else
|
||||
@@ -137,13 +138,13 @@ namespace OpenRA.Graphics
|
||||
public void BeforeRender(WorldRenderer wr) {}
|
||||
public void Render(WorldRenderer wr)
|
||||
{
|
||||
if (!actor.IsInWorld || actor.IsDead())
|
||||
if (!actor.IsInWorld || actor.IsDead)
|
||||
return;
|
||||
|
||||
var health = actor.TraitOrDefault<Health>();
|
||||
|
||||
var screenPos = wr.ScreenPxPosition(pos);
|
||||
var bounds = actor.Bounds.Value;
|
||||
var bounds = actor.Bounds;
|
||||
bounds.Offset(screenPos.X, screenPos.Y);
|
||||
|
||||
var xy = new float2(bounds.Left, bounds.Top);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Graphics
|
||||
readonly Color color;
|
||||
|
||||
public SelectionBoxRenderable(Actor actor, Color color)
|
||||
: this(actor.CenterPosition, actor.Bounds.Value, 1f, color) { }
|
||||
: this(actor.CenterPosition, actor.Bounds, 1f, color) { }
|
||||
|
||||
public SelectionBoxRenderable(WPos pos, Rectangle bounds, float scale, Color color)
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Scripting
|
||||
protected override string MemberNotFoundError(string memberName)
|
||||
{
|
||||
var actorName = actor.Info.Name;
|
||||
if (actor.IsDead())
|
||||
if (actor.IsDead)
|
||||
actorName += " (dead)";
|
||||
|
||||
return "Actor '{0}' does not define a property '{1}'".F(actorName, memberName);
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA
|
||||
return;
|
||||
}
|
||||
|
||||
var groupActors = controlGroups[group].Where(a => !a.IsDead());
|
||||
var groupActors = controlGroups[group].Where(a => !a.IsDead);
|
||||
|
||||
if (mods.HasModifier(Modifiers.Alt) || MultiTapCount >= 2)
|
||||
{
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Traits
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDamageStateChanged>())
|
||||
nd.DamageStateChanged(self, ai);
|
||||
|
||||
if (Info.NotifyAppliedDamage && repairer != null && repairer.IsInWorld && !repairer.IsDead())
|
||||
if (Info.NotifyAppliedDamage && repairer != null && repairer.IsInWorld && !repairer.IsDead)
|
||||
foreach (var nd in repairer.TraitsImplementing<INotifyAppliedDamage>()
|
||||
.Concat(repairer.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
nd.AppliedDamage(repairer, self, ai);
|
||||
@@ -141,7 +141,7 @@ namespace OpenRA.Traits
|
||||
foreach (var nd in self.TraitsImplementing<INotifyDamageStateChanged>())
|
||||
nd.DamageStateChanged(self, ai);
|
||||
|
||||
if (Info.NotifyAppliedDamage && attacker != null && attacker.IsInWorld && !attacker.IsDead())
|
||||
if (Info.NotifyAppliedDamage && attacker != null && attacker.IsInWorld && !attacker.IsDead)
|
||||
foreach (var nd in attacker.TraitsImplementing<INotifyAppliedDamage>()
|
||||
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
|
||||
nd.AppliedDamage(attacker, self, ai);
|
||||
|
||||
@@ -47,13 +47,13 @@ namespace OpenRA.Traits
|
||||
FootprintRegion = footprintRegion;
|
||||
|
||||
CenterPosition = self.CenterPosition;
|
||||
Bounds = self.Bounds.Value;
|
||||
Bounds = self.Bounds;
|
||||
}
|
||||
|
||||
public uint ID { get { return actor.ActorID; } }
|
||||
public bool IsValid { get { return Owner != null && HasRenderables; } }
|
||||
public ActorInfo Info { get { return actor.Info; } }
|
||||
public Actor Actor { get { return !actor.IsDead() ? actor : null; } }
|
||||
public Actor Actor { get { return !actor.IsDead ? actor : null; } }
|
||||
|
||||
int flashTicks;
|
||||
public void Tick(World world, Shroud shroud)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Traits
|
||||
|
||||
IEnumerable<WPos> ActivityTargetPath()
|
||||
{
|
||||
if (!self.IsInWorld || self.IsDead())
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
yield break;
|
||||
|
||||
var activity = self.GetCurrentActivity();
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Traits
|
||||
if (!self.Owner.IsAlliedWith(self.World.RenderPlayer) && self.World.FogObscures(self))
|
||||
yield break;
|
||||
|
||||
var b = self.Bounds.Value;
|
||||
var b = self.Bounds;
|
||||
var pos = wr.ScreenPxPosition(self.CenterPosition);
|
||||
var tl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Top));
|
||||
var bl = wr.Viewport.WorldToViewPx(pos + new int2(b.Left, b.Bottom));
|
||||
@@ -85,7 +85,7 @@ namespace OpenRA.Traits
|
||||
var pipxyBase = basePosition + new int2(1 - pipSize.X / 2, - (3 + pipSize.Y / 2));
|
||||
var pipxyOffset = new int2(0, 0);
|
||||
var pal = wr.Palette(Info.Palette);
|
||||
var width = self.Bounds.Value.Width;
|
||||
var width = self.Bounds.Width;
|
||||
|
||||
foreach (var pips in pipSources)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Traits
|
||||
if (type == TargetType.Actor)
|
||||
{
|
||||
// Actor is no longer in the world
|
||||
if (!actor.IsInWorld || actor.IsDead())
|
||||
if (!actor.IsInWorld || actor.IsDead)
|
||||
return TargetType.Invalid;
|
||||
|
||||
// Actor generation has changed (teleported or captured)
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace OpenRA.Traits
|
||||
public void Add(Actor a)
|
||||
{
|
||||
var pos = worldRenderer.ScreenPxPosition(a.CenterPosition);
|
||||
var bounds = a.Bounds.Value;
|
||||
var bounds = a.Bounds;
|
||||
bounds.Offset(pos.X, pos.Y);
|
||||
|
||||
var top = Math.Max(0, bounds.Top / info.BinSize);
|
||||
|
||||
Reference in New Issue
Block a user