forked from Davidslv/rogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_level.c
231 lines (214 loc) · 5.01 KB
/
new_level.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
/*
* new_level:
* Dig and draw a new level
*
* @(#)new_level.c 4.38 (Berkeley) 02/05/99
*
* Rogue: Exploring the Dungeons of Doom
* Copyright (C) 1980-1983, 1985, 1999 Michael Toy, Ken Arnold and Glenn Wichman
* All rights reserved.
*
* See the file LICENSE.TXT for full copyright and licensing information.
*/
#include <curses.h>
#include <string.h>
#include "rogue.h"
#define TREAS_ROOM 20 /* one chance in TREAS_ROOM for a treasure room */
#define MAXTREAS 10 /* maximum number of treasures in a treasure room */
#define MINTREAS 2 /* minimum number of treasures in a treasure room */
void
new_level()
{
THING *tp;
PLACE *pp;
char *sp;
int i;
player.t_flags &= ~ISHELD; /* unhold when you go down just in case */
if (level > max_level)
max_level = level;
/*
* Clean things off from last level
*/
for (pp = places; pp < &places[MAXCOLS*MAXLINES]; pp++)
{
pp->p_ch = ' ';
pp->p_flags = F_REAL;
pp->p_monst = NULL;
}
clear();
/*
* Free up the monsters on the last level
*/
for (tp = mlist; tp != NULL; tp = next(tp))
free_list(tp->t_pack);
free_list(mlist);
/*
* Throw away stuff left on the previous level (if anything)
*/
free_list(lvl_obj);
do_rooms(); /* Draw rooms */
do_passages(); /* Draw passages */
no_food++;
put_things(); /* Place objects (if any) */
/*
* Place the traps
*/
if (rnd(10) < level)
{
ntraps = rnd(level / 4) + 1;
if (ntraps > MAXTRAPS)
ntraps = MAXTRAPS;
i = ntraps;
while (i--)
{
/*
* not only wouldn't it be NICE to have traps in mazes
* (not that we care about being nice), since the trap
* number is stored where the passage number is, we
* can't actually do it.
*/
do
{
find_floor((struct room *) NULL, &stairs, FALSE, FALSE);
} while (chat(stairs.y, stairs.x) != FLOOR);
sp = &flat(stairs.y, stairs.x);
*sp &= ~F_REAL;
*sp |= rnd(NTRAPS);
}
}
/*
* Place the staircase down.
*/
find_floor((struct room *) NULL, &stairs, FALSE, FALSE);
chat(stairs.y, stairs.x) = STAIRS;
seenstairs = FALSE;
for (tp = mlist; tp != NULL; tp = next(tp))
tp->t_room = roomin(&tp->t_pos);
find_floor((struct room *) NULL, &hero, FALSE, TRUE);
enter_room(&hero);
mvaddch(hero.y, hero.x, PLAYER);
if (on(player, SEEMONST))
turn_see(FALSE);
if (on(player, ISHALU))
visuals();
}
/*
* rnd_room:
* Pick a room that is really there
*/
int
rnd_room()
{
int rm;
do
{
rm = rnd(MAXROOMS);
} while (rooms[rm].r_flags & ISGONE);
return rm;
}
/*
* put_things:
* Put potions and scrolls on this level
*/
void
put_things()
{
int i;
THING *obj;
/*
* Once you have found the amulet, the only way to get new stuff is
* go down into the dungeon.
*/
if (amulet && level < max_level)
return;
/*
* check for treasure rooms, and if so, put it in.
*/
if (rnd(TREAS_ROOM) == 0)
treas_room();
/*
* Do MAXOBJ attempts to put things on a level
*/
for (i = 0; i < MAXOBJ; i++)
if (rnd(100) < 36)
{
/*
* Pick a new object and link it in the list
*/
obj = new_thing();
attach(lvl_obj, obj);
/*
* Put it somewhere
*/
find_floor((struct room *) NULL, &obj->o_pos, FALSE, FALSE);
chat(obj->o_pos.y, obj->o_pos.x) = (char) obj->o_type;
}
/*
* If he is really deep in the dungeon and he hasn't found the
* amulet yet, put it somewhere on the ground
*/
if (level >= AMULETLEVEL && !amulet)
{
obj = new_item();
attach(lvl_obj, obj);
obj->o_hplus = 0;
obj->o_dplus = 0;
strncpy(obj->o_damage,"0x0",sizeof(obj->o_damage));
strncpy(obj->o_hurldmg,"0x0",sizeof(obj->o_hurldmg));
obj->o_arm = 11;
obj->o_type = AMULET;
/*
* Put it somewhere
*/
find_floor((struct room *) NULL, &obj->o_pos, FALSE, FALSE);
chat(obj->o_pos.y, obj->o_pos.x) = AMULET;
}
}
/*
* treas_room:
* Add a treasure room
*/
#define MAXTRIES 10 /* max number of tries to put down a monster */
void
treas_room()
{
int nm;
THING *tp;
struct room *rp;
int spots, num_monst;
static coord mp;
rp = &rooms[rnd_room()];
spots = (rp->r_max.y - 2) * (rp->r_max.x - 2) - MINTREAS;
if (spots > (MAXTREAS - MINTREAS))
spots = (MAXTREAS - MINTREAS);
num_monst = nm = rnd(spots) + MINTREAS;
while (nm--)
{
find_floor(rp, &mp, 2 * MAXTRIES, FALSE);
tp = new_thing();
tp->o_pos = mp;
attach(lvl_obj, tp);
chat(mp.y, mp.x) = (char) tp->o_type;
}
/*
* fill up room with monsters from the next level down
*/
if ((nm = rnd(spots) + MINTREAS) < num_monst + 2)
nm = num_monst + 2;
spots = (rp->r_max.y - 2) * (rp->r_max.x - 2);
if (nm > spots)
nm = spots;
level++;
while (nm--)
{
spots = 0;
if (find_floor(rp, &mp, MAXTRIES, TRUE))
{
tp = new_item();
new_monster(tp, randmonster(FALSE), &mp);
tp->t_flags |= ISMEAN; /* no sloughers in THIS room */
give_pack(tp);
}
}
level--;
}