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
36 * @(#)pack.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/rogue/pack.c,v 1.8 1999/11/30 03:49:25 billf Exp $
38 * $DragonFly: src/games/rogue/pack.c,v 1.3 2003/08/26 23:52:50 drhodus Exp $
44 * This source herein may be modified and/or distributed by anybody who
45 * so desires, with the following restrictions:
46 * 1.) No portion of this notice shall be removed.
47 * 2.) Credit shall not be taken for the creation of this source.
48 * 3.) This code is not to be traded, sold, or used for personal
55 const char *curse_message = "you can't, it appears to be cursed";
57 extern short levitate;
60 add_to_pack(obj, pack, condense)
67 if (op = check_duplicate(obj, pack)) {
71 obj->ichar = next_avail_ichar();
74 if (pack->next_object == 0) {
75 pack->next_object = obj;
77 op = pack->next_object;
79 while (op->next_object) {
82 op->next_object = obj;
88 take_from_pack(obj, pack)
91 while (pack->next_object != obj) {
92 pack = pack->next_object;
94 pack->next_object = pack->next_object->next_object;
97 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
98 * of scare-monster and it turns to dust. *status is otherwise set to 1.
102 pick_up(row, col, status)
111 message("you're floating in the air!", 0);
112 return((object *) 0);
114 obj = object_at(&level_objects, row, col);
116 message("pick_up(): inconsistent", 1);
119 if ( (obj->what_is == SCROL) &&
120 (obj->which_kind == SCARE_MONSTER) &&
122 message("the scroll turns to dust as you pick it up", 0);
123 dungeon[row][col] &= (~OBJECT);
124 vanish(obj, 0, &level_objects);
126 if (id_scrolls[SCARE_MONSTER].id_status == UNIDENTIFIED) {
127 id_scrolls[SCARE_MONSTER].id_status = IDENTIFIED;
129 return((object *) 0);
131 if (obj->what_is == GOLD) {
132 rogue.gold += obj->quantity;
133 dungeon[row][col] &= ~(OBJECT);
134 take_from_pack(obj, &level_objects);
135 print_stats(STAT_GOLD);
136 return(obj); /* obj will be free_object()ed in caller */
138 if (pack_count(obj) >= MAX_PACK_COUNT) {
139 message("pack too full", 1);
140 return((object *) 0);
142 dungeon[row][col] &= ~(OBJECT);
143 take_from_pack(obj, &level_objects);
144 obj = add_to_pack(obj, &rogue.pack, 1);
155 if (dungeon[rogue.row][rogue.col] & (OBJECT | STAIRS | TRAP)) {
156 message("there's already something there", 0);
159 if (!rogue.pack.next_object) {
160 message("you have nothing to drop", 0);
163 if ((ch = pack_letter("drop what?", ALL_OBJECTS)) == CANCEL) {
166 if (!(obj = get_letter_object(ch))) {
167 message("no such item.", 0);
170 if (obj->in_use_flags & BEING_WIELDED) {
171 if (obj->is_cursed) {
172 message(curse_message, 0);
175 unwield(rogue.weapon);
176 } else if (obj->in_use_flags & BEING_WORN) {
177 if (obj->is_cursed) {
178 message(curse_message, 0);
183 print_stats(STAT_ARMOR);
184 } else if (obj->in_use_flags & ON_EITHER_HAND) {
185 if (obj->is_cursed) {
186 message(curse_message, 0);
191 obj->row = rogue.row;
192 obj->col = rogue.col;
194 if ((obj->quantity > 1) && (obj->what_is != WEAPON)) {
196 new = alloc_object();
202 take_from_pack(obj, &rogue.pack);
204 place_at(obj, rogue.row, rogue.col);
205 (void) strcpy(desc, "dropped ");
206 get_desc(obj, desc+8);
212 check_duplicate(obj, pack)
217 if (!(obj->what_is & (WEAPON | FOOD | SCROL | POTION))) {
220 if ((obj->what_is == FOOD) && (obj->which_kind == FRUIT)) {
223 op = pack->next_object;
226 if ((op->what_is == obj->what_is) &&
227 (op->which_kind == obj->which_kind)) {
229 if ((obj->what_is != WEAPON) ||
230 ((obj->what_is == WEAPON) &&
231 ((obj->which_kind == ARROW) ||
232 (obj->which_kind == DAGGER) ||
233 (obj->which_kind == DART) ||
234 (obj->which_kind == SHURIKEN)) &&
235 (obj->quiver == op->quiver))) {
236 op->quantity += obj->quantity;
240 op = op->next_object;
251 for (i = 0; i < 26; i++) {
254 obj = rogue.pack.next_object;
256 ichars[(obj->ichar - 'a')] = 1;
257 obj = obj->next_object;
259 for (i = 0; i < 26; i++) {
269 if (!isatty(0) || !isatty(1))
271 while (rgetchar() != ' ') ;
274 pack_letter(prompt, mask)
279 unsigned short tmask = mask;
281 if (!mask_pack(&rogue.pack, mask)) {
282 message("nothing appropriate", 0);
291 if (!is_pack_letter(&ch, &mask)) {
301 inventory(&rogue.pack, mask);
317 if (rogue.armor->is_cursed) {
318 message(curse_message, 0);
323 (void) strcpy(desc, "was wearing ");
324 get_desc(obj, desc+12);
326 print_stats(STAT_ARMOR);
330 message("not wearing any", 0);
341 message("you're already wearing some", 0);
344 ch = pack_letter("wear what?", ARMOR);
349 if (!(obj = get_letter_object(ch))) {
350 message("no such item.", 0);
353 if (obj->what_is != ARMOR) {
354 message("you can't wear that", 0);
358 (void) strcpy(desc, "wearing ");
359 get_desc(obj, desc + 8);
362 print_stats(STAT_ARMOR);
370 obj->in_use_flags &= (~BEING_WORN);
372 rogue.armor = (object *) 0;
379 obj->in_use_flags |= BEING_WORN;
389 if (rogue.weapon && rogue.weapon->is_cursed) {
390 message(curse_message, 0);
393 ch = pack_letter("wield what?", WEAPON);
398 if (!(obj = get_letter_object(ch))) {
399 message("No such item.", 0);
402 if (obj->what_is & (ARMOR | RING)) {
403 sprintf(desc, "you can't wield %s",
404 ((obj->what_is == ARMOR) ? "armor" : "rings"));
408 if (obj->in_use_flags & BEING_WIELDED) {
409 message("in use", 0);
411 unwield(rogue.weapon);
412 (void) strcpy(desc, "wielding ");
413 get_desc(obj, desc + 9);
424 obj->in_use_flags |= BEING_WIELDED;
431 obj->in_use_flags &= (~BEING_WIELDED);
433 rogue.weapon = (object *) 0;
441 char buf[MAX_TITLE_LENGTH+2];
443 ch = pack_letter("call what?", (SCROL | POTION | WAND | RING));
448 if (!(obj = get_letter_object(ch))) {
449 message("no such item.", 0);
452 if (!(obj->what_is & (SCROL | POTION | WAND | RING))) {
453 message("surely you already know what that's called", 0);
456 id_table = get_id_table(obj);
458 if (get_input_line("call it:","",buf,id_table[obj->which_kind].title,1,1)) {
459 id_table[obj->which_kind].id_status = CALLED;
460 (void) strcpy(id_table[obj->which_kind].title, buf);
465 const object *new_obj;
470 obj = rogue.pack.next_object;
473 if (obj->what_is != WEAPON) {
474 count += obj->quantity;
475 } else if (!new_obj) {
477 } else if ((new_obj->what_is != WEAPON) ||
478 ((obj->which_kind != ARROW) &&
479 (obj->which_kind != DAGGER) &&
480 (obj->which_kind != DART) &&
481 (obj->which_kind != SHURIKEN)) ||
482 (new_obj->which_kind != obj->which_kind) ||
483 (obj->quiver != new_obj->quiver)) {
486 obj = obj->next_object;
492 mask_pack(pack, mask)
496 while (pack->next_object) {
497 pack = pack->next_object;
498 if (pack->what_is & mask) {
505 is_pack_letter(c, mask)
507 unsigned short *mask;
509 if (((*c == '?') || (*c == '!') || (*c == ':') || (*c == '=') ||
510 (*c == ')') || (*c == ']') || (*c == '/') || (*c == ','))) {
540 return(((*c >= 'a') && (*c <= 'z')) || (*c == CANCEL) || (*c == LIST));
545 return(mask_pack(&rogue.pack, AMULET));
554 if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
555 message("nothing here", 0);
557 if (obj = pick_up(rogue.row, rogue.col, &stat)) {
559 if (obj->what_is == GOLD) {
565 desc[n+1] = obj->ichar;
571 if (obj || (!stat)) {