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