+/* $NetBSD: object.c,v 1.14 2009/08/12 08:44:45 dholland Exp $ */
+
/*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Timothy C. Stoehr.
* 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.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)object.c 5.3 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: object.c,v 1.2 1993/08/01 18:52:21 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)object.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: object.c,v 1.14 2009/08/12 08:44:45 dholland Exp $");
+#endif
#endif /* not lint */
/*
object level_objects;
unsigned short dungeon[DROWS][DCOLS];
short foods = 0;
-object *free_list = (object *) 0;
-char *fruit = (char *) 0;
+char *fruit = NULL;
+
+static object *free_list = NULL;
fighter rogue = {
- INIT_AW, /* armor, weapon */
- INIT_RINGS, /* rings */
- INIT_HP, /* Hp current,max */
- INIT_STR, /* Str current,max */
+ INIT_AW, /* armor */
+ INIT_AW, /* weapon */
+ INIT_RINGS, /* left ring */
+ INIT_RINGS, /* right ring */
+ INIT_HP, /* Hp current */
+ INIT_HP, /* Hp max */
+ INIT_STR, /* Str current */
+ INIT_STR, /* Str max */
INIT_PACK, /* pack */
INIT_GOLD, /* gold */
- INIT_EXP, /* exp level,points */
+ INIT_EXPLEVEL, /* exp level */
+ INIT_EXP, /* exp points */
0, 0, /* row, col */
INIT_CHAR, /* char */
INIT_MOVES /* moves */
};
struct id id_potions[POTIONS] = {
-{100, "blue \0 ", "of increase strength ", 0},
-{250, "red \0 ", "of restore strength ", 0},
-{100, "green \0 ", "of healing ", 0},
-{200, "grey \0 ", "of extra healing ", 0},
- {10, "brown \0 ", "of poison ", 0},
-{300, "clear \0 ", "of raise level ", 0},
- {10, "pink \0 ", "of blindness ", 0},
- {25, "white \0 ", "of hallucination ", 0},
-{100, "purple \0 ", "of detect monster ", 0},
-{100, "black \0 ", "of detect things ", 0},
- {10, "yellow \0 ", "of confusion ", 0},
- {80, "plaid \0 ", "of levitation ", 0},
-{150, "burgundy \0 ", "of haste self ", 0},
-{145, "beige \0 ", "of see invisible ", 0}
+{100, "blue ", "of increase strength ", 0},
+{250, "red ", "of restore strength ", 0},
+{100, "green ", "of healing ", 0},
+{200, "grey ", "of extra healing ", 0},
+ {10, "brown ", "of poison ", 0},
+{300, "clear ", "of raise level ", 0},
+ {10, "pink ", "of blindness ", 0},
+ {25, "white ", "of hallucination ", 0},
+{100, "purple ", "of detect monster ", 0},
+{100, "black ", "of detect things ", 0},
+ {10, "yellow ", "of confusion ", 0},
+ {80, "plaid ", "of levitation ", 0},
+{150, "burgundy ", "of haste self ", 0},
+{145, "beige ", "of see invisible ", 0}
};
struct id id_scrolls[SCROLS] = {
-{505, " ", "of protect armor ", 0},
-{200, " ", "of hold monster ", 0},
-{235, " ", "of enchant weapon ", 0},
-{235, " ", "of enchant armor ", 0},
-{175, " ", "of identify ", 0},
-{190, " ", "of teleportation ", 0},
- {25, " ", "of sleep ", 0},
-{610, " ", "of scare monster ", 0},
-{210, " ", "of remove curse ", 0},
- {80, " ", "of create monster ",0},
- {25, " ", "of aggravate monster ",0},
-{180, " ", "of magic mapping ", 0},
- {90, " ", "of confuse monster ", 0}
+{505, "", "of protect armor ", 0},
+{200, "", "of hold monster ", 0},
+{235, "", "of enchant weapon ", 0},
+{235, "", "of enchant armor ", 0},
+{175, "", "of identify ", 0},
+{190, "", "of teleportation ", 0},
+ {25, "", "of sleep ", 0},
+{610, "", "of scare monster ", 0},
+{210, "", "of remove curse ", 0},
+ {80, "", "of create monster ",0},
+ {25, "", "of aggravate monster ",0},
+{180, "", "of magic mapping ", 0},
+ {90, "", "of confuse monster ", 0}
};
struct id id_weapons[WEAPONS] = {
};
struct id id_wands[WANDS] = {
- {25, " ", "of teleport away ",0},
- {50, " ", "of slow monster ", 0},
- {8, " ", "of invisibility ",0},
- {55, " ", "of polymorph ",0},
- {2, " ", "of haste monster ",0},
- {20, " ", "of magic missile ",0},
- {20, " ", "of cancellation ",0},
- {0, " ", "of do nothing ",0},
- {35, " ", "of drain life ",0},
- {20, " ", "of cold ",0},
- {20, " ", "of fire ",0}
+ {25, "", "of teleport away ",0},
+ {50, "", "of slow monster ", 0},
+ {8, "", "of invisibility ",0},
+ {55, "", "of polymorph ",0},
+ {2, "", "of haste monster ",0},
+ {20, "", "of magic missile ",0},
+ {20, "", "of cancellation ",0},
+ {0, "", "of do nothing ",0},
+ {35, "", "of drain life ",0},
+ {20, "", "of cold ",0},
+ {20, "", "of fire ",0}
};
struct id id_rings[RINGS] = {
- {250, " ", "of stealth ",0},
- {100, " ", "of teleportation ", 0},
- {255, " ", "of regeneration ",0},
- {295, " ", "of slow digestion ",0},
- {200, " ", "of add strength ",0},
- {250, " ", "of sustain strength ",0},
- {250, " ", "of dexterity ",0},
- {25, " ", "of adornment ",0},
- {300, " ", "of see invisible ",0},
- {290, " ", "of maintain armor ",0},
- {270, " ", "of searching ",0},
+ {250, "", "of stealth ",0},
+ {100, "", "of teleportation ", 0},
+ {255, "", "of regeneration ",0},
+ {295, "", "of slow digestion ",0},
+ {200, "", "of add strength ",0},
+ {250, "", "of sustain strength ",0},
+ {250, "", "of dexterity ",0},
+ {25, "", "of adornment ",0},
+ {300, "", "of see invisible ",0},
+ {290, "", "of maintain armor ",0},
+ {270, "", "of searching ",0},
};
-extern short cur_level, max_level;
-extern short party_room;
-extern char *error_file;
-extern boolean is_wood[];
-
-put_objects()
+static void gr_armor(object *);
+static void gr_potion(object *);
+static void gr_scroll(object *);
+static void gr_wand(object *);
+static void gr_weapon(object *, int);
+static unsigned short gr_what_is(void);
+static void make_party(void);
+static void plant_gold(short, short, boolean);
+static void put_gold(void);
+static void rand_place(object *);
+
+void
+put_objects(void)
{
short i, n;
object *obj;
put_gold();
}
-put_gold()
+static void
+put_gold(void)
{
short i, j;
short row,col;
}
}
-plant_gold(row, col, is_maze)
-short row, col;
-boolean is_maze;
+static void
+plant_gold(short row, short col, boolean is_maze)
{
object *obj;
obj->quantity += obj->quantity / 2;
}
dungeon[row][col] |= OBJECT;
- (void) add_to_pack(obj, &level_objects, 0);
+ (void)add_to_pack(obj, &level_objects, 0);
}
-place_at(obj, row, col)
-object *obj;
+void
+place_at(object *obj, int row, int col)
{
obj->row = row;
obj->col = col;
dungeon[row][col] |= OBJECT;
- (void) add_to_pack(obj, &level_objects, 0);
+ (void)add_to_pack(obj, &level_objects, 0);
}
object *
-object_at(pack, row, col)
-register object *pack;
-short row, col;
+object_at(object *pack, short row, short col)
{
- object *obj = (object *) 0;
+ object *obj = NULL;
if (dungeon[row][col] & (MONSTER | OBJECT)) {
obj = pack->next_object;
obj = obj->next_object;
}
if (!obj) {
- message("object_at(): inconsistent", 1);
+ messagef(1, "object_at(): inconsistent");
}
}
return(obj);
}
object *
-get_letter_object(ch)
+get_letter_object(int ch)
{
object *obj;
return(obj);
}
-free_stuff(objlist)
-object *objlist;
+void
+free_stuff(object *objlist)
{
object *obj;
}
}
-char *
-name_of(obj)
-object *obj;
+const char *
+name_of(const object *obj)
{
- char *retstring;
+ const char *retstring;
switch(obj->what_is) {
case SCROL:
}
object *
-gr_object()
+gr_object(void)
{
object *obj;
return(obj);
}
-unsigned short
-gr_what_is()
+static unsigned short
+gr_what_is(void)
{
short percent;
unsigned short what_is;
return(what_is);
}
-gr_scroll(obj)
-object *obj;
+static void
+gr_scroll(object *obj)
{
short percent;
}
}
-gr_potion(obj)
-object *obj;
+static void
+gr_potion(object *obj)
{
short percent;
}
}
-gr_weapon(obj, assign_wk)
-object *obj;
-int assign_wk;
+static void
+gr_weapon(object *obj, int assign_wk)
{
short percent;
short i;
obj->which_kind = get_rand(0, (WEAPONS - 1));
}
if ((obj->which_kind == ARROW) || (obj->which_kind == DAGGER) ||
- (obj->which_kind == SHURIKEN) | (obj->which_kind == DART)) {
+ (obj->which_kind == SHURIKEN) || (obj->which_kind == DART)) {
obj->quantity = get_rand(3, 15);
obj->quiver = get_rand(0, 126);
} else {
percent = get_rand(1, 96);
blessing = get_rand(1, 3);
- if (percent <= 16) {
- increment = 1;
- } else if (percent <= 32) {
- increment = -1;
- obj->is_cursed = 1;
- }
if (percent <= 32) {
+ if (percent <= 16) {
+ increment = 1;
+ } else {
+ increment = -1;
+ obj->is_cursed = 1;
+ }
for (i = 0; i < blessing; i++) {
if (coin_toss()) {
obj->hit_enchant += increment;
}
}
-gr_armor(obj)
-object *obj;
+static void
+gr_armor(object *obj)
{
short percent;
short blessing;
}
}
-gr_wand(obj)
-object *obj;
+static void
+gr_wand(object *obj)
{
obj->what_is = WAND;
obj->which_kind = get_rand(0, (WANDS - 1));
obj->class = get_rand(3, 7);
}
-get_food(obj, force_ration)
-object *obj;
-boolean force_ration;
+void
+get_food(object *obj, boolean force_ration)
{
obj->what_is = FOOD;
}
}
-put_stairs()
+void
+put_stairs(void)
{
short row, col;
dungeon[row][col] |= STAIRS;
}
-get_armor_class(obj)
-object *obj;
+int
+get_armor_class(const object *obj)
{
if (obj) {
return(obj->class + obj->d_enchant);
}
object *
-alloc_object()
+alloc_object(void)
{
object *obj;
if (free_list) {
obj = free_list;
free_list = free_list->next_object;
- } else if (!(obj = (object *) md_malloc(sizeof(object)))) {
- message("cannot allocate object, saving game", 0);
+ } else if (!(obj = md_malloc(sizeof(object)))) {
+ messagef(0, "cannot allocate object, saving game");
save_into_file(error_file);
+ clean_up("alloc_object: save failed");
}
obj->quantity = 1;
obj->ichar = 'L';
return(obj);
}
-free_object(obj)
-object *obj;
+void
+free_object(object *obj)
{
obj->next_object = free_list;
free_list = obj;
}
-make_party()
+static void
+make_party(void)
{
short n;
}
}
-show_objects()
+void
+show_objects(void)
{
object *obj;
short mc, rc, row, col;
rc = get_mask_char(obj->what_is);
if (dungeon[row][col] & MONSTER) {
- if (monster = object_at(&level_monsters, row, col)) {
+ if ((monster =
+ object_at(&level_monsters, row, col)) != NULL) {
monster->trail_char = rc;
}
}
while (monster) {
if (monster->m_flags & IMITATES) {
- mvaddch(monster->row, monster->col, (int) monster->disguise);
+ mvaddch(monster->row, monster->col, (int)monster->disguise);
}
monster = monster->next_monster;
}
}
-put_amulet()
+void
+put_amulet(void)
{
object *obj;
rand_place(obj);
}
-rand_place(obj)
-object *obj;
+static void
+rand_place(object *obj)
{
short row, col;
place_at(obj, row, col);
}
-c_object_for_wizard()
+void
+c_object_for_wizard(void)
{
short ch, max, wk;
object *obj;
char buf[80];
- if (pack_count((object *) 0) >= MAX_PACK_COUNT) {
- message("pack full", 0);
+ max = 0;
+ if (pack_count(NULL) >= MAX_PACK_COUNT) {
+ messagef(0, "pack full");
return;
}
- message("type of object?", 0);
+ messagef(0, "type of object?");
while (r_index("!?:)]=/,\033", (ch = rgetchar()), 0) == -1) {
sound_bell();
}
if ((ch != ',') && (ch != ':')) {
GIL:
- if (get_input_line("which kind?", "", buf, "", 0, 1)) {
+ if (get_input_line("which kind?", "", buf, sizeof(buf), "", 0, 1)) {
wk = get_number(buf);
if ((wk >= 0) && (wk <= max)) {
- obj->which_kind = (unsigned short) wk;
+ obj->which_kind = wk;
if (obj->what_is == RING) {
gr_ring(obj, 0);
}
return;
}
}
- get_desc(obj, buf);
- message(buf, 0);
- (void) add_to_pack(obj, &rogue.pack, 1);
+ get_desc(obj, buf, sizeof(buf));
+ messagef(0, "%s", buf);
+ (void)add_to_pack(obj, &rogue.pack, 1);
}