Merge pull request #8226 from pchote/actor-disposal
Dispose traits when destroying an actor.
This commit is contained in:
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.D2k.Activities
|
||||
|
||||
actor.World.AddFrameEndTask(_ =>
|
||||
{
|
||||
actor1.Destroy();
|
||||
actor1.Dispose();
|
||||
|
||||
// Harvester insurance
|
||||
if (!actor1.HasTrait<Harvester>())
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user