Merge pull request #8226 from pchote/actor-disposal
Dispose traits when destroying an actor.
This commit is contained in:
@@ -22,7 +22,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
public sealed class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>, IDisposable
|
||||||
{
|
{
|
||||||
public readonly ActorInfo Info;
|
public readonly ActorInfo Info;
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ namespace OpenRA
|
|||||||
[Sync] public Player Owner { get; set; }
|
[Sync] public Player Owner { get; set; }
|
||||||
|
|
||||||
public bool IsInWorld { get; internal set; }
|
public bool IsInWorld { get; internal set; }
|
||||||
public bool Destroyed { get; private set; }
|
public bool Disposed { get; private set; }
|
||||||
|
|
||||||
Activity currentActivity;
|
Activity currentActivity;
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ namespace OpenRA
|
|||||||
public IEffectiveOwner EffectiveOwner { get { return effectiveOwner.Value; } }
|
public IEffectiveOwner EffectiveOwner { get { return effectiveOwner.Value; } }
|
||||||
|
|
||||||
public bool IsIdle { get { return currentActivity == null; } }
|
public bool IsIdle { get { return currentActivity == null; } }
|
||||||
public bool IsDead { get { return Destroyed || (health.Value == null ? false : health.Value.IsDead); } }
|
public bool IsDead { get { return Disposed || (health.Value == null ? false : health.Value.IsDead); } }
|
||||||
|
|
||||||
public CPos Location { get { return occupySpace.Value.TopLeft; } }
|
public CPos Location { get { return occupySpace.Value.TopLeft; } }
|
||||||
public WPos CenterPosition { get { return occupySpace.Value.CenterPosition; } }
|
public WPos CenterPosition { get { return occupySpace.Value.CenterPosition; } }
|
||||||
@@ -215,18 +215,21 @@ namespace OpenRA
|
|||||||
World.TraitDict.AddTrait(this, trait);
|
World.TraitDict.AddTrait(this, trait);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Destroy()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
World.AddFrameEndTask(w =>
|
World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (Destroyed)
|
if (Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (IsInWorld)
|
if (IsInWorld)
|
||||||
World.Remove(this);
|
World.Remove(this);
|
||||||
|
|
||||||
|
foreach (var t in TraitsImplementing<INotifyActorDisposing>())
|
||||||
|
t.Disposing(this);
|
||||||
|
|
||||||
World.TraitDict.RemoveActor(this);
|
World.TraitDict.RemoveActor(this);
|
||||||
Destroyed = true;
|
Disposed = true;
|
||||||
|
|
||||||
if (luaInterface != null)
|
if (luaInterface != null)
|
||||||
luaInterface.Value.OnActorDestroyed();
|
luaInterface.Value.OnActorDestroyed();
|
||||||
@@ -238,7 +241,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
World.AddFrameEndTask(w =>
|
World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (Destroyed)
|
if (Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var oldOwner = Owner;
|
var oldOwner = Owner;
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
|
if (World.WorldActor.Disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
RefreshPalette();
|
RefreshPalette();
|
||||||
|
|
||||||
if (World.Type == WorldType.Shellmap && !Game.Settings.Game.ShowShellmap)
|
if (World.Type == WorldType.Shellmap && !Game.Settings.Game.ShowShellmap)
|
||||||
@@ -140,7 +143,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
// added for contrails
|
// added for contrails
|
||||||
foreach (var a in World.ActorsWithTrait<IPostRender>())
|
foreach (var a in World.ActorsWithTrait<IPostRender>())
|
||||||
if (a.Actor.IsInWorld && !a.Actor.Destroyed)
|
if (a.Actor.IsInWorld && !a.Actor.Disposed)
|
||||||
a.Trait.RenderAfterWorld(this, a.Actor);
|
a.Trait.RenderAfterWorld(this, a.Actor);
|
||||||
|
|
||||||
var renderShroud = World.RenderPlayer != null ? World.RenderPlayer.Shroud : null;
|
var renderShroud = World.RenderPlayer != null ? World.RenderPlayer.Shroud : null;
|
||||||
@@ -154,7 +157,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
Game.Renderer.DisableScissor();
|
Game.Renderer.DisableScissor();
|
||||||
|
|
||||||
var overlayRenderables = World.Selection.Actors.Where(a => !a.Destroyed)
|
var overlayRenderables = World.Selection.Actors.Where(a => !a.Disposed)
|
||||||
.SelectMany(a => a.TraitsImplementing<IPostRenderSelection>())
|
.SelectMany(a => a.TraitsImplementing<IPostRenderSelection>())
|
||||||
.SelectMany(t => t.RenderAfterWorld(this));
|
.SelectMany(t => t.RenderAfterWorld(this));
|
||||||
|
|
||||||
@@ -174,7 +177,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (World.Type == WorldType.Regular && Game.Settings.Game.AlwaysShowStatusBars)
|
if (World.Type == WorldType.Regular && Game.Settings.Game.AlwaysShowStatusBars)
|
||||||
{
|
{
|
||||||
foreach (var g in World.Actors.Where(a => !a.Destroyed
|
foreach (var g in World.Actors.Where(a => !a.Disposed
|
||||||
&& a.HasTrait<Selectable>()
|
&& a.HasTrait<Selectable>()
|
||||||
&& !World.FogObscures(a)
|
&& !World.FogObscures(a)
|
||||||
&& !World.Selection.Actors.Contains(a)))
|
&& !World.Selection.Actors.Contains(a)))
|
||||||
@@ -273,6 +276,12 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
// HACK: Disposing the world from here violates ownership
|
||||||
|
// but the WorldRenderer lifetime matches the disposal
|
||||||
|
// behavior we want for the world, and the root object setup
|
||||||
|
// is so horrible that doing it properly would be a giant mess.
|
||||||
|
World.Dispose();
|
||||||
|
|
||||||
palette.Dispose();
|
palette.Dispose();
|
||||||
Theater.Dispose();
|
Theater.Dispose();
|
||||||
terrainRenderer.Dispose();
|
terrainRenderer.Dispose();
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace OpenRA.Orders
|
|||||||
if (self.Owner != self.World.LocalPlayer)
|
if (self.Owner != self.World.LocalPlayer)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (self.Destroyed || !target.IsValidFor(self))
|
if (self.Disposed || !target.IsValidFor(self))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action)
|
if (mi.Button == Game.Settings.Game.MouseButtonPreference.Action)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Scripting
|
|||||||
var commandClasses = Context.ActorCommands[actor.Info].AsEnumerable();
|
var commandClasses = Context.ActorCommands[actor.Info].AsEnumerable();
|
||||||
|
|
||||||
// Destroyed actors cannot have their traits queried
|
// Destroyed actors cannot have their traits queried
|
||||||
if (actor.Destroyed)
|
if (actor.Disposed)
|
||||||
commandClasses = commandClasses.Where(c => c.HasAttribute<ExposedForDestroyedActors>());
|
commandClasses = commandClasses.Where(c => c.HasAttribute<ExposedForDestroyedActors>());
|
||||||
|
|
||||||
var args = new object[] { Context, actor };
|
var args = new object[] { Context, actor };
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA
|
|||||||
foreach (var cg in controlGroups.Values)
|
foreach (var cg in controlGroups.Values)
|
||||||
{
|
{
|
||||||
// note: NOT `!a.IsInWorld`, since that would remove things that are in transports.
|
// note: NOT `!a.IsInWorld`, since that would remove things that are in transports.
|
||||||
cg.RemoveAll(a => a.Destroyed || a.Owner != world.LocalPlayer);
|
cg.RemoveAll(a => a.Disposed || a.Owner != world.LocalPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
static void CheckDestroyed(Actor actor)
|
static void CheckDestroyed(Actor actor)
|
||||||
{
|
{
|
||||||
if (actor.Destroyed)
|
if (actor.Disposed)
|
||||||
throw new InvalidOperationException("Attempted to get trait from destroyed object ({0})".F(actor));
|
throw new InvalidOperationException("Attempted to get trait from destroyed object ({0})".F(actor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var line = self.TraitOrDefault<DrawLineToTarget>();
|
var line = self.TraitOrDefault<DrawLineToTarget>();
|
||||||
@@ -120,7 +120,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
target.Flash();
|
target.Flash();
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ namespace OpenRA.Traits
|
|||||||
nd.Killed(self, ai);
|
nd.Killed(self, ai);
|
||||||
|
|
||||||
if (RemoveOnDeath)
|
if (RemoveOnDeath)
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
|
|
||||||
if (attacker == null)
|
if (attacker == null)
|
||||||
Log.Write("debug", "{0} #{1} was killed.", self.Info.Name, self.ActorID);
|
Log.Write("debug", "{0} #{1} was killed.", self.Info.Name, self.ActorID);
|
||||||
@@ -198,7 +198,7 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public static DamageState GetDamageState(this Actor self)
|
public static DamageState GetDamageState(this Actor self)
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Disposed)
|
||||||
return DamageState.Dead;
|
return DamageState.Dead;
|
||||||
|
|
||||||
var health = self.TraitOrDefault<Health>();
|
var health = self.TraitOrDefault<Health>();
|
||||||
@@ -207,7 +207,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public static void InflictDamage(this Actor self, Actor attacker, int damage, DamageWarhead warhead)
|
public static void InflictDamage(this Actor self, Actor attacker, int damage, DamageWarhead warhead)
|
||||||
{
|
{
|
||||||
if (self.Destroyed) return;
|
if (self.Disposed) return;
|
||||||
var health = self.TraitOrDefault<Health>();
|
var health = self.TraitOrDefault<Health>();
|
||||||
if (health == null) return;
|
if (health == null) return;
|
||||||
health.InflictDamage(self, attacker, damage, warhead, false);
|
health.InflictDamage(self, attacker, damage, warhead, false);
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace OpenRA.Traits
|
|||||||
if (NeedRenderables)
|
if (NeedRenderables)
|
||||||
{
|
{
|
||||||
NeedRenderables = false;
|
NeedRenderables = false;
|
||||||
if (!actor.Destroyed)
|
if (!actor.Disposed)
|
||||||
{
|
{
|
||||||
IsRendering = true;
|
IsRendering = true;
|
||||||
renderables = actor.Render(wr).ToArray();
|
renderables = actor.Render(wr).ToArray();
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ namespace OpenRA.Traits
|
|||||||
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
|
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
|
||||||
public interface INotifyRepair { void Repairing(Actor self, Actor host); }
|
public interface INotifyRepair { void Repairing(Actor self, Actor host); }
|
||||||
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
|
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
|
||||||
|
public interface INotifyActorDisposing { void Disposing(Actor self); }
|
||||||
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
|
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
|
||||||
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
||||||
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
|
public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); }
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ namespace OpenRA.Traits
|
|||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
for (var i = influence[a]; i != null; i = i.Next)
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
if (!i.Actor.Destroyed)
|
if (!i.Actor.Disposed)
|
||||||
yield return i.Actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ namespace OpenRA.Traits
|
|||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
for (var i = influence[a]; i != null; i = i.Next)
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
if (!i.Actor.Destroyed && (i.SubCell == sub || i.SubCell == SubCell.FullCell))
|
if (!i.Actor.Disposed && (i.SubCell == sub || i.SubCell == SubCell.FullCell))
|
||||||
yield return i.Actor;
|
yield return i.Actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
var always = sub == SubCell.FullCell || sub == SubCell.Any;
|
var always = sub == SubCell.FullCell || sub == SubCell.Any;
|
||||||
for (var i = influence[a]; i != null; i = i.Next)
|
for (var i = influence[a]; i != null; i = i.Next)
|
||||||
if ((always || i.SubCell == sub || i.SubCell == SubCell.FullCell) && !i.Actor.Destroyed && withCondition(i.Actor))
|
if ((always || i.SubCell == sub || i.SubCell == SubCell.FullCell) && !i.Actor.Disposed && withCondition(i.Actor))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRA
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var orderSubject = o.Subject;
|
var orderSubject = o.Subject;
|
||||||
if (orderSubject.Destroyed)
|
if (orderSubject.Disposed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var voice in orderSubject.TraitsImplementing<IVoiced>())
|
foreach (var voice in orderSubject.TraitsImplementing<IVoiced>())
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public enum WorldType { Regular, Shellmap, Editor }
|
public enum WorldType { Regular, Shellmap, Editor }
|
||||||
|
|
||||||
public class World
|
public sealed class World : IDisposable
|
||||||
{
|
{
|
||||||
class ActorIDComparer : IComparer<Actor>
|
class ActorIDComparer : IComparer<Actor>
|
||||||
{
|
{
|
||||||
@@ -369,6 +369,19 @@ namespace OpenRA
|
|||||||
pi.OutcomeTimestampUtc = DateTime.UtcNow;
|
pi.OutcomeTimestampUtc = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
frameEndActions.Clear();
|
||||||
|
|
||||||
|
// Dispose newer actors first, and the world actor last
|
||||||
|
foreach (var a in actors.Reverse())
|
||||||
|
a.Dispose();
|
||||||
|
|
||||||
|
// Actor disposals are done in a FrameEndTask
|
||||||
|
while (frameEndActions.Count != 0)
|
||||||
|
frameEndActions.Dequeue()(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct TraitPair<T>
|
public struct TraitPair<T>
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
case BuildingType.Defense:
|
case BuildingType.Defense:
|
||||||
|
|
||||||
// Build near the closest enemy structure
|
// Build near the closest enemy structure
|
||||||
var closestEnemy = World.Actors.Where(a => !a.Destroyed && a.HasTrait<Building>() && Player.Stances[a.Owner] == Stance.Enemy)
|
var closestEnemy = World.Actors.Where(a => !a.Disposed && a.HasTrait<Building>() && Player.Stances[a.Owner] == Stance.Enemy)
|
||||||
.ClosestTo(World.Map.CenterOfCell(defenseCenter));
|
.ClosestTo(World.Map.CenterOfCell(defenseCenter));
|
||||||
|
|
||||||
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;
|
var targetCell = closestEnemy != null ? closestEnemy.Location : baseCenter;
|
||||||
@@ -944,7 +944,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.Attacker.Destroyed)
|
if (e.Attacker.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!e.Attacker.HasTrait<ITargetable>())
|
if (!e.Attacker.HasTrait<ITargetable>())
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WRange.FromCells(12))
|
var enemies = owner.World.FindActorsInCircle(leader.CenterPosition, WRange.FromCells(12))
|
||||||
.Where(a1 => !a1.Destroyed && !a1.IsDead);
|
.Where(a1 => !a1.Disposed && !a1.IsDead);
|
||||||
var enemynearby = enemies.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy);
|
var enemynearby = enemies.Where(a1 => a1.HasTrait<ITargetable>() && leader.Owner.Stances[a1.Owner] == Stance.Enemy);
|
||||||
var target = enemynearby.ClosestTo(leader.CenterPosition);
|
var target = enemynearby.ClosestTo(leader.CenterPosition);
|
||||||
if (target != null)
|
if (target != null)
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
|
weapon.Impact(Target.FromPos(self.CenterPosition), self, Enumerable.Empty<int>());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
actor.InflictDamage(self, damage, null);
|
actor.InflictDamage(self, damage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
|
target.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
|
|
||||||
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30)));
|
self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30)));
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
capturable.EndCapture();
|
capturable.EndCapture();
|
||||||
|
|
||||||
if (capturesInfo != null && capturesInfo.ConsumeActor)
|
if (capturesInfo != null && capturesInfo.ConsumeActor)
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (IsCanceled) return NextActivity;
|
if (IsCanceled) return NextActivity;
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing || hut.Bridge.GetHut(0) == null || hut.Bridge.GetHut(1) == null)
|
if (hut.BridgeDamageState == DamageState.Undamaged || hut.Repairing || hut.Bridge.GetHut(0) == null || hut.Bridge.GetHut(1) == null)
|
||||||
return;
|
return;
|
||||||
hut.Repair(self);
|
hut.Repair(self);
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (health.DamageState == DamageState.Undamaged)
|
if (health.DamageState == DamageState.Undamaged)
|
||||||
return;
|
return;
|
||||||
target.InflictDamage(self, -health.MaxHP, null);
|
target.InflictDamage(self, -health.MaxHP, null);
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
|
||||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30)));
|
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30)));
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var selected = w.Selection.Contains(self);
|
var selected = w.Selection.Contains(self);
|
||||||
var controlgroup = w.Selection.GetControlGroupForActor(self);
|
var controlgroup = w.Selection.GetControlGroupForActor(self);
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
foreach (var s in Sounds)
|
foreach (var s in Sounds)
|
||||||
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
cargo.Unload(self);
|
cargo.Unload(self);
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (actor.Destroyed)
|
if (actor.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var move = actor.Trait<IMove>();
|
var move = actor.Trait<IMove>();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
|
|
||||||
foreach (var actor in world.Selection.Actors)
|
foreach (var actor in world.Selection.Actors)
|
||||||
{
|
{
|
||||||
if (actor.IsDead || actor.Destroyed)
|
if (actor.IsDead || actor.Disposed)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var leveluporder = new Order("DevLevelUp", actor, false);
|
var leveluporder = new Order("DevLevelUp", actor, false);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (a.Destroyed || wr.World.FogObscures(a))
|
if (a.Disposed || wr.World.FogObscures(a))
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
return anim.Render(a.CenterPosition, wr.Palette(canPowerDown.Info.IndicatorPalette));
|
return anim.Render(a.CenterPosition, wr.Palette(canPowerDown.Info.IndicatorPalette));
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (building.Destroyed || wr.World.FogObscures(building) || rb.Repairers.Count == 0)
|
if (building.Disposed || wr.World.FogObscures(building) || rb.Repairers.Count == 0)
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
PaletteReference palette;
|
PaletteReference palette;
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (!sma.Actors.TryGetValue(actorName, out ret))
|
if (!sma.Actors.TryGetValue(actorName, out ret))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (ret.Destroyed)
|
if (ret.Disposed)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
bool IOccupySpaceInfo.SharesCell { get { return false; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Aircraft : IFacing, IPositionable, ISync, INotifyKilled, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld
|
public class Aircraft : IFacing, IPositionable, ISync, IIssueOrder, IOrderVoice, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
static readonly Pair<CPos, SubCell>[] NoCells = { };
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Disposing(Actor self)
|
||||||
{
|
{
|
||||||
UnReserve();
|
UnReserve();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var attacker = e.Attacker;
|
var attacker = e.Attacker;
|
||||||
if (attacker.Destroyed || Stance < UnitStance.ReturnFire)
|
if (attacker.Disposed || Stance < UnitStance.ReturnFire)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!attacker.IsInWorld && !attacker.Destroyed)
|
if (!attacker.IsInWorld && !attacker.Disposed)
|
||||||
{
|
{
|
||||||
// If the aggressor is in a transport, then attack the transport instead
|
// If the aggressor is in a transport, then attack the transport instead
|
||||||
var passenger = attacker.TraitOrDefault<Passenger>();
|
var passenger = attacker.TraitOrDefault<Passenger>();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Activities;
|
using OpenRA.Activities;
|
||||||
@@ -42,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public virtual object Create(ActorInitializer init) { return new Refinery(init.Self, this); }
|
public virtual object Create(ActorInitializer init) { return new Refinery(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Refinery : ITick, IAcceptResources, INotifyKilled, INotifySold, INotifyCapture, INotifyOwnerChanged, IExplodeModifier, ISync
|
public class Refinery : ITick, IAcceptResources, INotifySold, INotifyCapture, INotifyOwnerChanged, IExplodeModifier, ISync, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly RefineryInfo info;
|
readonly RefineryInfo info;
|
||||||
@@ -118,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Disposing(Actor self)
|
||||||
{
|
{
|
||||||
CancelDock(self);
|
CancelDock(self);
|
||||||
foreach (var harv in GetLinkedHarvesters())
|
foreach (var harv in GetLinkedHarvesters())
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
[Desc("Reserve landing places for aircraft.")]
|
[Desc("Reserve landing places for aircraft.")]
|
||||||
class ReservableInfo : TraitInfo<Reservable> { }
|
class ReservableInfo : TraitInfo<Reservable> { }
|
||||||
|
|
||||||
public class Reservable : ITick, INotifyKilled, INotifyOwnerChanged, INotifySold
|
public class Reservable : ITick, INotifyOwnerChanged, INotifySold, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
Actor reservedFor;
|
Actor reservedFor;
|
||||||
Aircraft reservedForAircraft;
|
Aircraft reservedForAircraft;
|
||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return res != null && res.reservedFor != null;
|
return res != null && res.reservedFor != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
public void Disposing(Actor self)
|
||||||
{
|
{
|
||||||
if (reservedForAircraft != null)
|
if (reservedForAircraft != null)
|
||||||
reservedForAircraft.UnReserve();
|
reservedForAircraft.UnReserve();
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new Cargo(init, this); }
|
public object Create(ActorInitializer init) { return new Cargo(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled, INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, IDisableMove
|
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||||
|
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, IDisableMove, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
public readonly CargoInfo Info;
|
public readonly CargoInfo Info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
@@ -305,6 +306,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
cargo.Clear();
|
cargo.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Disposing(Actor self)
|
||||||
|
{
|
||||||
|
foreach (var c in cargo)
|
||||||
|
c.Dispose();
|
||||||
|
|
||||||
|
cargo.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void Selling(Actor self) { }
|
public void Selling(Actor self) { }
|
||||||
public void Sold(Actor self)
|
public void Sold(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var crateActions = self.TraitsImplementing<CrateAction>();
|
var crateActions = self.TraitsImplementing<CrateAction>();
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
collected = true;
|
collected = true;
|
||||||
|
|
||||||
if (crateActions.Any())
|
if (crateActions.Any())
|
||||||
@@ -112,13 +112,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (collector != null)
|
if (collector != null)
|
||||||
OnCrush(collector);
|
OnCrush(collector);
|
||||||
else
|
else
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (info.Lifetime != 0 && ++ticks >= info.Lifetime * 25)
|
if (info.Lifetime != 0 && ++ticks >= info.Lifetime * 25)
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft { get { return Location; } }
|
public CPos TopLeft { get { return Location; } }
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pilot.Destroy();
|
pilot.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsSuitableCell(Actor self, Actor actorToDrop)
|
static bool IsSuitableCell(Actor self, Actor actorToDrop)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var info = self.Info.Traits.Get<GivesBountyInfo>();
|
var info = self.Info.Traits.Get<GivesBountyInfo>();
|
||||||
|
|
||||||
if (e.Attacker == null || e.Attacker.Destroyed) return;
|
if (e.Attacker == null || e.Attacker.Disposed) return;
|
||||||
|
|
||||||
if (!info.Stances.Contains(e.Attacker.Owner.Stances[self.Owner])) return;
|
if (!info.Stances.Contains(e.Attacker.Owner.Stances[self.Owner])) return;
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
// Prevent TK from giving exp
|
// Prevent TK from giving exp
|
||||||
if (e.Attacker == null || e.Attacker.Destroyed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally))
|
if (e.Attacker == null || e.Attacker.Disposed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void SetProcLines(Actor proc)
|
public void SetProcLines(Actor proc)
|
||||||
{
|
{
|
||||||
if (proc == null) return;
|
if (proc == null) return;
|
||||||
if (proc.Destroyed) return;
|
if (proc.Disposed) return;
|
||||||
|
|
||||||
var linkedHarvs = proc.World.ActorsWithTrait<Harvester>()
|
var linkedHarvs = proc.World.ActorsWithTrait<Harvester>()
|
||||||
.Where(a => a.Trait.LinkedProc == proc)
|
.Where(a => a.Trait.LinkedProc == proc)
|
||||||
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
// Check that we're not in a critical location and being useless (refinery drop-off):
|
// Check that we're not in a critical location and being useless (refinery drop-off):
|
||||||
var lastproc = LastLinkedProc ?? LinkedProc;
|
var lastproc = LastLinkedProc ?? LinkedProc;
|
||||||
if (lastproc != null && !lastproc.Destroyed)
|
if (lastproc != null && !lastproc.Disposed)
|
||||||
{
|
{
|
||||||
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
|
var deliveryLoc = lastproc.Location + lastproc.Trait<IAcceptResources>().DeliveryOffset;
|
||||||
if (self.Location == deliveryLoc)
|
if (self.Location == deliveryLoc)
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (Info.RemoveInstead || !self.HasTrait<Health>())
|
if (Info.RemoveInstead || !self.HasTrait<Health>())
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
else
|
else
|
||||||
self.Kill(self);
|
self.Kill(self);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
VisibilityHash = 0;
|
VisibilityHash = 0;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (self.Destroyed || captor.Destroyed) return;
|
if (self.Disposed || captor.Disposed) return;
|
||||||
|
|
||||||
var previousOwner = self.Owner;
|
var previousOwner = self.Owner;
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
IEnumerable<Actor> UnitsInRange()
|
IEnumerable<Actor> UnitsInRange()
|
||||||
{
|
{
|
||||||
return Self.World.FindActorsInCircle(Self.CenterPosition, WRange.FromCells(Info.Range))
|
return Self.World.FindActorsInCircle(Self.CenterPosition, WRange.FromCells(Info.Range))
|
||||||
.Where(a => a.IsInWorld && a != Self && !a.Destroyed && !a.Owner.NonCombatant);
|
.Where(a => a.IsInWorld && a != Self && !a.Disposed && !a.Owner.NonCombatant);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsClear(Actor self, Player currentOwner, Player originalOwner)
|
bool IsClear(Actor self, Player currentOwner, Player originalOwner)
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
if (!self.Destroyed)
|
if (!self.Disposed)
|
||||||
w.Add(new Corpse(w, self.CenterPosition, rs.GetImage(self), sequence, palette));
|
w.Add(new Corpse(w, self.CenterPosition, rs.GetImage(self), sequence, palette));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -24,7 +25,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
|
public object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class StoresResources : IPips, INotifyOwnerChanged, INotifyCapture, INotifyKilled, IExplodeModifier, IStoreResources, ISync
|
class StoresResources : IPips, INotifyOwnerChanged, INotifyCapture, IExplodeModifier, IStoreResources, ISync, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
readonly StoresResourcesInfo info;
|
readonly StoresResourcesInfo info;
|
||||||
|
|
||||||
@@ -51,9 +52,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
newOwner.PlayerActor.Trait<PlayerResources>().GiveResources(resources);
|
newOwner.PlayerActor.Trait<PlayerResources>().GiveResources(resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
bool disposed;
|
||||||
|
public void Disposing(Actor self)
|
||||||
{
|
{
|
||||||
|
if (disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
player.TakeResources(Stored); // lose the stored resources
|
player.TakeResources(Stored); // lose the stored resources
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PipType> GetPips(Actor self)
|
public IEnumerable<PipType> GetPips(Actor self)
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void ActorEntered(Actor a)
|
void ActorEntered(Actor a)
|
||||||
{
|
{
|
||||||
if (a.Destroyed)
|
if (a.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (a == self && !info.AffectsParent)
|
if (a == self && !info.AffectsParent)
|
||||||
@@ -122,7 +122,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void ActorExited(Actor a)
|
void ActorExited(Actor a)
|
||||||
{
|
{
|
||||||
if (a == self || a.Destroyed)
|
if (a == self || a.Disposed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stance = self.Owner.Stances[a.Owner];
|
var stance = self.Owner.Stances[a.Owner];
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
if (claimByActor.Remove(claim.Claimer) & claimByCell.Remove(claim.Cell))
|
if (claimByActor.Remove(claim.Claimer) & claimByCell.Remove(claim.Cell))
|
||||||
{
|
{
|
||||||
if (claim.Claimer.Destroyed) return;
|
if (claim.Claimer.Disposed) return;
|
||||||
if (!claim.Claimer.IsInWorld) return;
|
if (!claim.Claimer.IsInWorld) return;
|
||||||
if (claim.Claimer.IsDead) return;
|
if (claim.Claimer.IsDead) return;
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
void PerformKeyboardOrderOnSelection(Func<Actor, Order> f)
|
void PerformKeyboardOrderOnSelection(Func<Actor, Order> f)
|
||||||
{
|
{
|
||||||
var orders = world.Selection.Actors
|
var orders = world.Selection.Actors
|
||||||
.Where(a => a.Owner == world.LocalPlayer && !a.Destroyed)
|
.Where(a => a.Owner == world.LocalPlayer && !a.Disposed)
|
||||||
.Select(f)
|
.Select(f)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
bool PerformStanceCycle()
|
bool PerformStanceCycle()
|
||||||
{
|
{
|
||||||
var actor = world.Selection.Actors
|
var actor = world.Selection.Actors
|
||||||
.Where(a => a.Owner == world.LocalPlayer && !a.Destroyed)
|
.Where(a => a.Owner == world.LocalPlayer && !a.Disposed)
|
||||||
.Select(a => Pair.New(a, a.TraitOrDefault<AutoTarget>()))
|
.Select(a => Pair.New(a, a.TraitOrDefault<AutoTarget>()))
|
||||||
.FirstOrDefault(a => a.Second != null);
|
.FirstOrDefault(a => a.Second != null);
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
bool PerformGuard()
|
bool PerformGuard()
|
||||||
{
|
{
|
||||||
var actors = world.Selection.Actors
|
var actors = world.Selection.Actors
|
||||||
.Where(a => !a.Destroyed && a.Owner == world.LocalPlayer && a.HasTrait<Guard>());
|
.Where(a => !a.Disposed && a.Owner == world.LocalPlayer && a.HasTrait<Guard>());
|
||||||
|
|
||||||
if (actors.Any())
|
if (actors.Any())
|
||||||
world.OrderGenerator = new GuardOrderGenerator(actors);
|
world.OrderGenerator = new GuardOrderGenerator(actors);
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.D2k.Activities
|
|||||||
|
|
||||||
actor.World.AddFrameEndTask(_ =>
|
actor.World.AddFrameEndTask(_ =>
|
||||||
{
|
{
|
||||||
actor1.Destroy();
|
actor1.Dispose();
|
||||||
|
|
||||||
// Harvester insurance
|
// Harvester insurance
|
||||||
if (!actor1.HasTrait<Harvester>())
|
if (!actor1.HasTrait<Harvester>())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -27,7 +28,7 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
public object Create(ActorInitializer init) { return new Carryall(init.Self, this); }
|
public object Create(ActorInitializer init) { return new Carryall(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Carryall : INotifyBecomingIdle, INotifyKilled, ISync, IRender
|
public class Carryall : INotifyBecomingIdle, INotifyKilled, ISync, IRender, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
readonly WRange carryHeight;
|
readonly WRange carryHeight;
|
||||||
@@ -166,6 +167,15 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
UnreserveCarryable();
|
UnreserveCarryable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Disposing(Actor self)
|
||||||
|
{
|
||||||
|
if (Carrying != null && IsCarrying)
|
||||||
|
{
|
||||||
|
Carrying.Dispose();
|
||||||
|
Carrying = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Called when carryable is inside.
|
// Called when carryable is inside.
|
||||||
public void AttachCarryable(Actor carryable)
|
public void AttachCarryable(Actor carryable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new Sandworm(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new Sandworm(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sandworm : Wanders, ITick, INotifyKilled
|
class Sandworm : Wanders, ITick, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
public readonly SandwormInfo Info;
|
public readonly SandwormInfo Info;
|
||||||
|
|
||||||
@@ -151,9 +151,14 @@ namespace OpenRA.Mods.D2k.Traits
|
|||||||
IsMovingTowardTarget = true;
|
IsMovingTowardTarget = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Killed(Actor self, AttackInfo e)
|
bool disposed;
|
||||||
|
public void Disposing(Actor self)
|
||||||
{
|
{
|
||||||
|
if (disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
manager.DecreaseWormCount();
|
manager.DecreaseWormCount();
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
foreach (var t in target.TraitsImplementing<INotifyInfiltrated>())
|
||||||
t.Infiltrated(target, self);
|
t.Infiltrated(target, self);
|
||||||
|
|
||||||
self.Destroy();
|
self.Dispose();
|
||||||
|
|
||||||
if (target.HasTrait<Building>())
|
if (target.HasTrait<Building>())
|
||||||
Sound.PlayToPlayer(self.Owner, "bldginf1.aud");
|
Sound.PlayToPlayer(self.Owner, "bldginf1.aud");
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
|
foreach (var a in self.World.ActorsWithTrait<ChronoshiftPaletteEffect>())
|
||||||
a.Trait.Enable();
|
a.Trait.Enable();
|
||||||
|
|
||||||
if (teleporter != null && self != teleporter && !teleporter.Destroyed)
|
if (teleporter != null && self != teleporter && !teleporter.Disposed)
|
||||||
{
|
{
|
||||||
var building = teleporter.TraitOrDefault<RenderBuilding>();
|
var building = teleporter.TraitOrDefault<RenderBuilding>();
|
||||||
if (building != null)
|
if (building != null)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
if (self.Destroyed)
|
if (self.Disposed)
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
show = false;
|
show = false;
|
||||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
if (!show || self.Destroyed)
|
if (!show || self.Disposed)
|
||||||
return SpriteRenderable.None;
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
var palette = wr.Palette(info.IndicatorPalettePrefix + self.Owner.InternalName);
|
var palette = wr.Palette(info.IndicatorPalettePrefix + self.Owner.InternalName);
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.RA.Traits
|
|||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
// damage is inflicted by the chronosphere
|
// damage is inflicted by the chronosphere
|
||||||
if (!self.Destroyed)
|
if (!self.Disposed)
|
||||||
self.InflictDamage(chronosphere, int.MaxValue, null);
|
self.InflictDamage(chronosphere, int.MaxValue, null);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user