home *** CD-ROM | disk | FTP | other *** search
- /*
- ** townmaze.h 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.
- */
-
- /*
- ** Avoid infinite loops in several routines.
- */
-
- #define MAXTRIES 5000
-
- /*
- ** Define PROGRESS as 1 to see a "walking progress" line of routines
- ** announcing themselves as they run, 0 otherwise.
- **
- ** Define SHOWSTART as 1 to see a debug maze that shows the situation
- ** after the gates and courts are added but before the streets are
- ** otherwise built; 0 to skip it.
- **
- ** Define SHOWEND as 1 to see a debug maze that shows the situation
- ** after the maze is completed; 0 to skip it;
- **
- ** Define HEADER as 1 to see the parameter values echoed back just above
- ** the maze, 0 to suppress the header.
- **
- ** Define RAND48 in the makefile to use the srand48() and lrand48()
- ** functions instead of the srandom() and random() functions.
- */
-
- #define PROGRESS 0
- #define SHOWSTART 0
- #define SHOWEND 0
- #define HEADER 1
-
- #ifdef RAND48
- #include <math.h>
- #define RANDOM lrand48
- #define SEEDRANDOM srand48
- #else
- #define RANDOM random
- #define SEEDRANDOM srandom
- #endif
-
- /*
- ** Control for defintion (allocation) of globals in main only,
- ** declaration only elsewhere.
- */
-
- #ifdef MAINLINE
- #define SIDETRACK
- #else
- #define SIDETRACK extern
- #endif
-
- /*
- **
- ** The maze is sized in terms of X cells by Y cells, and of X charcters
- ** by Y characters; there are 2*cells+1 characters in each maze
- ** direction. For purposes of screen display, the horizontal direction
- ** is X and the vertical direction is Y, and the origin is at the top
- ** left, with Y positive going down and X positive going right.
- **
- ** For various reasons in the code, a maze must have at least 5 cells
- ** per side (which will be a very boring maze indeed. Corner cells are
- ** not used, to ease the design problem.
- **
- ** The primary maze determinant is its size in characters; this
- ** must be odd in both dimensions.
- **
- */
-
- /*
- ** P A R A M E T E R S
- **
- ** -h mazeheight -- Y size in characters
- ** -w mazewidth -- X size in characters
- ** listsize -- number of cells in the cell array; computed global
- ** -r randomseed -- use to get the same maze again; replaces clock
- ** seed; seed used is reported in the header for use
- ** in a repeat run.
- ** -g mazegates -- number of streets to start at the city wall
- ** -l leftgates -- number of them to leave doors leading outside on
- ** -c mazecourts -- number of streets to start away from the city wall
- ** -u mazeunused -- number of cells to leave unused in the maze
- ** -s mazestraightness -- times per thousand to retry on average before
- ** accepting a random cell that makes a street turn
- ** rather than go straight
- **
- ** All parameters have default values. Listsize is computed when mazeheight
- ** and mazewidth are known.
- **
- */
-
- #ifdef MAINLINE
- int mazeheight = 23;
- int mazewidth = 77;
- int listsize;
- long randomseed;
- int mazegates = 4;
- int leftgates = 2;
- int mazecourts = 0;
- int mazeunused = 0;
- int mazestraightness = 750;
- #else
- extern int mazeheight;
- extern int mazewidth;
- extern int listsize;
- extern long randomseed;
- extern int mazegates;
- extern int leftgates;
- extern int mazecourts;
- extern int mazeunused;
- extern int mazestraightness;
- #endif
-
- /*
- ** T Y P E D E F S
- */
-
- typedef struct dlelem
- {
- int next;
- int prev;
- int status;
- int streetnum;
- int streetdir;
- } DLENODE;
-
- /*
- ** M A Z E A R R A Y S
- */
-
- /*
- ** The cell list used for storing cell status information. Although the
- ** maze is 2D, this list is kept 1D to make it simple to use list array
- ** indices as link list "pointers".
- */
-
- SIDETRACK DLENODE *statlist;
- SIDETRACK int isolated, street, live, dead, unused;
- SIDETRACK int isolatedct,streetct,livect,deadct, unusedct;
- SIDETRACK int streetnumct;
-
- /*
- ** The maze used for display.
- */
-
- SIDETRACK char **cmaze;
-
- /*
- ** P R I N T I N G S Y M B O L S
- */
-
- /*
- ** maze drawing elements for ascii screen presentation
- */
-
- #define WALL '#'
- #define VDOOR '|'
- #define HDOOR '-'
- #define BLANK ' '
-
- /*
- ** D E F I N E D C O N S T A N T S
- */
-
- /*
- ** status of maze locations
- */
-
- #define ISOLATED 1
- #define LIVE 2
- #define DEAD 3
- #define STREET 4
- #define UNUSED 5
-
- /*
- ** Bogus null pointer for indices used as pointers, since zero is valid.
- */
-
- #define NOPOINTER -1
-