Home | History | Annotate | Line # | Download | only in rogue
zap.c revision 1.6
      1  1.6      agc /*	$NetBSD: zap.c,v 1.6 2003/08/07 09:37:40 agc 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.6      agc __RCSID("$NetBSD: zap.c,v 1.6 2003/08/07 09:37:40 agc 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.1      cgd boolean wizard = 0;
     59  1.1      cgd 
     60  1.4    lukem void
     61  1.1      cgd zapp()
     62  1.1      cgd {
     63  1.1      cgd 	short wch;
     64  1.1      cgd 	boolean first_miss = 1;
     65  1.1      cgd 	object *wand;
     66  1.1      cgd 	short dir, d, row, col;
     67  1.1      cgd 	object *monster;
     68  1.1      cgd 
     69  1.1      cgd 	while (!is_direction(dir = rgetchar(), &d)) {
     70  1.1      cgd 		sound_bell();
     71  1.1      cgd 		if (first_miss) {
     72  1.1      cgd 			message("direction? ", 0);
     73  1.1      cgd 			first_miss = 0;
     74  1.1      cgd 		}
     75  1.1      cgd 	}
     76  1.1      cgd 	check_message();
     77  1.1      cgd 	if (dir == CANCEL) {
     78  1.1      cgd 		return;
     79  1.1      cgd 	}
     80  1.1      cgd 	if ((wch = pack_letter("zap with what?", WAND)) == CANCEL) {
     81  1.1      cgd 		return;
     82  1.1      cgd 	}
     83  1.1      cgd 	check_message();
     84  1.1      cgd 
     85  1.1      cgd 	if (!(wand = get_letter_object(wch))) {
     86  1.1      cgd 		message("no such item.", 0);
     87  1.1      cgd 		return;
     88  1.1      cgd 	}
     89  1.1      cgd 	if (wand->what_is != WAND) {
     90  1.1      cgd 		message("you can't zap with that", 0);
     91  1.1      cgd 		return;
     92  1.1      cgd 	}
     93  1.1      cgd 	if (wand->class <= 0) {
     94  1.1      cgd 		message("nothing happens", 0);
     95  1.1      cgd 	} else {
     96  1.1      cgd 		wand->class--;
     97  1.1      cgd 		row = rogue.row; col = rogue.col;
     98  1.1      cgd 		if ((wand->which_kind == COLD) || (wand->which_kind == FIRE)) {
     99  1.1      cgd 			bounce((short) wand->which_kind, d, row, col, 0);
    100  1.1      cgd 		} else {
    101  1.1      cgd 			monster = get_zapped_monster(d, &row, &col);
    102  1.1      cgd 			if (wand->which_kind == DRAIN_LIFE) {
    103  1.1      cgd 				wdrain_life(monster);
    104  1.1      cgd 			} else if (monster) {
    105  1.1      cgd 				wake_up(monster);
    106  1.1      cgd 				s_con_mon(monster);
    107  1.1      cgd 				zap_monster(monster, wand->which_kind);
    108  1.1      cgd 				relight();
    109  1.1      cgd 			}
    110  1.1      cgd 		}
    111  1.1      cgd 	}
    112  1.1      cgd 	(void) reg_move();
    113  1.1      cgd }
    114  1.1      cgd 
    115  1.1      cgd object *
    116  1.1      cgd get_zapped_monster(dir, row, col)
    117  1.4    lukem 	short dir;
    118  1.4    lukem 	short *row, *col;
    119  1.1      cgd {
    120  1.1      cgd 	short orow, ocol;
    121  1.1      cgd 
    122  1.1      cgd 	for (;;) {
    123  1.1      cgd 		orow = *row; ocol = *col;
    124  1.1      cgd 		get_dir_rc(dir, row, col, 0);
    125  1.1      cgd 		if (((*row == orow) && (*col == ocol)) ||
    126  1.1      cgd 		   (dungeon[*row][*col] & (HORWALL | VERTWALL)) ||
    127  1.1      cgd 		   (dungeon[*row][*col] == NOTHING)) {
    128  1.1      cgd 			return(0);
    129  1.1      cgd 		}
    130  1.1      cgd 		if (dungeon[*row][*col] & MONSTER) {
    131  1.1      cgd 			if (!imitating(*row, *col)) {
    132  1.1      cgd 				return(object_at(&level_monsters, *row, *col));
    133  1.1      cgd 			}
    134  1.1      cgd 		}
    135  1.1      cgd 	}
    136  1.1      cgd }
    137  1.1      cgd 
    138  1.4    lukem void
    139  1.1      cgd zap_monster(monster, kind)
    140  1.4    lukem 	object *monster;
    141  1.4    lukem 	unsigned short kind;
    142  1.1      cgd {
    143  1.1      cgd 	short row, col;
    144  1.1      cgd 	object *nm;
    145  1.1      cgd 	short tc;
    146  1.1      cgd 
    147  1.1      cgd 	row = monster->row;
    148  1.1      cgd 	col = monster->col;
    149  1.1      cgd 
    150  1.1      cgd 	switch(kind) {
    151  1.1      cgd 	case SLOW_MONSTER:
    152  1.1      cgd 		if (monster->m_flags & HASTED) {
    153  1.1      cgd 			monster->m_flags &= (~HASTED);
    154  1.1      cgd 		} else {
    155  1.1      cgd 			monster->slowed_toggle = 0;
    156  1.1      cgd 			monster->m_flags |= SLOWED;
    157  1.1      cgd 		}
    158  1.1      cgd 		break;
    159  1.1      cgd 	case HASTE_MONSTER:
    160  1.1      cgd 		if (monster->m_flags & SLOWED) {
    161  1.1      cgd 			monster->m_flags &= (~SLOWED);
    162  1.1      cgd 		} else {
    163  1.1      cgd 			monster->m_flags |= HASTED;
    164  1.1      cgd 		}
    165  1.1      cgd 		break;
    166  1.1      cgd 	case TELE_AWAY:
    167  1.1      cgd 		tele_away(monster);
    168  1.1      cgd 		break;
    169  1.1      cgd 	case INVISIBILITY:
    170  1.1      cgd 		monster->m_flags |= INVISIBLE;
    171  1.1      cgd 		break;
    172  1.1      cgd 	case POLYMORPH:
    173  1.1      cgd 		if (monster->m_flags & HOLDS) {
    174  1.1      cgd 			being_held = 0;
    175  1.1      cgd 		}
    176  1.1      cgd 		nm = monster->next_monster;
    177  1.1      cgd 		tc = monster->trail_char;
    178  1.1      cgd 		(void) gr_monster(monster, get_rand(0, MONSTERS-1));
    179  1.1      cgd 		monster->row = row;
    180  1.1      cgd 		monster->col = col;
    181  1.1      cgd 		monster->next_monster = nm;
    182  1.1      cgd 		monster->trail_char = tc;
    183  1.1      cgd 		if (!(monster->m_flags & IMITATES)) {
    184  1.1      cgd 			wake_up(monster);
    185  1.1      cgd 		}
    186  1.1      cgd 		break;
    187  1.1      cgd 	case MAGIC_MISSILE:
    188  1.1      cgd 		rogue_hit(monster, 1);
    189  1.1      cgd 		break;
    190  1.1      cgd 	case CANCELLATION:
    191  1.1      cgd 		if (monster->m_flags & HOLDS) {
    192  1.1      cgd 			being_held = 0;
    193  1.1      cgd 		}
    194  1.1      cgd 		if (monster->m_flags & STEALS_ITEM) {
    195  1.1      cgd 			monster->drop_percent = 0;
    196  1.1      cgd 		}
    197  1.1      cgd 		monster->m_flags &= (~(FLIES | FLITS | SPECIAL_HIT | INVISIBLE |
    198  1.1      cgd 			FLAMES | IMITATES | CONFUSES | SEEKS_GOLD | HOLDS));
    199  1.1      cgd 		break;
    200  1.1      cgd 	case DO_NOTHING:
    201  1.1      cgd 		message("nothing happens", 0);
    202  1.1      cgd 		break;
    203  1.1      cgd 	}
    204  1.1      cgd }
    205  1.1      cgd 
    206  1.4    lukem void
    207  1.1      cgd tele_away(monster)
    208  1.4    lukem 	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.1      cgd wizardize()
    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.1      cgd 		message("not wizard anymore", 0);
    234  1.1      cgd 	} else {
    235  1.1      cgd 		if (get_input_line("wizard's password:", "", buf, "", 0, 0)) {
    236  1.1      cgd 			(void) xxx(1);
    237  1.1      cgd 			xxxx(buf, strlen(buf));
    238  1.1      cgd 			if (!strncmp(buf, "\247\104\126\272\115\243\027", 7)) {
    239  1.1      cgd 				wizard = 1;
    240  1.1      cgd 				score_only = 1;
    241  1.1      cgd 				message("Welcome, mighty wizard!", 0);
    242  1.1      cgd 			} else {
    243  1.1      cgd 				message("sorry", 0);
    244  1.1      cgd 			}
    245  1.1      cgd 		}
    246  1.1      cgd 	}
    247  1.1      cgd }
    248  1.1      cgd 
    249  1.4    lukem void
    250  1.1      cgd wdrain_life(monster)
    251  1.4    lukem 	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.1      cgd 				(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.1      cgd 			(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.1      cgd bounce(ball, dir, row, col, r)
    281  1.4    lukem 	short ball, dir, row, col, r;
    282  1.1      cgd {
    283  1.1      cgd 	short orow, ocol;
    284  1.5  hubertf 	char buf[DCOLS];
    285  1.5  hubertf 	const char *s;
    286  1.1      cgd 	short i, ch, new_dir = -1, damage;
    287  1.1      cgd 	static short btime;
    288  1.1      cgd 
    289  1.1      cgd 	if (++r == 1) {
    290  1.1      cgd 		btime = get_rand(3, 6);
    291  1.1      cgd 	} else if (r > btime) {
    292  1.1      cgd 		return;
    293  1.1      cgd 	}
    294  1.1      cgd 
    295  1.1      cgd 	if (ball == FIRE) {
    296  1.1      cgd 		s = "fire";
    297  1.1      cgd 	} else {
    298  1.1      cgd 		s = "ice";
    299  1.1      cgd 	}
    300  1.1      cgd 	if (r > 1) {
    301  1.1      cgd 		sprintf(buf, "the %s bounces", s);
    302  1.1      cgd 		message(buf, 0);
    303  1.1      cgd 	}
    304  1.1      cgd 	orow = row;
    305  1.1      cgd 	ocol = col;
    306  1.1      cgd 	do {
    307  1.1      cgd 		ch = mvinch(orow, ocol);
    308  1.1      cgd 		standout();
    309  1.1      cgd 		mvaddch(orow, ocol, ch);
    310  1.1      cgd 		get_dir_rc(dir, &orow, &ocol, 1);
    311  1.1      cgd 	} while (!(	(ocol <= 0) ||
    312  1.1      cgd 				(ocol >= DCOLS-1) ||
    313  1.1      cgd 				(dungeon[orow][ocol] == NOTHING) ||
    314  1.1      cgd 				(dungeon[orow][ocol] & MONSTER) ||
    315  1.1      cgd 				(dungeon[orow][ocol] & (HORWALL | VERTWALL)) ||
    316  1.1      cgd 				((orow == rogue.row) && (ocol == rogue.col))));
    317  1.1      cgd 	standend();
    318  1.1      cgd 	refresh();
    319  1.1      cgd 	do {
    320  1.1      cgd 		orow = row;
    321  1.1      cgd 		ocol = col;
    322  1.1      cgd 		ch = mvinch(row, col);
    323  1.1      cgd 		mvaddch(row, col, ch);
    324  1.1      cgd 		get_dir_rc(dir, &row, &col, 1);
    325  1.1      cgd 	} while (!(	(col <= 0) ||
    326  1.1      cgd 				(col >= DCOLS-1) ||
    327  1.1      cgd 				(dungeon[row][col] == NOTHING) ||
    328  1.1      cgd 				(dungeon[row][col] & MONSTER) ||
    329  1.1      cgd 				(dungeon[row][col] & (HORWALL | VERTWALL)) ||
    330  1.1      cgd 				((row == rogue.row) && (col == rogue.col))));
    331  1.1      cgd 
    332  1.1      cgd 	if (dungeon[row][col] & MONSTER) {
    333  1.1      cgd 		object *monster;
    334  1.1      cgd 
    335  1.1      cgd 		monster = object_at(&level_monsters, row, col);
    336  1.1      cgd 
    337  1.1      cgd 		wake_up(monster);
    338  1.1      cgd 		if (rand_percent(33)) {
    339  1.1      cgd 			sprintf(buf, "the %s misses the %s", s, mon_name(monster));
    340  1.1      cgd 			message(buf, 0);
    341  1.1      cgd 			goto ND;
    342  1.1      cgd 		}
    343  1.1      cgd 		if (ball == FIRE) {
    344  1.1      cgd 			if (!(monster->m_flags & RUSTS)) {
    345  1.1      cgd 				if (monster->m_flags & FREEZES) {
    346  1.1      cgd 					damage = monster->hp_to_kill;
    347  1.1      cgd 				} else if (monster->m_flags & FLAMES) {
    348  1.1      cgd 					damage = (monster->hp_to_kill / 10) + 1;
    349  1.1      cgd 				} else {
    350  1.1      cgd 					damage = get_rand((rogue.hp_current / 3), rogue.hp_max);
    351  1.1      cgd 				}
    352  1.1      cgd 			} else {
    353  1.1      cgd 				damage = (monster->hp_to_kill / 2) + 1;
    354  1.1      cgd 			}
    355  1.1      cgd 			sprintf(buf, "the %s hits the %s", s, mon_name(monster));
    356  1.1      cgd 			message(buf, 0);
    357  1.1      cgd 			(void) mon_damage(monster, damage);
    358  1.1      cgd 		} else {
    359  1.1      cgd 			damage = -1;
    360  1.1      cgd 			if (!(monster->m_flags & FREEZES)) {
    361  1.1      cgd 				if (rand_percent(33)) {
    362  1.1      cgd 					message("the monster is frozen", 0);
    363  1.1      cgd 					monster->m_flags |= (ASLEEP | NAPPING);
    364  1.1      cgd 					monster->nap_length = get_rand(3, 6);
    365  1.1      cgd 				} else {
    366  1.1      cgd 					damage = rogue.hp_current / 4;
    367  1.1      cgd 				}
    368  1.1      cgd 			} else {
    369  1.1      cgd 				damage = -2;
    370  1.1      cgd 			}
    371  1.1      cgd 			if (damage != -1) {
    372  1.1      cgd 				sprintf(buf, "the %s hits the %s", s, mon_name(monster));
    373  1.1      cgd 				message(buf, 0);
    374  1.1      cgd 				(void) mon_damage(monster, damage);
    375  1.1      cgd 			}
    376  1.1      cgd 		}
    377  1.1      cgd 	} else if ((row == rogue.row) && (col == rogue.col)) {
    378  1.1      cgd 		if (rand_percent(10 + (3 * get_armor_class(rogue.armor)))) {
    379  1.1      cgd 			sprintf(buf, "the %s misses", s);
    380  1.1      cgd 			message(buf, 0);
    381  1.1      cgd 			goto ND;
    382  1.1      cgd 		} else {
    383  1.1      cgd 			damage = get_rand(3, (3 * rogue.exp));
    384  1.1      cgd 			if (ball == FIRE) {
    385  1.1      cgd 				damage = (damage * 3) / 2;
    386  1.1      cgd 				damage -= get_armor_class(rogue.armor);
    387  1.1      cgd 			}
    388  1.1      cgd 			sprintf(buf, "the %s hits", s);
    389  1.1      cgd 			rogue_damage(damage, (object *) 0,
    390  1.1      cgd 					((ball == FIRE) ? KFIRE : HYPOTHERMIA));
    391  1.1      cgd 			message(buf, 0);
    392  1.1      cgd 		}
    393  1.1      cgd 	} else {
    394  1.1      cgd 		short nrow, ncol;
    395  1.1      cgd 
    396  1.1      cgd ND:		for (i = 0; i < 10; i++) {
    397  1.1      cgd 			dir = get_rand(0, DIRS-1);
    398  1.1      cgd 			nrow = orow;
    399  1.1      cgd 			ncol = ocol;
    400  1.1      cgd 			get_dir_rc(dir, &nrow, &ncol, 1);
    401  1.1      cgd 			if (((ncol >= 0) && (ncol <= DCOLS-1)) &&
    402  1.1      cgd 				(dungeon[nrow][ncol] != NOTHING) &&
    403  1.1      cgd 				(!(dungeon[nrow][ncol] & (VERTWALL | HORWALL)))) {
    404  1.1      cgd 				new_dir = dir;
    405  1.1      cgd 				break;
    406  1.1      cgd 			}
    407  1.1      cgd 		}
    408  1.1      cgd 		if (new_dir != -1) {
    409  1.1      cgd 			bounce(ball, new_dir, orow, ocol, r);
    410  1.1      cgd 		}
    411  1.1      cgd 	}
    412  1.1      cgd }
    413