Exemple #1
0
    public static SpellMem AddSpellMem(ref SpellMem llist, int c)
    {
        //{Add a new element to the end of LList.}

        //{Check first to see if the spell is already known. If so,}
        //{do nothing now.}
        SpellMem it = LocateSpellMem(llist, c);

        if (it == null)
        {
            //{Allocate memory for our new element.}
            //{Initialize values.}
            it = new SpellMem(c, ' ');

            //{Attach IT to the list.}
            if (llist == null)
            {
                llist = it;
            }
            else
            {
                LastSpellMem(llist).next = it;
            }
        }

        //{Return a pointer to the new element.}
        return(it);
    }
Exemple #2
0
    public static void WriteSpellMem(SpellMem SL, StreamWriter f)
    {
        //{Save the linked list of spells to the file F.}
        while (SL != null)
        {
            f.WriteLine(SL.code);
            f.WriteLine(SL.mnem);
            SL = SL.next;
        }

        f.WriteLine(-1);
    }
Exemple #3
0
    static SpellMem LastSpellMem(SpellMem llist)
    {
        //{Search through the linked list, and return the last element.}
        //{If LList is empty, return Nil.}
        if (llist != null)
        {
            while (llist.next != null)
            {
                llist = llist.next;
            }
        }

        return(llist);
    }
Exemple #4
0
    public static SpellMem ReadSpellMem(StreamReader f)
    {
        //{Load a list of items saved by the above procedure from}
        //{the file F.}
        SpellMem SL = null;

        int code = int.Parse(f.ReadLine());

        while (code != -1)
        {
            SL      = AddSpellMem(ref SL, code);
            SL.mnem = char.Parse(f.ReadLine());

            code = int.Parse(f.ReadLine());
        }

        return(SL);
    }
Exemple #5
0
    public static SpellMem LocateSpellMem(SpellMem llist, int s)
    {
        //{Search through list LList looking for SpellMem S.}
        //{If found, return the address of that list member.}
        //{If not found, return Nil.}
        SpellMem it = null;

        while (llist != null)
        {
            if (llist.code == s)
            {
                it = llist;
            }

            llist = llist.next;
        }

        return(it);
    }
Exemple #6
0
    public static void RemoveSpellMem(ref SpellMem llist, SpellMem lmember)
    {
        //{Locate and extract member LMember from list LList.}
        //{Then, dispose of LMember.}

        //{Initialize A and B}
        SpellMem b = llist;
        SpellMem a = null;

        //{Locate LMember in the list. A will thereafter be either Nil,}
        //{if LMember if first in the list, or it will be equal to the}
        //{element directly preceding LMember.}
        while (b != lmember && b != null)
        {
            a = b;
            b = b.next;
        }

        if (b == null)
        {
            //{Major FUBAR. The member we were trying to remove can't}
            //{be found in the list.}
            Crt.Write("ERROR- RemoveSpellMem asked to remove a link that doesnt exist.\n");
            do
            {
                rpgtext.RPGKey();
            } while (true);
        }
        else if (a == null)
        {
            //{There's no element before the one we want to remove,}
            //{i.e. it's the first one in the list.}
            llist = b.next;
        }
        else
        {
            //{We found the attribute we want to delete and have another}
            //{one standing before it in line. Go to work.}
            a.next = b.next;
        }
    }