]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - rogue/object.c
1 /* $NetBSD: object.c,v 1.10 2006/03/30 04:27:24 jnemeth 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.10 2006/03/30 04:27:24 jnemeth 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
];
61 object
*free_list
= (object
*) 0;
62 char *fruit
= (char *) 0;
67 INIT_RINGS
, /* left ring */
68 INIT_RINGS
, /* right ring */
69 INIT_HP
, /* Hp current */
71 INIT_STR
, /* Str current */
72 INIT_STR
, /* Str max */
75 INIT_EXPLEVEL
, /* exp level */
76 INIT_EXP
, /* exp points */
79 INIT_MOVES
/* moves */
82 struct id id_potions
[POTIONS
] = {
83 {100, "blue \0 ", "of increase strength ", 0},
84 {250, "red \0 ", "of restore strength ", 0},
85 {100, "green \0 ", "of healing ", 0},
86 {200, "grey \0 ", "of extra healing ", 0},
87 {10, "brown \0 ", "of poison ", 0},
88 {300, "clear \0 ", "of raise level ", 0},
89 {10, "pink \0 ", "of blindness ", 0},
90 {25, "white \0 ", "of hallucination ", 0},
91 {100, "purple \0 ", "of detect monster ", 0},
92 {100, "black \0 ", "of detect things ", 0},
93 {10, "yellow \0 ", "of confusion ", 0},
94 {80, "plaid \0 ", "of levitation ", 0},
95 {150, "burgundy \0 ", "of haste self ", 0},
96 {145, "beige \0 ", "of see invisible ", 0}
99 struct id id_scrolls
[SCROLS
] = {
100 {505, " ", "of protect armor ", 0},
101 {200, " ", "of hold monster ", 0},
102 {235, " ", "of enchant weapon ", 0},
103 {235, " ", "of enchant armor ", 0},
104 {175, " ", "of identify ", 0},
105 {190, " ", "of teleportation ", 0},
106 {25, " ", "of sleep ", 0},
107 {610, " ", "of scare monster ", 0},
108 {210, " ", "of remove curse ", 0},
109 {80, " ", "of create monster ",0},
110 {25, " ", "of aggravate monster ",0},
111 {180, " ", "of magic mapping ", 0},
112 {90, " ", "of confuse monster ", 0}
115 struct id id_weapons
[WEAPONS
] = {
116 {150, "short bow ", "", 0},
117 {8, "darts ", "", 0},
118 {15, "arrows ", "", 0},
119 {27, "daggers ", "", 0},
120 {35, "shurikens ", "", 0},
121 {360, "mace ", "", 0},
122 {470, "long sword ", "", 0},
123 {580, "two-handed sword ", "", 0}
126 struct id id_armors
[ARMORS
] = {
127 {300, "leather armor ", "", (UNIDENTIFIED
)},
128 {300, "ring mail ", "", (UNIDENTIFIED
)},
129 {400, "scale mail ", "", (UNIDENTIFIED
)},
130 {500, "chain mail ", "", (UNIDENTIFIED
)},
131 {600, "banded mail ", "", (UNIDENTIFIED
)},
132 {600, "splint mail ", "", (UNIDENTIFIED
)},
133 {700, "plate mail ", "", (UNIDENTIFIED
)}
136 struct id id_wands
[WANDS
] = {
137 {25, " ", "of teleport away ",0},
138 {50, " ", "of slow monster ", 0},
139 {8, " ", "of invisibility ",0},
140 {55, " ", "of polymorph ",0},
141 {2, " ", "of haste monster ",0},
142 {20, " ", "of magic missile ",0},
143 {20, " ", "of cancellation ",0},
144 {0, " ", "of do nothing ",0},
145 {35, " ", "of drain life ",0},
146 {20, " ", "of cold ",0},
147 {20, " ", "of fire ",0}
150 struct id id_rings
[RINGS
] = {
151 {250, " ", "of stealth ",0},
152 {100, " ", "of teleportation ", 0},
153 {255, " ", "of regeneration ",0},
154 {295, " ", "of slow digestion ",0},
155 {200, " ", "of add strength ",0},
156 {250, " ", "of sustain strength ",0},
157 {250, " ", "of dexterity ",0},
158 {25, " ", "of adornment ",0},
159 {300, " ", "of see invisible ",0},
160 {290, " ", "of maintain armor ",0},
161 {270, " ", "of searching ",0},
170 if (cur_level
< max_level
) {
173 n
= coin_toss() ? get_rand(2, 4) : get_rand(3, 5);
174 while (rand_percent(33)) {
177 if (party_room
!= NO_ROOM
) {
180 for (i
= 0; i
< n
; i
++) {
192 boolean is_maze
, is_room
;
194 for (i
= 0; i
< MAXROOMS
; i
++) {
195 is_maze
= (rooms
[i
].is_room
& R_MAZE
) ? 1 : 0;
196 is_room
= (rooms
[i
].is_room
& R_ROOM
) ? 1 : 0;
198 if (!(is_room
|| is_maze
)) {
201 if (is_maze
|| rand_percent(GOLD_PERCENT
)) {
202 for (j
= 0; j
< 50; j
++) {
203 row
= get_rand(rooms
[i
].top_row
+1,
204 rooms
[i
].bottom_row
-1);
205 col
= get_rand(rooms
[i
].left_col
+1,
206 rooms
[i
].right_col
-1);
207 if ((dungeon
[row
][col
] == FLOOR
) ||
208 (dungeon
[row
][col
] == TUNNEL
)) {
209 plant_gold(row
, col
, is_maze
);
218 plant_gold(row
, col
, is_maze
)
224 obj
= alloc_object();
225 obj
->row
= row
; obj
->col
= col
;
227 obj
->quantity
= get_rand((2 * cur_level
), (16 * cur_level
));
229 obj
->quantity
+= obj
->quantity
/ 2;
231 dungeon
[row
][col
] |= OBJECT
;
232 (void) add_to_pack(obj
, &level_objects
, 0);
236 place_at(obj
, row
, col
)
242 dungeon
[row
][col
] |= OBJECT
;
243 (void) add_to_pack(obj
, &level_objects
, 0);
247 object_at(pack
, row
, col
)
251 object
*obj
= (object
*) 0;
253 if (dungeon
[row
][col
] & (MONSTER
| OBJECT
)) {
254 obj
= pack
->next_object
;
256 while (obj
&& ((obj
->row
!= row
) || (obj
->col
!= col
))) {
257 obj
= obj
->next_object
;
260 message("object_at(): inconsistent", 1);
267 get_letter_object(ch
)
272 obj
= rogue
.pack
.next_object
;
274 while (obj
&& (obj
->ichar
!= ch
)) {
275 obj
= obj
->next_object
;
286 while (objlist
->next_object
) {
287 obj
= objlist
->next_object
;
288 objlist
->next_object
=
289 objlist
->next_object
->next_object
;
298 const char *retstring
;
300 switch(obj
->what_is
) {
302 retstring
= obj
->quantity
> 1 ? "scrolls " : "scroll ";
305 retstring
= obj
->quantity
> 1 ? "potions " : "potion ";
308 if (obj
->which_kind
== RATION
) {
315 retstring
= is_wood
[obj
->which_kind
] ? "staff " : "wand ";
318 switch(obj
->which_kind
) {
320 retstring
=obj
->quantity
> 1 ? "darts " : "dart ";
323 retstring
=obj
->quantity
> 1 ? "arrows " : "arrow ";
326 retstring
=obj
->quantity
> 1 ? "daggers " : "dagger ";
329 retstring
=obj
->quantity
> 1?"shurikens ":"shuriken ";
332 retstring
= id_weapons
[obj
->which_kind
].title
;
336 retstring
= "armor ";
342 retstring
= "amulet ";
345 retstring
= "unknown ";
356 obj
= alloc_object();
358 if (foods
< (cur_level
/ 3)) {
362 obj
->what_is
= gr_what_is();
364 switch(obj
->what_is
) {
394 unsigned short what_is
;
396 percent
= get_rand(1, 91);
400 } else if (percent
<= 60) {
402 } else if (percent
<= 64) {
404 } else if (percent
<= 74) {
406 } else if (percent
<= 83) {
408 } else if (percent
<= 88) {
422 percent
= get_rand(0, 91);
424 obj
->what_is
= SCROL
;
427 obj
->which_kind
= PROTECT_ARMOR
;
428 } else if (percent
<= 10) {
429 obj
->which_kind
= HOLD_MONSTER
;
430 } else if (percent
<= 20) {
431 obj
->which_kind
= CREATE_MONSTER
;
432 } else if (percent
<= 35) {
433 obj
->which_kind
= IDENTIFY
;
434 } else if (percent
<= 43) {
435 obj
->which_kind
= TELEPORT
;
436 } else if (percent
<= 50) {
437 obj
->which_kind
= SLEEP
;
438 } else if (percent
<= 55) {
439 obj
->which_kind
= SCARE_MONSTER
;
440 } else if (percent
<= 64) {
441 obj
->which_kind
= REMOVE_CURSE
;
442 } else if (percent
<= 69) {
443 obj
->which_kind
= ENCH_ARMOR
;
444 } else if (percent
<= 74) {
445 obj
->which_kind
= ENCH_WEAPON
;
446 } else if (percent
<= 80) {
447 obj
->which_kind
= AGGRAVATE_MONSTER
;
448 } else if (percent
<= 86) {
449 obj
->which_kind
= CON_MON
;
451 obj
->which_kind
= MAGIC_MAPPING
;
461 percent
= get_rand(1, 118);
463 obj
->what_is
= POTION
;
466 obj
->which_kind
= RAISE_LEVEL
;
467 } else if (percent
<= 15) {
468 obj
->which_kind
= DETECT_OBJECTS
;
469 } else if (percent
<= 25) {
470 obj
->which_kind
= DETECT_MONSTER
;
471 } else if (percent
<= 35) {
472 obj
->which_kind
= INCREASE_STRENGTH
;
473 } else if (percent
<= 45) {
474 obj
->which_kind
= RESTORE_STRENGTH
;
475 } else if (percent
<= 55) {
476 obj
->which_kind
= HEALING
;
477 } else if (percent
<= 65) {
478 obj
->which_kind
= EXTRA_HEALING
;
479 } else if (percent
<= 75) {
480 obj
->which_kind
= BLINDNESS
;
481 } else if (percent
<= 85) {
482 obj
->which_kind
= HALLUCINATION
;
483 } else if (percent
<= 95) {
484 obj
->which_kind
= CONFUSION
;
485 } else if (percent
<= 105) {
486 obj
->which_kind
= POISON
;
487 } else if (percent
<= 110) {
488 obj
->which_kind
= LEVITATION
;
489 } else if (percent
<= 114) {
490 obj
->which_kind
= HASTE_SELF
;
492 obj
->which_kind
= SEE_INVISIBLE
;
497 gr_weapon(obj
, assign_wk
)
503 short blessing
, increment
;
505 obj
->what_is
= WEAPON
;
507 obj
->which_kind
= get_rand(0, (WEAPONS
- 1));
509 if ((obj
->which_kind
== ARROW
) || (obj
->which_kind
== DAGGER
) ||
510 (obj
->which_kind
== SHURIKEN
) | (obj
->which_kind
== DART
)) {
511 obj
->quantity
= get_rand(3, 15);
512 obj
->quiver
= get_rand(0, 126);
516 obj
->hit_enchant
= obj
->d_enchant
= 0;
518 percent
= get_rand(1, 96);
519 blessing
= get_rand(1, 3);
528 for (i
= 0; i
< blessing
; i
++) {
530 obj
->hit_enchant
+= increment
;
532 obj
->d_enchant
+= increment
;
536 switch(obj
->which_kind
) {
556 case TWO_HANDED_SWORD
:
569 obj
->what_is
= ARMOR
;
570 obj
->which_kind
= get_rand(0, (ARMORS
- 1));
571 obj
->class = obj
->which_kind
+ 2;
572 if ((obj
->which_kind
== PLATE
) || (obj
->which_kind
== SPLINT
)) {
575 obj
->is_protected
= 0;
578 percent
= get_rand(1, 100);
579 blessing
= get_rand(1, 3);
583 obj
->d_enchant
-= blessing
;
584 } else if (percent
<= 33) {
585 obj
->d_enchant
+= blessing
;
594 obj
->which_kind
= get_rand(0, (WANDS
- 1));
595 obj
->class = get_rand(3, 7);
599 get_food(obj
, force_ration
)
601 boolean force_ration
;
605 if (force_ration
|| rand_percent(80)) {
606 obj
->which_kind
= RATION
;
608 obj
->which_kind
= FRUIT
;
617 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
618 dungeon
[row
][col
] |= STAIRS
;
626 return(obj
->class + obj
->d_enchant
);
638 free_list
= free_list
->next_object
;
639 } else if (!(obj
= (object
*) md_malloc(sizeof(object
)))) {
640 message("cannot allocate object, saving game", 0);
641 save_into_file(error_file
);
642 clean_up("alloc_object: save failed");
646 obj
->picked_up
= obj
->is_cursed
= 0;
647 obj
->in_use_flags
= NOT_USED
;
648 obj
->identified
= UNIDENTIFIED
;
657 obj
->next_object
= free_list
;
666 party_room
= gr_room();
668 n
= rand_percent(99) ? party_objects(party_room
) : 11;
669 if (rand_percent(99)) {
670 party_monsters(party_room
, n
);
678 short mc
, rc
, row
, col
;
681 obj
= level_objects
.next_object
;
687 rc
= get_mask_char(obj
->what_is
);
689 if (dungeon
[row
][col
] & MONSTER
) {
691 object_at(&level_monsters
, row
, col
)) != NULL
) {
692 monster
->trail_char
= rc
;
695 mc
= mvinch(row
, col
);
696 if (((mc
< 'A') || (mc
> 'Z')) &&
697 ((row
!= rogue
.row
) || (col
!= rogue
.col
))) {
698 mvaddch(row
, col
, rc
);
700 obj
= obj
->next_object
;
703 monster
= level_monsters
.next_object
;
706 if (monster
->m_flags
& IMITATES
) {
707 mvaddch(monster
->row
, monster
->col
, (int) monster
->disguise
);
709 monster
= monster
->next_monster
;
718 obj
= alloc_object();
719 obj
->what_is
= AMULET
;
729 gr_row_col(&row
, &col
, (FLOOR
| TUNNEL
));
730 place_at(obj
, row
, col
);
734 c_object_for_wizard()
741 if (pack_count((object
*) 0) >= MAX_PACK_COUNT
) {
742 message("pack full", 0);
745 message("type of object?", 0);
747 while (r_index("!?:)]=/,\033", (ch
= rgetchar()), 0) == -1) {
755 obj
= alloc_object();
759 obj
->what_is
= POTION
;
763 obj
->what_is
= SCROL
;
767 obj
->what_is
= AMULET
;
789 if ((ch
!= ',') && (ch
!= ':')) {
791 if (get_input_line("which kind?", "", buf
, "", 0, 1)) {
792 wk
= get_number(buf
);
793 if ((wk
>= 0) && (wk
<= max
)) {
794 obj
->which_kind
= (unsigned short) wk
;
795 if (obj
->what_is
== RING
) {
809 (void) add_to_pack(obj
, &rogue
.pack
, 1);