Home | History | Annotate | Line # | Download | only in rogue
zap.c revision 1.4
      1  1.4  lukem /*	$NetBSD: zap.c,v 1.4 1997/10/12 11:46:15 lukem 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.4  lukem #include <sys/cdefs.h>
     40  1.1    cgd #ifndef lint
     41  1.3    cgd #if 0
     42  1.3    cgd static char sccsid[] = "@(#)zap.c	8.1 (Berkeley) 5/31/93";
     43  1.3    cgd #else
     44  1.4  lukem __RCSID("$NetBSD: zap.c,v 1.4 1997/10/12 11:46:15 lukem Exp $");
     45  1.3    cgd #endif
     46  1.1    cgd #endif /* not lint */
     47  1.1    cgd 
     48  1.1    cgd /*
     49  1.1    cgd  * zap.c
     50  1.1    cgd  *
     51  1.1    cgd  * This source herein may be modified and/or distributed by anybody who
     52  1.1    cgd  * so desires, with the following restrictions:
     53  1.1    cgd  *    1.)  No portion of this notice shall be removed.
     54  1.1    cgd  *    2.)  Credit shall not be taken for the creation of this source.
     55  1.1    cgd  *    3.)  This code is not to be traded, sold, or used for personal
     56  1.1    cgd  *         gain or profit.
     57  1.1    cgd  *
     58  1.1    cgd  */
     59  1.1    cgd 
     60  1.1    cgd #include "rogue.h"
     61  1.1    cgd 
     62  1.1    cgd boolean wizard = 0;
     63  1.1    cgd 
     64  1.4  lukem void
     65  1.1    cgd zapp()
     66  1.1    cgd {
     67  1.1    cgd 	short wch;
     68  1.1    cgd 	boolean first_miss = 1;
     69  1.1    cgd 	object *wand;
     70  1.1    cgd 	short dir, d, row, col;
     71  1.1    cgd 	object *monster;
     72  1.1    cgd 
     73  1.1    cgd 	while (!is_direction(dir = rgetchar(), &d)) {
     74  1.1    cgd 		sound_bell();
     75  1.1    cgd 		if (first_miss) {
     76  1.1    cgd 			message("direction? ", 0);
     77  1.1    cgd 			first_miss = 0;
     78  1.1    cgd 		}
     79  1.1    cgd 	}
     80  1.1    cgd 	check_message();
     81  1.1    cgd 	if (dir == CANCEL) {
     82  1.1    cgd 		return;
     83  1.1    cgd 	}
     84  1.1    cgd 	if ((wch = pack_letter("zap with what?", WAND)) == CANCEL) {
     85  1.1    cgd 		return;
     86  1.1    cgd 	}
     87  1.1    cgd 	check_message();
     88  1.1    cgd 
     89  1.1    cgd 	if (!(wand = get_letter_object(wch))) {
     90  1.1    cgd 		message("no such item.", 0);
     91  1.1    cgd 		return;
     92  1.1    cgd 	}
     93  1.1    cgd 	if (wand->what_is != WAND) {
     94  1.1    cgd 		message("you can't zap with that", 0);
     95  1.1    cgd 		return;
     96  1.1    cgd 	}
     97  1.1    cgd 	if (wand->class <= 0) {
     98  1.1    cgd 		message("nothing happens", 0);
     99  1.1    cgd 	} else {
    100  1.1    cgd 		wand->class--;
    101  1.1    cgd 		row = rogue.row; col = rogue.col;
    102  1.1    cgd 		if ((wand->which_kind == COLD) || (wand->which_kind == FIRE)) {
    103  1.1    cgd 			bounce((short) wand->which_kind, d, row, col, 0);
    104  1.1    cgd 		} else {
    105  1.1    cgd 			monster = get_zapped_monster(d, &row, &col);
    106  1.1    cgd 			if (wand->which_kind == DRAIN_LIFE) {
    107  1.1    cgd 				wdrain_life(monster);
    108  1.1    cgd 			} else if (monster) {
    109  1.1    cgd 				wake_up(monster);
    110  1.1    cgd 				s_con_mon(monster);
    111  1.1    cgd 				zap_monster(monster, wand->which_kind);
    112  1.1    cgd 				relight();
    113  1.1    cgd 			}
    114  1.1    cgd 		}
    115  1.1    cgd 	}
    116  1.1    cgd 	(void) reg_move();
    117  1.1    cgd }
    118  1.1    cgd 
    119  1.1    cgd object *
    120  1.1    cgd get_zapped_monster(dir, row, col)
    121  1.4  lukem 	short dir;
    122  1.4  lukem 	short *row, *col;
    123  1.1    cgd {
    124  1.1    cgd 	short orow, ocol;
    125  1.1    cgd 
    126  1.1    cgd 	for (;;) {
    127  1.1    cgd 		orow = *row; ocol = *col;
    128  1.1    cgd 		get_dir_rc(dir, row, col, 0);
    129  1.1    cgd 		if (((*row == orow) && (*col == ocol)) ||
    130  1.1    cgd 		   (dungeon[*row][*col] & (HORWALL | VERTWALL)) ||
    131  1.1    cgd 		   (dungeon[*row][*col] == NOTHING)) {
    132  1.1    cgd 			return(0);
    133  1.1    cgd 		}
    134  1.1    cgd 		if (dungeon[*row][*col] & MONSTER) {
    135  1.1    cgd 			if (!imitating(*row, *col)) {
    136  1.1    cgd 				return(object_at(&level_monsters, *row, *col));
    137  1.1    cgd 			}
    138  1.1    cgd 		}
    139  1.1    cgd 	}
    140  1.1    cgd }
    141  1.1    cgd 
    142  1.4  lukem void
    143  1.1    cgd zap_monster(monster, kind)
    144  1.4  lukem 	object *monster;
    145  1.4  lukem 	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.4  lukem void
    211  1.1    cgd tele_away(monster)
    212  1.4  lukem 	object *monster;
    213  1.1    cgd {
    214  1.1    cgd 	short row, col;
    215  1.1    cgd 
    216  1.1    cgd 	if (monster->m_flags & HOLDS) {
    217  1.1    cgd 		being_held = 0;
    218  1.1    cgd 	}
    219  1.1    cgd 	gr_row_col(&row, &col, (FLOOR | TUNNEL | STAIRS | OBJECT));
    220  1.1    cgd 	mvaddch(monster->row, monster->col, monster->trail_char);
    221  1.1    cgd 	dungeon[monster->row][monster->col] &= ~MONSTER;
    222  1.1    cgd 	monster->row = row; monster->col = col;
    223  1.1    cgd 	dungeon[row][col] |= MONSTER;
    224  1.1    cgd 	monster->trail_char = mvinch(row, col);
    225  1.1    cgd 	if (detect_monster || rogue_can_see(row, col)) {
    226  1.1    cgd 		mvaddch(row, col, gmc(monster));
    227  1.1    cgd 	}
    228  1.1    cgd }
    229  1.1    cgd 
    230  1.4  lukem void
    231  1.1    cgd wizardize()
    232  1.1    cgd {
    233  1.1    cgd 	char buf[100];
    234  1.1    cgd 
    235  1.1    cgd 	if (wizard) {
    236  1.1    cgd 		wizard = 0;
    237  1.1    cgd 		message("not wizard anymore", 0);
    238  1.1    cgd 	} else {
    239  1.1    cgd 		if (get_input_line("wizard's password:", "", buf, "", 0, 0)) {
    240  1.1    cgd 			(void) xxx(1);
    241  1.1    cgd 			xxxx(buf, strlen(buf));
    242  1.1    cgd 			if (!strncmp(buf, "\247\104\126\272\115\243\027", 7)) {
    243  1.1    cgd 				wizard = 1;
    244  1.1    cgd 				score_only = 1;
    245  1.1    cgd 				message("Welcome, mighty wizard!", 0);
    246  1.1    cgd 			} else {
    247  1.1    cgd 				message("sorry", 0);
    248  1.1    cgd 			}
    249  1.1    cgd 		}
    250  1.1    cgd 	}
    251  1.1    cgd }
    252  1.1    cgd 
    253  1.4  lukem void
    254  1.1    cgd wdrain_life(monster)
    255  1.4  lukem 	object *monster;
    256  1.1    cgd {
    257  1.1    cgd 	short hp;
    258  1.1    cgd 	object *lmon, *nm;
    259  1.1    cgd 
    260  1.1    cgd 	hp = rogue.hp_current / 3;
    261  1.1    cgd 	rogue.hp_current = (rogue.hp_current + 1) / 2;
    262  1.1    cgd 
    263  1.1    cgd 	if (cur_room >= 0) {
    264  1.1    cgd 		lmon = level_monsters.next_monster;
    265  1.1    cgd 		while (lmon) {
    266  1.1    cgd 			nm = lmon->next_monster;
    267  1.1    cgd 			if (get_room_number(lmon->row, lmon->col) == cur_room) {
    268  1.1    cgd 				wake_up(lmon);
    269  1.1    cgd 				(void) mon_damage(lmon, hp);
    270  1.1    cgd 			}
    271  1.1    cgd 			lmon = nm;
    272  1.1    cgd 		}
    273  1.1    cgd 	} else {
    274  1.1    cgd 		if (monster) {
    275  1.1    cgd 			wake_up(monster);
    276  1.1    cgd 			(void) mon_damage(monster, hp);
    277  1.1    cgd 		}
    278  1.1    cgd 	}
    279  1.1    cgd 	print_stats(STAT_HP);
    280  1.1    cgd 	relight();
    281  1.1    cgd }
    282  1.1    cgd 
    283  1.4  lukem void
    284  1.1    cgd bounce(ball, dir, row, col, r)
    285  1.4  lukem 	short ball, dir, row, col, r;
    286  1.1    cgd {
    287  1.1    cgd 	short orow, ocol;
    288  1.1    cgd 	char buf[DCOLS], *s;
    289  1.1    cgd 	short i, ch, new_dir = -1, damage;
    290  1.1    cgd 	static short btime;
    291  1.1    cgd 
    292  1.1    cgd 	if (++r == 1) {
    293  1.1    cgd 		btime = get_rand(3, 6);
    294  1.1    cgd 	} else if (r > btime) {
    295  1.1    cgd 		return;
    296  1.1    cgd 	}
    297  1.1    cgd 
    298  1.1    cgd 	if (ball == FIRE) {
    299  1.1    cgd 		s = "fire";
    300  1.1    cgd 	} else {
    301  1.1    cgd 		s = "ice";
    302  1.1    cgd 	}
    303  1.1    cgd 	if (r > 1) {
    304  1.1    cgd 		sprintf(buf, "the %s bounces", s);
    305  1.1    cgd 		message(buf, 0);
    306  1.1    cgd 	}
    307  1.1    cgd 	orow = row;
    308  1.1    cgd 	ocol = col;
    309  1.1    cgd 	do {
    310  1.1    cgd 		ch = mvinch(orow, ocol);
    311  1.1    cgd 		standout();
    312  1.1    cgd 		mvaddch(orow, ocol, ch);
    313  1.1    cgd 		get_dir_rc(dir, &orow, &ocol, 1);
    314  1.1    cgd 	} while (!(	(ocol <= 0) ||
    315  1.1    cgd 				(ocol >= DCOLS-1) ||
    316  1.1    cgd 				(dungeon[orow][ocol] == NOTHING) ||
    317  1.1    cgd 				(dungeon[orow][ocol] & MONSTER) ||
    318  1.1    cgd 				(dungeon[orow][ocol] & (HORWALL | VERTWALL)) ||
    319  1.1    cgd 				((orow == rogue.row) && (ocol == rogue.col))));
    320  1.1    cgd 	standend();
    321  1.1    cgd 	refresh();
    322  1.1    cgd 	do {
    323  1.1    cgd 		orow = row;
    324  1.1    cgd 		ocol = col;
    325  1.1    cgd 		ch = mvinch(row, col);
    326  1.1    cgd 		mvaddch(row, col, ch);
    327  1.1    cgd 		get_dir_rc(dir, &row, &col, 1);
    328  1.1    cgd 	} while (!(	(col <= 0) ||
    329  1.1    cgd 				(col >= DCOLS-1) ||
    330  1.1    cgd 				(dungeon[row][col] == NOTHING) ||
    331  1.1    cgd 				(dungeon[row][col] & MONSTER) ||
    332  1.1    cgd 				(dungeon[row][col] & (HORWALL | VERTWALL)) ||
    333  1.1    cgd 				((row == rogue.row) && (col == rogue.col))));
    334  1.1    cgd 
    335  1.1    cgd 	if (dungeon[row][col] & MONSTER) {
    336  1.1    cgd 		object *monster;
    337  1.1    cgd 
    338  1.1    cgd 		monster = object_at(&level_monsters, row, col);
    339  1.1    cgd 
    340  1.1    cgd 		wake_up(monster);
    341  1.1    cgd 		if (rand_percent(33)) {
    342  1.1    cgd 			sprintf(buf, "the %s misses the %s", s, mon_name(monster));
    343  1.1    cgd 			message(buf, 0);
    344  1.1    cgd 			goto ND;
    345  1.1    cgd 		}
    346  1.1    cgd 		if (ball == FIRE) {
    347  1.1    cgd 			if (!(monster->m_flags & RUSTS)) {
    348  1.1    cgd 				if (monster->m_flags & FREEZES) {
    349  1.1    cgd 					damage = monster->hp_to_kill;
    350  1.1    cgd 				} else if (monster->m_flags & FLAMES) {
    351  1.1    cgd 					damage = (monster->hp_to_kill / 10) + 1;
    352  1.1    cgd 				} else {
    353  1.1    cgd 					damage = get_rand((rogue.hp_current / 3), rogue.hp_max);
    354  1.1    cgd 				}
    355  1.1    cgd 			} else {
    356  1.1    cgd 				damage = (monster->hp_to_kill / 2) + 1;
    357  1.1    cgd 			}
    358  1.1    cgd 			sprintf(buf, "the %s hits the %s", s, mon_name(monster));
    359  1.1    cgd 			message(buf, 0);
    360  1.1    cgd 			(void) mon_damage(monster, damage);
    361  1.1    cgd 		} else {
    362  1.1    cgd 			damage = -1;
    363  1.1    cgd 			if (!(monster->m_flags & FREEZES)) {
    364  1.1    cgd 				if (rand_percent(33)) {
    365  1.1    cgd 					message("the monster is frozen", 0);
    366  1.1    cgd 					monster->m_flags |= (ASLEEP | NAPPING);
    367  1.1    cgd 					monster->nap_length = get_rand(3, 6);
    368  1.1    cgd 				} else {
    369  1.1    cgd 					damage = rogue.hp_current / 4;
    370  1.1    cgd 				}
    371  1.1    cgd 			} else {
    372  1.1    cgd 				damage = -2;
    373  1.1    cgd 			}
    374  1.1    cgd 			if (damage != -1) {
    375  1.1    cgd 				sprintf(buf, "the %s hits the %s", s, mon_name(monster));
    376  1.1    cgd 				message(buf, 0);
    377  1.1    cgd 				(void) mon_damage(monster, damage);
    378  1.1    cgd 			}
    379  1.1    cgd 		}
    380  1.1    cgd 	} else if ((row == rogue.row) && (col == rogue.col)) {
    381  1.1    cgd 		if (rand_percent(10 + (3 * get_armor_class(rogue.armor)))) {
    382  1.1    cgd 			sprintf(buf, "the %s misses", s);
    383  1.1    cgd 			message(buf, 0);
    384  1.1    cgd 			goto ND;
    385  1.1    cgd 		} else {
    386  1.1    cgd 			damage = get_rand(3, (3 * rogue.exp));
    387  1.1    cgd 			if (ball == FIRE) {
    388  1.1    cgd 				damage = (damage * 3) / 2;
    389  1.1    cgd 				damage -= get_armor_class(rogue.armor);
    390  1.1    cgd 			}
    391  1.1    cgd 			sprintf(buf, "the %s hits", s);
    392  1.1    cgd 			rogue_damage(damage, (object *) 0,
    393  1.1    cgd 					((ball == FIRE) ? KFIRE : HYPOTHERMIA));
    394  1.1    cgd 			message(buf, 0);
    395  1.1    cgd 		}
    396  1.1    cgd 	} else {
    397  1.1    cgd 		short nrow, ncol;
    398  1.1    cgd 
    399  1.1    cgd ND:		for (i = 0; i < 10; i++) {
    400  1.1    cgd 			dir = get_rand(0, DIRS-1);
    401  1.1    cgd 			nrow = orow;
    402  1.1    cgd 			ncol = ocol;
    403  1.1    cgd 			get_dir_rc(dir, &nrow, &ncol, 1);
    404  1.1    cgd 			if (((ncol >= 0) && (ncol <= DCOLS-1)) &&
    405  1.1    cgd 				(dungeon[nrow][ncol] != NOTHING) &&
    406  1.1    cgd 				(!(dungeon[nrow][ncol] & (VERTWALL | HORWALL)))) {
    407  1.1    cgd 				new_dir = dir;
    408  1.1    cgd 				break;
    409  1.1    cgd 			}
    410  1.1    cgd 		}
    411  1.1    cgd 		if (new_dir != -1) {
    412  1.1    cgd 			bounce(ball, new_dir, orow, ocol, r);
    413  1.1    cgd 		}
    414  1.1    cgd 	}
    415  1.1    cgd }
    416