2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static char sccsid[] = "@(#)object.c 8.1 (Berkeley) 5/31/93";
41 static const char rcsid[] =
48 * This source herein may be modified and/or distributed by anybody who
49 * so desires, with the following restrictions:
50 * 1.) No portion of this notice shall be removed.
51 * 2.) Credit shall not be taken for the creation of this source.
52 * 3.) This code is not to be traded, sold, or used for personal
60 unsigned short dungeon[DROWS][DCOLS];
62 object *free_list = (object *) 0;
63 char *fruit = (char *) 0;
66 INIT_AW, /* armor, weapon */
67 INIT_RINGS, /* rings */
68 INIT_HP, /* Hp current,max */
69 INIT_STR, /* Str current,max */
72 INIT_EXP, /* exp level,points */
75 INIT_MOVES /* moves */
78 struct id id_potions[POTIONS] = {
79 {100, "blue \0 ", "of increase strength ", 0},
80 {250, "red \0 ", "of restore strength ", 0},
81 {100, "green \0 ", "of healing ", 0},
82 {200, "grey \0 ", "of extra healing ", 0},
83 {10, "brown \0 ", "of poison ", 0},
84 {300, "clear \0 ", "of raise level ", 0},
85 {10, "pink \0 ", "of blindness ", 0},
86 {25, "white \0 ", "of hallucination ", 0},
87 {100, "purple \0 ", "of detect monster ", 0},
88 {100, "black \0 ", "of detect things ", 0},
89 {10, "yellow \0 ", "of confusion ", 0},
90 {80, "plaid \0 ", "of levitation ", 0},
91 {150, "burgundy \0 ", "of haste self ", 0},
92 {145, "beige \0 ", "of see invisible ", 0}
95 struct id id_scrolls[SCROLS] = {
96 {505, " ", "of protect armor ", 0},
97 {200, " ", "of hold monster ", 0},
98 {235, " ", "of enchant weapon ", 0},
99 {235, " ", "of enchant armor ", 0},
100 {175, " ", "of identify ", 0},
101 {190, " ", "of teleportation ", 0},
102 {25, " ", "of sleep ", 0},
103 {610, " ", "of scare monster ", 0},
104 {210, " ", "of remove curse ", 0},
105 {80, " ", "of create monster ",0},
106 {25, " ", "of aggravate monster ",0},
107 {180, " ", "of magic mapping ", 0},
108 {90, " ", "of confuse monster ", 0}
111 struct id id_weapons[WEAPONS] = {
112 {150, "short bow ", "", 0},
113 {8, "darts ", "", 0},
114 {15, "arrows ", "", 0},
115 {27, "daggers ", "", 0},
116 {35, "shurikens ", "", 0},
117 {360, "mace ", "", 0},
118 {470, "long sword ", "", 0},
119 {580, "two-handed sword ", "", 0}
122 struct id id_armors[ARMORS] = {
123 {300, "leather armor ", "", (UNIDENTIFIED)},
124 {300, "ring mail ", "", (UNIDENTIFIED)},
125 {400, "scale mail ", "", (UNIDENTIFIED)},
126 {500, "chain mail ", "", (UNIDENTIFIED)},
127 {600, "banded mail ", "", (UNIDENTIFIED)},
128 {600, "splint mail ", "", (UNIDENTIFIED)},
129 {700, "plate mail ", "", (UNIDENTIFIED)}
132 struct id id_wands[WANDS] = {
133 {25, " ", "of teleport away ",0},
134 {50, " ", "of slow monster ", 0},
135 {8, " ", "of invisibility ",0},
136 {55, " ", "of polymorph ",0},
137 {2, " ", "of haste monster ",0},
138 {20, " ", "of magic missile ",0},
139 {20, " ", "of cancellation ",0},
140 {0, " ", "of do nothing ",0},
141 {35, " ", "of drain life ",0},
142 {20, " ", "of cold ",0},
143 {20, " ", "of fire ",0}
146 struct id id_rings[RINGS] = {
147 {250, " ", "of stealth ",0},
148 {100, " ", "of teleportation ", 0},
149 {255, " ", "of regeneration ",0},
150 {295, " ", "of slow digestion ",0},
151 {200, " ", "of add strength ",0},
152 {250, " ", "of sustain strength ",0},
153 {250, " ", "of dexterity ",0},
154 {25, " ", "of adornment ",0},
155 {300, " ", "of see invisible ",0},
156 {290, " ", "of maintain armor ",0},
157 {270, " ", "of searching ",0},
160 extern short cur_level, max_level;
161 extern short party_room;
162 extern char *error_file;
163 extern boolean is_wood[];
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++) {
191 boolean is_maze, is_room;
193 for (i = 0; i < MAXROOMS; i++) {
194 is_maze = (rooms[i].is_room & R_MAZE) ? 1 : 0;
195 is_room = (rooms[i].is_room & R_ROOM) ? 1 : 0;
197 if (!(is_room || is_maze)) {
200 if (is_maze || rand_percent(GOLD_PERCENT)) {
201 for (j = 0; j < 50; j++) {
202 row = get_rand(rooms[i].top_row+1,
203 rooms[i].bottom_row-1);
204 col = get_rand(rooms[i].left_col+1,
205 rooms[i].right_col-1);
206 if ((dungeon[row][col] == FLOOR) ||
207 (dungeon[row][col] == TUNNEL)) {
208 plant_gold(row, col, is_maze);
216 plant_gold(row, col, is_maze)
222 obj = alloc_object();
223 obj->row = row; obj->col = col;
225 obj->quantity = get_rand((2 * cur_level), (16 * cur_level));
227 obj->quantity += obj->quantity / 2;
229 dungeon[row][col] |= OBJECT;
230 (void) add_to_pack(obj, &level_objects, 0);
233 place_at(obj, row, col)
239 dungeon[row][col] |= OBJECT;
240 (void) add_to_pack(obj, &level_objects, 0);
244 object_at(pack, row, col)
248 object *obj = (object *) 0;
250 if (dungeon[row][col] & (MONSTER | OBJECT)) {
251 obj = pack->next_object;
253 while (obj && ((obj->row != row) || (obj->col != col))) {
254 obj = obj->next_object;
257 message("object_at(): inconsistent", 1);
264 get_letter_object(ch)
269 obj = rogue.pack.next_object;
271 while (obj && (obj->ichar != ch)) {
272 obj = obj->next_object;
282 while (objlist->next_object) {
283 obj = objlist->next_object;
284 objlist->next_object =
285 objlist->next_object->next_object;
294 const char *retstring;
296 switch(obj->what_is) {
298 retstring = obj->quantity > 1 ? "scrolls " : "scroll ";
301 retstring = obj->quantity > 1 ? "potions " : "potion ";
304 if (obj->which_kind == RATION) {
311 retstring = is_wood[obj->which_kind] ? "staff " : "wand ";
314 switch(obj->which_kind) {
316 retstring=obj->quantity > 1 ? "darts " : "dart ";
319 retstring=obj->quantity > 1 ? "arrows " : "arrow ";
322 retstring=obj->quantity > 1 ? "daggers " : "dagger ";
325 retstring=obj->quantity > 1?"shurikens ":"shuriken ";
328 retstring = id_weapons[obj->which_kind].title;
332 retstring = "armor ";
338 retstring = "amulet ";
341 retstring = "unknown ";
352 obj = alloc_object();
354 if (foods < (cur_level / 3)) {
358 obj->what_is = gr_what_is();
360 switch(obj->what_is) {
390 unsigned short what_is;
392 percent = get_rand(1, 91);
396 } else if (percent <= 60) {
398 } else if (percent <= 64) {
400 } else if (percent <= 74) {
402 } else if (percent <= 83) {
404 } else if (percent <= 88) {
417 percent = get_rand(0, 91);
419 obj->what_is = SCROL;
422 obj->which_kind = PROTECT_ARMOR;
423 } else if (percent <= 10) {
424 obj->which_kind = HOLD_MONSTER;
425 } else if (percent <= 20) {
426 obj->which_kind = CREATE_MONSTER;
427 } else if (percent <= 35) {
428 obj->which_kind = IDENTIFY;
429 } else if (percent <= 43) {
430 obj->which_kind = TELEPORT;
431 } else if (percent <= 50) {
432 obj->which_kind = SLEEP;
433 } else if (percent <= 55) {
434 obj->which_kind = SCARE_MONSTER;
435 } else if (percent <= 64) {
436 obj->which_kind = REMOVE_CURSE;
437 } else if (percent <= 69) {
438 obj->which_kind = ENCH_ARMOR;
439 } else if (percent <= 74) {
440 obj->which_kind = ENCH_WEAPON;
441 } else if (percent <= 80) {
442 obj->which_kind = AGGRAVATE_MONSTER;
443 } else if (percent <= 86) {
444 obj->which_kind = CON_MON;
446 obj->which_kind = MAGIC_MAPPING;
455 percent = get_rand(1, 118);
457 obj->what_is = POTION;
460 obj->which_kind = RAISE_LEVEL;
461 } else if (percent <= 15) {
462 obj->which_kind = DETECT_OBJECTS;
463 } else if (percent <= 25) {
464 obj->which_kind = DETECT_MONSTER;
465 } else if (percent <= 35) {
466 obj->which_kind = INCREASE_STRENGTH;
467 } else if (percent <= 45) {
468 obj->which_kind = RESTORE_STRENGTH;
469 } else if (percent <= 55) {
470 obj->which_kind = HEALING;
471 } else if (percent <= 65) {
472 obj->which_kind = EXTRA_HEALING;
473 } else if (percent <= 75) {
474 obj->which_kind = BLINDNESS;
475 } else if (percent <= 85) {
476 obj->which_kind = HALLUCINATION;
477 } else if (percent <= 95) {
478 obj->which_kind = CONFUSION;
479 } else if (percent <= 105) {
480 obj->which_kind = POISON;
481 } else if (percent <= 110) {
482 obj->which_kind = LEVITATION;
483 } else if (percent <= 114) {
484 obj->which_kind = HASTE_SELF;
486 obj->which_kind = SEE_INVISIBLE;
490 gr_weapon(obj, assign_wk)
496 short blessing, increment;
498 obj->what_is = WEAPON;
500 obj->which_kind = get_rand(0, (WEAPONS - 1));
502 if ((obj->which_kind == ARROW) || (obj->which_kind == DAGGER) ||
503 (obj->which_kind == SHURIKEN) | (obj->which_kind == DART)) {
504 obj->quantity = get_rand(3, 15);
505 obj->quiver = get_rand(0, 126);
509 obj->hit_enchant = obj->d_enchant = 0;
511 percent = get_rand(1, 96);
512 blessing = get_rand(1, 3);
516 } else if (percent <= 32) {
521 for (i = 0; i < blessing; i++) {
523 obj->hit_enchant += increment;
525 obj->d_enchant += increment;
529 switch(obj->which_kind) {
549 case TWO_HANDED_SWORD:
561 obj->what_is = ARMOR;
562 obj->which_kind = get_rand(0, (ARMORS - 1));
563 obj->class = obj->which_kind + 2;
564 if ((obj->which_kind == PLATE) || (obj->which_kind == SPLINT)) {
567 obj->is_protected = 0;
570 percent = get_rand(1, 100);
571 blessing = get_rand(1, 3);
575 obj->d_enchant -= blessing;
576 } else if (percent <= 33) {
577 obj->d_enchant += blessing;
585 obj->which_kind = get_rand(0, (WANDS - 1));
586 obj->class = get_rand(3, 7);
589 get_food(obj, force_ration)
591 boolean force_ration;
595 if (force_ration || rand_percent(80)) {
596 obj->which_kind = RATION;
598 obj->which_kind = FRUIT;
606 gr_row_col(&row, &col, (FLOOR | TUNNEL));
607 dungeon[row][col] |= STAIRS;
614 return(obj->class + obj->d_enchant);
626 free_list = free_list->next_object;
627 } else if (!(obj = (object *) md_malloc(sizeof(object)))) {
628 message("cannot allocate object, saving game", 0);
629 save_into_file(error_file);
633 obj->picked_up = obj->is_cursed = 0;
634 obj->in_use_flags = NOT_USED;
635 obj->identified = UNIDENTIFIED;
643 obj->next_object = free_list;
651 party_room = gr_room();
653 n = rand_percent(99) ? party_objects(party_room) : 11;
654 if (rand_percent(99)) {
655 party_monsters(party_room, n);
662 short mc, rc, row, col;
665 obj = level_objects.next_object;
671 rc = get_mask_char(obj->what_is);
673 if (dungeon[row][col] & MONSTER) {
674 if (monster = object_at(&level_monsters, row, col)) {
675 monster->trail_char = rc;
678 mc = mvinch(row, col);
679 if (((mc < 'A') || (mc > 'Z')) &&
680 ((row != rogue.row) || (col != rogue.col))) {
681 mvaddch(row, col, rc);
683 obj = obj->next_object;
686 monster = level_monsters.next_object;
689 if (monster->m_flags & IMITATES) {
690 mvaddch(monster->row, monster->col, (int) monster->disguise);
692 monster = monster->next_monster;
700 obj = alloc_object();
701 obj->what_is = AMULET;
710 gr_row_col(&row, &col, (FLOOR | TUNNEL));
711 place_at(obj, row, col);
714 c_object_for_wizard()
720 if (pack_count((object *) 0) >= MAX_PACK_COUNT) {
721 message("pack full", 0);
724 message("type of object?", 0);
726 while (r_index("!?:)]=/,\033", (ch = rgetchar()), 0) == -1) {
734 obj = alloc_object();
738 obj->what_is = POTION;
742 obj->what_is = SCROL;
746 obj->what_is = AMULET;
768 if ((ch != ',') && (ch != ':')) {
770 if (get_input_line("which kind?", "", buf, "", 0, 1)) {
771 wk = get_number(buf);
772 if ((wk >= 0) && (wk <= max)) {
773 obj->which_kind = (unsigned short) wk;
774 if (obj->what_is == RING) {
788 (void) add_to_pack(obj, &rogue.pack, 1);