Home | History | Annotate | Line # | Download | only in rogue
use.c revision 1.3
      1 /*	$NetBSD: use.c,v 1.3 1995/04/22 10:28:38 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Timothy C. Stoehr.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  */
     38 
     39 #ifndef lint
     40 #if 0
     41 static char sccsid[] = "@(#)use.c	8.1 (Berkeley) 5/31/93";
     42 #else
     43 static char rcsid[] = "$NetBSD: use.c,v 1.3 1995/04/22 10:28:38 cgd Exp $";
     44 #endif
     45 #endif /* not lint */
     46 
     47 /*
     48  * use.c
     49  *
     50  * This source herein may be modified and/or distributed by anybody who
     51  * so desires, with the following restrictions:
     52  *    1.)  No portion of this notice shall be removed.
     53  *    2.)  Credit shall not be taken for the creation of this source.
     54  *    3.)  This code is not to be traded, sold, or used for personal
     55  *         gain or profit.
     56  *
     57  */
     58 
     59 #include "rogue.h"
     60 
     61 short halluc = 0;
     62 short blind = 0;
     63 short confused = 0;
     64 short levitate = 0;
     65 short haste_self = 0;
     66 boolean see_invisible = 0;
     67 short extra_hp = 0;
     68 boolean detect_monster = 0;
     69 boolean con_mon = 0;
     70 char *strange_feeling = "you have a strange feeling for a moment, then it passes";
     71 
     72 extern short bear_trap;
     73 extern char hunger_str[];
     74 extern short cur_room;
     75 extern long level_points[];
     76 extern boolean being_held;
     77 extern char *fruit, *you_can_move_again;
     78 extern boolean sustain_strength;
     79 
     80 quaff()
     81 {
     82 	short ch;
     83 	char buf[80];
     84 	object *obj;
     85 
     86 	ch = pack_letter("quaff what?", POTION);
     87 
     88 	if (ch == CANCEL) {
     89 		return;
     90 	}
     91 	if (!(obj = get_letter_object(ch))) {
     92 		message("no such item.", 0);
     93 		return;
     94 	}
     95 	if (obj->what_is != POTION) {
     96 		message("you can't drink that", 0);
     97 		return;
     98 	}
     99 	switch(obj->which_kind) {
    100 		case INCREASE_STRENGTH:
    101 			message("you feel stronger now, what bulging muscles!",
    102 			0);
    103 			rogue.str_current++;
    104 			if (rogue.str_current > rogue.str_max) {
    105 				rogue.str_max = rogue.str_current;
    106 			}
    107 			break;
    108 		case RESTORE_STRENGTH:
    109 			rogue.str_current = rogue.str_max;
    110 			message("this tastes great, you feel warm all over", 0);
    111 			break;
    112 		case HEALING:
    113 			message("you begin to feel better", 0);
    114 			potion_heal(0);
    115 			break;
    116 		case EXTRA_HEALING:
    117 			message("you begin to feel much better", 0);
    118 			potion_heal(1);
    119 			break;
    120 		case POISON:
    121 			if (!sustain_strength) {
    122 				rogue.str_current -= get_rand(1, 3);
    123 				if (rogue.str_current < 1) {
    124 					rogue.str_current = 1;
    125 				}
    126 			}
    127 			message("you feel very sick now", 0);
    128 			if (halluc) {
    129 				unhallucinate();
    130 			}
    131 			break;
    132 		case RAISE_LEVEL:
    133 			rogue.exp_points = level_points[rogue.exp - 1];
    134 			message("you suddenly feel much more skillful", 0);
    135 			add_exp(1, 1);
    136 			break;
    137 		case BLINDNESS:
    138 			go_blind();
    139 			break;
    140 		case HALLUCINATION:
    141 			message("oh wow, everything seems so cosmic", 0);
    142 			halluc += get_rand(500, 800);
    143 			break;
    144 		case DETECT_MONSTER:
    145 			show_monsters();
    146 			if (!(level_monsters.next_monster)) {
    147 				message(strange_feeling, 0);
    148 			}
    149 			break;
    150 		case DETECT_OBJECTS:
    151 			if (level_objects.next_object) {
    152 				if (!blind) {
    153 					show_objects();
    154 				}
    155 			} else {
    156 				message(strange_feeling, 0);
    157 			}
    158 			break;
    159 		case CONFUSION:
    160 			message((halluc ? "what a trippy feeling" :
    161 			"you feel confused"), 0);
    162 			cnfs();
    163 			break;
    164 		case LEVITATION:
    165 			message("you start to float in the air", 0);
    166 			levitate += get_rand(15, 30);
    167 			being_held = bear_trap = 0;
    168 			break;
    169 		case HASTE_SELF:
    170 			message("you feel yourself moving much faster", 0);
    171 			haste_self += get_rand(11, 21);
    172 			if (!(haste_self % 2)) {
    173 				haste_self++;
    174 			}
    175 			break;
    176 		case SEE_INVISIBLE:
    177 			sprintf(buf, "hmm, this potion tastes like %sjuice", fruit);
    178 			message(buf, 0);
    179 			if (blind) {
    180 				unblind();
    181 			}
    182 			see_invisible = 1;
    183 			relight();
    184 			break;
    185 	}
    186 	print_stats((STAT_STRENGTH | STAT_HP));
    187 	if (id_potions[obj->which_kind].id_status != CALLED) {
    188 		id_potions[obj->which_kind].id_status = IDENTIFIED;
    189 	}
    190 	vanish(obj, 1, &rogue.pack);
    191 }
    192 
    193 read_scroll()
    194 {
    195 	short ch;
    196 	object *obj;
    197 	char msg[DCOLS];
    198 
    199 	ch = pack_letter("read what?", SCROL);
    200 
    201 	if (ch == CANCEL) {
    202 		return;
    203 	}
    204 	if (!(obj = get_letter_object(ch))) {
    205 		message("no such item.", 0);
    206 		return;
    207 	}
    208 	if (obj->what_is != SCROL) {
    209 		message("you can't read that", 0);
    210 		return;
    211 	}
    212 	switch(obj->which_kind) {
    213 		case SCARE_MONSTER:
    214 			message("you hear a maniacal laughter in the distance",
    215 			0);
    216 			break;
    217 		case HOLD_MONSTER:
    218 			hold_monster();
    219 			break;
    220 		case ENCH_WEAPON:
    221 			if (rogue.weapon) {
    222 				if (rogue.weapon->what_is == WEAPON) {
    223 					sprintf(msg, "your %sglow%s %sfor a moment",
    224 					name_of(rogue.weapon),
    225 					((rogue.weapon->quantity <= 1) ? "s" : ""),
    226 					get_ench_color());
    227 					message(msg, 0);
    228 					if (coin_toss()) {
    229 						rogue.weapon->hit_enchant++;
    230 					} else {
    231 						rogue.weapon->d_enchant++;
    232 					}
    233 				}
    234 				rogue.weapon->is_cursed = 0;
    235 			} else {
    236 				message("your hands tingle", 0);
    237 			}
    238 			break;
    239 		case ENCH_ARMOR:
    240 			if (rogue.armor) {
    241 				sprintf(msg, "your armor glows %sfor a moment",
    242 				get_ench_color());
    243 				message(msg, 0);
    244 				rogue.armor->d_enchant++;
    245 				rogue.armor->is_cursed = 0;
    246 				print_stats(STAT_ARMOR);
    247 			} else {
    248 				message("your skin crawls", 0);
    249 			}
    250 			break;
    251 		case IDENTIFY:
    252 			message("this is a scroll of identify", 0);
    253 			obj->identified = 1;
    254 			id_scrolls[obj->which_kind].id_status = IDENTIFIED;
    255 			idntfy();
    256 			break;
    257 		case TELEPORT:
    258 			tele();
    259 			break;
    260 		case SLEEP:
    261 			message("you fall asleep", 0);
    262 			take_a_nap();
    263 			break;
    264 		case PROTECT_ARMOR:
    265 			if (rogue.armor) {
    266 				message( "your armor is covered by a shimmering gold shield",0);
    267 				rogue.armor->is_protected = 1;
    268 				rogue.armor->is_cursed = 0;
    269 			} else {
    270 				message("your acne seems to have disappeared", 0);
    271 			}
    272 			break;
    273 		case REMOVE_CURSE:
    274 				message((!halluc) ?
    275 					"you feel as though someone is watching over you" :
    276 					"you feel in touch with the universal oneness", 0);
    277 			uncurse_all();
    278 			break;
    279 		case CREATE_MONSTER:
    280 			create_monster();
    281 			break;
    282 		case AGGRAVATE_MONSTER:
    283 			aggravate();
    284 			break;
    285 		case MAGIC_MAPPING:
    286 			message("this scroll seems to have a map on it", 0);
    287 			draw_magic_map();
    288 			break;
    289 		case CON_MON:
    290 			con_mon = 1;
    291 			sprintf(msg, "your hands glow %sfor a moment", get_ench_color());
    292 			message(msg, 0);
    293 			break;
    294 	}
    295 	if (id_scrolls[obj->which_kind].id_status != CALLED) {
    296 		id_scrolls[obj->which_kind].id_status = IDENTIFIED;
    297 	}
    298 	vanish(obj, (obj->which_kind != SLEEP), &rogue.pack);
    299 }
    300 
    301 /* vanish() does NOT handle a quiver of weapons with more than one
    302  *  arrow (or whatever) in the quiver.  It will only decrement the count.
    303  */
    304 
    305 vanish(obj, rm, pack)
    306 object *obj;
    307 short rm;
    308 object *pack;
    309 {
    310 	if (obj->quantity > 1) {
    311 		obj->quantity--;
    312 	} else {
    313 		if (obj->in_use_flags & BEING_WIELDED) {
    314 			unwield(obj);
    315 		} else if (obj->in_use_flags & BEING_WORN) {
    316 			unwear(obj);
    317 		} else if (obj->in_use_flags & ON_EITHER_HAND) {
    318 			un_put_on(obj);
    319 		}
    320 		take_from_pack(obj, pack);
    321 		free_object(obj);
    322 	}
    323 	if (rm) {
    324 		(void) reg_move();
    325 	}
    326 }
    327 
    328 potion_heal(extra)
    329 {
    330 	float ratio;
    331 	short add;
    332 
    333 	rogue.hp_current += rogue.exp;
    334 
    335 	ratio = ((float)rogue.hp_current) / rogue.hp_max;
    336 
    337 	if (ratio >= 1.00) {
    338 		rogue.hp_max += (extra ? 2 : 1);
    339 		extra_hp += (extra ? 2 : 1);
    340 		rogue.hp_current = rogue.hp_max;
    341 	} else if (ratio >= 0.90) {
    342 		rogue.hp_max += (extra ? 1 : 0);
    343 		extra_hp += (extra ? 1 : 0);
    344 		rogue.hp_current = rogue.hp_max;
    345 	} else {
    346 		if (ratio < 0.33) {
    347 			ratio = 0.33;
    348 		}
    349 		if (extra) {
    350 			ratio += ratio;
    351 		}
    352 		add = (short)(ratio * ((float)rogue.hp_max - rogue.hp_current));
    353 		rogue.hp_current += add;
    354 		if (rogue.hp_current > rogue.hp_max) {
    355 			rogue.hp_current = rogue.hp_max;
    356 		}
    357 	}
    358 	if (blind) {
    359 		unblind();
    360 	}
    361 	if (confused && extra) {
    362 			unconfuse();
    363 	} else if (confused) {
    364 		confused = (confused / 2) + 1;
    365 	}
    366 	if (halluc && extra) {
    367 		unhallucinate();
    368 	} else if (halluc) {
    369 		halluc = (halluc / 2) + 1;
    370 	}
    371 }
    372 
    373 idntfy()
    374 {
    375 	short ch;
    376 	object *obj;
    377 	struct id *id_table;
    378 	char desc[DCOLS];
    379 AGAIN:
    380 	ch = pack_letter("what would you like to identify?", ALL_OBJECTS);
    381 
    382 	if (ch == CANCEL) {
    383 		return;
    384 	}
    385 	if (!(obj = get_letter_object(ch))) {
    386 		message("no such item, try again", 0);
    387 		message("", 0);
    388 		check_message();
    389 		goto AGAIN;
    390 	}
    391 	obj->identified = 1;
    392 	if (obj->what_is & (SCROL | POTION | WEAPON | ARMOR | WAND | RING)) {
    393 		id_table = get_id_table(obj);
    394 		id_table[obj->which_kind].id_status = IDENTIFIED;
    395 	}
    396 	get_desc(obj, desc);
    397 	message(desc, 0);
    398 }
    399 
    400 eat()
    401 {
    402 	short ch;
    403 	short moves;
    404 	object *obj;
    405 	char buf[70];
    406 
    407 	ch = pack_letter("eat what?", FOOD);
    408 
    409 	if (ch == CANCEL) {
    410 		return;
    411 	}
    412 	if (!(obj = get_letter_object(ch))) {
    413 		message("no such item.", 0);
    414 		return;
    415 	}
    416 	if (obj->what_is != FOOD) {
    417 		message("you can't eat that", 0);
    418 		return;
    419 	}
    420 	if ((obj->which_kind == FRUIT) || rand_percent(60)) {
    421 		moves = get_rand(950, 1150);
    422 		if (obj->which_kind == RATION) {
    423 			message("yum, that tasted good", 0);
    424 		} else {
    425 			sprintf(buf, "my, that was a yummy %s", fruit);
    426 			message(buf, 0);
    427 		}
    428 	} else {
    429 		moves = get_rand(750, 950);
    430 		message("yuk, that food tasted awful", 0);
    431 		add_exp(2, 1);
    432 	}
    433 	rogue.moves_left /= 3;
    434 	rogue.moves_left += moves;
    435 	hunger_str[0] = 0;
    436 	print_stats(STAT_HUNGER);
    437 
    438 	vanish(obj, 1, &rogue.pack);
    439 }
    440 
    441 hold_monster()
    442 {
    443 	short i, j;
    444 	short mcount = 0;
    445 	object *monster;
    446 	short row, col;
    447 
    448 	for (i = -2; i <= 2; i++) {
    449 		for (j = -2; j <= 2; j++) {
    450 			row = rogue.row + i;
    451 			col = rogue.col + j;
    452 			if ((row < MIN_ROW) || (row > (DROWS-2)) || (col < 0) ||
    453 				 (col > (DCOLS-1))) {
    454 				continue;
    455 			}
    456 			if (dungeon[row][col] & MONSTER) {
    457 				monster = object_at(&level_monsters, row, col);
    458 				monster->m_flags |= ASLEEP;
    459 				monster->m_flags &= (~WAKENS);
    460 				mcount++;
    461 			}
    462 		}
    463 	}
    464 	if (mcount == 0) {
    465 		message("you feel a strange sense of loss", 0);
    466 	} else if (mcount == 1) {
    467 		message("the monster freezes", 0);
    468 	} else {
    469 		message("the monsters around you freeze", 0);
    470 	}
    471 }
    472 
    473 tele()
    474 {
    475 	mvaddch(rogue.row, rogue.col, get_dungeon_char(rogue.row, rogue.col));
    476 
    477 	if (cur_room >= 0) {
    478 		darken_room(cur_room);
    479 	}
    480 	put_player(get_room_number(rogue.row, rogue.col));
    481 	being_held = 0;
    482 	bear_trap = 0;
    483 }
    484 
    485 hallucinate()
    486 {
    487 	object *obj, *monster;
    488 	short ch;
    489 
    490 	if (blind) return;
    491 
    492 	obj = level_objects.next_object;
    493 
    494 	while (obj) {
    495 		ch = mvinch(obj->row, obj->col);
    496 		if (((ch < 'A') || (ch > 'Z')) &&
    497 			((obj->row != rogue.row) || (obj->col != rogue.col)))
    498 		if ((ch != ' ') && (ch != '.') && (ch != '#') && (ch != '+')) {
    499 			addch(gr_obj_char());
    500 		}
    501 		obj = obj->next_object;
    502 	}
    503 	monster = level_monsters.next_monster;
    504 
    505 	while (monster) {
    506 		ch = mvinch(monster->row, monster->col);
    507 		if ((ch >= 'A') && (ch <= 'Z')) {
    508 			addch(get_rand('A', 'Z'));
    509 		}
    510 		monster = monster->next_monster;
    511 	}
    512 }
    513 
    514 unhallucinate()
    515 {
    516 	halluc = 0;
    517 	relight();
    518 	message("everything looks SO boring now", 1);
    519 }
    520 
    521 unblind()
    522 {
    523 	blind = 0;
    524 	message("the veil of darkness lifts", 1);
    525 	relight();
    526 	if (halluc) {
    527 		hallucinate();
    528 	}
    529 	if (detect_monster) {
    530 		show_monsters();
    531 	}
    532 }
    533 
    534 relight()
    535 {
    536 	if (cur_room == PASSAGE) {
    537 		light_passage(rogue.row, rogue.col);
    538 	} else {
    539 		light_up_room(cur_room);
    540 	}
    541 	mvaddch(rogue.row, rogue.col, rogue.fchar);
    542 }
    543 
    544 take_a_nap()
    545 {
    546 	short i;
    547 
    548 	i = get_rand(2, 5);
    549 	md_sleep(1);
    550 
    551 	while (i--) {
    552 		mv_mons();
    553 	}
    554 	md_sleep(1);
    555 	message(you_can_move_again, 0);
    556 }
    557 
    558 go_blind()
    559 {
    560 	short i, j;
    561 
    562 	if (!blind) {
    563 		message("a cloak of darkness falls around you", 0);
    564 	}
    565 	blind += get_rand(500, 800);
    566 
    567 	if (detect_monster) {
    568 		object *monster;
    569 
    570 		monster = level_monsters.next_monster;
    571 
    572 		while (monster) {
    573 			mvaddch(monster->row, monster->col, monster->trail_char);
    574 			monster = monster->next_monster;
    575 		}
    576 	}
    577 	if (cur_room >= 0) {
    578 		for (i = rooms[cur_room].top_row + 1;
    579 			 i < rooms[cur_room].bottom_row; i++) {
    580 			for (j = rooms[cur_room].left_col + 1;
    581 				 j < rooms[cur_room].right_col; j++) {
    582 				mvaddch(i, j, ' ');
    583 			}
    584 		}
    585 	}
    586 	mvaddch(rogue.row, rogue.col, rogue.fchar);
    587 }
    588 
    589 char *
    590 get_ench_color()
    591 {
    592 	if (halluc) {
    593 		return(id_potions[get_rand(0, POTIONS-1)].title);
    594 	} else if (con_mon) {
    595 		return("red ");
    596 	}
    597 	return("blue ");
    598 }
    599 
    600 cnfs()
    601 {
    602 	confused += get_rand(12, 22);
    603 }
    604 
    605 unconfuse()
    606 {
    607 	char msg[80];
    608 
    609 	confused = 0;
    610 	sprintf(msg, "you feel less %s now", (halluc ? "trippy" : "confused"));
    611 	message(msg, 1);
    612 }
    613 
    614 uncurse_all()
    615 {
    616 	object *obj;
    617 
    618 	obj = rogue.pack.next_object;
    619 
    620 	while (obj) {
    621 		obj->is_cursed = 0;
    622 		obj = obj->next_object;
    623 	}
    624 }
    625