/*
 * Maze Format                                                              *
 *                                                                          *
 * short int *mazeDat;                                                      *
 *                                                                          *
 *        1                                                                 *
 *   劇劅劅劅劅                                                             *
 *   劆丂                                                                   *
 *  2劆丂 3                                                                 *
 *   劆丂                                                                   *
 *                                                                          *
 *                                                                          *
 * mazeDat[n];                                                              *
 *    16        8 7 6 5 4  2  0                                             *
 *     |XXXXXXXX|X|X|X|X|XX|XX|                                             *
 *          劆  劆劆劆劆 劆劋  暻侾宍忬  00:柍  01:暻  10:斷  11:儕僓乕僽   *
 *          劆  劆劆劆劆 劋劅  暻俀宍忬丂00:柍  01:暻  10:斷  11:儕僓乕僽   *
 * 丂丂 丂丂劆  劆劆劆劋劅劅劅 暻侾捠夁丂0:壜擻  1:晄壜                     *
 * 丂丂 丂丂劆  劆劆劋劅劅劅劅 暻俀捠夁丂0:壜擻  1:晄壜                     *
 *          劆  劆劋劅劅劅劅劅 彴偺僾儕儞僩 1:桳 2:柍                       *
 *          劆  劋劅劅劅劅劅劅 揤堜偺僾儕儞僩 1:桳 2:柍                     *
 * 丂丂 丂丂劋劅劅劅劅劅劅劅劅 僾儘僌儔儅乕巊梡壜乮僀儀儞僩梡乯             *
 *                                                                          *
 *                                                                          */


typedef struct {
	int bl;               /* 1僽儘僢僋暘偺暻偺挿偝(cm) */
	int bh;               /* 暻偺崅偝 (cm) */
	int lx,ly;            /* 柪楬偺僽儘僢僋悢(搶惣,撿杒) */
	short *map;           /* 儅僢僾僨乕僞 */
} MAZEMAP;

typedef struct {
	int cx,cy;            /* 夋柺拞怱 */
	int x0,y0,x1,y1;      /* 夋柺昤夋斖埻 */
	int wc,dc;            /* 暻偺怓,僪傾偺怓 */
	int cont;             /* 僐儞僩儔僗僩(婸搙偺嫍棧1m偵懳偡傞尭悐棪(%)) */
	int mag;              /* 奼戝棪 */
} MAZESCREEN;

typedef struct {
	int viewz;     /* 偦偺儔僀儞偲暻偲偺岎揰偺帇栰嵗昗宯偺Z嵗昗 */
	int edgedist;  /*  暻偺抂偐傜偺挿偝 */
	int door;      /*  暻偺庬椶(僪傾偱偁傞偐暻偱偁傞偐) */
	struct {
		int mark;  /* 彴/揤堜偺僾儕儞僩僼儔僌(b0:彴 b1:揤堜) */
		int z1;    /*  僾儕儞僩偲儔僀儞偲偺岎揰偺庤慜偺Z嵗昗 */
		int z2     /*  僾儕儞僩偲儔僀儞偲偺岎揰偺墱偺Z嵗昗 */
	} floor[2];
} MAZEZBUF;





#define MazeFloorCeiling(mz,bx,by) ((mz->map[by*((*mz).lx)+bx]/64)&3)
#define MazeFloorNumber(mz,bx,by) ((mz->map[by*((*mz).lx)+bx]/256)&255)

/* wall.c */
int MazeWall(MAZEMAP *mz,int bx,int by,int dir);
int MazePass(MAZEMAP *mz,int bx,int by,int dir);
void MazeSetWall(MAZEMAP *mz,int bx,int by,int sid,int wal,int pas);


/* drawmaze.c */
void MazeGetLines(MAZEZBUF *buf,MAZEMAP *mz,MAZESCREEN *ms,
         int bx,int by,int h,int lng);
void MazeDrawWalls(PAGE *wp,
         MAZEMAP *mz,MAZESCREEN *ms,MAZEZBUF *buf);

/* printmap.c */
void MazeDrawMapOneWall(PAGE *wp,MAZEMAP *mz,
         int sx,int sy,int bx,int by,int dir,int l);
void MazeDrawMap(PAGE *wp,MAZEMAP *mz,
         int lx,int ly,int x1,int y1,int x2,int y2,int l);
void MazeDrawMapColor(int wall,int space,int secretDoor);



/* create.c */
void MazeCreate(MAZEMAP *mz);



/* mzbitmap.c */
void MazePrepareInsertBitmap(int x,int z,int dir,int len,MAZESCREEN *ims);
void MazeInsertBitmap(char *bm,int bx,int by,int lx,int ly,int x,int z);
void MazeFlushBitmap(PAGE *wp,MAZEZBUF *zb,char *buf);

