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. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)pack.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/games/rogue/pack.c,v 1.8 1999/11/30 03:49:25 billf Exp $
34 * $DragonFly: src/games/rogue/pack.c,v 1.4 2006/09/02 19:31:07 pavalos Exp $
40 * This source herein may be modified and/or distributed by anybody who
41 * so desires, with the following restrictions:
42 * 1.) No portion of this notice shall be removed.
43 * 2.) Credit shall not be taken for the creation of this source.
44 * 3.) This code is not to be traded, sold, or used for personal
52 const char *curse_message = "you can't, it appears to be cursed";
54 extern short levitate;
56 static object *check_duplicate(object *, object *);
57 static boolean is_pack_letter(short *, unsigned short *);
58 static boolean mask_pack(const object *, unsigned short);
59 static int next_avail_ichar(void);
62 add_to_pack(object *obj, object *pack, int condense)
67 if ((op = check_duplicate(obj, pack)) != NULL) {
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;
89 take_from_pack(object *obj, object *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(int row, int col, short *status)
109 message("you're floating in the air!", 0);
112 obj = object_at(&level_objects, row, col);
114 message("pick_up(): inconsistent", 1);
117 if ( (obj->what_is == SCROL) &&
118 (obj->which_kind == SCARE_MONSTER) &&
120 message("the scroll turns to dust as you pick it up", 0);
121 dungeon[row][col] &= (~OBJECT);
122 vanish(obj, 0, &level_objects);
124 if (id_scrolls[SCARE_MONSTER].id_status == UNIDENTIFIED) {
125 id_scrolls[SCARE_MONSTER].id_status = IDENTIFIED;
129 if (obj->what_is == GOLD) {
130 rogue.gold += obj->quantity;
131 dungeon[row][col] &= ~(OBJECT);
132 take_from_pack(obj, &level_objects);
133 print_stats(STAT_GOLD);
134 return(obj); /* obj will be free_object()ed in caller */
136 if (pack_count(obj) >= MAX_PACK_COUNT) {
137 message("pack too full", 1);
140 dungeon[row][col] &= ~(OBJECT);
141 take_from_pack(obj, &level_objects);
142 obj = add_to_pack(obj, &rogue.pack, 1);
154 if (dungeon[rogue.row][rogue.col] & (OBJECT | STAIRS | TRAP)) {
155 message("there's already something there", 0);
158 if (!rogue.pack.next_object) {
159 message("you have nothing to drop", 0);
162 if ((ch = pack_letter("drop what?", ALL_OBJECTS)) == CANCEL) {
165 if (!(obj = get_letter_object(ch))) {
166 message("no such item.", 0);
169 if (obj->in_use_flags & BEING_WIELDED) {
170 if (obj->is_cursed) {
171 message(curse_message, 0);
174 unwield(rogue.weapon);
175 } else if (obj->in_use_flags & BEING_WORN) {
176 if (obj->is_cursed) {
177 message(curse_message, 0);
182 print_stats(STAT_ARMOR);
183 } else if (obj->in_use_flags & ON_EITHER_HAND) {
184 if (obj->is_cursed) {
185 message(curse_message, 0);
190 obj->row = rogue.row;
191 obj->col = rogue.col;
193 if ((obj->quantity > 1) && (obj->what_is != WEAPON)) {
195 new = alloc_object();
201 take_from_pack(obj, &rogue.pack);
203 place_at(obj, rogue.row, rogue.col);
204 strcpy(desc, "dropped ");
205 get_desc(obj, desc + 8);
211 check_duplicate(object *obj, object *pack)
215 if (!(obj->what_is & (WEAPON | FOOD | SCROL | POTION))) {
218 if ((obj->what_is == FOOD) && (obj->which_kind == FRUIT)) {
221 op = pack->next_object;
224 if ((op->what_is == obj->what_is) &&
225 (op->which_kind == obj->which_kind)) {
227 if ((obj->what_is != WEAPON) ||
228 ((obj->what_is == WEAPON) &&
229 ((obj->which_kind == ARROW) ||
230 (obj->which_kind == DAGGER) ||
231 (obj->which_kind == DART) ||
232 (obj->which_kind == SHURIKEN)) &&
233 (obj->quiver == op->quiver))) {
234 op->quantity += obj->quantity;
238 op = op->next_object;
244 next_avail_ichar(void)
250 for (i = 0; i < 26; i++) {
253 obj = rogue.pack.next_object;
255 ichars[(obj->ichar - 'a')] = 1;
256 obj = obj->next_object;
258 for (i = 0; i < 26; i++) {
269 if (!isatty(0) || !isatty(1))
271 while (rgetchar() != ' ')
276 pack_letter(const char *prompt, unsigned short 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);
318 if (rogue.armor->is_cursed) {
319 message(curse_message, 0);
324 strcpy(desc, "was wearing ");
325 get_desc(obj, desc+12);
327 print_stats(STAT_ARMOR);
331 message("not wearing any", 0);
343 message("you're already wearing some", 0);
346 ch = pack_letter("wear what?", ARMOR);
351 if (!(obj = get_letter_object(ch))) {
352 message("no such item.", 0);
355 if (obj->what_is != ARMOR) {
356 message("you can't wear that", 0);
360 strcpy(desc, "wearing ");
361 get_desc(obj, desc + 8);
364 print_stats(STAT_ARMOR);
372 obj->in_use_flags &= (~BEING_WORN);
381 obj->in_use_flags |= BEING_WORN;
392 if (rogue.weapon && rogue.weapon->is_cursed) {
393 message(curse_message, 0);
396 ch = pack_letter("wield what?", WEAPON);
401 if (!(obj = get_letter_object(ch))) {
402 message("No such item.", 0);
405 if (obj->what_is & (ARMOR | RING)) {
406 sprintf(desc, "you can't wield %s",
407 ((obj->what_is == ARMOR) ? "armor" : "rings"));
411 if (obj->in_use_flags & BEING_WIELDED) {
412 message("in use", 0);
414 unwield(rogue.weapon);
415 strcpy(desc, "wielding ");
416 get_desc(obj, desc + 9);
424 do_wield(object *obj)
427 obj->in_use_flags |= BEING_WIELDED;
434 obj->in_use_flags &= (~BEING_WIELDED);
445 char buf[MAX_TITLE_LENGTH+2];
447 ch = pack_letter("call what?", (SCROL | POTION | WAND | RING));
452 if (!(obj = get_letter_object(ch))) {
453 message("no such item.", 0);
456 if (!(obj->what_is & (SCROL | POTION | WAND | RING))) {
457 message("surely you already know what that's called", 0);
460 id_table = get_id_table(obj);
462 if (get_input_line("call it:","",buf,id_table[obj->which_kind].title,1,1)) {
463 id_table[obj->which_kind].id_status = CALLED;
464 strcpy(id_table[obj->which_kind].title, buf);
469 pack_count(const object *new_obj)
474 obj = rogue.pack.next_object;
477 if (obj->what_is != WEAPON) {
478 count += obj->quantity;
479 } else if (!new_obj) {
481 } else if ((new_obj->what_is != WEAPON) ||
482 ((obj->which_kind != ARROW) &&
483 (obj->which_kind != DAGGER) &&
484 (obj->which_kind != DART) &&
485 (obj->which_kind != SHURIKEN)) ||
486 (new_obj->which_kind != obj->which_kind) ||
487 (obj->quiver != new_obj->quiver)) {
490 obj = obj->next_object;
496 mask_pack(const object *pack, unsigned short mask)
498 while (pack->next_object) {
499 pack = pack->next_object;
500 if (pack->what_is & mask) {
508 is_pack_letter(short *c, unsigned short *mask)
510 if (((*c == '?') || (*c == '!') || (*c == ':') || (*c == '=') ||
511 (*c == ')') || (*c == ']') || (*c == '/') || (*c == ','))) {
541 return(((*c >= 'a') && (*c <= 'z')) || (*c == CANCEL) || (*c == LIST));
547 return(mask_pack(&rogue.pack, AMULET));
557 if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
558 message("nothing here", 0);
560 if ((obj = pick_up(rogue.row, rogue.col, &stat)) != NULL) {
562 if (obj->what_is == GOLD) {
568 desc[n+1] = obj->ichar;
574 if (obj || (!stat)) {