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[] = "@(#)pack.c 8.1 (Berkeley) 5/31/93";
41 static const char rcsid[] =
42 "$FreeBSD: src/games/rogue/pack.c,v 1.8 1999/11/30 03:49:25 billf Exp $";
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
59 const char *curse_message = "you can't, it appears to be cursed";
61 extern short levitate;
64 add_to_pack(obj, pack, condense)
71 if (op = check_duplicate(obj, pack)) {
75 obj->ichar = next_avail_ichar();
78 if (pack->next_object == 0) {
79 pack->next_object = obj;
81 op = pack->next_object;
83 while (op->next_object) {
86 op->next_object = obj;
92 take_from_pack(obj, pack)
95 while (pack->next_object != obj) {
96 pack = pack->next_object;
98 pack->next_object = pack->next_object->next_object;
101 /* Note: *status is set to 0 if the rogue attempts to pick up a scroll
102 * of scare-monster and it turns to dust. *status is otherwise set to 1.
106 pick_up(row, col, status)
115 message("you're floating in the air!", 0);
116 return((object *) 0);
118 obj = object_at(&level_objects, row, col);
120 message("pick_up(): inconsistent", 1);
123 if ( (obj->what_is == SCROL) &&
124 (obj->which_kind == SCARE_MONSTER) &&
126 message("the scroll turns to dust as you pick it up", 0);
127 dungeon[row][col] &= (~OBJECT);
128 vanish(obj, 0, &level_objects);
130 if (id_scrolls[SCARE_MONSTER].id_status == UNIDENTIFIED) {
131 id_scrolls[SCARE_MONSTER].id_status = IDENTIFIED;
133 return((object *) 0);
135 if (obj->what_is == GOLD) {
136 rogue.gold += obj->quantity;
137 dungeon[row][col] &= ~(OBJECT);
138 take_from_pack(obj, &level_objects);
139 print_stats(STAT_GOLD);
140 return(obj); /* obj will be free_object()ed in caller */
142 if (pack_count(obj) >= MAX_PACK_COUNT) {
143 message("pack too full", 1);
144 return((object *) 0);
146 dungeon[row][col] &= ~(OBJECT);
147 take_from_pack(obj, &level_objects);
148 obj = add_to_pack(obj, &rogue.pack, 1);
159 if (dungeon[rogue.row][rogue.col] & (OBJECT | STAIRS | TRAP)) {
160 message("there's already something there", 0);
163 if (!rogue.pack.next_object) {
164 message("you have nothing to drop", 0);
167 if ((ch = pack_letter("drop what?", ALL_OBJECTS)) == CANCEL) {
170 if (!(obj = get_letter_object(ch))) {
171 message("no such item.", 0);
174 if (obj->in_use_flags & BEING_WIELDED) {
175 if (obj->is_cursed) {
176 message(curse_message, 0);
179 unwield(rogue.weapon);
180 } else if (obj->in_use_flags & BEING_WORN) {
181 if (obj->is_cursed) {
182 message(curse_message, 0);
187 print_stats(STAT_ARMOR);
188 } else if (obj->in_use_flags & ON_EITHER_HAND) {
189 if (obj->is_cursed) {
190 message(curse_message, 0);
195 obj->row = rogue.row;
196 obj->col = rogue.col;
198 if ((obj->quantity > 1) && (obj->what_is != WEAPON)) {
200 new = alloc_object();
206 take_from_pack(obj, &rogue.pack);
208 place_at(obj, rogue.row, rogue.col);
209 (void) strcpy(desc, "dropped ");
210 get_desc(obj, desc+8);
216 check_duplicate(obj, pack)
221 if (!(obj->what_is & (WEAPON | FOOD | SCROL | POTION))) {
224 if ((obj->what_is == FOOD) && (obj->which_kind == FRUIT)) {
227 op = pack->next_object;
230 if ((op->what_is == obj->what_is) &&
231 (op->which_kind == obj->which_kind)) {
233 if ((obj->what_is != WEAPON) ||
234 ((obj->what_is == WEAPON) &&
235 ((obj->which_kind == ARROW) ||
236 (obj->which_kind == DAGGER) ||
237 (obj->which_kind == DART) ||
238 (obj->which_kind == SHURIKEN)) &&
239 (obj->quiver == op->quiver))) {
240 op->quantity += obj->quantity;
244 op = op->next_object;
255 for (i = 0; i < 26; i++) {
258 obj = rogue.pack.next_object;
260 ichars[(obj->ichar - 'a')] = 1;
261 obj = obj->next_object;
263 for (i = 0; i < 26; i++) {
273 if (!isatty(0) || !isatty(1))
275 while (rgetchar() != ' ') ;
278 pack_letter(prompt, mask)
283 unsigned short tmask = mask;
285 if (!mask_pack(&rogue.pack, mask)) {
286 message("nothing appropriate", 0);
295 if (!is_pack_letter(&ch, &mask)) {
305 inventory(&rogue.pack, mask);
321 if (rogue.armor->is_cursed) {
322 message(curse_message, 0);
327 (void) strcpy(desc, "was wearing ");
328 get_desc(obj, desc+12);
330 print_stats(STAT_ARMOR);
334 message("not wearing any", 0);
345 message("your already wearing some", 0);
348 ch = pack_letter("wear what?", ARMOR);
353 if (!(obj = get_letter_object(ch))) {
354 message("no such item.", 0);
357 if (obj->what_is != ARMOR) {
358 message("you can't wear that", 0);
362 (void) strcpy(desc, "wearing ");
363 get_desc(obj, desc + 8);
366 print_stats(STAT_ARMOR);
374 obj->in_use_flags &= (~BEING_WORN);
376 rogue.armor = (object *) 0;
383 obj->in_use_flags |= BEING_WORN;
393 if (rogue.weapon && rogue.weapon->is_cursed) {
394 message(curse_message, 0);
397 ch = pack_letter("wield what?", WEAPON);
402 if (!(obj = get_letter_object(ch))) {
403 message("No such item.", 0);
406 if (obj->what_is & (ARMOR | RING)) {
407 sprintf(desc, "you can't wield %s",
408 ((obj->what_is == ARMOR) ? "armor" : "rings"));
412 if (obj->in_use_flags & BEING_WIELDED) {
413 message("in use", 0);
415 unwield(rogue.weapon);
416 (void) strcpy(desc, "wielding ");
417 get_desc(obj, desc + 9);
428 obj->in_use_flags |= BEING_WIELDED;
435 obj->in_use_flags &= (~BEING_WIELDED);
437 rogue.weapon = (object *) 0;
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 (void) strcpy(id_table[obj->which_kind].title, buf);
469 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(pack, mask)
500 while (pack->next_object) {
501 pack = pack->next_object;
502 if (pack->what_is & mask) {
509 is_pack_letter(c, mask)
511 unsigned short *mask;
513 if (((*c == '?') || (*c == '!') || (*c == ':') || (*c == '=') ||
514 (*c == ')') || (*c == ']') || (*c == '/') || (*c == ','))) {
544 return(((*c >= 'a') && (*c <= 'z')) || (*c == CANCEL) || (*c == LIST));
549 return(mask_pack(&rogue.pack, AMULET));
558 if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
559 message("nothing here", 0);
561 if (obj = pick_up(rogue.row, rogue.col, &stat)) {
563 if (obj->what_is == GOLD) {
569 desc[n+1] = obj->ichar;
575 if (obj || (!stat)) {