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