Mercurial > hg > early-roguelike
comparison srogue/passages.c @ 36:2128c7dc8a40
Import Super-Rogue 9.0 from the Roguelike Restoration Project (r1490)
author | elwin |
---|---|
date | Thu, 25 Nov 2010 12:21:41 +0000 |
parents | |
children | 7f5f5f1ba09c |
comparison
equal
deleted
inserted
replaced
35:05018c63a721 | 36:2128c7dc8a40 |
---|---|
1 /* | |
2 * Draw the connecting passages | |
3 * | |
4 * @(#)passages.c 9.0 (rdk) 7/17/84 | |
5 * | |
6 * Super-Rogue | |
7 * Copyright (C) 1984 Robert D. Kindelberger | |
8 * All rights reserved. | |
9 * | |
10 * Based on "Rogue: Exploring the Dungeons of Doom" | |
11 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
12 * All rights reserved. | |
13 * | |
14 * See the file LICENSE.TXT for full copyright and licensing information. | |
15 */ | |
16 | |
17 #include "rogue.h" | |
18 #include "rogue.ext" | |
19 | |
20 /* | |
21 * do_passages: | |
22 * Draw all the passages on a level. | |
23 */ | |
24 | |
25 do_passages() | |
26 { | |
27 reg struct rdes *r1, *r2; | |
28 reg int i, j; | |
29 reg int roomcount; | |
30 static struct rdes { | |
31 bool conn[MAXROOMS]; /* possible to connect to room i */ | |
32 bool isconn[MAXROOMS]; /* connection was made to room i */ | |
33 bool ingraph; /* this room in graph already? */ | |
34 } rdes[MAXROOMS] = { | |
35 {{ 0, 1, 0, 1, 0, 0, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
36 {{ 1, 0, 1, 0, 1, 0, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
37 {{ 0, 1, 0, 0, 0, 1, 0, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
38 {{ 1, 0, 0, 0, 1, 0, 1, 0, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
39 {{ 0, 1, 0, 1, 0, 1, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
40 {{ 0, 0, 1, 0, 1, 0, 0, 0, 1 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
41 {{ 0, 0, 0, 1, 0, 0, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
42 {{ 0, 0, 0, 0, 1, 0, 1, 0, 1 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
43 {{ 0, 0, 0, 0, 0, 1, 0, 1, 0 },{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 }, | |
44 }; | |
45 | |
46 /* | |
47 * reinitialize room graph description | |
48 */ | |
49 for (r1 = rdes; r1 < &rdes[MAXROOMS]; r1++) { | |
50 for (j = 0; j < MAXROOMS; j++) | |
51 r1->isconn[j] = FALSE; | |
52 r1->ingraph = FALSE; | |
53 } | |
54 | |
55 /* | |
56 * starting with one room, connect it to a random adjacent room and | |
57 * then pick a new room to start with. | |
58 */ | |
59 roomcount = 1; | |
60 r1 = &rdes[rnd(MAXROOMS)]; | |
61 r1->ingraph = TRUE; | |
62 do { | |
63 /* | |
64 * find a room to connect with | |
65 */ | |
66 j = 0; | |
67 for (i = 0; i < MAXROOMS; i++) | |
68 if (r1->conn[i] && !rdes[i].ingraph && rnd(++j) == 0) | |
69 r2 = &rdes[i]; | |
70 /* | |
71 * if no adjacent rooms are outside the graph, pick a new room | |
72 * to look from | |
73 */ | |
74 if (j == 0) { | |
75 do { | |
76 r1 = &rdes[rnd(MAXROOMS)]; | |
77 } until (r1->ingraph); | |
78 } | |
79 /* | |
80 * otherwise, connect new room to the graph, and draw a tunnel | |
81 * to it | |
82 */ | |
83 else { | |
84 r2->ingraph = TRUE; | |
85 i = r1 - rdes; | |
86 j = r2 - rdes; | |
87 conn(i, j); | |
88 r1->isconn[j] = TRUE; | |
89 r2->isconn[i] = TRUE; | |
90 roomcount++; | |
91 } | |
92 } while (roomcount < MAXROOMS); | |
93 | |
94 /* | |
95 * attempt to add passages to the graph a random number of times so | |
96 * that there isn't just one unique passage through it. | |
97 */ | |
98 for (roomcount = rnd(5); roomcount > 0; roomcount--) { | |
99 r1 = &rdes[rnd(MAXROOMS)]; /* a random room to look from */ | |
100 /* | |
101 * find an adjacent room not already connected | |
102 */ | |
103 j = 0; | |
104 for (i = 0; i < MAXROOMS; i++) | |
105 if (r1->conn[i] && !r1->isconn[i] && rnd(++j) == 0) | |
106 r2 = &rdes[i]; | |
107 /* | |
108 * if there is one, connect it and look for the next added | |
109 * passage | |
110 */ | |
111 if (j != 0) { | |
112 i = r1 - rdes; | |
113 j = r2 - rdes; | |
114 conn(i, j); | |
115 r1->isconn[j] = TRUE; | |
116 r2->isconn[i] = TRUE; | |
117 } | |
118 } | |
119 } | |
120 | |
121 /* | |
122 * conn: | |
123 * Cconnect two rooms. | |
124 */ | |
125 | |
126 conn(r1, r2) | |
127 int r1, r2; | |
128 { | |
129 reg struct room *rpf, *rpt; | |
130 reg char rmt, direc; | |
131 reg int distance, turn_spot, turn_distance, rm; | |
132 struct coord curr, turn_delta, spos, epos; | |
133 | |
134 if (r1 < r2) { | |
135 rm = r1; | |
136 if (r1 + 1 == r2) | |
137 direc = 'r'; | |
138 else | |
139 direc = 'd'; | |
140 } | |
141 else { | |
142 rm = r2; | |
143 if (r2 + 1 == r1) | |
144 direc = 'r'; | |
145 else | |
146 direc = 'd'; | |
147 } | |
148 rpf = &rooms[rm]; | |
149 /* | |
150 * Set up the movement variables, in two cases: | |
151 * first drawing one down. | |
152 */ | |
153 if (direc == 'd') { | |
154 rmt = rm + 3; /* room # of dest */ | |
155 rpt = &rooms[rmt]; /* room pointer of dest */ | |
156 delta.x = 0; /* direction of move */ | |
157 delta.y = 1; | |
158 spos.x = rpf->r_pos.x; /* start of move */ | |
159 spos.y = rpf->r_pos.y; | |
160 epos.x = rpt->r_pos.x; /* end of move */ | |
161 epos.y = rpt->r_pos.y; | |
162 if (!rf_on(rpf,ISGONE)) { /* if not gone pick door pos */ | |
163 spos.x += rnd(rpf->r_max.x-2)+1; | |
164 spos.y += rpf->r_max.y-1; | |
165 } | |
166 if (!rf_on(rpt,ISGONE)) | |
167 epos.x += rnd(rpt->r_max.x-2)+1; | |
168 distance = abs(spos.y - epos.y) - 1; /* distance to move */ | |
169 turn_delta.y = 0; /* direction to turn */ | |
170 turn_delta.x = (spos.x < epos.x ? 1 : -1); | |
171 turn_distance = abs(spos.x - epos.x); /* how far to turn */ | |
172 turn_spot = rnd(distance-1) + 1; /* where turn starts */ | |
173 } | |
174 else if (direc == 'r') { /* setup for moving right */ | |
175 rmt = rm + 1; | |
176 rpt = &rooms[rmt]; | |
177 delta.x = 1; | |
178 delta.y = 0; | |
179 spos.x = rpf->r_pos.x; | |
180 spos.y = rpf->r_pos.y; | |
181 epos.x = rpt->r_pos.x; | |
182 epos.y = rpt->r_pos.y; | |
183 if (!rf_on(rpf,ISGONE)) { | |
184 spos.x += rpf->r_max.x-1; | |
185 spos.y += rnd(rpf->r_max.y-2)+1; | |
186 } | |
187 if (!rf_on(rpt,ISGONE)) | |
188 epos.y += rnd(rpt->r_max.y-2)+1; | |
189 distance = abs(spos.x - epos.x) - 1; | |
190 turn_delta.y = (spos.y < epos.y ? 1 : -1); | |
191 turn_delta.x = 0; | |
192 turn_distance = abs(spos.y - epos.y); | |
193 turn_spot = rnd(distance-1) + 1; | |
194 } | |
195 else { | |
196 msg("Error in connection tables."); | |
197 } | |
198 /* | |
199 * Draw in the doors on either side of the passage | |
200 * or just put #'s if the rooms are gone. Set up | |
201 * pointers to the connected room. | |
202 */ | |
203 rpf->r_ptr[rpf->r_nexits] = rpt; | |
204 if (rf_on(rpf,ISGONE)) { | |
205 cmov(spos); | |
206 addch('#'); /* gone "from" room */ | |
207 } | |
208 else | |
209 door(rpf, &spos); /* add the door */ | |
210 rpt->r_ptr[rpt->r_nexits] = rpf; | |
211 if (rf_on(rpt,ISGONE)) { | |
212 cmov(epos); | |
213 addch('#'); /* gone "to" room */ | |
214 } | |
215 else | |
216 door(rpt, &epos); /* add door */ | |
217 /* | |
218 * Get ready to move... | |
219 */ | |
220 curr.x = spos.x; | |
221 curr.y = spos.y; | |
222 while(distance > 0) { | |
223 /* | |
224 * Move to new position | |
225 */ | |
226 curr.x += delta.x; | |
227 curr.y += delta.y; | |
228 /* | |
229 * Check if we are at the turn place, if so do the turn | |
230 */ | |
231 if (distance == turn_spot && turn_distance > 0) { | |
232 while(turn_distance-- > 0) { | |
233 cmov(curr); | |
234 addch(PASSAGE); | |
235 curr.x += turn_delta.x; | |
236 curr.y += turn_delta.y; | |
237 } | |
238 } | |
239 /* | |
240 * Continue digging along | |
241 */ | |
242 cmov(curr); | |
243 addch(PASSAGE); | |
244 distance--; | |
245 } | |
246 curr.x += delta.x; | |
247 curr.y += delta.y; | |
248 if (!ce(curr, epos)) { | |
249 msg("Warning, connectivity problem on this level."); | |
250 } | |
251 } | |
252 | |
253 /* | |
254 * Add a door or possibly a secret door | |
255 * also enters the door in the exits array of the room. | |
256 */ | |
257 | |
258 door(rm, cp) | |
259 struct room *rm; | |
260 struct coord *cp; | |
261 { | |
262 cmov(*cp); | |
263 addch(rnd(10) < level - 1 && rnd(100) < 20 ? SECRETDOOR : DOOR); | |
264 rm->r_exit[rm->r_nexits++] = *cp; | |
265 } | |
266 | |
267 | |
268 /* | |
269 * add_pass: | |
270 * add the passages to the current window (wizard command) | |
271 */ | |
272 add_pass() | |
273 { | |
274 reg int y, x, ch; | |
275 | |
276 for (y = 1; y < LINES - 3; y++) | |
277 for (x = 0; x < COLS; x++) | |
278 if ((ch = mvinch(y, x)) == PASSAGE || ch == DOOR || | |
279 ch == SECRETDOOR) | |
280 mvwaddch(cw, y, x, ch); | |
281 } |