[Circle] Safe Character extraction.

From: Patrick Dughi (dughi@imaxx.net)
Date: 06/27/00


        I said i'd do it, and I still haven't had time to yet.  Still
working on a neat setup involving the ability to load or unload zones; or
individual parts thereof (object(s), mob(s), or room(s)).

        However, I'm far enough along that I'm thinking about how to do
it.  It being the abritrairy extraction of a character (PC or NPC) at any
given point in code with no foul side effects.  Anyone who's tried to make
any changes to the combat system knows what I mean;

        Character 1 hits character 2.
        Character 2 dies.
        Character 1 still has another swing, he takes it; and dereferences
either a null, or mangled pointer (freed mem).
        Mud crashes.

        I have already put in an ad-hoc solution which involves as sort of
indirect removal, and wait-until-the-last-second extraction.  It does
actually work; characters are queued to be extracted, and are, but at the
end of a pulse.  There's some additional checking in certain functions
(damage(), esp, but spells and others as well) which check if a character
to be acted upon is already in the queue, but generally that's more for
cosmetic reasons.  Wouldn't want you to be showing that you killed someone
twice.

        The problem is that this is very kludgey.  It works, but it still
requires a decent knowledge of the system to write new code.  Though it
hasn't broken down yet, I see situations where it [(sh)c]ould.

        Right now, all I can think of is abstracting the character
interface.  That is, if you want to access a player, you can't just do
something like "FIGHTING(ch)"; you'd have to lookup_player(FIGHTING((ch)).
The FIGHTING macro would no longer return a direct player reference, but a
lookup reference.  As a programmer, you'd have to stick to using the
indirect reference, and always checking for NULL values.

        Any alternatives?  I see running through all potential references
upon each extraction a bit time consuming, and hard to extend.  You'd also
have to write some sort of check before each potential extraction case to
deal with it if it does occur.

        Ideas are welcome.

                                        PjD


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT