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