1 /* $NetBSD: use.c,v 1.10 2009/08/12 08:44:45 dholland Exp $ */
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)use.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: use.c,v 1.10 2009/08/12 08:44:45 dholland Exp $");
47 * This source herein may be modified and/or distributed by anybody who
48 * so desires, with the following restrictions:
49 * 1.) No portion of this notice shall be removed.
50 * 2.) Credit shall not be taken for the creation of this source.
51 * 3.) This code is not to be traded, sold, or used for personal
63 boolean see_invisible
= 0;
65 boolean detect_monster
= 0;
68 static const char strange_feeling
[] =
69 "you have a strange feeling for a moment, then it passes";
71 static const char *get_ench_color(void);
72 static void go_blind(void);
73 static void hold_monster(void);
74 static void idntfy(void);
75 static void potion_heal(int);
76 static void uncurse_all(void);
84 ch
= pack_letter("quaff what?", POTION
);
89 if (!(obj
= get_letter_object(ch
))) {
90 messagef(0, "no such item.");
93 if (obj
->what_is
!= POTION
) {
94 messagef(0, "you can't drink that");
97 switch(obj
->which_kind
) {
98 case INCREASE_STRENGTH
:
99 messagef(0, "you feel stronger now, what bulging muscles!");
101 if (rogue
.str_current
> rogue
.str_max
) {
102 rogue
.str_max
= rogue
.str_current
;
105 case RESTORE_STRENGTH
:
106 rogue
.str_current
= rogue
.str_max
;
107 messagef(0, "this tastes great, you feel warm all over");
110 messagef(0, "you begin to feel better");
114 messagef(0, "you begin to feel much better");
118 if (!sustain_strength
) {
119 rogue
.str_current
-= get_rand(1, 3);
120 if (rogue
.str_current
< 1) {
121 rogue
.str_current
= 1;
124 messagef(0, "you feel very sick now");
130 rogue
.exp_points
= level_points
[rogue
.exp
- 1];
131 messagef(0, "you suddenly feel much more skillful");
138 messagef(0, "oh wow, everything seems so cosmic");
139 halluc
+= get_rand(500, 800);
143 if (!(level_monsters
.next_monster
)) {
144 messagef(0, "%s", strange_feeling
);
148 if (level_objects
.next_object
) {
153 messagef(0, "%s", strange_feeling
);
157 messagef(0, (halluc
? "what a trippy feeling" :
158 "you feel confused"));
162 messagef(0, "you start to float in the air");
163 levitate
+= get_rand(15, 30);
164 being_held
= bear_trap
= 0;
167 messagef(0, "you feel yourself moving much faster");
168 haste_self
+= get_rand(11, 21);
169 if (!(haste_self
% 2)) {
174 messagef(0, "hmm, this potion tastes like %sjuice",
183 print_stats((STAT_STRENGTH
| STAT_HP
));
184 if (id_potions
[obj
->which_kind
].id_status
!= CALLED
) {
185 id_potions
[obj
->which_kind
].id_status
= IDENTIFIED
;
187 vanish(obj
, 1, &rogue
.pack
);
196 ch
= pack_letter("read what?", SCROL
);
201 if (!(obj
= get_letter_object(ch
))) {
202 messagef(0, "no such item.");
205 if (obj
->what_is
!= SCROL
) {
206 messagef(0, "you can't read that");
209 switch(obj
->which_kind
) {
211 messagef(0, "you hear a maniacal laughter in the distance");
218 if (rogue
.weapon
->what_is
== WEAPON
) {
219 messagef(0, "your %sglow%s %sfor a moment",
220 name_of(rogue
.weapon
),
221 ((rogue
.weapon
->quantity
<= 1) ? "s" : ""),
224 rogue
.weapon
->hit_enchant
++;
226 rogue
.weapon
->d_enchant
++;
229 rogue
.weapon
->is_cursed
= 0;
231 messagef(0, "your hands tingle");
236 messagef(0, "your armor glows %sfor a moment",
238 rogue
.armor
->d_enchant
++;
239 rogue
.armor
->is_cursed
= 0;
240 print_stats(STAT_ARMOR
);
242 messagef(0, "your skin crawls");
246 messagef(0, "this is a scroll of identify");
248 id_scrolls
[obj
->which_kind
].id_status
= IDENTIFIED
;
255 messagef(0, "you fall asleep");
260 messagef(0, "your armor is covered by a shimmering gold shield");
261 rogue
.armor
->is_protected
= 1;
262 rogue
.armor
->is_cursed
= 0;
264 messagef(0, "your acne seems to have disappeared");
268 messagef(0, (!halluc
) ?
269 "you feel as though someone is watching over you" :
270 "you feel in touch with the universal oneness");
276 case AGGRAVATE_MONSTER
:
280 messagef(0, "this scroll seems to have a map on it");
285 messagef(0, "your hands glow %sfor a moment",
289 if (id_scrolls
[obj
->which_kind
].id_status
!= CALLED
) {
290 id_scrolls
[obj
->which_kind
].id_status
= IDENTIFIED
;
292 vanish(obj
, (obj
->which_kind
!= SLEEP
), &rogue
.pack
);
295 /* vanish() does NOT handle a quiver of weapons with more than one
296 * arrow (or whatever) in the quiver. It will only decrement the count.
300 vanish(object
*obj
, short rm
, object
*pack
)
302 if (obj
->quantity
> 1) {
305 if (obj
->in_use_flags
& BEING_WIELDED
) {
307 } else if (obj
->in_use_flags
& BEING_WORN
) {
309 } else if (obj
->in_use_flags
& ON_EITHER_HAND
) {
312 take_from_pack(obj
, pack
);
321 potion_heal(int extra
)
326 rogue
.hp_current
+= rogue
.exp
;
328 ratio
= ((float)rogue
.hp_current
) / rogue
.hp_max
;
331 rogue
.hp_max
+= (extra
? 2 : 1);
332 extra_hp
+= (extra
? 2 : 1);
333 rogue
.hp_current
= rogue
.hp_max
;
334 } else if (ratio
>= 0.90) {
335 rogue
.hp_max
+= (extra
? 1 : 0);
336 extra_hp
+= (extra
? 1 : 0);
337 rogue
.hp_current
= rogue
.hp_max
;
345 add
= (short)(ratio
* (rogue
.hp_max
- rogue
.hp_current
));
346 rogue
.hp_current
+= add
;
347 if (rogue
.hp_current
> rogue
.hp_max
) {
348 rogue
.hp_current
= rogue
.hp_max
;
354 if (confused
&& extra
) {
356 } else if (confused
) {
357 confused
= (confused
/ 2) + 1;
359 if (halluc
&& extra
) {
362 halluc
= (halluc
/ 2) + 1;
374 ch
= pack_letter("what would you like to identify?", ALL_OBJECTS
);
379 if (!(obj
= get_letter_object(ch
))) {
380 messagef(0, "no such item, try again");
381 messagef(0, "%s", ""); /* gcc objects to just "" */
386 if (obj
->what_is
& (SCROL
| POTION
| WEAPON
| ARMOR
| WAND
| RING
)) {
387 id_table
= get_id_table(obj
);
388 id_table
[obj
->which_kind
].id_status
= IDENTIFIED
;
390 get_desc(obj
, desc
, sizeof(desc
));
391 messagef(0, "%s", desc
);
401 ch
= pack_letter("eat what?", FOOD
);
406 if (!(obj
= get_letter_object(ch
))) {
407 messagef(0, "no such item.");
410 if (obj
->what_is
!= FOOD
) {
411 messagef(0, "you can't eat that");
414 if ((obj
->which_kind
== FRUIT
) || rand_percent(60)) {
415 moves
= get_rand(950, 1150);
416 if (obj
->which_kind
== RATION
) {
417 messagef(0, "yum, that tasted good");
419 messagef(0, "my, that was a yummy %s", fruit
);
422 moves
= get_rand(750, 950);
423 messagef(0, "yuk, that food tasted awful");
426 rogue
.moves_left
/= 3;
427 rogue
.moves_left
+= moves
;
429 print_stats(STAT_HUNGER
);
431 vanish(obj
, 1, &rogue
.pack
);
442 for (i
= -2; i
<= 2; i
++) {
443 for (j
= -2; j
<= 2; j
++) {
446 if ((row
< MIN_ROW
) || (row
> (DROWS
-2)) || (col
< 0) ||
450 if (dungeon
[row
][col
] & MONSTER
) {
451 monster
= object_at(&level_monsters
, row
, col
);
452 monster
->m_flags
|= ASLEEP
;
453 monster
->m_flags
&= (~WAKENS
);
459 messagef(0, "you feel a strange sense of loss");
460 } else if (mcount
== 1) {
461 messagef(0, "the monster freezes");
463 messagef(0, "the monsters around you freeze");
470 mvaddch(rogue
.row
, rogue
.col
, get_dungeon_char(rogue
.row
, rogue
.col
));
473 darken_room(cur_room
);
475 put_player(get_room_number(rogue
.row
, rogue
.col
));
483 object
*obj
, *monster
;
488 obj
= level_objects
.next_object
;
491 ch
= mvinch(obj
->row
, obj
->col
);
492 if (((ch
< 'A') || (ch
> 'Z')) &&
493 ((obj
->row
!= rogue
.row
) || (obj
->col
!= rogue
.col
)))
494 if ((ch
!= ' ') && (ch
!= '.') && (ch
!= '#') && (ch
!= '+')) {
495 addch(gr_obj_char());
497 obj
= obj
->next_object
;
499 monster
= level_monsters
.next_monster
;
502 ch
= mvinch(monster
->row
, monster
->col
);
503 if ((ch
>= 'A') && (ch
<= 'Z')) {
504 addch(get_rand('A', 'Z'));
506 monster
= monster
->next_monster
;
515 messagef(1, "everything looks SO boring now");
522 messagef(1, "the veil of darkness lifts");
527 if (detect_monster
) {
535 if (cur_room
== PASSAGE
) {
536 light_passage(rogue
.row
, rogue
.col
);
538 light_up_room(cur_room
);
540 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
555 messagef(0, "%s", you_can_move_again
);
564 messagef(0, "a cloak of darkness falls around you");
566 blind
+= get_rand(500, 800);
568 if (detect_monster
) {
571 monster
= level_monsters
.next_monster
;
574 mvaddch(monster
->row
, monster
->col
, monster
->trail_char
);
575 monster
= monster
->next_monster
;
579 for (i
= rooms
[cur_room
].top_row
+ 1;
580 i
< rooms
[cur_room
].bottom_row
; i
++) {
581 for (j
= rooms
[cur_room
].left_col
+ 1;
582 j
< rooms
[cur_room
].right_col
; j
++) {
587 mvaddch(rogue
.row
, rogue
.col
, rogue
.fchar
);
594 return(id_potions
[get_rand(0, POTIONS
-1)].title
);
595 } else if (con_mon
) {
604 confused
+= get_rand(12, 22);
611 messagef(1, "you feel less %s now", (halluc
? "trippy" : "confused"));
619 obj
= rogue
.pack
.next_object
;
623 obj
= obj
->next_object
;