zap.c revision 1.6 1 /* $NetBSD: zap.c,v 1.6 2003/08/07 09:37:40 agc Exp $ */
2
3 /*
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Timothy C. Stoehr.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)zap.c 8.1 (Berkeley) 5/31/93";
39 #else
40 __RCSID("$NetBSD: zap.c,v 1.6 2003/08/07 09:37:40 agc Exp $");
41 #endif
42 #endif /* not lint */
43
44 /*
45 * zap.c
46 *
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
52 * gain or profit.
53 *
54 */
55
56 #include "rogue.h"
57
58 boolean wizard = 0;
59
60 void
61 zapp()
62 {
63 short wch;
64 boolean first_miss = 1;
65 object *wand;
66 short dir, d, row, col;
67 object *monster;
68
69 while (!is_direction(dir = rgetchar(), &d)) {
70 sound_bell();
71 if (first_miss) {
72 message("direction? ", 0);
73 first_miss = 0;
74 }
75 }
76 check_message();
77 if (dir == CANCEL) {
78 return;
79 }
80 if ((wch = pack_letter("zap with what?", WAND)) == CANCEL) {
81 return;
82 }
83 check_message();
84
85 if (!(wand = get_letter_object(wch))) {
86 message("no such item.", 0);
87 return;
88 }
89 if (wand->what_is != WAND) {
90 message("you can't zap with that", 0);
91 return;
92 }
93 if (wand->class <= 0) {
94 message("nothing happens", 0);
95 } else {
96 wand->class--;
97 row = rogue.row; col = rogue.col;
98 if ((wand->which_kind == COLD) || (wand->which_kind == FIRE)) {
99 bounce((short) wand->which_kind, d, row, col, 0);
100 } else {
101 monster = get_zapped_monster(d, &row, &col);
102 if (wand->which_kind == DRAIN_LIFE) {
103 wdrain_life(monster);
104 } else if (monster) {
105 wake_up(monster);
106 s_con_mon(monster);
107 zap_monster(monster, wand->which_kind);
108 relight();
109 }
110 }
111 }
112 (void) reg_move();
113 }
114
115 object *
116 get_zapped_monster(dir, row, col)
117 short dir;
118 short *row, *col;
119 {
120 short orow, ocol;
121
122 for (;;) {
123 orow = *row; ocol = *col;
124 get_dir_rc(dir, row, col, 0);
125 if (((*row == orow) && (*col == ocol)) ||
126 (dungeon[*row][*col] & (HORWALL | VERTWALL)) ||
127 (dungeon[*row][*col] == NOTHING)) {
128 return(0);
129 }
130 if (dungeon[*row][*col] & MONSTER) {
131 if (!imitating(*row, *col)) {
132 return(object_at(&level_monsters, *row, *col));
133 }
134 }
135 }
136 }
137
138 void
139 zap_monster(monster, kind)
140 object *monster;
141 unsigned short kind;
142 {
143 short row, col;
144 object *nm;
145 short tc;
146
147 row = monster->row;
148 col = monster->col;
149
150 switch(kind) {
151 case SLOW_MONSTER:
152 if (monster->m_flags & HASTED) {
153 monster->m_flags &= (~HASTED);
154 } else {
155 monster->slowed_toggle = 0;
156 monster->m_flags |= SLOWED;
157 }
158 break;
159 case HASTE_MONSTER:
160 if (monster->m_flags & SLOWED) {
161 monster->m_flags &= (~SLOWED);
162 } else {
163 monster->m_flags |= HASTED;
164 }
165 break;
166 case TELE_AWAY:
167 tele_away(monster);
168 break;
169 case INVISIBILITY:
170 monster->m_flags |= INVISIBLE;
171 break;
172 case POLYMORPH:
173 if (monster->m_flags & HOLDS) {
174 being_held = 0;
175 }
176 nm = monster->next_monster;
177 tc = monster->trail_char;
178 (void) gr_monster(monster, get_rand(0, MONSTERS-1));
179 monster->row = row;
180 monster->col = col;
181 monster->next_monster = nm;
182 monster->trail_char = tc;
183 if (!(monster->m_flags & IMITATES)) {
184 wake_up(monster);
185 }
186 break;
187 case MAGIC_MISSILE:
188 rogue_hit(monster, 1);
189 break;
190 case CANCELLATION:
191 if (monster->m_flags & HOLDS) {
192 being_held = 0;
193 }
194 if (monster->m_flags & STEALS_ITEM) {
195 monster->drop_percent = 0;
196 }
197 monster->m_flags &= (~(FLIES | FLITS | SPECIAL_HIT | INVISIBLE |
198 FLAMES | IMITATES | CONFUSES | SEEKS_GOLD | HOLDS));
199 break;
200 case DO_NOTHING:
201 message("nothing happens", 0);
202 break;
203 }
204 }
205
206 void
207 tele_away(monster)
208 object *monster;
209 {
210 short row, col;
211
212 if (monster->m_flags & HOLDS) {
213 being_held = 0;
214 }
215 gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
216 mvaddch(monster->row, monster->col, monster->trail_char);
217 dungeon[monster->row][monster->col] &= ~MONSTER;
218 monster->row = row; monster->col = col;
219 dungeon[row][col] |= MONSTER;
220 monster->trail_char = mvinch(row, col);
221 if (detect_monster || rogue_can_see(row, col)) {
222 mvaddch(row, col, gmc(monster));
223 }
224 }
225
226 void
227 wizardize()
228 {
229 char buf[100];
230
231 if (wizard) {
232 wizard = 0;
233 message("not wizard anymore", 0);
234 } else {
235 if (get_input_line("wizard's password:", "", buf, "", 0, 0)) {
236 (void) xxx(1);
237 xxxx(buf, strlen(buf));
238 if (!strncmp(buf, "\247\104\126\272\115\243\027", 7)) {
239 wizard = 1;
240 score_only = 1;
241 message("Welcome, mighty wizard!", 0);
242 } else {
243 message("sorry", 0);
244 }
245 }
246 }
247 }
248
249 void
250 wdrain_life(monster)
251 object *monster;
252 {
253 short hp;
254 object *lmon, *nm;
255
256 hp = rogue.hp_current / 3;
257 rogue.hp_current = (rogue.hp_current + 1) / 2;
258
259 if (cur_room >= 0) {
260 lmon = level_monsters.next_monster;
261 while (lmon) {
262 nm = lmon->next_monster;
263 if (get_room_number(lmon->row, lmon->col) == cur_room) {
264 wake_up(lmon);
265 (void) mon_damage(lmon, hp);
266 }
267 lmon = nm;
268 }
269 } else {
270 if (monster) {
271 wake_up(monster);
272 (void) mon_damage(monster, hp);
273 }
274 }
275 print_stats(STAT_HP);
276 relight();
277 }
278
279 void
280 bounce(ball, dir, row, col, r)
281 short ball, dir, row, col, r;
282 {
283 short orow, ocol;
284 char buf[DCOLS];
285 const char *s;
286 short i, ch, new_dir = -1, damage;
287 static short btime;
288
289 if (++r == 1) {
290 btime = get_rand(3, 6);
291 } else if (r > btime) {
292 return;
293 }
294
295 if (ball == FIRE) {
296 s = "fire";
297 } else {
298 s = "ice";
299 }
300 if (r > 1) {
301 sprintf(buf, "the %s bounces", s);
302 message(buf, 0);
303 }
304 orow = row;
305 ocol = col;
306 do {
307 ch = mvinch(orow, ocol);
308 standout();
309 mvaddch(orow, ocol, ch);
310 get_dir_rc(dir, &orow, &ocol, 1);
311 } while (!( (ocol <= 0) ||
312 (ocol >= DCOLS-1) ||
313 (dungeon[orow][ocol] == NOTHING) ||
314 (dungeon[orow][ocol] & MONSTER) ||
315 (dungeon[orow][ocol] & (HORWALL | VERTWALL)) ||
316 ((orow == rogue.row) && (ocol == rogue.col))));
317 standend();
318 refresh();
319 do {
320 orow = row;
321 ocol = col;
322 ch = mvinch(row, col);
323 mvaddch(row, col, ch);
324 get_dir_rc(dir, &row, &col, 1);
325 } while (!( (col <= 0) ||
326 (col >= DCOLS-1) ||
327 (dungeon[row][col] == NOTHING) ||
328 (dungeon[row][col] & MONSTER) ||
329 (dungeon[row][col] & (HORWALL | VERTWALL)) ||
330 ((row == rogue.row) && (col == rogue.col))));
331
332 if (dungeon[row][col] & MONSTER) {
333 object *monster;
334
335 monster = object_at(&level_monsters, row, col);
336
337 wake_up(monster);
338 if (rand_percent(33)) {
339 sprintf(buf, "the %s misses the %s", s, mon_name(monster));
340 message(buf, 0);
341 goto ND;
342 }
343 if (ball == FIRE) {
344 if (!(monster->m_flags & RUSTS)) {
345 if (monster->m_flags & FREEZES) {
346 damage = monster->hp_to_kill;
347 } else if (monster->m_flags & FLAMES) {
348 damage = (monster->hp_to_kill / 10) + 1;
349 } else {
350 damage = get_rand((rogue.hp_current / 3), rogue.hp_max);
351 }
352 } else {
353 damage = (monster->hp_to_kill / 2) + 1;
354 }
355 sprintf(buf, "the %s hits the %s", s, mon_name(monster));
356 message(buf, 0);
357 (void) mon_damage(monster, damage);
358 } else {
359 damage = -1;
360 if (!(monster->m_flags & FREEZES)) {
361 if (rand_percent(33)) {
362 message("the monster is frozen", 0);
363 monster->m_flags |= (ASLEEP | NAPPING);
364 monster->nap_length = get_rand(3, 6);
365 } else {
366 damage = rogue.hp_current / 4;
367 }
368 } else {
369 damage = -2;
370 }
371 if (damage != -1) {
372 sprintf(buf, "the %s hits the %s", s, mon_name(monster));
373 message(buf, 0);
374 (void) mon_damage(monster, damage);
375 }
376 }
377 } else if ((row == rogue.row) && (col == rogue.col)) {
378 if (rand_percent(10 + (3 * get_armor_class(rogue.armor)))) {
379 sprintf(buf, "the %s misses", s);
380 message(buf, 0);
381 goto ND;
382 } else {
383 damage = get_rand(3, (3 * rogue.exp));
384 if (ball == FIRE) {
385 damage = (damage * 3) / 2;
386 damage -= get_armor_class(rogue.armor);
387 }
388 sprintf(buf, "the %s hits", s);
389 rogue_damage(damage, (object *) 0,
390 ((ball == FIRE) ? KFIRE : HYPOTHERMIA));
391 message(buf, 0);
392 }
393 } else {
394 short nrow, ncol;
395
396 ND: for (i = 0; i < 10; i++) {
397 dir = get_rand(0, DIRS-1);
398 nrow = orow;
399 ncol = ocol;
400 get_dir_rc(dir, &nrow, &ncol, 1);
401 if (((ncol >= 0) && (ncol <= DCOLS-1)) &&
402 (dungeon[nrow][ncol] != NOTHING) &&
403 (!(dungeon[nrow][ncol] & (VERTWALL | HORWALL)))) {
404 new_dir = dir;
405 break;
406 }
407 }
408 if (new_dir != -1) {
409 bounce(ball, new_dir, orow, ocol, r);
410 }
411 }
412 }
413