]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/object.c
1 /* $NetBSD: object.c,v 1.8 1998/11/10 13:01:32 hubertf 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. 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.
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
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)object.c 8.1 (Berkeley) 5/31/93";
44 __RCSID("$NetBSD: object.c,v 1.8 1998/11/10 13:01:32 hubertf Exp $");
51 * This source herein may be modified and/or distributed by anybody who
52 * so desires, with the following restrictions:
53 * 1.) No portion of this notice shall be removed.
54 * 2.) Credit shall not be taken for the creation of this source.
55 * 3.) This code is not to be traded, sold, or used for personal
63 unsigned short dungeon
[DROWS
][DCOLS
];
65 object
*free_list
= (object
*) 0;
66 char *fruit
= (char *) 0;
71 INIT_RINGS
, /* left ring */
72 INIT_RINGS
, /* right ring */
73 INIT_HP
, /* Hp current */
75 INIT_STR
, /* Str current */
76 INIT_STR
, /* Str max */
79 INIT_EXPLEVEL
, /* exp level */
80 INIT_EXP
, /* exp points */
83 INIT_MOVES
/* moves */
86 struct id id_potions
[POTIONS
] = {
87 {100, "blue \0 ", "of increase strength ", 0},
88 {250, "red \0 ", "of restore strength ", 0},
89 {100, "green \0 ", "of healing ", 0},
90 {200, "grey \0 ", "of extra healing ", 0},
91 {10, "brown \0 ", "of poison ", 0},
92 {300, "clear \0 ", "of raise level ", 0},
93 {10, "pink \0 ", "of blindness ", 0},
94 {25, "white \0 ", "of hallucination ", 0},
95 {100, "purple \0 ", "of detect monster ", 0},
96 {100, "black \0 ", "of detect things ", 0},
97 {10, "yellow \0 ", "of confusion ", 0},
98 {80, "plaid \0 ", "of levitation ", 0},
99 {150, "burgundy \0 ", "of haste self ", 0},
100 {145, "beige \0 ", "of see invisible ", 0}
103 struct id id_scrolls
[SCROLS
] = {
104 {505, " ", "of protect armor ", 0},
105 {200, " ", "of hold monster ", 0},
106 {235, " ", "of enchant weapon ", 0},
107 {235, " ", "of enchant armor ", 0},
108 {175, " ", "of identify ", 0},
109 {190, " ", "of teleportation ", 0},
110 {25, " ", "of sleep ", 0},
111 {610, " ", "of scare monster ", 0},
112 {210, " ", "of remove curse ", 0},
113 {80, " ", "of create monster ",0},
114 {25, " ", "of aggravate monster ",0},
115 {180, " ", "of magic mapping ", 0},
116 {90, " ", "of confuse monster ", 0}
119 struct id id_weapons
[WEAPONS
] = {
120 {150, "short bow ", "", 0},
121 {8, "darts ", "", 0},
122 {15, "arrows ", "", 0},
123 {27, "daggers ", "", 0},
124 {35, "shurikens ", "", 0},
125 {360, "mace ", "", 0},
126 {470, "long sword ", "", 0},
127 {580, "two-handed sword ", "", 0}
130 struct id id_armors
[ARMORS
] = {
131 {300, "leather armor ", "", (UNIDENTIFIED
)},
132 {300, "ring mail ", "", (UNIDENTIFIED
)},
133 {400, "scale mail ", "", (UNIDENTIFIED
)},
134 {500, "chain mail ", "", (UNIDENTIFIED
)},
135 {600, "banded mail ", "", (UNIDENTIFIED
)},
136 {600, "splint mail ", "", (UNIDENTIFIED
)},
137 {700, "plate mail ", "", (UNIDENTIFIED
)}
140 struct id id_wands
[WANDS
] = {
141 {25, " ", "of teleport away ",0},
142 {50, " ", "of slow monster ", 0},
143 {8, " ", "of invisibility ",0},
144 {55, " ", "of polymorph ",0},
145 {2, " ", "of haste monster ",0},
146 {20, " ", "of magic missile ",0},
147 {20, " ", "of cancellation ",0},
148 {0, " ", "of do nothing ",0},
149 {35, " ", "of drain life ",0},
150 {20, " ", "of cold ",0},
151 {20, " ", "of fire ",0}
154 struct id id_rings
[RINGS
] = {
155 {250, " ", "of stealth ",0},
156 {100, " ", "of teleportation ", 0},
157 {255, " ", "of regeneration ",0},
158 {295, " ", "of slow digestion ",0},
159 {200, " ", "of add strength ",0},
160 {250, " ", "of sustain strength ",0},
161 {250, " ", "of dexterity ",0},
162 {25, " ", "of adornment ",0},
163 {300, " ", "of see invisible ",0},
164 {290, " ", "of maintain armor ",0},
165 {270, " ", "of searching ",0},
174 if (cur_level
< max_level
) {
177 n
= coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
178 while (rand_percent(33)) {
181 if (party_room
!= NO_ROOM
) {
184 for (i
= 0; i
< n
; i
++) {
196 boolean is_maze
, is_room
;
198 for (i
= 0; i
< MAXROOMS
; i
++) {
199 is_maze
= (rooms
[i
].is_room
& R_MAZE
) ? 1 : 0;
200 is_room
= (rooms
[i
].is_room
& R_ROOM
) ? 1 : 0;
202 if (!(is_room
|| is_maze
)) {
205 if (is_maze
|| rand_percent(GOLD_PERCENT
)) {
206 for (j
= 0; j
< 50; j
++) {
207 row
= get_rand(rooms
[i
].top_row
+1,
208 rooms
[i
].bottom_row
-1);
209 col
= get_rand(rooms
[i
].left_col
+1,
210 rooms
[i
].right_col
-1);
211 if ((dungeon
[row
][col
] == FLOOR
) ||
212 (dungeon
[row
][col
] == TUNNEL
)) {
213 plant_gold(row
, col
, is_maze
);
222 plant_gold(row
, col
, is_maze
)
228 obj
= alloc_object();
229 obj
->row
= row
; obj
->col
= col
;
231 obj
->quantity
= get_rand((2 * cur_level
), (16 * cur_level
));
233 obj
->quantity
+= obj
->quantity
/ 2;
235 dungeon
[row
][col
] |= OBJECT
;
236 (void) add_to_pack(obj
, &level_objects
, 0);
240 place_at(obj
, row
, col
)
246 dungeon
[row
][col
] |= OBJECT
;
247 (void) add_to_pack(obj
, &level_objects
, 0);
251 object_at(pack
, row
, col
)
255 object
*obj
= (object
*) 0;
257 if (dungeon
[row
][col
] & (MONSTER
| OBJECT
)) {
258 obj
= pack
->next_object
;
260 while (obj
&& ((obj
->row
!= row
) || (obj
->col
!= col
))) {
261 obj
= obj
->next_object
;
264 message("object_at(): inconsistent", 1);
271 get_letter_object(ch
)
276 obj
= rogue
.pack
.next_object
;
278 while (obj
&& (obj
->ichar
!= ch
)) {
279 obj
= obj
->next_object
;
290 while (objlist
->next_object
) {
291 obj
= objlist
->next_object
;
292 objlist
->next_object
=
293 objlist
->next_object
->next_object
;
302 const char *retstring
;
304 switch(obj
->what_is
) {
306 retstring
= obj
->quantity
> 1 ? "scrolls " : "scroll ";
309 retstring
= obj
->quantity
> 1 ? "potions " : "potion ";
312 if (obj
->which_kind
== RATION
) {
319 retstring
= is_wood
[obj
->which_kind
] ? "staff " : "wand ";
322 switch(obj
->which_kind
) {
324 retstring
=obj
->quantity
> 1 ? "darts " : "dart ";
327 retstring
=obj
->quantity
> 1 ? "arrows " : "arrow ";
330 retstring
=obj
->quantity
> 1 ? "daggers " : "dagger ";
333 retstring
=obj
->quantity
> 1?"shurikens ":"shuriken ";
336 retstring
= id_weapons
[obj
->which_kind
].title
;
340 retstring
= "armor ";
346 retstring
= "amulet ";
349 retstring
= "unknown ";
360 obj
= alloc_object();
362 if (foods
< (cur_level
/ 3)) {
366 obj
->what_is
= gr_what_is();
368 switch(obj
->what_is
) {
398 unsigned short what_is
;
400 percent
= get_rand(1, 91);
404 } else if (percent
<= 60) {
406 } else if (percent
<= 64) {
408 } else if (percent
<= 74) {
410 } else if (percent
<= 83) {
412 } else if (percent
<= 88) {
426 percent
= get_rand(0, 91);
428 obj
->what_is
= SCROL
;
431 obj
->which_kind
= PROTECT_ARMOR
;
432 } else if (percent
<= 10) {
433 obj
->which_kind
= HOLD_MONSTER
;
434 } else if (percent
<= 20) {
435 obj
->which_kind
= CREATE_MONSTER
;
436 } else if (percent
<= 35) {
437 obj
->which_kind
= IDENTIFY
;
438 } else if (percent
<= 43) {
439 obj
->which_kind
= TELEPORT
;
440 } else if (percent
<= 50) {
441 obj
->which_kind
= SLEEP
;
442 } else if (percent
<= 55) {
443 obj
->which_kind
= SCARE_MONSTER
;
444 } else if (percent
<= 64) {
445 obj
->which_kind
= REMOVE_CURSE
;
446 } else if (percent
<= 69) {
447 obj
->which_kind
= ENCH_ARMOR
;
448 } else if (percent
<= 74) {
449 obj
->which_kind
= ENCH_WEAPON
;
450 } else if (percent
<= 80) {
451 obj
->which_kind
= AGGRAVATE_MONSTER
;
452 } else if (percent
<= 86) {
453 obj
->which_kind
= CON_MON
;
455 obj
->which_kind
= MAGIC_MAPPING
;
465 percent
= get_rand(1, 118);
467 obj
->what_is
= POTION
;
470 obj
->which_kind
= RAISE_LEVEL
;
471 } else if (percent
<= 15) {
472 obj
->which_kind
= DETECT_OBJECTS
;
473 } else if (percent
<= 25) {
474 obj
->which_kind
= DETECT_MONSTER
;
475 } else if (percent
<= 35) {
476 obj
->which_kind
= INCREASE_STRENGTH
;
477 } else if (percent
<= 45) {
478 obj
->which_kind
= RESTORE_STRENGTH
;
479 } else if (percent
<= 55) {
480 obj
->which_kind
= HEALING
;
481 } else if (percent
<= 65) {
482 obj
->which_kind
= EXTRA_HEALING
;
483 } else if (percent
<= 75) {
484 obj
->which_kind
= BLINDNESS
;
485 } else if (percent
<= 85) {
486 obj
->which_kind
= HALLUCINATION
;
487 } else if (percent
<= 95) {
488 obj
->which_kind
= CONFUSION
;
489 } else if (percent
<= 105) {
490 obj
->which_kind
= POISON
;
491 } else if (percent
<= 110) {
492 obj
->which_kind
= LEVITATION
;
493 } else if (percent
<= 114) {
494 obj
->which_kind
= HASTE_SELF
;
496 obj
->which_kind
= SEE_INVISIBLE
;
501 gr_weapon(obj
, assign_wk
)
507 short blessing
, increment
;
509 obj
->what_is
= WEAPON
;
511 obj
->which_kind
= get_rand(0, (WEAPONS
- 1));
513 if ((obj
->which_kind
== ARROW
) || (obj
->which_kind
== DAGGER
) ||
514 (obj
->which_kind
== SHURIKEN
) | (obj
->which_kind
== DART
)) {
515 obj
->quantity
= get_rand(3, 15);
516 obj
->quiver
= get_rand(0, 126);
520 obj
->hit_enchant
= obj
->d_enchant
= 0;
522 percent
= get_rand(1, 96);
523 blessing
= get_rand(1, 3);
532 for (i
= 0; i
< blessing
; i
++) {
534 obj
->hit_enchant
+= increment
;
536 obj
->d_enchant
+= increment
;
540 switch(obj
->which_kind
) {
560 case TWO_HANDED_SWORD
:
573 obj
->what_is
= ARMOR
;
574 obj
->which_kind
= get_rand(0, (ARMORS
- 1));
575 obj
->class = obj
->which_kind
+ 2;
576 if ((obj
->which_kind
== PLATE
) || (obj
->which_kind
== SPLINT
)) {
579 obj
->is_protected
= 0;
582 percent
= get_rand(1, 100);
583 blessing
= get_rand(1, 3);
587 obj
->d_enchant
-= blessing
;
588 } else if (percent
<= 33) {
589 obj
->d_enchant
+= blessing
;
598 obj
->which_kind
= get_rand(0, (WANDS
- 1));
599 obj
->class = get_rand(3, 7);
603 get_food(obj
, force_ration
)
605 boolean force_ration
;
609 if (force_ration
|| rand_percent(80)) {
610 obj
->which_kind
= RATION
;
612 obj
->which_kind
= FRUIT
;
621 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
622 dungeon
[row
][col
] |= STAIRS
;
630 return(obj
->class + obj
->d_enchant
);
642 free_list
= free_list
->next_object
;
643 } else if (!(obj
= (object
*) md_malloc(sizeof(object
)))) {
644 message("cannot allocate object, saving game", 0);
645 save_into_file(error_file
);
649 obj
->picked_up
= obj
->is_cursed
= 0;
650 obj
->in_use_flags
= NOT_USED
;
651 obj
->identified
= UNIDENTIFIED
;
660 obj
->next_object
= free_list
;
669 party_room
= gr_room();
671 n
= rand_percent(99) ? party_objects(party_room
) : 11;
672 if (rand_percent(99)) {
673 party_monsters(party_room
, n
);
681 short mc
, rc
, row
, col
;
684 obj
= level_objects
.next_object
;
690 rc
= get_mask_char(obj
->what_is
);
692 if (dungeon
[row
][col
] & MONSTER
) {
694 object_at(&level_monsters
, row
, col
)) != NULL
) {
695 monster
->trail_char
= rc
;
698 mc
= mvinch(row
, col
);
699 if (((mc
< 'A') || (mc
> 'Z')) &&
700 ((row
!= rogue
.row
) || (col
!= rogue
.col
))) {
701 mvaddch(row
, col
, rc
);
703 obj
= obj
->next_object
;
706 monster
= level_monsters
.next_object
;
709 if (monster
->m_flags
& IMITATES
) {
710 mvaddch(monster
->row
, monster
->col
, (int) monster
->disguise
);
712 monster
= monster
->next_monster
;
721 obj
= alloc_object();
722 obj
->what_is
= AMULET
;
732 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
733 place_at(obj
, row
, col
);
737 c_object_for_wizard()
744 if (pack_count((object
*) 0) >= MAX_PACK_COUNT
) {
745 message("pack full", 0);
748 message("type of object?", 0);
750 while (r_index("!?:)]=/,\033", (ch
= rgetchar()), 0) == -1) {
758 obj
= alloc_object();
762 obj
->what_is
= POTION
;
766 obj
->what_is
= SCROL
;
770 obj
->what_is
= AMULET
;
792 if ((ch
!= ',') && (ch
!= ':')) {
794 if (get_input_line("which kind?", "", buf
, "", 0, 1)) {
795 wk
= get_number(buf
);
796 if ((wk
>= 0) && (wk
<= max
)) {
797 obj
->which_kind
= (unsigned short) wk
;
798 if (obj
->what_is
== RING
) {
812 (void) add_to_pack(obj
, &rogue
.pack
, 1);