-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew_leve.c
253 lines (216 loc) · 4.65 KB
/
new_leve.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
* Do anything associated with a new dungeon level
*
* @(#)new_level.c 9.0 (rdk) 7/17/84
*
* Super-Rogue
* Copyright (C) 1984 Robert D. Kindelberger
* All rights reserved.
*
* Based on "Rogue: Exploring the Dungeons of Doom"
* Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include "rogue.h"
#include "rogue.ext"
/*
* new_level:
* Dig and draw a new level
*/
new_level(ltype)
int ltype;
{
register i;
register char ch;
struct coord traploc;
struct room *rp;
if (level > max_level)
max_level = level;
wclear(cw);
wclear(mw);
clear();
isfight = FALSE;
levtype = ltype;
free_list(mlist); /* free monster list */
if (levtype == POSTLEV)
do_post();
else {
lev_mon(); /* fill in monster list */
if (levtype == MAZELEV)
do_maze();
else { /* normal levels */
do_rooms(); /* Draw rooms */
do_passages(); /* Draw passages */
}
no_food++;
put_things(); /* Place objects (if any) */
}
/*
* Place the staircase down.
*/
stairs = *rnd_pos(&rooms[rnd_room()]);
mvaddch(stairs.y, stairs.x, STAIRS);
ntraps = 0;
if (levtype == NORMLEV)
{
struct trap *trp, *maxtrp;
/* Place the traps for normal levels only */
if (rnd(10) < level)
{
ntraps = rnd(level / 4) + 1;
if (ntraps > MAXTRAPS)
ntraps = MAXTRAPS;
maxtrp = &traps[ntraps];
for (trp = &traps[0]; trp < maxtrp; trp++)
{
again:
switch(rnd(TYPETRAPS + 1))
{
case 0:
if (rnd(100) > 25)
goto again;
else
ch = POST;
when 1: ch = TRAPDOOR;
when 2: ch = BEARTRAP;
when 3: ch = SLEEPTRAP;
when 4: ch = ARROWTRAP;
when 5: ch = TELTRAP;
when 6: ch = DARTTRAP;
when 7: ch = MAZETRAP;
when 8:
case 9:
if (rnd(100) > 80)
goto again;
else
ch = POOL;
}
trp->tr_flags = 0;
traploc = *rnd_pos(&rooms[rnd_room()]);
mvaddch(traploc.y,traploc.x,ch);
trp->tr_type = ch;
trp->tr_pos = traploc;
if (ch == POOL || ch == POST)
trp->tr_flags |= ISFOUND;
if (ch==TELTRAP && rnd(100)<20 && trp<maxtrp-1)
{
struct coord newloc;
newloc = *rnd_pos(&rooms[rnd_room()]);
trp->tr_goto = newloc;
trp++;
trp->tr_goto = traploc;
trp->tr_type = TELTRAP;
trp->tr_pos = newloc;
mvaddch(newloc.y, newloc.x, TELTRAP);
}
else
trp->tr_goto = rndspot;
}
}
}
do
{
rp = &rooms[rnd_room()];
hero = *rnd_pos(rp);
} while(levtype==MAZELEV&&DISTANCE(hero.y,hero.x,stairs.y,stairs.x)<10);
player.t_room = rp;
player.t_oldch = mvinch(hero.y, hero.x);
light(&hero);
mvwaddch(cw,hero.y,hero.x,PLAYER);
nochange = FALSE;
}
/*
* rnd_room:
* Pick a room that is really there
*/
rnd_room()
{
register rm;
if (levtype != NORMLEV)
rm = 0;
else
{
do {
rm = rnd(MAXROOMS);
} while (rf_on(&rooms[rm],ISGONE));
}
return rm;
}
/*
* put_things:
* put potions and scrolls on this level
*/
put_things()
{
register i, cnt, rm;
struct linked_list *item;
struct object *cur;
struct coord tp;
/* Throw away stuff left on the previous level (if anything) */
free_list(lvl_obj);
/* The only way to get new stuff is to go down into the dungeon. */
if (goingup())
return;
/* Do MAXOBJ attempts to put things on a level */
for (i = 0; i < MAXOBJ; i++)
{
if (rnd(100) < 40)
{
item = new_thing(FALSE, ANYTHING);
attach(lvl_obj, item);
cur = OBJPTR(item);
cnt = 0;
do {
/* skip treasure rooms */
rm = rnd_room();
if (++cnt > 500)
break;
} while(rf_on(&rooms[rm],ISTREAS) && levtype!=MAZELEV);
tp = *rnd_pos(&rooms[rm]);
mvaddch(tp.y, tp.x, cur->o_type);
cur->o_pos = tp;
}
}
/*
* If he is really deep in the dungeon and he hasn't found the
* amulet yet, put it somewhere on the ground
*/
if (level >= AMLEVEL && !amulet && rnd(100) < 70)
{
item = new_thing(FALSE, AMULET, 0);
attach(lvl_obj, item);
cur = OBJPTR(item);
rm = rnd_room();
tp = *rnd_pos(&rooms[rm]);
mvaddch(tp.y, tp.x, cur->o_type);
cur->o_pos = tp;
}
for (i = 0; i < MAXROOMS; i++) /* loop through all */
{
if (rf_on(&rooms[i],ISTREAS)) /* treasure rooms */
{
int numthgs, isfood;
numthgs = rnd(level / 3) + 6;
while (numthgs-- >= 0)
{
isfood = TRUE;
do {
item = new_thing(TRUE, ANYTHING);
cur = OBJPTR(item);
/* dont create food for */
if (cur->o_type == FOOD)
discard(item);
/* treasure rooms */
else
isfood = FALSE;
} while (isfood);
attach(lvl_obj, item);
tp = *rnd_pos(&rooms[i]);
mvaddch(tp.y, tp.x, cur->o_type);
cur->o_pos = tp;
}
}
}
}