2 * Draw the connecting passages
4 * @(#)passages.c 3.4 (Berkeley) 6/15/81
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
10 * See the file LICENSE.TXT for full copyright and licensing information.
18 * Draw all the passages on a level.
23 register struct rdes
*r1
, *r2
;
25 register int roomcount
;
28 bool conn
[MAXROOMS
]; /* possible to connect to room i? */
29 bool isconn
[MAXROOMS
]; /* connection been made to room i? */
30 bool ingraph
; /* this room in graph already? */
32 { { 0, 1, 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
33 { { 1, 0, 1, 0, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
34 { { 0, 1, 0, 0, 0, 1, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
35 { { 1, 0, 0, 0, 1, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
36 { { 0, 1, 0, 1, 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
37 { { 0, 0, 1, 0, 1, 0, 0, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
38 { { 0, 0, 0, 1, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
39 { { 0, 0, 0, 0, 1, 0, 1, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
40 { { 0, 0, 0, 0, 0, 1, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0 },
44 * reinitialize room graph description
46 for (r1
= rdes
; r1
<= &rdes
[MAXROOMS
-1]; r1
++)
48 for (j
= 0; j
< MAXROOMS
; j
++)
49 r1
->isconn
[j
] = FALSE
;
54 * starting with one room, connect it to a random adjacent room and
55 * then pick a new room to start with.
58 r1
= &rdes
[rnd(MAXROOMS
)];
63 * find a room to connect with
66 for (i
= 0; i
< MAXROOMS
; i
++)
67 if (r1
->conn
[i
] && !rdes
[i
].ingraph
&& rnd(++j
) == 0)
70 * if no adjacent rooms are outside the graph, pick a new room
76 r1
= &rdes
[rnd(MAXROOMS
)];
80 * otherwise, connect new room to the graph, and draw a tunnel
93 } while (roomcount
< MAXROOMS
);
96 * attempt to add passages to the graph a random number of times so
97 * that there isn't just one unique passage through it.
99 for (roomcount
= rnd(5); roomcount
> 0; roomcount
--)
101 r1
= &rdes
[rnd(MAXROOMS
)]; /* a random room to look from */
103 * find an adjacent room not already connected
106 for (i
= 0; i
< MAXROOMS
; i
++)
107 if (r1
->conn
[i
] && !r1
->isconn
[i
] && rnd(++j
) == 0)
110 * if there is one, connect it and look for the next added
118 r1
->isconn
[j
] = TRUE
;
119 r2
->isconn
[i
] = TRUE
;
126 * Draw a corridor from a room in a certain direction.
132 register struct room
*rpf
, *rpt
;
134 register int distance
, turn_spot
, turn_distance
;
137 coord delta
, curr
, turn_delta
, spos
, epos
;
157 * Set up the movement variables, in two cases:
158 * first drawing one down.
162 rmt
= rm
+ 3; /* room # of dest */
163 rpt
= &rooms
[rmt
]; /* room pointer of dest */
164 delta
.x
= 0; /* direction of move */
166 spos
.x
= rpf
->r_pos
.x
; /* start of move */
167 spos
.y
= rpf
->r_pos
.y
;
168 epos
.x
= rpt
->r_pos
.x
; /* end of move */
169 epos
.y
= rpt
->r_pos
.y
;
170 if (!(rpf
->r_flags
& ISGONE
)) /* if not gone pick door pos */
172 spos
.x
+= rnd(rpf
->r_max
.x
-2)+1;
173 spos
.y
+= rpf
->r_max
.y
-1;
175 if (!(rpt
->r_flags
& ISGONE
))
176 epos
.x
+= rnd(rpt
->r_max
.x
-2)+1;
177 distance
= abs(spos
.y
- epos
.y
) - 1; /* distance to move */
178 turn_delta
.y
= 0; /* direction to turn */
179 turn_delta
.x
= (spos
.x
< epos
.x
? 1 : -1);
180 turn_distance
= abs(spos
.x
- epos
.x
); /* how far to turn */
181 turn_spot
= rnd(distance
-1) + 1; /* where turn starts */
183 else if (direc
== 'r') /* setup for moving right */
189 spos
.x
= rpf
->r_pos
.x
;
190 spos
.y
= rpf
->r_pos
.y
;
191 epos
.x
= rpt
->r_pos
.x
;
192 epos
.y
= rpt
->r_pos
.y
;
193 if (!(rpf
->r_flags
& ISGONE
))
195 spos
.x
+= rpf
->r_max
.x
-1;
196 spos
.y
+= rnd(rpf
->r_max
.y
-2)+1;
198 if (!(rpt
->r_flags
& ISGONE
))
199 epos
.y
+= rnd(rpt
->r_max
.y
-2)+1;
200 distance
= abs(spos
.x
- epos
.x
) - 1;
201 turn_delta
.y
= (spos
.y
< epos
.y
? 1 : -1);
203 turn_distance
= abs(spos
.y
- epos
.y
);
204 turn_spot
= rnd(distance
-1) + 1;
207 fatal("error in connection tables");
209 * Draw in the doors on either side of the passage or just put #'s
210 * if the rooms are gone.
212 if (!(rpf
->r_flags
& ISGONE
)) door(rpf
, &spos
);
218 if (!(rpt
->r_flags
& ISGONE
)) door(rpt
, &epos
);
225 * Get ready to move...
232 * Move to new position
237 * Check if we are at the turn place, if so do the turn
239 if (distance
== turn_spot
&& turn_distance
> 0)
240 while(turn_distance
--)
244 curr
.x
+= turn_delta
.x
;
245 curr
.y
+= turn_delta
.y
;
248 * Continue digging along
257 msg("Warning, connectivity problem on this level.");
261 * Add a door or possibly a secret door
262 * also enters the door in the exits array of the room.
266 register struct room
*rm
;
270 addch( (rnd(10) < level
- 1 && rnd(100) < 20 ? SECRETDOOR
: DOOR
) );
271 rm
->r_exit
[rm
->r_nexits
++] = *cp
;
276 * add the passages to the current window (wizard command)
281 register int y
, x
, ch
;
283 for (y
= 1; y
< LINES
- 2; y
++)
284 for (x
= 0; x
< COLS
; x
++)
285 if ((ch
=mvinch(y
, x
)) == PASSAGE
|| ch
== DOOR
|| ch
== SECRETDOOR
)
286 mvwaddch(cw
, y
, x
, ch
);