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