/*
** filllist.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 filllist()
#else
int filllist()
#endif
{
  int i;

#if PROGRESS
  fprintf(stderr,"Fill list ");
#endif


/*
** Everything starts in the isolated list; the others start empty.
*/

  isolated = 0;
  live     = NOPOINTER;
  dead     = NOPOINTER;
  street   = NOPOINTER;
  unused   = NOPOINTER;

  for (i = 0; i < listsize  - 1; i++)
    statlist[i].next = i+1;
  statlist[listsize -1].next = NOPOINTER;
  for (i = 1; i < listsize; i++)
    statlist[i].prev = i-1;
  statlist[0].prev = NOPOINTER;
  for (i = 0; i < listsize; i++)
  {
    statlist[i].status = ISOLATED;
    statlist[i].streetnum = -1;
    statlist[i].streetdir = -1;
  }

  isolatedct = listsize;
  livect     = 0;
  deadct     = 0;
  streetct   = 0;
  unusedct   = 0;

/*
** Corner cells are too hard to use; get them off the list.
*/

  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,0);
  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,
             (mazewidth/2) - 1);
  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,
             listsize-(mazewidth/2));
  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,listsize - 1);

/*
** There are no streets yet, so the streetnumct is zero too.
*/

  streetnumct = 0;

  return;
}
