Aggravate a monster if a flirt or gift was unsuccessful.
[rogue-pphs.git] / scrolls.c
1
2 /*
3 * Read a scroll and let it happen
4 *
5 * @(#)scrolls.c 3.5 (Berkeley) 6/15/81
6 *
7 * Rogue: Exploring the Cavern of Cuties
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 <stdlib.h>
16 #include <ctype.h>
17 #include <string.h>
18 #include "rogue.h"
19
20 read_scroll()
21 {
22 register struct object *obj;
23 register struct linked_list *item;
24 register struct room *rp;
25 register int i,j;
26 register char ch, nch;
27 register struct linked_list *titem;
28 char buf[80];
29
30 item = get_item("read", SCROLL);
31 if (item == NULL)
32 return;
33 obj = (struct object *) ldata(item);
34 if (obj->o_type != SCROLL)
35 {
36 if (!terse)
37 msg("There is nothing on it to read");
38 else
39 msg("Nothing to read");
40 return;
41 }
42 msg("As you read the scroll, it vanishes.");
43 /*
44 * Calculate the effect it has on the poor guy.
45 */
46 if (obj == cur_weapon)
47 cur_weapon = NULL;
48 switch(obj->o_which)
49 {
50 case S_CONFUSE:
51 /*
52 * Scroll of monster confusion. Give him that power.
53 */
54 msg("Your hands begin to glow red");
55 player.t_flags |= CANHUH;
56 when S_LIGHT:
57 s_know[S_LIGHT] = TRUE;
58 if ((rp = roomin(&hero)) == NULL)
59 msg("The corridor glows and then fades");
60 else
61 {
62 addmsg("The room is lit");
63 if (!terse)
64 addmsg(" by a shimmering blue light.");
65 endmsg();
66 rp->r_flags &= ~ISDARK;
67 /*
68 * Light the room and put the player back up
69 */
70 light(&hero);
71 mvwaddch(cw, hero.y, hero.x, PLAYER);
72 }
73 when S_ARMOR:
74 if (cur_armor != NULL)
75 {
76 msg("Your armor glows faintly for a moment");
77 cur_armor->o_ac--;
78 cur_armor->o_flags &= ~ISCURSED;
79 }
80 when S_HOLD:
81 /*
82 * Hold monster scroll. Stop all monsters within two spaces
83 * from chasing after the hero.
84 */
85 {
86 register int x,y;
87 register struct linked_list *mon;
88
89 for (x = hero.x-2; x <= hero.x+2; x++)
90 for (y = hero.y-2; y <= hero.y+2; y++)
91 if (y > 0 && x > 0 && isupper(mvwinch(mw, y, x)))
92 if ((mon = find_mons(y, x)) != NULL)
93 {
94 register struct thing *th;
95
96 th = (struct thing *) ldata(mon);
97 th->t_flags &= ~ISRUN;
98 th->t_flags |= ISHELD;
99 }
100 }
101 when S_SLEEP:
102 /*
103 * Scroll which makes you fall asleep
104 */
105 s_know[S_SLEEP] = TRUE;
106 msg("You fall asleep.");
107 no_command += 4 + rnd(SLEEPTIME);
108 when S_CREATE:
109 /*
110 * Create a monster
111 * First look in a circle around him, next try his room
112 * otherwise give up
113 */
114 {
115 register int x, y;
116 register bool appear = 0;
117 coord mp;
118
119 /*
120 * Search for an open place
121 */
122 for (y = hero.y-1; y <= hero.y+1; y++)
123 for (x = hero.x-1; x <= hero.x+1; x++)
124 {
125 /*
126 * Don't put a monster in top of the player.
127 */
128 if (y == hero.y && x == hero.x)
129 continue;
130 /*
131 * Or anything else nasty
132 */
133 if (step_ok(winat(y, x)))
134 {
135 if (rnd(++appear) == 0)
136 {
137 mp.y = y;
138 mp.x = x;
139 }
140 }
141 }
142 if (appear)
143 {
144 titem = new_item(sizeof (struct thing));
145 new_monster(titem, randmonster(FALSE), &mp);
146 }
147 else
148 msg("You hear a faint cry of anguish in the distance.");
149 }
150 when S_IDENT:
151 /*
152 * Identify, let the rogue figure something out
153 */
154 msg("This scroll is an identify scroll");
155 s_know[S_IDENT] = TRUE;
156 whatis();
157 when S_MAP:
158 /*
159 * Scroll of magic mapping.
160 */
161 s_know[S_MAP] = TRUE;
162 msg("Oh, now this scroll has a map on it.");
163 overwrite(stdscr, hw);
164 /*
165 * Take all the things we want to keep hidden out of the window
166 */
167 for (i = 0; i < LINES; i++)
168 for (j = 0; j < COLS; j++)
169 {
170 switch (nch = ch = mvwinch(hw, i, j))
171 {
172 case SECRETDOOR:
173 nch = DOOR;
174 mvaddch(i, j, nch);
175 case '-':
176 case '|':
177 case DOOR:
178 case PASSAGE:
179 case ' ':
180 case STAIRS:
181 if (mvwinch(mw, i, j) != ' ')
182 {
183 register struct thing *it;
184
185 it = (struct thing *) ldata(find_mons(i, j));
186 if ((it != NULL) && (it->t_oldch == ' '))
187 it->t_oldch = nch;
188 }
189 break;
190 default:
191 nch = ' ';
192 }
193 if (nch != ch)
194 waddch(hw, nch);
195 }
196 /*
197 * Copy in what he has discovered
198 */
199 overlay(cw, hw);
200 /*
201 * And set up for display
202 */
203 overwrite(hw, cw);
204 when S_GFIND:
205 /*
206 * Potion of gold detection
207 */
208 {
209 int gtotal = 0;
210
211 wclear(hw);
212 for (i = 0; i < MAXROOMS; i++)
213 {
214 gtotal += rooms[i].r_goldval;
215 if (rooms[i].r_goldval != 0 &&
216 mvwinch(stdscr, rooms[i].r_gold.y, rooms[i].r_gold.x)
217 == GOLD)
218 mvwaddch(hw,rooms[i].r_gold.y,rooms[i].r_gold.x,GOLD);
219 }
220 if (gtotal)
221 {
222 s_know[S_GFIND] = TRUE;
223 show_win(hw,
224 "You begin to feel greedy and you sense gold.--More--");
225 }
226 else msg("You begin to feel a pull downward");
227 }
228 when S_TELEP:
229 /*
230 * Scroll of teleportation:
231 * Make him dissapear and reappear
232 */
233 {
234 int rm;
235 struct room *cur_room;
236
237 cur_room = roomin(&hero);
238 rm = teleport();
239 if (cur_room != &rooms[rm])
240 s_know[S_TELEP] = TRUE;
241 }
242 when S_ENCH:
243 if (cur_weapon == NULL)
244 msg("You feel a strange sense of loss.");
245 else
246 {
247 cur_weapon->o_flags &= ~ISCURSED;
248 if (rnd(100) > 50)
249 cur_weapon->o_hplus++;
250 else
251 cur_weapon->o_dplus++;
252 msg("Your %s glows blue for a moment.", w_names[cur_weapon->o_which]);
253 }
254 when S_SCARE:
255 /*
256 * A monster will refuse to step on a scare monster scroll
257 * if it is dropped. Thus reading it is a mistake and produces
258 * laughter at the poor rogue's boo boo.
259 */
260 msg("You hear maniacal laughter in the distance.");
261 when S_REMOVE:
262 if (cur_armor != NULL)
263 cur_armor->o_flags &= ~ISCURSED;
264 if (cur_weapon != NULL)
265 cur_weapon->o_flags &= ~ISCURSED;
266 if (cur_ring[LEFT] != NULL)
267 cur_ring[LEFT]->o_flags &= ~ISCURSED;
268 if (cur_ring[RIGHT] != NULL)
269 cur_ring[RIGHT]->o_flags &= ~ISCURSED;
270 msg("You feel as if somebody is watching over you.");
271 when S_AGGR:
272 /*
273 * This scroll aggravates all the monsters on the current
274 * level and sets them running towards the hero
275 */
276 aggravate();
277 msg("You hear a high pitched humming noise.");
278 when S_NOP:
279 msg("This scroll seems to be blank.");
280 when S_GENOCIDE:
281 msg("You have been granted the boon of genocide");
282 genocide();
283 s_know[S_GENOCIDE] = TRUE;
284 otherwise:
285 msg("What a puzzling scroll!");
286 return;
287 }
288 look(TRUE); /* put the result of the scroll on the screen */
289 status();
290 if (s_know[obj->o_which] && s_guess[obj->o_which])
291 {
292 free(s_guess[obj->o_which]);
293 s_guess[obj->o_which] = NULL;
294 }
295 else if (!s_know[obj->o_which] && askme && s_guess[obj->o_which] == NULL)
296 {
297 msg(terse ? "Call it: " : "What do you want to call it? ");
298 if (get_str(buf, cw) == NORM)
299 {
300 s_guess[obj->o_which] = malloc((unsigned int) strlen(buf) + 1);
301 if (s_guess[obj->o_which] != NULL)
302 strcpy(s_guess[obj->o_which], buf);
303 }
304 }
305 /*
306 * Get rid of the thing
307 */
308 inpack--;
309 if (obj->o_count > 1)
310 obj->o_count--;
311 else
312 {
313 detach(pack, item);
314 discard(item);
315 }
316 }