-/* $NetBSD: pack.c,v 1.5 1998/09/11 14:10:39 hubertf Exp $ */
+/* $NetBSD: pack.c,v 1.12 2011/05/23 23:01:17 joerg Exp $ */
/*
* Copyright (c) 1988, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#if 0
static char sccsid[] = "@(#)pack.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pack.c,v 1.5 1998/09/11 14:10:39 hubertf Exp $");
+__RCSID("$NetBSD: pack.c,v 1.12 2011/05/23 23:01:17 joerg Exp $");
#endif
#endif /* not lint */
#include "rogue.h"
-char *curse_message = "you can't, it appears to be cursed";
+const char curse_message[] = "you can't, it appears to be cursed";
+
+static object *check_duplicate(object *, object *);
+static boolean is_pack_letter(short *, unsigned short *);
+static boolean mask_pack(const object *, unsigned short);
+static short next_avail_ichar(void);
object *
-add_to_pack(obj, pack, condense)
- object *obj, *pack;
- int condense;
+add_to_pack(object *obj, object *pack, int condense)
{
object *op;
}
void
-take_from_pack(obj, pack)
- object *obj, *pack;
+take_from_pack(object *obj, object *pack)
{
while (pack->next_object != obj) {
pack = pack->next_object;
*/
object *
-pick_up(row, col, status)
- short *status;
- int row, col;
+pick_up(int row, int col, short *status)
{
object *obj;
*status = 1;
if (levitate) {
- message("you're floating in the air!", 0);
- return((object *) 0);
+ messagef(0, "you're floating in the air!");
+ return NULL;
}
obj = object_at(&level_objects, row, col);
if (!obj) {
- message("pick_up(): inconsistent", 1);
+ messagef(1, "pick_up(): inconsistent");
return(obj);
}
if ( (obj->what_is == SCROL) &&
(obj->which_kind == SCARE_MONSTER) &&
obj->picked_up) {
- message("the scroll turns to dust as you pick it up", 0);
+ messagef(0, "the scroll turns to dust as you pick it up");
dungeon[row][col] &= (~OBJECT);
vanish(obj, 0, &level_objects);
*status = 0;
if (id_scrolls[SCARE_MONSTER].id_status == UNIDENTIFIED) {
id_scrolls[SCARE_MONSTER].id_status = IDENTIFIED;
}
- return((object *) 0);
+ return NULL;
}
if (obj->what_is == GOLD) {
rogue.gold += obj->quantity;
return(obj); /* obj will be free_object()ed in caller */
}
if (pack_count(obj) >= MAX_PACK_COUNT) {
- message("pack too full", 1);
- return((object *) 0);
+ messagef(1, "pack too full");
+ return NULL;
}
dungeon[row][col] &= ~(OBJECT);
take_from_pack(obj, &level_objects);
}
void
-drop()
+drop(void)
{
object *obj, *new;
short ch;
char desc[DCOLS];
if (dungeon[rogue.row][rogue.col] & (OBJECT | STAIRS | TRAP)) {
- message("there's already something there", 0);
+ messagef(0, "there's already something there");
return;
}
if (!rogue.pack.next_object) {
- message("you have nothing to drop", 0);
+ messagef(0, "you have nothing to drop");
return;
}
if ((ch = pack_letter("drop what?", ALL_OBJECTS)) == CANCEL) {
return;
}
if (!(obj = get_letter_object(ch))) {
- message("no such item.", 0);
+ messagef(0, "no such item.");
return;
}
if (obj->in_use_flags & BEING_WIELDED) {
if (obj->is_cursed) {
- message(curse_message, 0);
+ messagef(0, "%s", curse_message);
return;
}
unwield(rogue.weapon);
} else if (obj->in_use_flags & BEING_WORN) {
if (obj->is_cursed) {
- message(curse_message, 0);
+ messagef(0, "%s", curse_message);
return;
}
mv_aquatars();
print_stats(STAT_ARMOR);
} else if (obj->in_use_flags & ON_EITHER_HAND) {
if (obj->is_cursed) {
- message(curse_message, 0);
+ messagef(0, "%s", curse_message);
return;
}
un_put_on(obj);
take_from_pack(obj, &rogue.pack);
}
place_at(obj, rogue.row, rogue.col);
- (void) strcpy(desc, "dropped ");
- get_desc(obj, desc+8);
- message(desc, 0);
- (void) reg_move();
+ get_desc(obj, desc, sizeof(desc));
+ messagef(0, "dropped %s", desc);
+ (void)reg_move();
}
-object *
-check_duplicate(obj, pack)
- object *obj, *pack;
+static object *
+check_duplicate(object *obj, object *pack)
{
object *op;
op = pack->next_object;
while (op) {
- if ((op->what_is == obj->what_is) &&
+ if ((op->what_is == obj->what_is) &&
(op->which_kind == obj->which_kind)) {
if ((obj->what_is != WEAPON) ||
return(0);
}
-short
-next_avail_ichar()
+static short
+next_avail_ichar(void)
{
object *obj;
int i;
}
obj = rogue.pack.next_object;
while (obj) {
- ichars[(obj->ichar - 'a')] = 1;
+ if (obj->ichar >= 'a' && obj->ichar <= 'z') {
+ ichars[(obj->ichar - 'a')] = 1;
+ }
obj = obj->next_object;
}
for (i = 0; i < 26; i++) {
}
void
-wait_for_ack()
+wait_for_ack(void)
{
- while (rgetchar() != ' ') ;
+ while (rgetchar() != ' ')
+ ;
}
short
-pack_letter(prompt, mask)
- char *prompt;
- unsigned short mask;
+pack_letter(const char *prompt, unsigned short mask)
{
short ch;
unsigned short tmask = mask;
if (!mask_pack(&rogue.pack, mask)) {
- message("nothing appropriate", 0);
+ messagef(0, "nothing appropriate");
return(CANCEL);
}
for (;;) {
- message(prompt, 0);
+ messagef(0, "%s", prompt);
for (;;) {
ch = rgetchar();
}
void
-take_off()
+take_off(void)
{
char desc[DCOLS];
object *obj;
if (rogue.armor) {
if (rogue.armor->is_cursed) {
- message(curse_message, 0);
+ messagef(0, "%s", curse_message);
} else {
mv_aquatars();
obj = rogue.armor;
unwear(rogue.armor);
- (void) strcpy(desc, "was wearing ");
- get_desc(obj, desc+12);
- message(desc, 0);
+ get_desc(obj, desc, sizeof(desc));
+ messagef(0, "was wearing %s", desc);
print_stats(STAT_ARMOR);
- (void) reg_move();
+ (void)reg_move();
}
} else {
- message("not wearing any", 0);
+ messagef(0, "not wearing any");
}
}
void
-wear()
+wear(void)
{
short ch;
object *obj;
char desc[DCOLS];
if (rogue.armor) {
- message("your already wearing some", 0);
+ messagef(0, "you're already wearing some");
return;
}
ch = pack_letter("wear what?", ARMOR);
return;
}
if (!(obj = get_letter_object(ch))) {
- message("no such item.", 0);
+ messagef(0, "no such item.");
return;
}
if (obj->what_is != ARMOR) {
- message("you can't wear that", 0);
+ messagef(0, "you can't wear that");
return;
}
obj->identified = 1;
- (void) strcpy(desc, "wearing ");
- get_desc(obj, desc + 8);
- message(desc, 0);
+ get_desc(obj, desc, sizeof(desc));
+ messagef(0, "wearing %s", desc);
do_wear(obj);
print_stats(STAT_ARMOR);
- (void) reg_move();
+ (void)reg_move();
}
void
-unwear(obj)
- object *obj;
+unwear(object *obj)
{
if (obj) {
obj->in_use_flags &= (~BEING_WORN);
}
- rogue.armor = (object *) 0;
+ rogue.armor = NULL;
}
void
-do_wear(obj)
- object *obj;
+do_wear(object *obj)
{
rogue.armor = obj;
obj->in_use_flags |= BEING_WORN;
}
void
-wield()
+wield(void)
{
short ch;
object *obj;
char desc[DCOLS];
if (rogue.weapon && rogue.weapon->is_cursed) {
- message(curse_message, 0);
+ messagef(0, "%s", curse_message);
return;
}
ch = pack_letter("wield what?", WEAPON);
return;
}
if (!(obj = get_letter_object(ch))) {
- message("No such item.", 0);
+ messagef(0, "No such item.");
return;
}
if (obj->what_is & (ARMOR | RING)) {
- sprintf(desc, "you can't wield %s",
+ messagef(0, "you can't wield %s",
((obj->what_is == ARMOR) ? "armor" : "rings"));
- message(desc, 0);
return;
}
if (obj->in_use_flags & BEING_WIELDED) {
- message("in use", 0);
+ messagef(0, "in use");
} else {
unwield(rogue.weapon);
- (void) strcpy(desc, "wielding ");
- get_desc(obj, desc + 9);
- message(desc, 0);
+ get_desc(obj, desc, sizeof(desc));
+ messagef(0, "wielding %s", desc);
do_wield(obj);
- (void) reg_move();
+ (void)reg_move();
}
}
void
-do_wield(obj)
- object *obj;
+do_wield(object *obj)
{
rogue.weapon = obj;
obj->in_use_flags |= BEING_WIELDED;
}
void
-unwield(obj)
- object *obj;
+unwield(object *obj)
{
if (obj) {
obj->in_use_flags &= (~BEING_WIELDED);
}
- rogue.weapon = (object *) 0;
+ rogue.weapon = NULL;
}
void
-call_it()
+call_it(void)
{
short ch;
object *obj;
return;
}
if (!(obj = get_letter_object(ch))) {
- message("no such item.", 0);
+ messagef(0, "no such item.");
return;
}
if (!(obj->what_is & (SCROL | POTION | WAND | RING))) {
- message("surely you already know what that's called", 0);
+ messagef(0, "surely you already know what that's called");
return;
}
id_table = get_id_table(obj);
- if (get_input_line("call it:","",buf,id_table[obj->which_kind].title,1,1)) {
+ if (get_input_line("call it:", "", buf, sizeof(buf),
+ id_table[obj->which_kind].title, 1, 1)) {
id_table[obj->which_kind].id_status = CALLED;
- (void) strcpy(id_table[obj->which_kind].title, buf);
+ (void)strlcpy(id_table[obj->which_kind].title, buf,
+ sizeof(id_table[obj->which_kind].title));
}
}
short
-pack_count(new_obj)
- object *new_obj;
+pack_count(const object *new_obj)
{
object *obj;
short count = 0;
return(count);
}
-boolean
-mask_pack(pack, mask)
- object *pack;
- unsigned short mask;
+static boolean
+mask_pack(const object *pack, unsigned short mask)
{
while (pack->next_object) {
pack = pack->next_object;
return(0);
}
-boolean
-is_pack_letter(c, mask)
- short *c;
- unsigned short *mask;
+static boolean
+is_pack_letter(short *c, unsigned short *mask)
{
if (((*c == '?') || (*c == '!') || (*c == ':') || (*c == '=') ||
(*c == ')') || (*c == ']') || (*c == '/') || (*c == ','))) {
}
boolean
-has_amulet()
+has_amulet(void)
{
return(mask_pack(&rogue.pack, AMULET));
}
void
-kick_into_pack()
+kick_into_pack(void)
{
object *obj;
char desc[DCOLS];
- short n, stat;
+ short stat;
if (!(dungeon[rogue.row][rogue.col] & OBJECT)) {
- message("nothing here", 0);
+ messagef(0, "nothing here");
} else {
if ((obj = pick_up(rogue.row, rogue.col, &stat)) != NULL) {
- get_desc(obj, desc);
+ get_desc(obj, desc, sizeof(desc));
if (obj->what_is == GOLD) {
- message(desc, 0);
+ messagef(0, "%s", desc);
free_object(obj);
} else {
- n = strlen(desc);
- desc[n] = '(';
- desc[n+1] = obj->ichar;
- desc[n+2] = ')';
- desc[n+3] = 0;
- message(desc, 0);
+ messagef(0, "%s(%c)", desc, obj->ichar);
}
}
if (obj || (!stat)) {
- (void) reg_move();
+ (void)reg_move();
}
}
}