From: Martin Read Date: Mon, 30 Sep 2013 21:05:45 +0000 (+0100) Subject: Replacing explicit -1's with NO_MON NO_OBJ etc. X-Git-Tag: printmsg-purged~59 X-Git-Url: http://git.blackswordsonics.com/?a=commitdiff_plain;h=11c7f4df6268b3b98fd710f469668b4241e3a3d2;p=victrix-abyssi Replacing explicit -1's with NO_MON NO_OBJ etc. --- diff --git a/combat.cc b/combat.cc index 2269e32..34aba70 100644 --- a/combat.cc +++ b/combat.cc @@ -36,7 +36,7 @@ int player_attack(int dy, int dx) { ushootm(dy, dx); } - else if (lvl.mons[u.y + dy][u.x + dx] != -1) + else if (lvl.mons[u.y + dy][u.x + dx] != NO_MON) { uhitm(lvl.mons[u.y + dy][u.x + dx]); } @@ -50,10 +50,10 @@ int player_attack(int dy, int dx) int uhitm(int mon) { - struct mon *mp; - struct obj *wep; + Mon *mp; + Obj *wep; struct permobj *pwep; - struct obj *ring; + Obj *ring; int tohit; int damage; int healing; @@ -67,7 +67,7 @@ int uhitm(int mon) print_msg("You hit "); print_mon_name(mon, 1); print_msg(".\n"); - if (u.weapon != -1) + if (u.weapon != NO_OBJ) { wep = objects + u.weapon; pwep = permobjs + wep->obj_id; @@ -77,7 +77,7 @@ int uhitm(int mon) { damage = u.body / 10; } - if (u.ring != -1) + if (u.ring != NO_OBJ) { ring = objects + u.ring; switch (ring->obj_id) @@ -114,7 +114,7 @@ int uhitm(int mon) } print_msg("You do %d damage.\n", damage); damage_mon(mon, damage, 1); - if (u.weapon != -1) + if (u.weapon != NO_OBJ) { damage_obj(u.weapon); } @@ -129,8 +129,8 @@ int ushootm(int sy, int sx) int range; int y, x; int done = 0; - struct mon *mptr; - struct obj *wep; + Mon *mptr; + Obj *wep; struct permobj *pwep; int damage; wep = objects + u.weapon; @@ -141,7 +141,7 @@ int ushootm(int sy, int sx) range = 1; for ( ; !done; (y += sy), (x += sx)) { - if (lvl.mons[y][x] != -1) + if (lvl.mons[y][x] != NO_MON) { done = 1; mptr = monsters + lvl.mons[y][x]; @@ -202,12 +202,12 @@ int mhitu(int mon, Damtyp dtype) int tohit; int damage; int unaffected; - struct mon *mptr = monsters + mon; + Mon *mptr = monsters + mon; tohit = zero_die(mptr->mtohit + 5); if (tohit < u.defence) { /* Note: Yes, all attacks can damage your armour. Deal. */ - if ((u.armour != -1) && (tohit > agility_modifier())) + if ((u.armour != NO_OBJ) && (tohit > agility_modifier())) { /* Monster hit your armour. */ print_msg("Your armour deflects "); @@ -304,8 +304,8 @@ test_unaffected: int mshootu(int mon) { - struct mon *mptr; - struct mon *bystander; + Mon *mptr; + Mon *bystander; int y; int x; int dy; @@ -343,7 +343,7 @@ int mshootu(int mon) /* Use agility-based defence for necromantic blasts and lightning * bolts */ evasion = u.agility * 100; - if (u.armour != -1) + if (u.armour != NO_OBJ) { evasion -= (u.agility * evasion_penalty(u.armour)); } @@ -412,7 +412,7 @@ int mshootu(int mon) print_msg("It misses you.\n"); } } - else if (lvl.mons[y][x] != -1) + else if (lvl.mons[y][x] != NO_MON) { done = 1; bystander = monsters + lvl.mons[y][x]; @@ -466,14 +466,16 @@ int throw_flask(int obj, int sy, int sx) { int i; int y, x; + int mon; for (i = 0, y = u.y, x = u.x; i < 10; ++i) { y += sy; x += sx; - if ((lvl.mons[y][x] != -1) && - (monsters[lvl.mons[y][x]].used)) + mon = lvl.mons[y][x]; + if ((mon != NO_MON) && + (monsters[mon].used)) { - struct mon *mptr = monsters + lvl.mons[y][x]; + Mon *mptr = monsters + lvl.mons[y][x]; switch (objects[obj].obj_id) { case PO_FLASK_WEAKNESS: diff --git a/display-nc.cc b/display-nc.cc index baba660..3e7c2c7 100644 --- a/display-nc.cc +++ b/display-nc.cc @@ -130,7 +130,7 @@ const cchar_t *front_buffer[DISP_HEIGHT][DISP_WIDTH]; /* Prototypes for static funcs */ static const cchar_t *object_char(int object_id); static const cchar_t *monster_char(int monster_id); -static const cchar_t *terrain_char(enum terrain_num terrain_type); +static const cchar_t *terrain_char(Terrain terrain_type); static void draw_status_line(void); static void draw_world(void); @@ -148,7 +148,7 @@ static void draw_status_line(void) mvwprintw(status_window, 1, 44, "Agility: %02d/%02d", u.agility - u.adam, u.agility); } -static const cchar_t *terrain_char(enum terrain_num terrain_type) +static const cchar_t *terrain_char(Terrain terrain_type) { return terrain_tiles + terrain_type; } @@ -186,13 +186,13 @@ void newsym(int y, int x) { back_buffer[y][x] = &player_tile; } - else if ((!show_terrain) && (lvl.mons[y][x] != -1) && mon_visible(lvl.mons[y][x])) + else if ((!show_terrain) && (lvl.mons[y][x] != NO_MON) && mon_visible(lvl.mons[y][x])) { back_buffer[y][x] = monster_char(monsters[lvl.mons[y][x]].mon_id); } else if (lvl.flags[y][x] & MAPFLAG_EXPLORED) { - if ((!show_terrain) && (lvl.objs[y][x] != -1)) + if ((!show_terrain) && (lvl.objs[y][x] != NO_OBJ)) { back_buffer[y][x] = object_char(objects[lvl.objs[y][x]].obj_id); } @@ -445,7 +445,7 @@ void update_inv(enum poclass_num filter) wattr_set(inventory_window, colour_attrs[Gcol_d_grey], Gcol_d_grey, NULL); for (i = 0; i < 19; i++) { - if (u.inventory[i] == -1) + if (u.inventory[i] == NO_OBJ) { wattr_set(inventory_window, colour_attrs[Gcol_d_grey], Gcol_d_grey, NULL); mvwprintw(inventory_window, i + 1, 0, "%c) -----\n", 'a' + i); @@ -486,7 +486,7 @@ int inv_select(enum poclass_num filter, const char *action, int accept_blank) for (i = 0; i < 19; i++) { - if ((u.inventory[i] != -1) && ((filter == POCLASS_NONE) || (permobjs[objects[u.inventory[i]].obj_id].poclass == filter))) + if ((u.inventory[i] != NO_OBJ) && ((filter == POCLASS_NONE) || (permobjs[objects[u.inventory[i]].obj_id].poclass == filter))) { items++; } @@ -545,7 +545,7 @@ tryagain: * set is a strict superset of ASCII. IF we're not, the * following code may break. */ selection = ch - 'a'; - if ((u.inventory[selection] != -1) && ((filter == POCLASS_NONE) || (permobjs[objects[u.inventory[selection]].obj_id].poclass == filter))) + if ((u.inventory[selection] != NO_OBJ) && ((filter == POCLASS_NONE) || (permobjs[objects[u.inventory[selection]].obj_id].poclass == filter))) { hide_inv(); return selection; diff --git a/main.cc b/main.cc index 9199267..bddcd19 100644 --- a/main.cc +++ b/main.cc @@ -89,8 +89,8 @@ void save_game(void) fwrite(lvl.terrain, 1, sizeof lvl.terrain, fp); fwrite(lvl.flags, 1, sizeof lvl.flags, fp); fwrite(permobjs, NUM_OF_PERMOBJS, sizeof (struct permobj), fp); - fwrite(monsters, MONSTERS_IN_PLAY, sizeof (struct mon), fp); - fwrite(objects, OBJECTS_IN_PLAY, sizeof (struct obj), fp); + fwrite(monsters, MONSTERS_IN_PLAY, sizeof (Mon), fp); + fwrite(objects, OBJECTS_IN_PLAY, sizeof (Obj), fp); /* Write out the depth */ fwrite(&depth, 1, sizeof depth, fp); /* Write out the player. */ @@ -114,8 +114,8 @@ void load_game(void) fread(lvl.terrain, 1, sizeof lvl.terrain, fp); fread(lvl.flags, 1, sizeof lvl.flags, fp); fread(permobjs, NUM_OF_PERMOBJS, sizeof (struct permobj), fp); - fread(monsters, MONSTERS_IN_PLAY, sizeof (struct mon), fp); - fread(objects, OBJECTS_IN_PLAY, sizeof (struct obj), fp); + fread(monsters, MONSTERS_IN_PLAY, sizeof (Mon), fp); + fread(objects, OBJECTS_IN_PLAY, sizeof (Obj), fp); rebuild_mapobjs(); rebuild_mapmons(); fread(&depth, 1, sizeof depth, fp); @@ -216,7 +216,7 @@ int do_command(enum game_cmd cmd) return 0; case GET_ITEM: - if (lvl.objs[u.y][u.x] != -1) + if (lvl.objs[u.y][u.x] != NO_OBJ) { attempt_pickup(); return 1; @@ -232,7 +232,7 @@ int do_command(enum game_cmd cmd) i = inv_select(POCLASS_WEAPON, "wield", 1); if (i == -2) { - u.weapon = -1; + u.weapon = NO_OBJ; print_msg("Weapon unwielded.\n"); } else if (i >= 0) @@ -271,7 +271,7 @@ int do_command(enum game_cmd cmd) return 0; case EMANATE_ARMOUR: - if (u.armour == -1) + if (u.armour == NO_OBJ) { print_msg("You are not wearing any armour.\n"); return 0; @@ -279,7 +279,7 @@ int do_command(enum game_cmd cmd) return emanate_armour(); case ZAP_WEAPON: - if (u.weapon == -1) + if (u.weapon == NO_OBJ) { print_msg("You have no weapon in hand.\n"); return 0; @@ -287,7 +287,7 @@ int do_command(enum game_cmd cmd) return zap_weapon(); case MAGIC_RING: - if (u.weapon == -1) + if (u.weapon == NO_OBJ) { print_msg("You are not wearing a ring.\n"); return 0; @@ -295,7 +295,7 @@ int do_command(enum game_cmd cmd) return magic_ring(); case TAKE_OFF_ARMOUR: - if (u.armour != -1) + if (u.armour != NO_OBJ) { if ((u.resistances[DT_FIRE] == RESIST_ARMOUR) && (lvl.terrain[u.y][u.x] == LAVA)) @@ -303,7 +303,7 @@ int do_command(enum game_cmd cmd) print_msg("Your armour is your only current source of fire\nresistance; removing it here would incinerate you.\n"); return 0; } - u.armour = -1; + u.armour = NO_OBJ; recalc_defence(); print_msg("You take off your armour.\n"); return 1; @@ -340,7 +340,7 @@ int do_command(enum game_cmd cmd) j = read_scroll(u.inventory[i]); if (j) { - u.inventory[i] = -1; + u.inventory[i] = NO_OBJ; } return 1; } @@ -353,7 +353,7 @@ int do_command(enum game_cmd cmd) j = eat_food(u.inventory[i]); if (j == -1) { - u.inventory[i] = -1; + u.inventory[i] = NO_OBJ; } return 1; } @@ -366,7 +366,7 @@ int do_command(enum game_cmd cmd) j = quaff_potion(u.inventory[i]); if (j) { - u.inventory[i] = -1; + u.inventory[i] = NO_OBJ; } return 1; } @@ -385,7 +385,7 @@ int do_command(enum game_cmd cmd) return 0; case REMOVE_RING: - if (u.ring == -1) + if (u.ring == NO_OBJ) { print_msg("You have no ring to remove!\n"); return 0; @@ -403,11 +403,11 @@ int do_command(enum game_cmd cmd) else { print_msg("You remove your ring.\n"); - u.ring = -1; + u.ring = NO_OBJ; } return 1; case PUT_ON_RING: - if (u.ring != -1) + if (u.ring != NO_OBJ) { print_msg("You are already wearing a ring.\n"); return 0; @@ -424,7 +424,7 @@ int do_command(enum game_cmd cmd) return 0; case INSPECT_ITEM: i = inv_select(POCLASS_NONE, "inspect", 0); - if ((i >= 0) && (u.inventory[i] != -1)) + if ((i >= 0) && (u.inventory[i] != NO_OBJ)) { describe_object(u.inventory[i]); } @@ -464,7 +464,7 @@ int do_command(enum game_cmd cmd) print_msg("1d32-1: %d %d %d %d %d %d %d %d\n", zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32), zero_die(32)); return 0; case DROP_ITEM: - if (lvl.objs[u.y][u.x] != -1) + if (lvl.objs[u.y][u.x] != NO_OBJ) { print_msg("There is already an item here.\n"); return 0; @@ -472,7 +472,7 @@ int do_command(enum game_cmd cmd) i = inv_select(POCLASS_NONE, "drop", 0); if (i >= 0) { - if ((u.inventory[i] != -1) && + if ((u.inventory[i] != NO_OBJ) && ((u.inventory[i] == u.ring) || (u.inventory[i] == u.armour))) { diff --git a/map.cc b/map.cc index 0cb720a..67e02ca 100644 --- a/map.cc +++ b/map.cc @@ -356,7 +356,7 @@ static int excavation_write(int y, int x, void *data) { if (lvl.terrain[y][x] == overwrite[j]) { - lvl.terrain[y][x] = (terrain_num) newterr; + lvl.terrain[y][x] = (Terrain) newterr; return 1; } } @@ -443,7 +443,7 @@ int get_levgen_mon_floor(int *y, int *x) ty = exclusive_flat(0, DUN_HEIGHT - 1); tx = exclusive_flat(0, DUN_WIDTH - 1); if ((lvl.terrain[ty][tx] != FLOOR) || - (lvl.mons[ty][tx] != -1)) + (lvl.mons[ty][tx] != NO_MON)) { ty = -1; tx = -1; @@ -505,7 +505,7 @@ void inject_player(void) { continue; } - if (lvl.mons[u.y][u.x] != -1) + if (lvl.mons[u.y][u.x] != NO_MON) { continue; } @@ -526,7 +526,7 @@ bool terrain_opacity[NUM_TERRAINS] = false, false, false, false }; -bool terrain_is_opaque(enum terrain_num terr) +bool terrain_is_opaque(Terrain terr) { return terrain_opacity[terr]; } diff --git a/map.hh b/map.hh index ffddbf4..e8064c8 100644 --- a/map.hh +++ b/map.hh @@ -34,7 +34,7 @@ #endif /* XXX enum terrain_num */ -enum terrain_num { +enum Terrain { // cheap hack: opaque terrain goes first, and walls very first. WALL = 0, HARDWALL, DOOR, FLOOR, ALTAR, STAIRS, LAVA, WATER }; @@ -76,7 +76,7 @@ struct level { int objs[DUN_HEIGHT][DUN_WIDTH]; int mons[DUN_HEIGHT][DUN_WIDTH]; - terrain_num terrain[DUN_HEIGHT][DUN_WIDTH]; + Terrain terrain[DUN_HEIGHT][DUN_WIDTH]; uint32_t flags[DUN_HEIGHT][DUN_WIDTH]; level_theme theme; level_layout layout; @@ -94,7 +94,7 @@ extern void build_level(void); extern void populate_level(void); extern void inject_player(void); extern void explore_around(int y, int x); -extern bool terrain_is_opaque(enum terrain_num terr); +extern bool terrain_is_opaque(Terrain terr); #endif /* map.h */ diff --git a/mon2.cc b/mon2.cc index 5519d8e..4c96c09 100644 --- a/mon2.cc +++ b/mon2.cc @@ -723,7 +723,7 @@ void select_space(int *py, int *px, int dy, int dx, int selection_mode) void mon_acts(int mon) { - struct mon *mptr; + Mon *mptr; int dy, dx; int y, x; int sy, sx; @@ -742,17 +742,17 @@ void mon_acts(int mon) print_msg("Program disordered: monster in player's square.\n"); print_msg("Discarding misplaced monster.\n"); mptr->used = 0; - lvl.mons[y][x] = -1; + lvl.mons[y][x] = NO_MON; return; } if (lvl.mons[y][x] != mon) { print_msg("Program disordered: monster(s) misplaced.\n"); mptr->used = 0; - if (lvl.mons[y][x] != -1) + if (lvl.mons[y][x] != NO_MON) { monsters[lvl.mons[y][x]].used = 0; - lvl.mons[y][x] = -1; + lvl.mons[y][x] = NO_MON; } return; } diff --git a/monsters.cc b/monsters.cc index 1c1b0e1..b0fbfd5 100644 --- a/monsters.cc +++ b/monsters.cc @@ -30,7 +30,7 @@ #include "victrix-abyssi.hh" #include "monsters.hh" -struct mon monsters[100]; +Mon monsters[100]; static int reject_mon(int pm); int summoning(int y, int x, int how_many) @@ -49,7 +49,7 @@ int summoning(int y, int x, int how_many) dy = zero_die(3) - 1; dx = zero_die(3) - 1; if ((lvl.terrain[y + dy][x + dx] == FLOOR) && - (lvl.mons[y + dy][x + dx] == -1) && + (lvl.mons[y + dy][x + dx] == NO_MON) && ((y + dy != u.y) || (x + dx != u.x))) { pmon = get_random_pmon(); @@ -59,7 +59,7 @@ int summoning(int y, int x, int how_many) continue; } mon = create_mon(-1, y + dy, x + dx); - if (mon != -1) + if (mon != NO_MON) { created++; break; @@ -100,7 +100,7 @@ int get_random_pmon(void) int create_mon(int pm_idx, int y, int x) { int mon; - if (lvl.mons[y][x] != -1) + if (lvl.mons[y][x] != NO_MON) { print_msg("Attempt to create monster at occupied space %d %d\n", y, x); return -1; @@ -128,7 +128,7 @@ int create_mon(int pm_idx, int y, int x) monsters[mon].mtohit = permons[pm_idx].mtohit + ood(permons[pm_idx].power, 3); monsters[mon].defence = permons[pm_idx].defence + ood(permons[pm_idx].power, 3); monsters[mon].mdam = permons[pm_idx].mdam + ood(permons[pm_idx].power, 5); - if (permons[pm_idx].rdam != -1) + if (permons[pm_idx].rdam != NO_MON) { monsters[mon].rtohit = permons[pm_idx].rtohit + ood(permons[pm_idx].power, 3); monsters[mon].rdam = permons[pm_idx].rdam + ood(permons[pm_idx].power, 5); @@ -154,7 +154,7 @@ void death_drop(int mon) int x = monsters[mon].x; int dy, dx; int tryct; - while (((lvl.objs[y][x] != -1) || (lvl.terrain[y][x] != FLOOR)) && tryct < 100) + while (((lvl.objs[y][x] != NO_OBJ) || (lvl.terrain[y][x] != FLOOR)) && tryct < 100) { dy = zero_die(3) - 1; dx = zero_die(3) - 1; @@ -233,12 +233,12 @@ void death_drop(int mon) int mon_can_pass(int mon, int y, int x) { - enum terrain_num terr; + Terrain terr; if ((y < 0) || (x < 0) || (y >= DUN_HEIGHT) || (x >= DUN_WIDTH)) { return 0; } - if (lvl.mons[y][x] != -1) + if (lvl.mons[y][x] != NO_MON) { return 0; } @@ -321,7 +321,7 @@ void heal_mon(int mon, int amount, int cansee) void damage_mon(int mon, int amount, int by_you) { - struct mon *mptr; + Mon *mptr; mptr = monsters + mon; if (amount >= mptr->hpcur) { @@ -345,7 +345,7 @@ void damage_mon(int mon, int amount, int by_you) print_msg(" dies.\n"); } death_drop(mon); - lvl.mons[mptr->y][mptr->x] = -1; + lvl.mons[mptr->y][mptr->x] = NO_MON; newsym(mptr->y, mptr->x); mptr->used = 0; map_updated = 1; @@ -403,7 +403,7 @@ int teleport_mon(int mon) { y = exclusive_flat(0, DUN_HEIGHT - 1); x = exclusive_flat(0, DUN_WIDTH - 1); - if ((lvl.mons[y][x] == -1) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x))) + if ((lvl.mons[y][x] == NO_MON) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x))) { reloc_mon(mon, y, x); rval = 0; @@ -416,10 +416,10 @@ int teleport_mon(int mon) int knockback_mon(int mon, int sy, int sx, bool cansee, bool by_you) { /* 0 = blocked, 1 = knocked, 2 = killed */ - struct mon *mptr = monsters + mon; + Mon *mptr = monsters + mon; int y = mptr->y + sy; int x = mptr->x + sx; - enum terrain_num terr = lvl.terrain[y][x]; + Terrain terr = lvl.terrain[y][x]; if (mon_resists_knockback(mon)) { @@ -500,8 +500,8 @@ int knockback_mon(int mon, int sy, int sx, bool cansee, bool by_you) void reloc_mon(int mon, int y, int x) { - struct mon *mptr = monsters + mon; - lvl.mons[mptr->y][mptr->x] = -1; + Mon *mptr = monsters + mon; + lvl.mons[mptr->y][mptr->x] = NO_MON; newsym(mptr->y, mptr->x); mptr->y = y; mptr->x = x; @@ -511,7 +511,7 @@ void reloc_mon(int mon, int y, int x) void move_mon(int mon, int y, int x) { - struct mon *mptr; + Mon *mptr; if (!mon_can_pass(mon, y, x)) { print_msg("Warning: monster attempted an invalid move.\n"); @@ -534,11 +534,11 @@ void summon_demon_near(int y, int x) int i; y2 = y - 1 + zero_die(3); x2 = x - 1 + zero_die(3); - if ((lvl.terrain[y2][x2] == FLOOR) && (lvl.mons[y2][x2] == -1) && + if ((lvl.terrain[y2][x2] == FLOOR) && (lvl.mons[y2][x2] == NO_MON) && ((y2 != u.y) || (x2 != u.x))) { i = create_mon(PM_DEMON, y2, x2); - if (i != -1) + if (i != NO_MON) { print_msg("Another demon appears!\n"); } diff --git a/monsters.hh b/monsters.hh index 0154c63..d3798ef 100644 --- a/monsters.hh +++ b/monsters.hh @@ -84,7 +84,7 @@ extern struct permon permons[NUM_OF_PERMONS]; /* XXX struct mon */ #define MONSTERS_IN_PLAY 100 -struct mon { +struct Mon { int mon_id; int y; int x; @@ -102,7 +102,10 @@ struct mon { int next_summon; bool resists(Damtyp dt) const; }; -extern struct mon monsters[MONSTERS_IN_PLAY]; +extern Mon monsters[MONSTERS_IN_PLAY]; + +#define NO_MON (-1) +#define PLAYER_MON (-2) /* XXX monsters.c data and funcs */ extern void update_mon(int mon); diff --git a/objects.cc b/objects.cc index 91404a5..393df6c 100644 --- a/objects.cc +++ b/objects.cc @@ -30,7 +30,7 @@ #include "victrix-abyssi.hh" #include "monsters.hh" -struct obj objects[100]; +Obj objects[100]; int get_random_pobj(void); const char ring_colours[20][16] = { @@ -56,7 +56,7 @@ const char potion_colours[20][16] = { int read_scroll(int obj) { - struct obj *optr = objects + obj; + Obj *optr = objects + obj; int i; switch (optr->obj_id) { @@ -147,18 +147,18 @@ int consume_obj(int obj) } else { - u.armour = -1; + u.armour = NO_OBJ; } recalc_defence(); } else if (obj == u.weapon) { - u.weapon = -1; + u.weapon = NO_OBJ; recalc_defence(); } else if (obj == u.ring) { - u.ring = -1; + u.ring = NO_OBJ; recalc_defence(); } if (!objects[obj].used) @@ -167,7 +167,7 @@ int consume_obj(int obj) { if (u.inventory[i] == obj) { - u.inventory[i] = -1; + u.inventory[i] = NO_OBJ; break; } } @@ -180,7 +180,7 @@ int consume_obj(int obj) int eat_food(int obj) { - struct obj *optr = objects + obj; + Obj *optr = objects + obj; if (permobjs[optr->obj_id].poclass != POCLASS_FOOD) { print_msg("Error: attempt to eat non-food (%d)!\n", optr->obj_id); @@ -214,7 +214,7 @@ int eat_food(int obj) int quaff_potion(int obj) { - struct obj *optr = objects + obj; + Obj *optr = objects + obj; switch (optr->obj_id) { case PO_POT_BODY: @@ -460,7 +460,7 @@ int create_obj(int po_idx, int quantity, int with_you, int y, int x) void sprint_obj_name(char *buf, int obj, int len) { - struct obj *optr; + Obj *optr; struct permobj *poptr; optr = objects + obj; poptr = permobjs + optr->obj_id; @@ -485,7 +485,7 @@ void sprint_obj_name(char *buf, int obj, int len) void fprint_obj_name(FILE *fp, int obj) { - struct obj *optr; + Obj *optr; struct permobj *poptr; optr = objects + obj; poptr = permobjs + optr->obj_id; @@ -510,7 +510,7 @@ void fprint_obj_name(FILE *fp, int obj) void print_obj_name(int obj) { - struct obj *optr; + Obj *optr; struct permobj *poptr; optr = objects + obj; poptr = permobjs + optr->obj_id; @@ -535,18 +535,18 @@ void print_obj_name(int obj) int drop_obj(int inv_idx) { - struct obj *optr; + Obj *optr; optr = objects + u.inventory[inv_idx]; - if (lvl.objs[u.y][u.x] == -1) + if (lvl.objs[u.y][u.x] == NO_OBJ) { optr->y = u.y; optr->x = u.x; lvl.objs[u.y][u.x] = u.inventory[inv_idx]; if (u.weapon == u.inventory[inv_idx]) { - u.weapon = -1; + u.weapon = NO_OBJ; } - u.inventory[inv_idx] = -1; + u.inventory[inv_idx] = NO_OBJ; optr->with_you = 0; print_msg("You drop "); print_obj_name(lvl.objs[u.y][u.x]); @@ -589,7 +589,7 @@ void attempt_pickup(void) print_msg(".\nYou now have\n"); objects[u.inventory[i]].quan += objects[lvl.objs[u.y][u.x]].quan; objects[lvl.objs[u.y][u.x]].used = 0; - lvl.objs[u.y][u.x] = -1; + lvl.objs[u.y][u.x] = NO_OBJ; print_msg("%c) ", 'a' + i); print_obj_name(u.inventory[i]); print_msg("\n"); @@ -599,7 +599,7 @@ void attempt_pickup(void) } for (i = 0; i < 19; i++) { - if (u.inventory[i] == -1) + if (u.inventory[i] == NO_OBJ) { break; } @@ -610,7 +610,7 @@ void attempt_pickup(void) return; } u.inventory[i] = lvl.objs[u.y][u.x]; - lvl.objs[u.y][u.x] = -1; + lvl.objs[u.y][u.x] = NO_OBJ; objects[u.inventory[i]].with_you = 1; objects[u.inventory[i]].x = -1; objects[u.inventory[i]].y = -1; @@ -681,7 +681,7 @@ void damage_obj(int obj) void describe_object(int obj) { - struct obj *optr; + Obj *optr; struct permobj *poptr; print_obj_name(obj); optr = objects + obj; @@ -727,7 +727,7 @@ int evasion_penalty(int obj) int magic_ring(void) { - struct obj *optr = objects + u.ring; + Obj *optr = objects + u.ring; switch (optr->obj_id) { case PO_RING_TELEPORT: @@ -747,7 +747,7 @@ int magic_ring(void) int emanate_armour(void) { - struct obj *optr = objects + u.armour; + Obj *optr = objects + u.armour; switch (optr->obj_id) { case PO_RIBBONS: @@ -776,7 +776,7 @@ int emanate_armour(void) int zap_weapon(void) { - struct obj *optr = objects + u.weapon; + Obj *optr = objects + u.weapon; switch (optr->obj_id) { case PO_STAFF_OF_FIRE: @@ -797,9 +797,9 @@ int zap_weapon(void) { continue; } - if (lvl.mons[y][x] != -1) + if (lvl.mons[y][x] != NO_MON) { - struct mon *mptr = monsters + lvl.mons[y][x]; + Mon *mptr = monsters + lvl.mons[y][x]; if (!pmon_resists_fire(mptr->mon_id)) { print_mon_name(lvl.mons[y][x], 3); diff --git a/objects.hh b/objects.hh index fca5008..61050ec 100644 --- a/objects.hh +++ b/objects.hh @@ -93,10 +93,10 @@ struct permobj { }; extern struct permobj permobjs[NUM_OF_PERMOBJS]; -/* XXX struct obj */ +/* XXX Obj */ #define OBJ_MAX_DUR 100 #define OBJECTS_IN_PLAY 100 -struct obj { +struct Obj { int obj_id; int quan; int with_you; /* Preserved when item DB is reaped on level change. */ @@ -105,7 +105,9 @@ struct obj { int used; /* Entry is occupied. */ int durability; /* Weapons and armour degrade with use. */ }; -extern struct obj objects[OBJECTS_IN_PLAY]; +extern Obj objects[OBJECTS_IN_PLAY]; + +#define NO_OBJ (-1) /* XXX objects.c data and funcs */ extern void flavours_init(void); diff --git a/sorcery.cc b/sorcery.cc index a2dc180..7e8b35f 100644 --- a/sorcery.cc +++ b/sorcery.cc @@ -68,7 +68,7 @@ int mon_use_sorcery(int mon) { /* Returns zero for no spell selected, -1 for unsupported spell * selected, 1 for supported spell selected. */ - struct mon *mptr = monsters + mon; + Mon *mptr = monsters + mon; int dy, dx; int sy, sx; enum monspell to_cast = MS_REJECT; diff --git a/u.cc b/u.cc index 67ea6c1..dda7516 100644 --- a/u.cc +++ b/u.cc @@ -42,7 +42,7 @@ void recalc_defence(void) u.resistances[i] &= RESIST_MASK_TEMPORARY; } u.speed = (u.leadfoot ? 0 : 1); - if (u.armour != -1) + if (u.armour != NO_OBJ) { u.defence = u.armourmelt ? 0 : permobjs[objects[u.armour].obj_id].power; u.defence += u.withering ? (u.agility / 10) : (u.agility / 5); @@ -63,7 +63,7 @@ void recalc_defence(void) { u.defence = u.withering ? (u.agility / 10) : (u.agility / 5); } - if (u.ring != -1) + if (u.ring != NO_OBJ) { switch (objects[u.ring].obj_id) { @@ -90,9 +90,9 @@ int move_player(int dy, int dx) print_msg("Attempted move out of bounds.\n"); return 0; /* No movement. */ } - if (lvl.mons[u.y + dy][u.x + dx] != -1) + if (lvl.mons[u.y + dy][u.x + dx] != NO_MON) { - if (u.weapon != -1) + if (u.weapon != NO_OBJ) { if ((objects[u.weapon].obj_id == PO_BOW) || (objects[u.weapon].obj_id == PO_CROSSBOW)) @@ -131,7 +131,7 @@ int move_player(int dy, int dx) return 0; } case WATER: - if ((u.ring != -1) && (objects[u.ring].obj_id == PO_RING_FROST)) + if ((u.ring != NO_OBJ) && (objects[u.ring].obj_id == PO_RING_FROST)) { if (lvl.terrain[u.y][u.x] != WATER) { @@ -163,7 +163,7 @@ int reloc_player(int y, int x) map_updated = 1; status_updated = 1; display_update(); - if (lvl.objs[y][x] != -1) + if (lvl.objs[y][x] != NO_OBJ) { print_msg("You see here "); print_obj_name(lvl.objs[y][x]); @@ -423,7 +423,7 @@ void write_char_dump(void) fprintf(fp, "Inventory:\n"); for (i = 0; i < 19; i++) { - if (u.inventory[i] != -1) + if (u.inventory[i] != NO_OBJ) { fprint_obj_name(fp, u.inventory[i]); fputc('\n', fp); @@ -484,14 +484,14 @@ void u_init(void) u.food = 2000; memset(u.inventory, -1, sizeof u.inventory); u.inventory[0] = create_obj(PO_DAGGER, 1, 1, -1, -1); - if (u.inventory[0] == -1) + if (u.inventory[0] == NO_OBJ) { print_msg("Couldn't create dagger!\n"); } u.inventory[1] = create_obj(PO_IRON_RATION, 1, 1, -1, -1); u.inventory[2] = create_obj(PO_BATTLE_BALLGOWN, 1, 1, -1, -1); u.weapon = u.inventory[0]; - u.ring = -1; + u.ring = NO_OBJ; u.armour = u.inventory[2]; recalc_defence(); } @@ -564,7 +564,7 @@ int teleport_u(void) { y = exclusive_flat(0, DUN_HEIGHT - 1); x = exclusive_flat(0, DUN_WIDTH - 1); - if ((lvl.mons[y][x] == -1) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x))) + if ((lvl.mons[y][x] == NO_MON) && (lvl.terrain[y][x] == FLOOR) && ((y != u.y) || (x != u.x))) { print_msg("You are whisked away!\n"); reloc_player(y, x);