home *** CD-ROM | disk | FTP | other *** search
- /*
- ** movefromto.c Copyright 1991 Kent Paul Dolan,
- ** Mountain View, CA, USA 94039-0755
- **
- ** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
- ** May be freely used or modified in any non-commercial work. Copyrighted
- ** only to prevent patenting by someone else.
- */
-
- #include <stdio.h>
- #include "townmaze.h"
- #include "townproto.h"
-
- #ifdef __STDC__
- void movefromto(int *fromlist,int *fromcount,int *tolist,int *tocount,
- int newstat,int cellnum)
- #else
- int movefromto(fromlist,fromcount,tolist,tocount,newstat,cellnum)
- int *fromlist;
- int *fromcount;
- int *tolist;
- int *tocount;
- int newstat;
- int cellnum;
- #endif
- {
-
- int oldnext;
- int oldprev;
-
- /*
- ** Save vital existing links.
- */
-
- oldnext = statlist[cellnum].next;
- oldprev = statlist[cellnum].prev;
-
- /*
- ** Unlink cell from old position somewhere in fromlist.
- */
-
- if (statlist[cellnum].next != NOPOINTER)
- statlist[oldnext].prev = statlist[cellnum].prev;
-
- if (statlist[cellnum].prev != NOPOINTER)
- statlist[oldprev].next = statlist[cellnum].next;
- else *fromlist = statlist[cellnum].next;
-
- /*
- ** Link cell into new position at head of tolist.
- */
-
- statlist[cellnum].next = *tolist;
-
- statlist[cellnum].prev = NOPOINTER;
-
- if (*tolist != NOPOINTER)
- statlist[*tolist].prev = cellnum;
-
- *tolist = cellnum;
-
- /*
- ** Update list length counts.
- */
-
- (*fromcount)--;
- (*tocount)++;
-
- /*
- ** update cell status
- */
-
- statlist[cellnum].status = newstat;
-
- return;
- }
-