/*
 * 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);

