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