/*
** nhbrexists.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__
int nhbrexists(int cellid,int nhbrid)
#else
int nhbrexists(cellid,nhbrid)
  int cellid, nhbrid;
#endif
{
  int celli, cellj;

  celli = cellid / (mazewidth/2);
  cellj = cellid % (mazewidth/2);

  switch (nhbrid)
  {
    case 0: /* too far north? */
      return (((celli - 1) < 0) ? (1==0) : (1==1));
      break;

    case 1: /* too far east? */
      return (((cellj + 1) >= (mazewidth/2)) ? (1==0) : (1==1));
      break;

    case 2: /* too far south? */
      return (((celli + 1) >= (mazeheight/2)) ? (1==0) : (1==1));
      break;

    case 3:/* too far west? */
      return (((cellj - 1) < 0) ? (1==0) : (1==1));
      break;

    default:
      fprintf(stderr,"bad neighbor id value to nhbrexists %d\n",nhbrid);
      showdebugmaze();
      freespace();
      exit(1);
  }
}
