comparison xrogue/maze.c @ 142:6b5fbd7c3ece

Merge arogue7 and xrogue trees.
author John "Elwin" Edwards
date Tue, 12 May 2015 21:39:39 -0400
parents e6179860cb76
children f54901b9c39b
comparison
equal deleted inserted replaced
132:66b0263af424 142:6b5fbd7c3ece
1 /*
2 maze.c - functions for dealing with mazes
3
4 XRogue: Expeditions into the Dungeons of Doom
5 Copyright (C) 1991 Robert Pietkivitch
6 All rights reserved.
7
8 Based on "Advanced Rogue"
9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
10 All rights reserved.
11
12 See the file LICENSE.TXT for full copyright and licensing information.
13 */
14
15 #include <stdlib.h>
16 #include <curses.h>
17 #include "rogue.h"
18
19 struct cell {
20 char y_pos;
21 char x_pos;
22 };
23 struct b_cellscells {
24 char num_pos; /* number of frontier cells next to you */
25 struct cell conn[4]; /* the y,x position of above cell */
26 } b_cells;
27
28 static char *maze_frontier, *maze_bits;
29 static int maze_lines, maze_cols;
30 static char *moffset(), *foffset();
31 static int rmwall(),findcells(),crankout(),draw_maze();
32
33 /*
34 * crankout:
35 * Does actual drawing of maze to window
36 */
37
38 static
39 crankout()
40 {
41 reg int x, y;
42
43 for (y = 0; y < lines - 3; y++) {
44 move(y + 1, 0);
45 for (x = 0; x < cols - 1; x++) {
46 if (*moffset(y, x)) { /* here is a wall */
47 if(y==0 || y==lines-4) /* top or bottom line */
48 addch(HORZWALL);
49 else if(x==0 || x==cols-2) /* left | right side */
50 addch(VERTWALL);
51 else if (y % 2 == 0 && x % 2 == 0) {
52 if(*moffset(y, x-1) || *moffset(y, x+1))
53 addch(HORZWALL);
54 else
55 addch(VERTWALL);
56 }
57 else if (y % 2 == 0)
58 addch(HORZWALL);
59 else
60 addch(VERTWALL);
61 }
62 else
63 addch(FLOOR);
64 }
65 }
66 }
67
68 /*
69 * domaze:
70 * Draw the maze on this level.
71 */
72
73 do_maze()
74 {
75 reg int least;
76 reg struct room *rp;
77 reg struct linked_list *item;
78 reg struct object *obj;
79 int cnt;
80 bool treas;
81 coord tp;
82
83 for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) {
84 rp->r_flags = ISGONE; /* kill all rooms */
85 rp->r_fires = NULL; /* no fires */
86 }
87 rp = &rooms[0]; /* point to only room */
88 rp->r_flags = ISDARK; /* mazes always dark */
89 rp->r_pos.x = 0; /* room fills whole screen */
90 rp->r_pos.y = 1;
91 rp->r_max.x = cols - 1;
92 rp->r_max.y = lines - 3;
93 draw_maze(); /* put maze into window */
94 /*
95 * add some gold to make it worth looking for
96 */
97 item = spec_item(GOLD, NULL, NULL, NULL);
98 obj = OBJPTR(item);
99 obj->o_count *= (rnd(50) + 50); /* add in one large hunk */
100 attach(lvl_obj, item);
101 cnt = 0;
102 do {
103 rnd_pos(rp, &tp);
104 } until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 2500);
105 mvaddch(tp.y, tp.x, GOLD);
106 obj->o_pos = tp;
107 /*
108 * add in some food to make sure he has enough
109 */
110 item = spec_item(FOOD, NULL, NULL, NULL);
111 obj = OBJPTR(item);
112 attach(lvl_obj, item);
113 do {
114 rnd_pos(rp, &tp);
115 } until (mvinch(tp.y, tp.x) == FLOOR || cnt++ > 2500);
116 mvaddch(tp.y, tp.x, FOOD);
117 obj->o_pos = tp;
118
119 /* it doesn't mater if it's a treasure maze or a normal maze,
120 * more than enough monsters will be genned.
121 */
122 least = rnd(11)+5;
123 if (least < 6) {
124 least = 7;
125 treas = FALSE;
126 }
127 else treas = TRUE;
128 genmonsters(least, treas);
129
130 /* sometimes they're real angry */
131 if (rnd(100) < 65) {
132 /* protect the good charactors */
133 if (player.t_ctype == C_PALADIN ||
134 player.t_ctype == C_RANGER || player.t_ctype == C_MONK) {
135 aggravate(TRUE, FALSE);
136 }
137 else {
138 aggravate(TRUE, TRUE);
139 }
140 }
141 }
142
143 /*
144 * draw_maze:
145 * Generate and draw the maze on the screen
146 */
147
148 static
149 draw_maze()
150 {
151 reg int i, j, more;
152 reg char *ptr;
153
154 maze_lines = (lines - 3) / 2;
155 maze_cols = (cols - 1) / 2;
156 maze_bits = ALLOC((lines - 3) * (cols - 1));
157 maze_frontier = ALLOC(maze_lines * maze_cols);
158 ptr = maze_frontier;
159 while (ptr < (maze_frontier + (maze_lines * maze_cols)))
160 *ptr++ = TRUE;
161 for (i = 0; i < lines - 3; i++) {
162 for (j = 0; j < cols - 1; j++) {
163 if (i % 2 == 1 && j % 2 == 1)
164 *moffset(i, j) = FALSE; /* floor */
165 else
166 *moffset(i, j) = TRUE; /* wall */
167 }
168 }
169 for (i = 0; i < maze_lines; i++) {
170 for (j = 0; j < maze_cols; j++) {
171 do
172 more = findcells(i,j);