1 /* $NetBSD: object.c,v 1.14 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
[] = "@(#)object.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: object.c,v 1.14 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
59 unsigned short dungeon
[DROWS
][DCOLS
];
63 static object
*free_list
= NULL
;
68 INIT_RINGS
, /* left ring */
69 INIT_RINGS
, /* right ring */
70 INIT_HP
, /* Hp current */
72 INIT_STR
, /* Str current */
73 INIT_STR
, /* Str max */
76 INIT_EXPLEVEL
, /* exp level */
77 INIT_EXP
, /* exp points */
80 INIT_MOVES
/* moves */
83 struct id id_potions
[POTIONS
] = {
84 {100, "blue ", "of increase strength ", 0},
85 {250, "red ", "of restore strength ", 0},
86 {100, "green ", "of healing ", 0},
87 {200, "grey ", "of extra healing ", 0},
88 {10, "brown ", "of poison ", 0},
89 {300, "clear ", "of raise level ", 0},
90 {10, "pink ", "of blindness ", 0},
91 {25, "white ", "of hallucination ", 0},
92 {100, "purple ", "of detect monster ", 0},
93 {100, "black ", "of detect things ", 0},
94 {10, "yellow ", "of confusion ", 0},
95 {80, "plaid ", "of levitation ", 0},
96 {150, "burgundy ", "of haste self ", 0},
97 {145, "beige ", "of see invisible ", 0}
100 struct id id_scrolls
[SCROLS
] = {
101 {505, "", "of protect armor ", 0},
102 {200, "", "of hold monster ", 0},
103 {235, "", "of enchant weapon ", 0},
104 {235, "", "of enchant armor ", 0},
105 {175, "", "of identify ", 0},
106 {190, "", "of teleportation ", 0},
107 {25, "", "of sleep ", 0},
108 {610, "", "of scare monster ", 0},
109 {210, "", "of remove curse ", 0},
110 {80, "", "of create monster ",0},
111 {25, "", "of aggravate monster ",0},
112 {180, "", "of magic mapping ", 0},
113 {90, "", "of confuse monster ", 0}
116 struct id id_weapons
[WEAPONS
] = {
117 {150, "short bow ", "", 0},
118 {8, "darts ", "", 0},
119 {15, "arrows ", "", 0},
120 {27, "daggers ", "", 0},
121 {35, "shurikens ", "", 0},
122 {360, "mace ", "", 0},
123 {470, "long sword ", "", 0},
124 {580, "two-handed sword ", "", 0}
127 struct id id_armors
[ARMORS
] = {
128 {300, "leather armor ", "", (UNIDENTIFIED
)},
129 {300, "ring mail ", "", (UNIDENTIFIED
)},
130 {400, "scale mail ", "", (UNIDENTIFIED
)},
131 {500, "chain mail ", "", (UNIDENTIFIED
)},
132 {600, "banded mail ", "", (UNIDENTIFIED
)},
133 {600, "splint mail ", "", (UNIDENTIFIED
)},
134 {700, "plate mail ", "", (UNIDENTIFIED
)}
137 struct id id_wands
[WANDS
] = {
138 {25, "", "of teleport away ",0},
139 {50, "", "of slow monster ", 0},
140 {8, "", "of invisibility ",0},
141 {55, "", "of polymorph ",0},
142 {2, "", "of haste monster ",0},
143 {20, "", "of magic missile ",0},
144 {20, "", "of cancellation ",0},
145 {0, "", "of do nothing ",0},
146 {35, "", "of drain life ",0},
147 {20, "", "of cold ",0},
148 {20, "", "of fire ",0}
151 struct id id_rings
[RINGS
] = {
152 {250, "", "of stealth ",0},
153 {100, "", "of teleportation ", 0},
154 {255, "", "of regeneration ",0},
155 {295, "", "of slow digestion ",0},
156 {200, "", "of add strength ",0},
157 {250, "", "of sustain strength ",0},
158 {250, "", "of dexterity ",0},
159 {25, "", "of adornment ",0},
160 {300, "", "of see invisible ",0},
161 {290, "", "of maintain armor ",0},
162 {270, "", "of searching ",0},
165 static void gr_armor(object
*);
166 static void gr_potion(object
*);
167 static void gr_scroll(object
*);
168 static void gr_wand(object
*);
169 static void gr_weapon(object
*, int);
170 static unsigned short gr_what_is(void);
171 static void make_party(void);
172 static void plant_gold(short, short, boolean
);
173 static void put_gold(void);
174 static void rand_place(object
*);
182 if (cur_level
< max_level
) {
185 n
= coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
186 while (rand_percent(33)) {
189 if (party_room
!= NO_ROOM
) {
192 for (i
= 0; i
< n
; i
++) {
204 boolean is_maze
, is_room
;
206 for (i
= 0; i
< MAXROOMS
; i
++) {
207 is_maze
= (rooms
[i
].is_room
& R_MAZE
) ? 1 : 0;
208 is_room
= (rooms
[i
].is_room
& R_ROOM
) ? 1 : 0;
210 if (!(is_room
|| is_maze
)) {
213 if (is_maze
|| rand_percent(GOLD_PERCENT
)) {
214 for (j
= 0; j
< 50; j
++) {
215 row
= get_rand(rooms
[i
].top_row
+1,
216 rooms
[i
].bottom_row
-1);
217 col
= get_rand(rooms
[i
].left_col
+1,
218 rooms
[i
].right_col
-1);
219 if ((dungeon
[row
][col
] == FLOOR
) ||
220 (dungeon
[row
][col
] == TUNNEL
)) {
221 plant_gold(row
, col
, is_maze
);
230 plant_gold(short row
, short col
, boolean is_maze
)
234 obj
= alloc_object();
235 obj
->row
= row
; obj
->col
= col
;
237 obj
->quantity
= get_rand((2 * cur_level
), (16 * cur_level
));
239 obj
->quantity
+= obj
->quantity
/ 2;
241 dungeon
[row
][col
] |= OBJECT
;
242 (void)add_to_pack(obj
, &level_objects
, 0);
246 place_at(object
*obj
, int row
, int col
)
250 dungeon
[row
][col
] |= OBJECT
;
251 (void)add_to_pack(obj
, &level_objects
, 0);
255 object_at(object
*pack
, short row
, short col
)
259 if (dungeon
[row
][col
] & (MONSTER
| OBJECT
)) {
260 obj
= pack
->next_object
;
262 while (obj
&& ((obj
->row
!= row
) || (obj
->col
!= col
))) {
263 obj
= obj
->next_object
;
266 messagef(1, "object_at(): inconsistent");
273 get_letter_object(int ch
)
277 obj
= rogue
.pack
.next_object
;
279 while (obj
&& (obj
->ichar
!= ch
)) {
280 obj
= obj
->next_object
;
286 free_stuff(object
*objlist
)
290 while (objlist
->next_object
) {
291 obj
= objlist
->next_object
;
292 objlist
->next_object
=
293 objlist
->next_object
->next_object
;
299 name_of(const object
*obj
)
301 const char *retstring
;
303 switch(obj
->what_is
) {
305 retstring
= obj
->quantity
> 1 ? "scrolls " : "scroll ";
308 retstring
= obj
->quantity
> 1 ? "potions " : "potion ";
311 if (obj
->which_kind
== RATION
) {
318 retstring
= is_wood
[obj
->which_kind
] ? "staff " : "wand ";
321 switch(obj
->which_kind
) {
323 retstring
=obj
->quantity
> 1 ? "darts " : "dart ";
326 retstring
=obj
->quantity
> 1 ? "arrows " : "arrow ";
329 retstring
=obj
->quantity
> 1 ? "daggers " : "dagger ";
332 retstring
=obj
->quantity
> 1?"shurikens ":"shuriken ";
335 retstring
= id_weapons
[obj
->which_kind
].title
;
339 retstring
= "armor ";
345 retstring
= "amulet ";
348 retstring
= "unknown ";
359 obj
= alloc_object();
361 if (foods
< (cur_level
/ 3)) {
365 obj
->what_is
= gr_what_is();
367 switch(obj
->what_is
) {
393 static unsigned short
397 unsigned short what_is
;
399 percent
= get_rand(1, 91);
403 } else if (percent
<= 60) {
405 } else if (percent
<= 64) {
407 } else if (percent
<= 74) {
409 } else if (percent
<= 83) {
411 } else if (percent
<= 88) {
420 gr_scroll(object
*obj
)
424 percent
= get_rand(0, 91);
426 obj
->what_is
= SCROL
;
429 obj
->which_kind
= PROTECT_ARMOR
;
430 } else if (percent
<= 10) {
431 obj
->which_kind
= HOLD_MONSTER
;
432 } else if (percent
<= 20) {
433 obj
->which_kind
= CREATE_MONSTER
;
434 } else if (percent
<= 35) {
435 obj
->which_kind
= IDENTIFY
;
436 } else if (percent
<= 43) {
437 obj
->which_kind
= TELEPORT
;
438 } else if (percent
<= 50) {
439 obj
->which_kind
= SLEEP
;
440 } else if (percent
<= 55) {
441 obj
->which_kind
= SCARE_MONSTER
;
442 } else if (percent
<= 64) {
443 obj
->which_kind
= REMOVE_CURSE
;
444 } else if (percent
<= 69) {
445 obj
->which_kind
= ENCH_ARMOR
;
446 } else if (percent
<= 74) {
447 obj
->which_kind
= ENCH_WEAPON
;
448 } else if (percent
<= 80) {
449 obj
->which_kind
= AGGRAVATE_MONSTER
;
450 } else if (percent
<= 86) {
451 obj
->which_kind
= CON_MON
;
453 obj
->which_kind
= MAGIC_MAPPING
;
458 gr_potion(object
*obj
)
462 percent
= get_rand(1, 118);
464 obj
->what_is
= POTION
;
467 obj
->which_kind
= RAISE_LEVEL
;
468 } else if (percent
<= 15) {
469 obj
->which_kind
= DETECT_OBJECTS
;
470 } else if (percent
<= 25) {
471 obj
->which_kind
= DETECT_MONSTER
;
472 } else if (percent
<= 35) {
473 obj
->which_kind
= INCREASE_STRENGTH
;
474 } else if (percent
<= 45) {
475 obj
->which_kind
= RESTORE_STRENGTH
;
476 } else if (percent
<= 55) {
477 obj
->which_kind
= HEALING
;
478 } else if (percent
<= 65) {
479 obj
->which_kind
= EXTRA_HEALING
;
480 } else if (percent
<= 75) {
481 obj
->which_kind
= BLINDNESS
;
482 } else if (percent
<= 85) {
483 obj
->which_kind
= HALLUCINATION
;
484 } else if (percent
<= 95) {
485 obj
->which_kind
= CONFUSION
;
486 } else if (percent
<= 105) {
487 obj
->which_kind
= POISON
;
488 } else if (percent
<= 110) {
489 obj
->which_kind
= LEVITATION
;
490 } else if (percent
<= 114) {
491 obj
->which_kind
= HASTE_SELF
;
493 obj
->which_kind
= SEE_INVISIBLE
;
498 gr_weapon(object
*obj
, int assign_wk
)
502 short blessing
, increment
;
504 obj
->what_is
= WEAPON
;
506 obj
->which_kind
= get_rand(0, (WEAPONS
- 1));
508 if ((obj
->which_kind
== ARROW
) || (obj
->which_kind
== DAGGER
) ||
509 (obj
->which_kind
== SHURIKEN
) || (obj
->which_kind
== DART
)) {
510 obj
->quantity
= get_rand(3, 15);
511 obj
->quiver
= get_rand(0, 126);
515 obj
->hit_enchant
= obj
->d_enchant
= 0;
517 percent
= get_rand(1, 96);
518 blessing
= get_rand(1, 3);
527 for (i
= 0; i
< blessing
; i
++) {
529 obj
->hit_enchant
+= increment
;
531 obj
->d_enchant
+= increment
;
535 switch(obj
->which_kind
) {
555 case TWO_HANDED_SWORD
:
562 gr_armor(object
*obj
)
567 obj
->what_is
= ARMOR
;
568 obj
->which_kind
= get_rand(0, (ARMORS
- 1));
569 obj
->class = obj
->which_kind
+ 2;
570 if ((obj
->which_kind
== PLATE
) || (obj
->which_kind
== SPLINT
)) {
573 obj
->is_protected
= 0;
576 percent
= get_rand(1, 100);
577 blessing
= get_rand(1, 3);
581 obj
->d_enchant
-= blessing
;
582 } else if (percent
<= 33) {
583 obj
->d_enchant
+= blessing
;
591 obj
->which_kind
= get_rand(0, (WANDS
- 1));
592 obj
->class = get_rand(3, 7);
596 get_food(object
*obj
, boolean force_ration
)
600 if (force_ration
|| rand_percent(80)) {
601 obj
->which_kind
= RATION
;
603 obj
->which_kind
= FRUIT
;
612 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
613 dungeon
[row
][col
] |= STAIRS
;
617 get_armor_class(const object
*obj
)
620 return(obj
->class + obj
->d_enchant
);
632 free_list
= free_list
->next_object
;
633 } else if (!(obj
= md_malloc(sizeof(object
)))) {
634 messagef(0, "cannot allocate object, saving game");
635 save_into_file(error_file
);
636 clean_up("alloc_object: save failed");
640 obj
->picked_up
= obj
->is_cursed
= 0;
641 obj
->in_use_flags
= NOT_USED
;
642 obj
->identified
= UNIDENTIFIED
;
648 free_object(object
*obj
)
650 obj
->next_object
= free_list
;
659 party_room
= gr_room();
661 n
= rand_percent(99) ? party_objects(party_room
) : 11;
662 if (rand_percent(99)) {
663 party_monsters(party_room
, n
);
671 short mc
, rc
, row
, col
;
674 obj
= level_objects
.next_object
;
680 rc
= get_mask_char(obj
->what_is
);
682 if (dungeon
[row
][col
] & MONSTER
) {
684 object_at(&level_monsters
, row
, col
)) != NULL
) {
685 monster
->trail_char
= rc
;
688 mc
= mvinch(row
, col
);
689 if (((mc
< 'A') || (mc
> 'Z')) &&
690 ((row
!= rogue
.row
) || (col
!= rogue
.col
))) {
691 mvaddch(row
, col
, rc
);
693 obj
= obj
->next_object
;
696 monster
= level_monsters
.next_object
;
699 if (monster
->m_flags
& IMITATES
) {
700 mvaddch(monster
->row
, monster
->col
, (int)monster
->disguise
);
702 monster
= monster
->next_monster
;
711 obj
= alloc_object();
712 obj
->what_is
= AMULET
;
717 rand_place(object
*obj
)
721 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
722 place_at(obj
, row
, col
);
726 c_object_for_wizard(void)
733 if (pack_count(NULL
) >= MAX_PACK_COUNT
) {
734 messagef(0, "pack full");
737 messagef(0, "type of object?");
739 while (r_index("!?:)]=/,\033", (ch
= rgetchar()), 0) == -1) {
747 obj
= alloc_object();
751 obj
->what_is
= POTION
;
755 obj
->what_is
= SCROL
;
759 obj
->what_is
= AMULET
;
781 if ((ch
!= ',') && (ch
!= ':')) {
783 if (get_input_line("which kind?", "", buf
, sizeof(buf
), "", 0, 1)) {
784 wk
= get_number(buf
);
785 if ((wk
>= 0) && (wk
<= max
)) {
786 obj
->which_kind
= wk
;
787 if (obj
->what_is
== RING
) {
799 get_desc(obj
, buf
, sizeof(buf
));
800 messagef(0, "%s", buf
);
801 (void)add_to_pack(obj
, &rogue
.pack
, 1);