/// <summary> /// If this actor is a creatable, bin him up by creatableId. /// </summary> /// <param name="actor"></param> /// <returns>true if binned by ID, else false</returns> private static bool RecycleCreatable(GameActor actor) { if (actor.CreatableId != Guid.Empty) { Stack <GameActor> freeActors = null; if (!creatableBin.TryGetValue(actor.CreatableId, out freeActors)) { freeActors = new Stack <GameActor>(); creatableBin.Add(actor.CreatableId, freeActors); } freeActors.Push(actor); /// Stash away the creatable ID, it will get reset /// in InitDefaults. Guid creatableId = actor.CreatableId; actor.InitDefaults(false); actor.Brain.Reset(0, true, true); actor.InRecycleBin = true; actor.CreatableId = creatableId; actor.Version = GameThing.CurrentVersion; return(true); } return(false); }
/// <summary> /// Return the actor to the factory. Returns true if the actor was accepted back into the factory. /// </summary> /// <param name="actor"></param> /// <returns></returns> public static bool Recycle(GameActor actor) { if (actor == null) { return(false); } Debug.Assert(actor.CurrentState == GameThing.State.Inactive); // Due to complicated issues including cut/paste, we only recycle deactivated objects during simulation run. if (!Enabled) { return(false); } // We may not recycle creatable masters. Though they are inactive, they are held in the creatable list during gameplay. if (actor.Creatable) { return(false); } /// Try to recycle it as a creatable clone. if (RecycleCreatable(actor)) { return(true); } Stack <GameActor> freeActors; if (!recycleBin.TryGetValue(actor.StaticActor, out freeActors)) { freeActors = new Stack <GameActor>(); recycleBin.Add(actor.StaticActor, freeActors); } Debug.Assert(!freeActors.Contains(actor)); freeActors.Push(actor); actor.InitDefaults(false); /// MF_BRAIN_TRASH /// If we made it here, then this actor is not a creatable, but it might have a brain. /// We'd like to give it an empty brain if it has a non-empty brain, else leave it /// alone. if (!actor.Brain.IsEmpty) { actor.Brain = Brain.CreateEmpty(); } actor.InRecycleBin = true; actor.Version = GameThing.CurrentVersion; return(true); }