]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/object.c
1 /* $NetBSD: object.c,v 1.13 2008/01/14 03:50:02 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.13 2008/01/14 03:50:02 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},
171 if (cur_level
< max_level
) {
174 n
= coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
175 while (rand_percent(33)) {
178 if (party_room
!= NO_ROOM
) {
181 for (i
= 0; i
< n
; i
++) {
193 boolean is_maze
, is_room
;
195 for (i
= 0; i
< MAXROOMS
; i
++) {
196 is_maze
= (rooms
[i
].is_room
& R_MAZE
) ? 1 : 0;
197 is_room
= (rooms
[i
].is_room
& R_ROOM
) ? 1 : 0;
199 if (!(is_room
|| is_maze
)) {
202 if (is_maze
|| rand_percent(GOLD_PERCENT
)) {
203 for (j
= 0; j
< 50; j
++) {
204 row
= get_rand(rooms
[i
].top_row
+1,
205 rooms
[i
].bottom_row
-1);
206 col
= get_rand(rooms
[i
].left_col
+1,
207 rooms
[i
].right_col
-1);
208 if ((dungeon
[row
][col
] == FLOOR
) ||
209 (dungeon
[row
][col
] == TUNNEL
)) {
210 plant_gold(row
, col
, is_maze
);
219 plant_gold(short row
, short col
, boolean is_maze
)
223 obj
= alloc_object();
224 obj
->row
= row
; obj
->col
= col
;
226 obj
->quantity
= get_rand((2 * cur_level
), (16 * cur_level
));
228 obj
->quantity
+= obj
->quantity
/ 2;
230 dungeon
[row
][col
] |= OBJECT
;
231 (void)add_to_pack(obj
, &level_objects
, 0);
235 place_at(object
*obj
, int row
, int col
)
239 dungeon
[row
][col
] |= OBJECT
;
240 (void)add_to_pack(obj
, &level_objects
, 0);
244 object_at(object
*pack
, short row
, short col
)
248 if (dungeon
[row
][col
] & (MONSTER
| OBJECT
)) {
249 obj
= pack
->next_object
;
251 while (obj
&& ((obj
->row
!= row
) || (obj
->col
!= col
))) {
252 obj
= obj
->next_object
;
255 messagef(1, "object_at(): inconsistent");
262 get_letter_object(int ch
)
266 obj
= rogue
.pack
.next_object
;
268 while (obj
&& (obj
->ichar
!= ch
)) {
269 obj
= obj
->next_object
;
275 free_stuff(object
*objlist
)
279 while (objlist
->next_object
) {
280 obj
= objlist
->next_object
;
281 objlist
->next_object
=
282 objlist
->next_object
->next_object
;
288 name_of(const object
*obj
)
290 const char *retstring
;
292 switch(obj
->what_is
) {
294 retstring
= obj
->quantity
> 1 ? "scrolls " : "scroll ";
297 retstring
= obj
->quantity
> 1 ? "potions " : "potion ";
300 if (obj
->which_kind
== RATION
) {
307 retstring
= is_wood
[obj
->which_kind
] ? "staff " : "wand ";
310 switch(obj
->which_kind
) {
312 retstring
=obj
->quantity
> 1 ? "darts " : "dart ";
315 retstring
=obj
->quantity
> 1 ? "arrows " : "arrow ";
318 retstring
=obj
->quantity
> 1 ? "daggers " : "dagger ";
321 retstring
=obj
->quantity
> 1?"shurikens ":"shuriken ";
324 retstring
= id_weapons
[obj
->which_kind
].title
;
328 retstring
= "armor ";
334 retstring
= "amulet ";
337 retstring
= "unknown ";
348 obj
= alloc_object();
350 if (foods
< (cur_level
/ 3)) {
354 obj
->what_is
= gr_what_is();
356 switch(obj
->what_is
) {
386 unsigned short what_is
;
388 percent
= get_rand(1, 91);
392 } else if (percent
<= 60) {
394 } else if (percent
<= 64) {
396 } else if (percent
<= 74) {
398 } else if (percent
<= 83) {
400 } else if (percent
<= 88) {
409 gr_scroll(object
*obj
)
413 percent
= get_rand(0, 91);
415 obj
->what_is
= SCROL
;
418 obj
->which_kind
= PROTECT_ARMOR
;
419 } else if (percent
<= 10) {
420 obj
->which_kind
= HOLD_MONSTER
;
421 } else if (percent
<= 20) {
422 obj
->which_kind
= CREATE_MONSTER
;
423 } else if (percent
<= 35) {
424 obj
->which_kind
= IDENTIFY
;
425 } else if (percent
<= 43) {
426 obj
->which_kind
= TELEPORT
;
427 } else if (percent
<= 50) {
428 obj
->which_kind
= SLEEP
;
429 } else if (percent
<= 55) {
430 obj
->which_kind
= SCARE_MONSTER
;
431 } else if (percent
<= 64) {
432 obj
->which_kind
= REMOVE_CURSE
;
433 } else if (percent
<= 69) {
434 obj
->which_kind
= ENCH_ARMOR
;
435 } else if (percent
<= 74) {
436 obj
->which_kind
= ENCH_WEAPON
;
437 } else if (percent
<= 80) {
438 obj
->which_kind
= AGGRAVATE_MONSTER
;
439 } else if (percent
<= 86) {
440 obj
->which_kind
= CON_MON
;
442 obj
->which_kind
= MAGIC_MAPPING
;
447 gr_potion(object
*obj
)
451 percent
= get_rand(1, 118);
453 obj
->what_is
= POTION
;
456 obj
->which_kind
= RAISE_LEVEL
;
457 } else if (percent
<= 15) {
458 obj
->which_kind
= DETECT_OBJECTS
;
459 } else if (percent
<= 25) {
460 obj
->which_kind
= DETECT_MONSTER
;
461 } else if (percent
<= 35) {
462 obj
->which_kind
= INCREASE_STRENGTH
;
463 } else if (percent
<= 45) {
464 obj
->which_kind
= RESTORE_STRENGTH
;
465 } else if (percent
<= 55) {
466 obj
->which_kind
= HEALING
;
467 } else if (percent
<= 65) {
468 obj
->which_kind
= EXTRA_HEALING
;
469 } else if (percent
<= 75) {
470 obj
->which_kind
= BLINDNESS
;
471 } else if (percent
<= 85) {
472 obj
->which_kind
= HALLUCINATION
;
473 } else if (percent
<= 95) {
474 obj
->which_kind
= CONFUSION
;
475 } else if (percent
<= 105) {
476 obj
->which_kind
= POISON
;
477 } else if (percent
<= 110) {
478 obj
->which_kind
= LEVITATION
;
479 } else if (percent
<= 114) {
480 obj
->which_kind
= HASTE_SELF
;
482 obj
->which_kind
= SEE_INVISIBLE
;
487 gr_weapon(object
*obj
, int assign_wk
)
491 short blessing
, increment
;
493 obj
->what_is
= WEAPON
;
495 obj
->which_kind
= get_rand(0, (WEAPONS
- 1));
497 if ((obj
->which_kind
== ARROW
) || (obj
->which_kind
== DAGGER
) ||
498 (obj
->which_kind
== SHURIKEN
) || (obj
->which_kind
== DART
)) {
499 obj
->quantity
= get_rand(3, 15);
500 obj
->quiver
= get_rand(0, 126);
504 obj
->hit_enchant
= obj
->d_enchant
= 0;
506 percent
= get_rand(1, 96);
507 blessing
= get_rand(1, 3);
516 for (i
= 0; i
< blessing
; i
++) {
518 obj
->hit_enchant
+= increment
;
520 obj
->d_enchant
+= increment
;
524 switch(obj
->which_kind
) {
544 case TWO_HANDED_SWORD
:
551 gr_armor(object
*obj
)
556 obj
->what_is
= ARMOR
;
557 obj
->which_kind
= get_rand(0, (ARMORS
- 1));
558 obj
->class = obj
->which_kind
+ 2;
559 if ((obj
->which_kind
== PLATE
) || (obj
->which_kind
== SPLINT
)) {
562 obj
->is_protected
= 0;
565 percent
= get_rand(1, 100);
566 blessing
= get_rand(1, 3);
570 obj
->d_enchant
-= blessing
;
571 } else if (percent
<= 33) {
572 obj
->d_enchant
+= blessing
;
580 obj
->which_kind
= get_rand(0, (WANDS
- 1));
581 obj
->class = get_rand(3, 7);
585 get_food(object
*obj
, boolean force_ration
)
589 if (force_ration
|| rand_percent(80)) {
590 obj
->which_kind
= RATION
;
592 obj
->which_kind
= FRUIT
;
601 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
602 dungeon
[row
][col
] |= STAIRS
;
606 get_armor_class(const object
*obj
)
609 return(obj
->class + obj
->d_enchant
);
621 free_list
= free_list
->next_object
;
622 } else if (!(obj
= md_malloc(sizeof(object
)))) {
623 messagef(0, "cannot allocate object, saving game");
624 save_into_file(error_file
);
625 clean_up("alloc_object: save failed");
629 obj
->picked_up
= obj
->is_cursed
= 0;
630 obj
->in_use_flags
= NOT_USED
;
631 obj
->identified
= UNIDENTIFIED
;
637 free_object(object
*obj
)
639 obj
->next_object
= free_list
;
648 party_room
= gr_room();
650 n
= rand_percent(99) ? party_objects(party_room
) : 11;
651 if (rand_percent(99)) {
652 party_monsters(party_room
, n
);
660 short mc
, rc
, row
, col
;
663 obj
= level_objects
.next_object
;
669 rc
= get_mask_char(obj
->what_is
);
671 if (dungeon
[row
][col
] & MONSTER
) {
673 object_at(&level_monsters
, row
, col
)) != NULL
) {
674 monster
->trail_char
= rc
;
677 mc
= mvinch(row
, col
);
678 if (((mc
< 'A') || (mc
> 'Z')) &&
679 ((row
!= rogue
.row
) || (col
!= rogue
.col
))) {
680 mvaddch(row
, col
, rc
);
682 obj
= obj
->next_object
;
685 monster
= level_monsters
.next_object
;
688 if (monster
->m_flags
& IMITATES
) {
689 mvaddch(monster
->row
, monster
->col
, (int)monster
->disguise
);
691 monster
= monster
->next_monster
;
700 obj
= alloc_object();
701 obj
->what_is
= AMULET
;
706 rand_place(object
*obj
)
710 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
711 place_at(obj
, row
, col
);
715 c_object_for_wizard(void)
722 if (pack_count(NULL
) >= MAX_PACK_COUNT
) {
723 messagef(0, "pack full");
726 messagef(0, "type of object?");
728 while (r_index("!?:)]=/,\033", (ch
= rgetchar()), 0) == -1) {
736 obj
= alloc_object();
740 obj
->what_is
= POTION
;
744 obj
->what_is
= SCROL
;
748 obj
->what_is
= AMULET
;
770 if ((ch
!= ',') && (ch
!= ':')) {
772 if (get_input_line("which kind?", "", buf
, sizeof(buf
), "", 0, 1)) {
773 wk
= get_number(buf
);
774 if ((wk
>= 0) && (wk
<= max
)) {
775 obj
->which_kind
= wk
;
776 if (obj
->what_is
== RING
) {
788 get_desc(obj
, buf
, sizeof(buf
));
789 messagef(0, "%s", buf
);
790 (void)add_to_pack(obj
, &rogue
.pack
, 1);