Rogue 3.6 reconstruction from http://rogue.rogueforge.net/rogue36/.
[rogue-pphs.git] / newlevel.c
1 /*
2 * new_level:
3 * Dig and draw a new level
4 *
5 * @(#)new_level.c 3.7 (Berkeley) 6/2/81
6 *
7 * Rogue: Exploring the Dungeons of Doom
8 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
9 * All rights reserved.
10 *
11 * See the file LICENSE.TXT for full copyright and licensing information.
12 */
13
14 #include "curses.h"
15 #include "rogue.h"
16
17 #include <string.h>
18
19 new_level()
20 {
21 register int rm, i;
22 register char ch;
23 coord stairs;
24
25 if (level > max_level)
26 max_level = level;
27 wclear(cw);
28 wclear(mw);
29 clear();
30 status();
31 /*
32 * Free up the monsters on the last level
33 */
34 free_list(mlist);
35 do_rooms(); /* Draw rooms */
36 do_passages(); /* Draw passages */
37 no_food++;
38 put_things(); /* Place objects (if any) */
39 /*
40 * Place the staircase down.
41 */
42 do {
43 rm = rnd_room();
44 rnd_pos(&rooms[rm], &stairs);
45 } until (winat(stairs.y, stairs.x) == FLOOR);
46 addch(STAIRS);
47 /*
48 * Place the traps
49 */
50 if (rnd(10) < level)
51 {
52 ntraps = rnd(level/4)+1;
53 if (ntraps > MAXTRAPS)
54 ntraps = MAXTRAPS;
55 i = ntraps;
56 while (i--)
57 {
58 do
59 {
60 rm = rnd_room();
61 rnd_pos(&rooms[rm], &stairs);
62 } until (winat(stairs.y, stairs.x) == FLOOR);
63 switch(rnd(6))
64 {
65 case 0: ch = TRAPDOOR;
66 when 1: ch = BEARTRAP;
67 when 2: ch = SLEEPTRAP;
68 when 3: ch = ARROWTRAP;
69 when 4: ch = TELTRAP;
70 when 5: ch = DARTTRAP;
71 }
72 addch(TRAP);
73 traps[i].tr_type = ch;
74 traps[i].tr_flags = 0;
75 traps[i].tr_pos = stairs;
76 }
77 }
78 do
79 {
80 rm = rnd_room();
81 rnd_pos(&rooms[rm], &hero);
82 }
83 until(winat(hero.y, hero.x) == FLOOR);
84 light(&hero);
85 wmove(cw, hero.y, hero.x);
86 waddch(cw, PLAYER);
87 }
88
89 /*
90 * Pick a room that is really there
91 */
92
93 rnd_room()
94 {
95 register int rm;
96
97 do
98 {
99 rm = rnd(MAXROOMS);
100 } while (rooms[rm].r_flags & ISGONE);
101 return rm;
102 }
103
104 /*
105 * put_things:
106 * put potions and scrolls on this level
107 */
108
109 put_things()
110 {
111 register int i;
112 register struct linked_list *item;
113 register struct object *cur;
114 register int rm;
115 coord tp;
116
117 /*
118 * Throw away stuff left on the previous level (if anything)
119 */
120 free_list(lvl_obj);
121 /*
122 * Once you have found the amulet, the only way to get new stuff is
123 * go down into the dungeon.
124 */
125 if (amulet && level < max_level)
126 return;
127 /*
128 * Do MAXOBJ attempts to put things on a level
129 */
130 for (i = 0; i < MAXOBJ; i++)
131 if (rnd(100) < 35)
132 {
133 /*
134 * Pick a new object and link it in the list
135 */
136 item = new_thing();
137 attach(lvl_obj, item);
138 cur = (struct object *) ldata(item);
139 /*
140 * Put it somewhere
141 */
142 rm = rnd_room();
143 do {
144 rnd_pos(&rooms[rm], &tp);
145 } until (winat(tp.y, tp.x) == FLOOR);
146 mvaddch(tp.y, tp.x, cur->o_type);
147 cur->o_pos = tp;
148 }
149 /*
150 * If he is really deep in the dungeon and he hasn't found the
151 * amulet yet, put it somewhere on the ground
152 */
153 if (level > 25 && !amulet)
154 {
155 item = new_item(sizeof *cur);
156 attach(lvl_obj, item);
157 cur = (struct object *) ldata(item);
158 cur->o_hplus = cur->o_dplus = 0;
159 strcpy(cur->o_damage, "0d0");
160 strcpy(cur->o_hurldmg, "0d0");
161 cur->o_ac = 11;
162 cur->o_type = AMULET;
163 /*
164 * Put it somewhere
165 */
166 do {
167 rm = rnd_room();
168 rnd_pos(&rooms[rm], &tp);
169 } until (winat(tp.y, tp.x) == FLOOR);
170 mvaddch(tp.y, tp.x, cur->o_type);
171 cur->o_pos = tp;
172 }
173 }