Properly clean up traits that used to hook only death.

This commit is contained in:
Paul Chote
2015-05-23 22:09:50 +01:00
parent 4ff309811f
commit 8ae3afa3c5
9 changed files with 47 additions and 12 deletions

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
@@ -27,7 +28,7 @@ namespace OpenRA.Mods.D2k.Traits
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 WRange carryHeight;
@@ -166,6 +167,15 @@ namespace OpenRA.Mods.D2k.Traits
UnreserveCarryable();
}
public void Disposing(Actor self)
{
if (Carrying != null && IsCarrying)
{
Carrying.Dispose();
Carrying = null;
}
}
// Called when carryable is inside.
public void AttachCarryable(Actor carryable)
{

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.D2k.Traits
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;
@@ -151,9 +151,14 @@ namespace OpenRA.Mods.D2k.Traits
IsMovingTowardTarget = true;
}
public void Killed(Actor self, AttackInfo e)
bool disposed;
public void Disposing(Actor self)
{
if (disposed)
return;
manager.DecreaseWormCount();
disposed = true;
}
}
}