comparison rogue4/scrolls.c @ 12:9535a08ddc39

Import Rogue 5.2 from the Roguelike Restoration Project (r1490)
author edwarj4
date Sat, 24 Oct 2009 16:52:52 +0000
parents
children 1b73a8641b37
comparison
equal deleted inserted replaced
11:949d558c2162 12:9535a08ddc39
1 /*
2 * Read a scroll and let it happen
3 *
4 * @(#)scrolls.c 4.21 (Berkeley) 4/6/82
5 *
6 * Rogue: Exploring the Dungeons of Doom
7 * Copyright (C) 1980, 1981, 1982 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #include <curses.h>
14 #include <ctype.h>
15 #include "rogue.h"
16
17 /*
18 * read_scroll:
19 * Read a scroll from the pack and do the appropriate thing
20 */
21 read_scroll()
22 {
23 register THING *obj;
24 register int y, x;
25 register char ch;
26 register THING *op;
27 register int index;
28 register bool discardit = FALSE;
29
30 obj = get_item("read", SCROLL);
31 if (obj == NULL)
32 return;
33 if (obj->o_type != SCROLL)
34 {
35 if (!terse)
36 msg("there is nothing on it to read");
37 else
38 msg("nothing to read");
39 return;
40 }
41 msg("as you read the scroll, it vanishes");
42 /*
43 * Calculate the effect it has on the poor guy.
44 */
45 if (obj == cur_weapon)
46 cur_weapon = NULL;
47 switch (obj->o_which)
48 {
49 case S_CONFUSE:
50 /*
51 * Scroll of monster confusion. Give him that power.
52 */
53 player.t_flags |= CANHUH;
54 msg("your hands begin to glow red");
55 when S_ARMOR:
56 if (cur_armor != NULL)
57 {
58 cur_armor->o_ac--;
59 cur_armor->o_flags &= ~ISCURSED;
60 msg("your armor glows faintly for a moment");
61 }
62 when S_HOLD:
63 /*
64 * Hold monster scroll. Stop all monsters within two spaces
65 * from chasing after the hero.
66 */
67
68 for (x = hero.x - 2; x <= hero.x + 2; x++)
69 if (x >= 0 && x < COLS)
70 for (y = hero.y - 2; y <= hero.y + 2; y++)
71 if (y >= 0 && y <= LINES - 1)
72 if ((op = moat(y, x)) != NULL)
73 {
74 op->t_flags &= ~ISRUN;
75 op->t_flags |= ISHELD;
76 }
77 when S_SLEEP:
78 /*
79 * Scroll which makes you fall asleep
80 */
81 s_know[S_SLEEP] = TRUE;
82 no_command += rnd(SLEEPTIME) + 4;
83 player.t_flags &= ~ISRUN;
84 msg("you fall asleep");
85 when S_CREATE:
86 /*
87 * Create a monster
88 * First look in a circle around him, next try his room
89 * otherwise give up
90 */
91 {
92 register bool appear = 0;
93 coord mp;
94
95 /*
96 * Search for an open place
97 */
98 for (y = hero.y - 1; y <= hero.y + 1; y++)
99 for (x = hero.x - 1; x <= hero.x + 1; x++)
100 {
101 /*
102 * Don't put a monster in top of the player.
103 */
104 if (y == hero.y && x == hero.x)
105 continue;
106 /*
107 * Or anything else nasty
108 * Also avoid a mimic which is disguised as scroll
109 */
110 if (moat(y, x) == NULL && step_ok(ch = winat(y, x)))
111 {
112 if (ch == SCROLL
113 && find_obj(y, x)->o_which == S_SCARE)
114 continue;
115 if (rnd(++appear) == 0)
116 {
117 mp.y = y;
118 mp.x = x;
119 }
120 }
121 }
122 if (appear)
123 {
124 op = new_item();
125 new_monster(op, randmonster(FALSE), &mp);
126 }
127 else
128 msg("you hear a faint cry of anguish in the distance");
129 }
130 when S_IDENT:
131 /*
132 * Identify, let the rogue figure something out
133 */
134 s_know[S_IDENT] = TRUE;
135 msg("this scroll is an identify scroll");
136 whatis(TRUE);
137 when S_MAP:
138 /*
139 * Scroll of magic mapping.
140 */
141 s_know[S_MAP] = TRUE;
142 msg("oh, now this scroll has a map on it");
143 /*
144 * Take all the things we want to keep hidden out of the window
145 */
146 for (y = 1; y < LINES - 1; y++)
147 for (x = 0; x < COLS; x++)
148 {
149 index = INDEX(y, x);
150 switch (ch = _level[index])
151 {
152 case '-':
153 case '|':
154 if (!(_flags[index] & F_REAL))
155 {
156 ch = _level[index] = DOOR;
157 _flags[index] &= ~F_REAL;
158 }
159 case PASSAGE:
160 _flags[index] |= F_SEEN;
161 case DOOR:
162 case STAIRS:
163 if ((op = moat(y, x)) != NULL)
164 if (op->t_oldch == ' ')
165 op->t_oldch = ch;
166 break;
167 default:
168 ch = ' ';
169 }
170 if (ch != ' ')
171 mvaddch(y, x, ch);
172 }
173 when S_GFIND:
174 /*
175 * Potion of gold detection
176 */
177 ch = FALSE;
178 wclear(hw);
179 for (op = lvl_obj; op != NULL; op = next(op))
180 if (op->o_type == GOLD)
181 {
182 ch = TRUE;
183 mvwaddch(hw, op->o_pos.y, op->o_pos.x, GOLD);
184 }
185 if (ch)
186 {
187 s_know[S_GFIND] = TRUE;
188 show_win(hw,
189 "You begin to feel greedy and you sense gold.--More--");
190 }
191 else
192 msg("you feel a pull downward");
193 when S_TELEP:
194 /*
195 * Scroll of teleportation:
196 * Make him dissapear and reappear
197 */
198 {
199 register struct room *cur_room;
200
201 cur_room = proom;
202 teleport();
203 if (cur_room != proom)
204 s_know[S_TELEP] = TRUE;
205 }
206 when S_ENCH:
207 if (cur_weapon == NULL || cur_weapon->o_type != WEAPON)
208 msg("you feel a strange sense of loss");
209 else
210 {
211 cur_weapon->o_flags &= ~ISCURSED;
212 if (rnd(2) == 0)
213 cur_weapon->o_hplus++;
214 else
215 cur_weapon->o_dplus++;
216 msg("your %s glows blue for a moment", w_names[cur_weapon->o_which]);
217 }
218 when S_SCARE:
219 /*
220 * Reading it is a mistake and produces laughter at the
221 * poor rogue's boo boo.
222 */
223 msg("you hear maniacal laughter in the distance");
224 when S_REMOVE:
225 if (cur_armor != NULL)
226 cur_armor->o_flags &= ~ISCURSED;
227 if (cur_weapon != NULL)
228 cur_weapon->o_flags &= ~ISCURSED;
229 if (cur_ring[LEFT] != NULL)
230 cur_ring[LEFT]->o_flags &= ~ISCURSED;
231 if (cur_ring[RIGHT] != NULL)
232 cur_ring[RIGHT]->o_flags &= ~ISCURSED;
233 msg("you feel as if somebody is watching over you");
234 when S_AGGR:
235 /*
236 * This scroll aggravates all the monsters on the current
237 * level and sets them running towards the hero
238 */
239 aggravate();
240 msg("you hear a high pitched humming noise");
241 when S_NOP:
242 msg("this scroll seems to be blank");
243 when S_GENOCIDE:
244 s_know[S_GENOCIDE] = TRUE;
245 msg("you have been granted the boon of genocide");
246 genocide();
247 otherwise:
248 msg("what a puzzling scroll!");
249 return;
250 }
251 look(TRUE); /* put the result of the scroll on the screen */
252 status();
253 /*
254 * Get rid of the thing
255 */
256 inpack--;
257 if (obj->o_count > 1)
258 obj->o_count--;
259 else
260 {
261 detach(pack, obj);
262 discardit = TRUE;
263 }
264
265 call_it(s_know[obj->o_which], &s_guess[obj->o_which]);
266
267 if (discardit)
268 discard(obj);
269 }