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