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