Miscellaneous refactoring - remove spurious field from permobj, kill magic numbers
authorMartin Read <martin@blackswordsonics.com>
Mon, 30 Sep 2013 22:16:59 +0000 (23:16 +0100)
committerMartin Read <martin@blackswordsonics.com>
Mon, 30 Sep 2013 22:16:59 +0000 (23:16 +0100)
15 files changed:
combat.cc
combat.hh
display-nc.cc
main.cc
map.cc
mon2.cc
monsters.cc
monsters.hh
objects.cc
objects.hh
permobj.cc
rng.cc
u.cc
vector.cc
victrix-abyssi.hh

index 34aba70..d8511da 100644 (file)
--- a/combat.cc
+++ b/combat.cc
@@ -30,7 +30,7 @@
 #include "combat.hh"
 #include "monsters.hh"
 
-int player_attack(int dy, int dx)
+Action_cost player_attack(int dy, int dx)
 {
     if ((objects[u.weapon].obj_id == PO_BOW) || (objects[u.weapon].obj_id == PO_CROSSBOW))
     {
@@ -43,9 +43,9 @@ int player_attack(int dy, int dx)
     else
     {
         print_msg("Nothing to attack.\n");
-        return 0;
+        return Cost_none;
     }
-    return 1;
+    return Cost_std;
 }
 
 int uhitm(int mon)
@@ -113,7 +113,7 @@ int uhitm(int mon)
         }
     }
     print_msg("You do %d damage.\n", damage);
-    damage_mon(mon, damage, 1);
+    damage_mon(mon, damage, true);
     if (u.weapon != NO_OBJ)
     {
         damage_obj(u.weapon);
@@ -160,7 +160,7 @@ int ushootm(int sy, int sx)
                     print_msg(".\n");
                     print_msg("You do %d damage.\n", damage);
                 }
-                damage_mon(lvl.mons[y][x], damage, 1);
+                damage_mon(lvl.mons[y][x], damage, true);
                 if ((mptr->used) && (wep->obj_id == PO_THUNDERBOW))
                 {
                     int kb = knockback_mon(lvl.mons[y][x], sy, sx, true, true);
@@ -455,72 +455,88 @@ int mshootu(int mon)
             if (tohit >= bystander->defence)
             {
                 damage = one_die(mptr->rdam);
-                damage_mon(lvl.mons[y][x], dtype, 0);
+                damage_mon(lvl.mons[y][x], dtype, false);
             }
         }
     }
     return 0;
 }
 
-int throw_flask(int obj, int sy, int sx)
+static void flask_effect_weakness(Mon *mptr)
+{
+    if (!pmon_is_undead(mptr->mon_id))
+    {
+        print_msg("Your foe shrivels and twists horribly.\n");
+        mptr->hpmax = (mptr->hpmax + 1) / 2;
+        mptr->hpcur = (mptr->hpcur + 1) / 2;
+    }
+    else
+    {
+        print_msg("What does not live cannot degenerate.\n");
+    }
+}
+
+static void flask_effect_poison(Mon *mptr)
+{
+    print_msg("Your foe is drenched in contact poison.\n");
+    if (!pmon_resists_poison(mptr->mon_id))
+    {
+        damage_mon(mptr - monsters, inclusive_flat((mptr->hpmax + 5) / 6, (mptr->hpmax + 2) / 3), true);
+    }
+    else
+    {
+        print_msg("... to little effect.\n");
+    }
+}
+static void flask_effect_fire(Mon *mptr)
+{
+    print_msg("Your foe is drenched in burning oil.\n");
+    if (!pmon_resists_fire(mptr->mon_id))
+    {
+        damage_mon(mptr - monsters, 15 + dice(5, 4), true);
+    }
+    else
+    {
+        print_msg("... to little effect.\n");
+    }
+}
+
+Action_cost throw_flask(int obj, int sy, int sx)
 {
     int i;
     int y, x;
     int mon;
+    void (*flask_effect)(Mon *);
+    switch (objects[obj].obj_id)
+    {
+    case PO_FLASK_WEAKNESS:
+        flask_effect = flask_effect_weakness;
+        break;
+    case PO_FLASK_POISON:
+        flask_effect = flask_effect_poison;
+        break;
+    case PO_FLASK_FIRE:
+        flask_effect = flask_effect_fire;
+        break;
+    default:
+        print_msg("internal error: attempt to throw non-flask.\n");
+        return Cost_none;
+    }
     for (i = 0, y = u.y, x = u.x; i < 10; ++i)
     {
         y += sy;
         x += sx;
         mon = lvl.mons[y][x];
-        if ((mon != NO_MON) &&
-            (monsters[mon].used))
+        if ((mon != NO_MON) && (monsters[mon].used))
         {
-            Mon *mptr = monsters + lvl.mons[y][x];
-            switch (objects[obj].obj_id)
-            {
-            case PO_FLASK_WEAKNESS:
-                if (!pmon_is_undead(mptr->mon_id))
-                {
-                    print_msg("Your foe shrivels and twists horribly.\n");
-                    mptr->hpmax = (mptr->hpmax + 1) / 2;
-                    mptr->hpcur = (mptr->hpcur + 1) / 2;
-                }
-                else
-                {
-                    print_msg("What does not live cannot degenerate.\n");
-                }
-                break;
-            case PO_FLASK_POISON:
-                print_msg("Your foe is drenched in contact poison.\n");
-                if (!pmon_resists_poison(mptr->mon_id))
-                {
-                    damage_mon(mptr - monsters, inclusive_flat((mptr->hpmax + 5) / 6, (mptr->hpmax + 2) / 3), 1);
-                }
-                else
-                {
-                    print_msg("... to little effect.\n");
-                }
-                break;
-            case PO_FLASK_FIRE:
-                print_msg("Your foe is drenched in burning oil.\n");
-                if (!pmon_resists_fire(mptr->mon_id))
-                {
-                    damage_mon(mptr - monsters, 15 + dice(5, 4), 1);
-                }
-                else
-                {
-                    print_msg("... to little effect.\n");
-                }
-                break;
-            default:
-                print_msg("internal error: attempt to throw non-flask.\n");
-                return 0;
-            }
+            Mon *mptr = monsters + mon;
+            flask_effect(mptr);
             consume_obj(obj);
-            return 1;
+            return Cost_std;
         }
     }
-    return 1;
+    print_msg("That would be a waste; there's nobody to throw it at.\n");
+    return Cost_std;
 }
 
 /* combat.c */
index 55e1668..caf5b96 100644 (file)
--- a/combat.hh
+++ b/combat.hh
@@ -37,8 +37,8 @@
 
 #define agility_modifier() (u.withering ? (u.agility / 10) : (u.agility / 5))
 /* XXX combat.c data and funcs */
-extern int throw_flask(int obj, int sy, int sx);
-extern int player_attack(int dy, int dx);
+extern Action_cost throw_flask(int obj, int sy, int sx);
+extern Action_cost player_attack(int dy, int dx);
 extern int mhitu(int mon, Damtyp dtyp);
 extern int uhitm(int mon);
 extern int mshootu(int mon);
index 3e7c2c7..af0086b 100644 (file)
@@ -494,7 +494,7 @@ int inv_select(enum poclass_num filter, const char *action, int accept_blank)
     if (items == 0)
     {
         print_msg("You have nothing to %s.\n", action);
-        return -1;
+        return SLOT_CANCEL;
     }
     wattrset(inventory_window, colour_attrs[Gcol_l_grey]);
     snprintf(msg, 58, "What do you want to %s?\n", action);
@@ -514,14 +514,14 @@ tryagain:
             reset_inventory_message();
             update_inv(POCLASS_NONE);
             hide_inv();
-            return -2;
+            return SLOT_NOTHING;
         }
     case 'x':
     case '\x1b':
     case ' ':
         hide_inv();
         print_msg("\nNever mind.\n");
-        return -1;
+        return SLOT_CANCEL;
     case 'a':
     case 'b':
     case 'c':
diff --git a/main.cc b/main.cc
index bddcd19..615113c 100644 (file)
--- a/main.cc
+++ b/main.cc
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <time.h>
+#include <limits.h>
+
+/* Coord/Offset constants */
+const Coord Nowhere = { INT_MIN, INT_MIN };
+const Offset North = { -1, 0 };
+const Offset Northeast = { -1, 1 };
+const Offset East = { 0, 1 };
+const Offset Southeast = { 1, 1 };
+const Offset South = { 1, 0 };
+const Offset Southwest = { 1, -1 };
+const Offset West = { 0, -1 };
+const Offset Northwest = { -1, -1 };
+const Offset Stationary = { 0, 0 };
 
 void save_game(void);
 static void load_game(void);
@@ -72,14 +85,7 @@ static void rebuild_mapobjs(void)
 
 unsigned int convert_range(int dy, int dx)
 {
-    int ady, adx;
-    ady = dy > 0 ? dy : -dy;
-    adx = dx > 0 ? dx : -dx;
-    if (ady > adx)
-    {
-        return ady;
-    }
-    return adx;
+    return std::max(myabs(dy), myabs(dx));
 }
 
 void save_game(void)
@@ -183,10 +189,12 @@ void new_game(void)
     print_msg("Initialisation complete.\n");
 }
 
-int do_command(enum game_cmd cmd)
+Action_cost do_command(enum game_cmd cmd)
 {
     int i;
     int j;
+    int slot;
+    Action_cost cost;
     int sy, sx;
     switch (cmd)
     {
@@ -213,68 +221,71 @@ int do_command(enum game_cmd cmd)
         {
             return player_attack(sy, sx);
         }
-        return 0;
+        return Cost_none;
 
     case GET_ITEM:
         if (lvl.objs[u.y][u.x] != NO_OBJ)
         {
             attempt_pickup();
-            return 1;
+            return Cost_std;
         }
         else
         {
             print_msg("Nothing to get.\n");
-            return 0;
+            return Cost_none;
         }
 
     case WIELD_WEAPON:
-        j = 0;
-        i = inv_select(POCLASS_WEAPON, "wield", 1);
-        if (i == -2)
+        cost = Cost_none;
+        slot = inv_select(POCLASS_WEAPON, "wield", 1);
+        if (slot == SLOT_NOTHING)
         {
             u.weapon = NO_OBJ;
             print_msg("Weapon unwielded.\n");
         }
-        else if (i >= 0)
+        else if (slot != SLOT_CANCEL)
         {
-            u.weapon = u.inventory[i];
-            j = 1;
+            u.weapon = u.inventory[slot];
+            cost = Cost_std;
             print_msg("Wielding ");
             print_obj_name(u.weapon);
             print_msg(".\n");
         }
-        return j;
+        return cost;
 
     case WEAR_ARMOUR:
-        if (u.armour >= 0)
+        cost = Cost_none;
+        if (u.armour != NO_OBJ)
         {
             print_msg("You are already wearing armour.\n");
-            return 0;
         }
-        i = inv_select(POCLASS_ARMOUR, "wear", 0);
-        if (i >= 0)
+        else
         {
-            u.armour = u.inventory[i];
-            recalc_defence();
-            if (objects[u.armour].obj_id == PO_RIBBONS)
-            {
-                print_msg("You grit your teeth, trying to get used to the tingle of\nthe ribbons' magic against your skin.\n");
-            }
-            else
+            slot = inv_select(POCLASS_ARMOUR, "wear", 0);
+            if (slot != SLOT_CANCEL)
             {
-                print_msg("Wearing ");
-                print_obj_name(u.armour);
-                print_msg(".\n");
+                u.armour = u.inventory[slot];
+                recalc_defence();
+                if (objects[u.armour].obj_id == PO_RIBBONS)
+                {
+                    print_msg("You grit your teeth, trying to get used to the tingle of\nthe ribbons' magic against your skin.\n");
+                }
+                else
+                {
+                    print_msg("Wearing ");
+                    print_obj_name(u.armour);
+                    print_msg(".\n");
+                }
+                cost = Cost_std;
             }
-            return 1;
         }
-        return 0;
+        return cost;
 
     case EMANATE_ARMOUR:
         if (u.armour == NO_OBJ)
         {
             print_msg("You are not wearing any armour.\n");
-            return 0;
+            return Cost_none;
         }
         return emanate_armour();
 
@@ -282,7 +293,7 @@ int do_command(enum game_cmd cmd)
         if (u.weapon == NO_OBJ)
         {
             print_msg("You have no weapon in hand.\n");
-            return 0;
+            return Cost_none;
         }
         return zap_weapon();
 
@@ -290,7 +301,7 @@ int do_command(enum game_cmd cmd)
         if (u.weapon == NO_OBJ)
         {
             print_msg("You are not wearing a ring.\n");
-            return 0;
+            return Cost_none;
         }
         return magic_ring();
 
@@ -301,22 +312,22 @@ int do_command(enum game_cmd cmd)
                 (lvl.terrain[u.y][u.x] == LAVA))
             {
                 print_msg("Your armour is your only current source of fire\nresistance; removing it here would incinerate you.\n");
-                return 0;
+                return Cost_none;
             }
             u.armour = NO_OBJ;
             recalc_defence();
             print_msg("You take off your armour.\n");
-            return 1;
+            return Cost_std;
         }
         else
         {
             print_msg("You aren't wearing any armour.\n");
-            return 0;
+            return Cost_none;
         }
 
     case GIVE_HELP:
         print_help();
-        return 0;
+        return Cost_none;
 
     case GO_DOWN_STAIRS:
         if (lvl.terrain[u.y][u.x] == STAIRS)
@@ -328,110 +339,108 @@ int do_command(enum game_cmd cmd)
         {
             print_msg("There are no stairs here.\n");
         }
-        return 0;
+        return Cost_none;
 
     case STAND_STILL:
-        return 1;
+        return Cost_std;
 
     case READ_SCROLL:
-        i = inv_select(POCLASS_SCROLL, "read", 0);
-        if (i >= 0)
+        slot = inv_select(POCLASS_SCROLL, "read", 0);
+        if (slot != SLOT_CANCEL)
         {
-            j = read_scroll(u.inventory[i]);
-            if (j)
-            {
-                u.inventory[i] = NO_OBJ;
-            }
-            return 1;
+            return read_scroll(u.inventory[slot]);
         }
-        return 0;
+        return Cost_none;
 
     case EAT_FOOD:
-        i = inv_select(POCLASS_FOOD, "eat", 0);
-        if (i >= 0)
+        slot = inv_select(POCLASS_FOOD, "eat", 0);
+        if (slot != SLOT_CANCEL)
         {
-            j = eat_food(u.inventory[i]);
+            j = eat_food(u.inventory[slot]);
             if (j == -1)
             {
-                u.inventory[i] = NO_OBJ;
+                u.inventory[slot] = NO_OBJ;
             }
-            return 1;
+            return Cost_std;
         }
-        return 0;
+        return Cost_none;
 
     case QUAFF_POTION:
-        i = inv_select(POCLASS_POTION, "quaff", 0);
-        if (i >= 0)
+        slot = inv_select(POCLASS_POTION, "quaff", 0);
+        if (slot != SLOT_CANCEL)
         {
-            j = quaff_potion(u.inventory[i]);
+            j = quaff_potion(u.inventory[slot]);
             if (j)
             {
-                u.inventory[i] = NO_OBJ;
+                u.inventory[slot] = NO_OBJ;
             }
-            return 1;
+            return Cost_std;
         }
-        return 0;
+        return Cost_none;
 
     case THROW_FLASK:
-        i = inv_select(POCLASS_FLASK, "throw", 0);
-        if (i >= 0)
+        slot = inv_select(POCLASS_FLASK, "throw", 0);
+        if (slot != SLOT_CANCEL)
         {
             j = select_dir(&sy, &sx);
             if (j != -1)
             {
-                return throw_flask(u.inventory[i], sy, sx);
+                return throw_flask(u.inventory[slot], sy, sx);
             }
         }
-        return 0;
+        return Cost_none;
 
     case REMOVE_RING:
         if (u.ring == NO_OBJ)
         {
             print_msg("You have no ring to remove!\n");
-            return 0;
+            return Cost_none;
         }
         else if ((lvl.terrain[u.y][u.x] == LAVA) && (u.resistances[DT_FIRE] == RESIST_RING))
         {
             print_msg("That ring is your only current source of fire resistance. Removing\nit here would incinerate you.\n");
-            return 0;
+            return Cost_none;
         }
         else if ((objects[u.ring].obj_id == PO_RING_FROST) && (lvl.terrain[u.y][u.x] == WATER))
         {
             print_msg("Since nobody ever taught you to swim, removing that ring\nhere would result in your death by drowning.\n");
-            return 0;
+            return Cost_none;
         }
         else
         {
             print_msg("You remove your ring.\n");
             u.ring = NO_OBJ;
         }
-        return 1;
+        return Cost_std;
     case PUT_ON_RING:
+        cost = Cost_none;
         if (u.ring != NO_OBJ)
         {
             print_msg("You are already wearing a ring.\n");
-            return 0;
         }
-        i = inv_select(POCLASS_RING, "put on", 0);
-        if (i >= 0)
+        else
         {
-            u.ring = u.inventory[i];
-            print_msg("You put on ");
-            print_obj_name(u.ring);
-            print_msg(".\n");
-            return 1;
+            slot = inv_select(POCLASS_RING, "put on", 0);
+            if (slot != SLOT_CANCEL)
+            {
+                u.ring = u.inventory[slot];
+                print_msg("You put on ");
+                print_obj_name(u.ring);
+                print_msg(".\n");
+                cost = Cost_std;
+            }
         }
-        return 0;
+        return cost;
     case INSPECT_ITEM:
-        i = inv_select(POCLASS_NONE, "inspect", 0);
-        if ((i >= 0) && (u.inventory[i] != NO_OBJ))
+        slot = inv_select(POCLASS_NONE, "inspect", 0);
+        if ((slot != SLOT_CANCEL) && (u.inventory[slot] != NO_OBJ))
         {
-            describe_object(u.inventory[i]);
+            describe_object(u.inventory[slot]);
         }
-        return 0;
+        return Cost_none;
     case EXAMINE_MONSTER:
         print_msg("Monster examination not implemented yet.\n");
-        return 0;
+        return Cost_none;
     case SHOW_TERRAIN:
         show_terrain = 1;
         touch_back_buffer();
@@ -441,7 +450,7 @@ int do_command(enum game_cmd cmd)
         show_terrain = 0;
         touch_back_buffer();
         display_update();
-        return 0;
+        return Cost_none;
     case RNG_TEST:
         {
             int odds = 0;
@@ -462,38 +471,38 @@ int do_command(enum game_cmd cmd)
         print_msg("1d2-1: %d %d %d %d %d %d %d %d\n", zero_die(2), zero_die(2), zero_die(2), zero_die(2), zero_die(2), zero_die(2), zero_die(2), zero_die(2));
         print_msg("1d8-1: %d %d %d %d %d %d %d %d\n", zero_die(8), zero_die(8), zero_die(8), zero_die(8), zero_die(8), zero_die(8), zero_die(8), zero_die(8));
         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;
+        return Cost_none;
     case DROP_ITEM:
+        cost = Cost_none;
         if (lvl.objs[u.y][u.x] != NO_OBJ)
         {
             print_msg("There is already an item here.\n");
-            return 0;
         }
-        i = inv_select(POCLASS_NONE, "drop", 0);
-        if (i >= 0)
+        else
         {
-            if ((u.inventory[i] != NO_OBJ) &&
-                ((u.inventory[i] == u.ring) ||
-                 (u.inventory[i] == u.armour)))
+            slot = inv_select(POCLASS_NONE, "drop", 0);
+            if (slot >= 0)
             {
-                print_msg("You cannot drop something you are wearing.\n");
-                return 0;
-            }
-            j = drop_obj(i);
-            if (j == -1)
-            {
-                return 0;
+                if ((u.inventory[slot] != NO_OBJ) &&
+                    ((u.inventory[slot] == u.ring) ||
+                     (u.inventory[slot] == u.armour)))
+                {
+                    print_msg("You cannot drop something you are wearing.\n");
+                }
+                else
+                {
+                    cost = drop_obj(slot);
+                }
             }
-            return 1;
         }
-        return 0;
+        return cost;
     case DUMP_CHARA:
         write_char_dump();
-        return 0;
+        return Cost_none;
     case SAVE_GAME:
         game_finished = 1;
         save_game();
-        return 0;
+        return Cost_none;
     case QUIT:
         j = getYN("Really quit?\n");
         if (j > 0)
@@ -504,7 +513,7 @@ int do_command(enum game_cmd cmd)
         {
             print_msg("Never mind.\n");
         }
-        return 0;
+        return Cost_none;
 
     case WIZARD_DESCEND:
         if (wizard_mode)
@@ -516,20 +525,23 @@ int do_command(enum game_cmd cmd)
         {
             print_msg("You aren't a wizard.\n");
         }
-        return 0;
+        return Cost_none;
 
     case WIZARD_LEVELUP:
         if (wizard_mode)
         {
-            gain_experience((lev_threshold(u.level) - u.experience) + 1);
+            if (lev_threshold(u.level) != INT_MAX)
+            {
+                gain_experience((lev_threshold(u.level) - u.experience) + 1);
+            }
         }
         else
         {
             print_msg("You aren't a wizard.\n");
         }
-        return 0;
+        return Cost_none;
     }
-    return 0;
+    return Cost_none;
 }
 
 void main_loop(void)
diff --git a/map.cc b/map.cc
index 67e02ca..4936251 100644 (file)
--- a/map.cc
+++ b/map.cc
@@ -50,11 +50,11 @@ void leave_level(void)
     for (i = 0; i < 100; i++)
     {
         /* Throw away each monster */
-        monsters[i].used = 0;
+        monsters[i].used = false;
         /* and each object not carried by the player */
         if (!objects[i].with_you)
         {
-            objects[i].used = 0;
+            objects[i].used = false;
         }
     }
     depth++;
diff --git a/mon2.cc b/mon2.cc
index 4c96c09..e3da689 100644 (file)
--- a/mon2.cc
+++ b/mon2.cc
@@ -729,7 +729,7 @@ void mon_acts(int mon)
     int sy, sx;
     int meleerange;
     int oncardinal;
-    int special_used = 0;
+    int special_used = false;
     mptr = monsters + mon;
     /* dy,dx == direction monster must go to reach you. */
     y = mptr->y;
@@ -741,24 +741,24 @@ void mon_acts(int mon)
     {
         print_msg("Program disordered: monster in player's square.\n");
         print_msg("Discarding misplaced monster.\n");
-        mptr->used = 0;
+        mptr->used = false;
         lvl.mons[y][x] = NO_MON;
         return;
     }
     if (lvl.mons[y][x] != mon)
     {
         print_msg("Program disordered: monster(s) misplaced.\n");
-        mptr->used = 0;
+        mptr->used = false;
         if (lvl.mons[y][x] != NO_MON)
         {
-            monsters[lvl.mons[y][x]].used = 0;
+            monsters[lvl.mons[y][x]].used = false;
             lvl.mons[y][x] = NO_MON;
         }
         return;
     }
     if (mon_visible(mon))
     {
-        mptr->awake = 1;
+        mptr->awake = true;
     }
     if (meleerange)
     {
index b0fbfd5..9f7b16d 100644 (file)
@@ -89,7 +89,7 @@ int get_random_pmon(void)
         pm = zero_die(NUM_OF_PERMONS);
         if (reject_mon(pm))
         {
-            pm = -1;
+            pm = NO_PMON;
             continue;
         }
         break;
@@ -103,22 +103,22 @@ int create_mon(int pm_idx, int y, int x)
     if (lvl.mons[y][x] != NO_MON)
     {
         print_msg("Attempt to create monster at occupied space %d %d\n", y, x);
-        return -1;
+        return NO_MON;
     }
-    if (pm_idx == -1)
+    if (pm_idx == NO_PMON)
     {
         pm_idx = get_random_pmon();
-        if (pm_idx == -1)
+        if (pm_idx == NO_PMON)
         {
-            return -1;
+            return NO_MON;
         }
     }
     for (mon = 0; mon < 100; mon++)
     {
-        if (monsters[mon].used == 0)
+        if (!monsters[mon].used)
         {
             monsters[mon].mon_id = pm_idx;
-            monsters[mon].used = 1;
+            monsters[mon].used = true;
             monsters[mon].y = y;
             monsters[mon].x = x;
             monsters[mon].ai_lasty = -1;
@@ -138,13 +138,13 @@ int create_mon(int pm_idx, int y, int x)
                 monsters[mon].rtohit = -1;
                 monsters[mon].rdam = -1;
             }
-            monsters[mon].awake = 0;
+            monsters[mon].awake = false;
             lvl.mons[y][x] = mon;
             newsym(y, x);
             return mon;
         }
     }
-    return -1;
+    return NO_MON;
 }
 
 void death_drop(int mon)
@@ -231,51 +231,47 @@ void death_drop(int mon)
     map_updated = 1;
 }
 
-int mon_can_pass(int mon, int y, int x)
+bool mon_can_pass(int mon, int y, int x)
 {
     Terrain terr;
     if ((y < 0) || (x < 0) || (y >= DUN_HEIGHT) || (x >= DUN_WIDTH))
     {
-        return 0;
+        return false;
     }
     if (lvl.mons[y][x] != NO_MON)
     {
-        return 0;
+        return false;
     }
     if ((y == u.y) && (x == u.x))
     {
         /* Sanity check! */
-        return 0;
+        return false;
     }
     if (mon_is_ethereal(mon))
     {
-        return 1;
+        return true;
     }
     terr = lvl.terrain[y][x];
     switch (terr)
     {
     case WALL:
     case HARDWALL:
-        return 0;
+        return false;
     case LAVA:
         if (!mon_can_fly(mon) && !mon_resists_fire(mon))
         {
-            return 0;
+            return false;
         }
         break;
     case WATER:
         if (!mon_can_fly(mon) && !mon_resists_drowning(mon))
         {
-            return 0;
+            return false;
         }
     default:
         break;
     }
-    if ((lvl.terrain[y][x] == WATER) && !mon_resists_drowning(mon))
-    {
-        return 0;
-    }
-    return 1;
+    return true;
 }
 
 void print_mon_name(int mon, int article)
@@ -319,7 +315,7 @@ void heal_mon(int mon, int amount, int cansee)
     }
 }
 
-void damage_mon(int mon, int amount, int by_you)
+void damage_mon(int mon, int amount, bool by_you)
 {
     Mon *mptr;
     mptr = monsters + mon;
@@ -549,12 +545,12 @@ void summon_demon_near(int y, int x)
     }
 }
 
-int mon_visible(int mon)
+bool mon_visible(int mon)
 {
     int dy, dx;
     if (monsters[mon].used == 0)
     {
-        return 0;
+        return false;
     }
     dy = monsters[mon].y - u.y;
     dx = monsters[mon].x - u.x;
@@ -564,7 +560,7 @@ int mon_visible(int mon)
     }
     else
     {
-        return 0;
+        return false;
     }
 }
 
index d3798ef..d2f2380 100644 (file)
@@ -82,6 +82,8 @@ struct permon {
 };
 extern struct permon permons[NUM_OF_PERMONS];
 
+#define NO_PMON (-1)
+
 /* XXX struct mon */
 #define MONSTERS_IN_PLAY 100
 struct Mon {
@@ -90,7 +92,7 @@ struct Mon {
     int x;
     int ai_lasty;       /* AI's belief about your last position. -1 == lost you. */
     int ai_lastx;       /* AI's belief about your last position. -1 == lost you. */
-    int used;
+    bool used;
     int hpmax;  /* Improved by OOD rating at 1:1. */
     int hpcur;  /* <= 0 is dead. */
     int mtohit; /* Improved by OOD rating at 1:3. */
@@ -98,7 +100,7 @@ struct Mon {
     int defence;        /* Improved by OOD rating at 1:3. */
     int mdam;   /* Improved by OOD rating at 1:5. */
     int rdam;   /* Improved by OOD rating at 1:5. */
-    int awake;
+    bool awake;
     int next_summon;
     bool resists(Damtyp dt) const;
 };
@@ -117,9 +119,9 @@ extern int create_mon(int pm_idx, int y, int x);
 extern int summoning(int y, int x, int how_many);
 extern int ood(int power, int ratio);
 extern int get_random_pmon(void);
-extern void damage_mon(int mon, int amount, int by_you);
-extern int mon_can_pass(int mon, int y, int x);
-extern int mon_visible(int mon);
+extern void damage_mon(int mon, int amount, bool by_you);
+extern bool mon_can_pass(int mon, int y, int x);
+extern bool mon_visible(int mon);
 extern int knockback_mon(int mon, int sy, int sx, bool cansee, bool by_you);
 extern void move_mon(int mon, int y, int x);
 extern void reloc_mon(int mon, int y, int x);
index 393df6c..98422a2 100644 (file)
@@ -54,7 +54,7 @@ const char potion_colours[20][16] = {
     "navy blue", "bottle green", "amber", "lilac", "ivory"
 };
 
-int read_scroll(int obj)
+Action_cost read_scroll(int obj)
 {
     Obj *optr = objects + obj;
     int i;
@@ -89,7 +89,7 @@ int read_scroll(int obj)
                 {
                     print_mon_name(i, 3);
                     print_msg(" is burned.\n");
-                    damage_mon(i, dice(4, 10), 1);
+                    damage_mon(i, dice(4, 10), true);
                 }
             }
         }
@@ -120,18 +120,19 @@ int read_scroll(int obj)
         break;
     default:
         print_msg("Impossible: reading non-scroll\n");
-        return 0;
+        return Cost_none;
     }
-    return consume_obj(obj);
+    consume_obj(obj);
+    return Cost_std;
 }
 
-int consume_obj(int obj)
+bool consume_obj(int obj)
 {
     int i;
     objects[obj].quan--;
     if (objects[obj].quan == 0)
     {
-        objects[obj].used = 0;
+        objects[obj].used = false;
         if (objects[obj].with_you)
         {
             if (obj == u.armour)
@@ -140,7 +141,7 @@ int consume_obj(int obj)
                     (objects[obj].obj_id == PO_IMPERATRIX_GOWN))
                 {
                     objects[obj].quan = 1;
-                    objects[obj].used = 1;
+                    objects[obj].used = true;
                     objects[obj].durability = 50 + zero_die(51);
                     objects[obj].obj_id = PO_RAGGED_SHIFT;
                     print_msg("Your dress has been reduced to a tattered wreck.\n");
@@ -173,9 +174,9 @@ int consume_obj(int obj)
                 }
             }
         }
-        return 1;
+        return true;
     }
-    return 0;
+    return false;
 }
 
 int eat_food(int obj)
@@ -340,7 +341,7 @@ void flavours_init(void)
     permobjs[PO_POT_RESTORATION].power = colour_choices[3];
 }
 
-int create_obj_class(enum poclass_num po_class, int quantity, int with_you, int y, int x)
+int create_obj_class(enum poclass_num po_class, int quantity, bool with_you, int y, int x)
 {
     int obj;
     int po_idx;
@@ -355,7 +356,7 @@ int create_obj_class(enum poclass_num po_class, int quantity, int with_you, int
     if (obj == 100)
     {
         print_msg("ERROR: Ran out of objects[].\n");
-        return -1;
+        return NO_OBJ;
     }
     for (tryct = 0; tryct < 200; tryct++)
     {
@@ -372,7 +373,7 @@ int create_obj_class(enum poclass_num po_class, int quantity, int with_you, int
             break;
         default:
             /* No getting armour/weapons by class... yet. */
-            return -1;
+            return NO_OBJ;
         }
         if (zero_die(100) < permobjs[po_idx].rarity)
         {
@@ -394,7 +395,7 @@ int get_random_pobj(void)
         po_idx = zero_die(NUM_OF_PERMOBJS);
         if (zero_die(100) < permobjs[po_idx].rarity)
         {
-            po_idx = -1;
+            po_idx = NO_POBJ;
             continue;
         }
         /* v1.3: Do not permit generation of particularly powerful
@@ -402,7 +403,7 @@ int get_random_pobj(void)
          * (game balance fix) */
         if (depth < permobjs[po_idx].depth)
         {
-            po_idx = -1;
+            po_idx = NO_POBJ;
             continue;
         }
         break;
@@ -410,7 +411,7 @@ int get_random_pobj(void)
     return po_idx;
 }
 
-int create_obj(int po_idx, int quantity, int with_you, int y, int x)
+int create_obj(int po_idx, int quantity, bool with_you, int y, int x)
 {
     int i;
     for (i = 0; i < 100; i++)
@@ -423,19 +424,19 @@ int create_obj(int po_idx, int quantity, int with_you, int y, int x)
     if (i == 100)
     {
         print_msg("ERROR: Ran out of objects[].\n");
-        return -1;
+        return NO_OBJ;
     }
-    if (po_idx == -1)
+    if (po_idx == NO_POBJ)
     {
         po_idx = get_random_pobj();
-        if (po_idx == -1)
+        if (po_idx == NO_POBJ)
         {
-            return -1;
+            return NO_OBJ;
         }
     }
     objects[i].obj_id = po_idx;
     objects[i].with_you = with_you;
-    objects[i].used = 1;
+    objects[i].used = true;
     objects[i].y = y;
     objects[i].x = x;
     objects[i].quan = quantity;
@@ -533,7 +534,7 @@ void print_obj_name(int obj)
     }
 }
 
-int drop_obj(int inv_idx)
+Action_cost drop_obj(int inv_idx)
 {
     Obj *optr;
     optr = objects + u.inventory[inv_idx];
@@ -547,29 +548,29 @@ int drop_obj(int inv_idx)
             u.weapon = NO_OBJ;
         }
         u.inventory[inv_idx] = NO_OBJ;
-        optr->with_you = 0;
+        optr->with_you = false;
         print_msg("You drop ");
         print_obj_name(lvl.objs[u.y][u.x]);
         print_msg(".\n");
-        return 0;
+        return Cost_std;
     }
     else
     {
         print_msg("There is already an item here.\n");
+        return Cost_none;
     }
-    return -1;
 }
 
-int po_is_stackable(int po)
+bool po_is_stackable(int po)
 {
     switch (permobjs[po].poclass)
     {
     default:
-        return 0;
+        return false;
     case POCLASS_POTION:
     case POCLASS_SCROLL:
     case POCLASS_FOOD:
-        return 1;
+        return true;
     }
 }
 
@@ -588,7 +589,7 @@ void attempt_pickup(void)
                 print_obj_name(lvl.objs[u.y][u.x]);
                 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;
+                objects[lvl.objs[u.y][u.x]].used = false;
                 lvl.objs[u.y][u.x] = NO_OBJ;
                 print_msg("%c) ", 'a' + i);
                 print_obj_name(u.inventory[i]);
@@ -611,7 +612,7 @@ void attempt_pickup(void)
     }
     u.inventory[i] = lvl.objs[u.y][u.x];
     lvl.objs[u.y][u.x] = NO_OBJ;
-    objects[u.inventory[i]].with_you = 1;
+    objects[u.inventory[i]].with_you = true;
     objects[u.inventory[i]].x = -1;
     objects[u.inventory[i]].y = -1;
     print_msg("You now have\n");
@@ -725,7 +726,7 @@ int evasion_penalty(int obj)
     }
 }
 
-int magic_ring(void)
+Action_cost magic_ring(void)
 {
     Obj *optr = objects + u.ring;
     switch (optr->obj_id)
@@ -736,18 +737,23 @@ int magic_ring(void)
             u.food -= 50;
             print_msg("You activate your ring's power of teleportation.\n");
             teleport_u();
-            return 1;
+            return Cost_std;
         }
-        return 0;
+        else
+        {
+            print_msg("You're too hungry to activate your ring.\n");
+        }
+        return Cost_none;
     default:
         print_msg("Your current ring has no activatable power.\n");
-        return 0;
+        return Cost_none;
     }
 }
 
-int emanate_armour(void)
+Action_cost emanate_armour(void)
 {
     Obj *optr = objects + u.armour;
+    Action_cost cost = Cost_none;
     switch (optr->obj_id)
     {
     case PO_RIBBONS:
@@ -756,25 +762,28 @@ int emanate_armour(void)
             if (u.food < 5 * (OBJ_MAX_DUR - optr->durability))
             {
                 print_msg("You are too hungry to willingly let the ribbons draw on\nyour strength.\n");
-                return 0;
             }
             else
             {
                 print_msg("You gasp as the ribbons draw on your strength to\nrepair themselves.\n");
                 u.food -= 5 * (OBJ_MAX_DUR - optr->durability);
                 optr->durability = OBJ_MAX_DUR;
-                return 1;
+                cost = Cost_std;
             }
         }
-        return 1;
+        else
+        {
+            print_msg("The ribbons are undamaged.\n");
+        }
+        break;
     default:
         print_msg("Your current attire has no activatable powers.\n");
         break;
     }
-    return 0;
+    return Cost_none;
 }
 
-int zap_weapon(void)
+Action_cost zap_weapon(void)
 {
     Obj *optr = objects + u.weapon;
     switch (optr->obj_id)
@@ -804,16 +813,21 @@ int zap_weapon(void)
                         {
                             print_mon_name(lvl.mons[y][x], 3);
                             print_msg(" is engulfed in roaring flames.\n");
-                            damage_mon(lvl.mons[y][x], dice(4, 10), 1);
+                            damage_mon(lvl.mons[y][x], dice(4, 10), true);
                         }
                     }
                 }
             }
             damage_obj(u.weapon);
         }
+        else
+        {
+            print_msg("You are too hungry to activate your staff's power.\n");
+        }
+        return Cost_std;
     default:
         print_msg("Your current weapon has no activatable powers.\n");
-        return 0;
+        return Cost_none;
     }
 }
 
index 61050ec..5351d2b 100644 (file)
@@ -84,13 +84,15 @@ struct permobj {
     const char *description;
     enum poclass_num poclass;
     int rarity; /* Chance in 100 of being thrown away and regen'd. */
-    int sym;
+    char sym;   /* ASCII */
+    const char *unicode; /* UTF-8 */
     int power;  /* AC for armour; damage for weapons; colour/title for
                  * scrolls and potions and rings and such. */
-    int used;   /* Set to 1 for valid entries. */
     int depth;  /* If greater than 1, this item cannot be given out
                  * by get_random_pobj() before the specified depth. */
 };
+#define NO_POBJ (-1)
+
 extern struct permobj permobjs[NUM_OF_PERMOBJS];
 
 /* XXX Obj */
@@ -98,11 +100,11 @@ extern struct permobj permobjs[NUM_OF_PERMOBJS];
 #define OBJECTS_IN_PLAY 100
 struct Obj {
     int obj_id;
+    bool used;   /* Entry is occupied. */
+    bool with_you;       /* Preserved when item DB is reaped on level change. */
     int quan;
-    int with_you;       /* Preserved when item DB is reaped on level change. */
     int y;
     int x;
-    int used;   /* Entry is occupied. */
     int durability;     /* Weapons and armour degrade with use. */
 };
 extern Obj objects[OBJECTS_IN_PLAY];
@@ -115,12 +117,13 @@ extern void sprint_obj_name(char *s, int obj, int len);
 extern void fprint_obj_name(FILE *fp, int obj);
 extern void print_obj_name(int obj);
 extern void describe_object(int obj);
-extern int create_obj(int po_idx, int quantity, int with_you, int y, int x);
-extern int drop_obj(int inv_idx);
-extern int consume_obj(int obj);
-extern int create_obj_class(enum poclass_num pocl, int quantity, int with_you, int y, int x);
+extern int create_obj(int po_idx, int quantity, bool with_you, int y, int x);
+extern bool consume_obj(int obj);
+extern int create_obj_class(enum poclass_num pocl, int quantity, bool with_you, int y, int x);
 extern int create_obj_random(int y, int x);
-extern int read_scroll(int obj);
+
+extern Action_cost drop_obj(int inv_idx);
+extern Action_cost read_scroll(int obj);
 
 #endif
 
index 482e4f3..9959ed7 100644 (file)
 #define PERMOBJ_CC
 #include "victrix-abyssi.hh"
 
-struct permobj permobjs[NUM_OF_PERMOBJS] = {
-    {
-        "dagger", "daggers", "A long knife, designed for stabbing.", POCLASS_WEAPON, 25, ')', 4, 1, 1
-    },
-    {
-        "long sword", "long swords", "A steel sword of simple but sturdy construction; the\nblade is three feet long.", POCLASS_WEAPON, 30, ')', 10, 1, 4
-    },
-    {
-        "mace", "maces", "A flanged lump of iron on an iron haft.", POCLASS_WEAPON, 30, ')', 7, 1, 2
-    },
-    {
-        "runesword", "runeswords", "An eerily glowing sword engraved with many strange\nrunes.", POCLASS_WEAPON, 80, ')', 20, 1, 12
-    },
-    {
-        "bow", "bows", "A recurve composite bow.", POCLASS_WEAPON, 45, '(', 8, 1, 1
-    },
-    {
-        "crossbow", "crossbows", "A crossbow.", POCLASS_WEAPON, 70, '(', 16, 1, 6
-    },
-    {
-        "thunderbow", "thunderbows", "A recurve composite bow decorated with eldritch signs.\nArrows fired with this bow strike with staggering force.", POCLASS_WEAPON, 70, '(', 16, 1, 30
-    },
-    {
-        "tormentor's lash", "tormentor's lash", "A bone-handled whip that crackles with malefic energies.", POCLASS_WEAPON, 80, ')', 20, 1, 30
-    },
-    {
-        "staff of fire", "staff of fire", "A jet-black staff with a glowing ruby in its headpiece.", POCLASS_WEAPON, 80, ')', 10, 1, 20
-    },
-    {
-        "healing potion", "healing potions", "This magic elixir restores some lost hit points.", POCLASS_POTION, 10, '!', 0, 1, 1
-    },
-    {
-        "body potion", "body potions", "This magic elixir will improve your physique.", POCLASS_POTION, 70, '!', 0, 1, 5
-    },
-    {
-        "agility potion", "agility potions", "This magic elixir will sharpen your reflexes.", POCLASS_POTION, 70, '!', 0, 1, 5
-    },
-    {
-        "restoration potion", "restoration potions", "This magic elixir cures temporary damage to one's\nabilities.", POCLASS_POTION, 70, '!', 0, 1, 1
-    },
-    {
-        "poison flask", "poison flask", "This fragile bottle is full of contact poison.", POCLASS_FLASK, 10, '~', 0, 1, 1
-    },
-    {
-        "fire flask", "fire flasks", "The volatile, phosphorus-laced liquid in this sealed\nflask will ignite spontaneously when exposed to the air.", POCLASS_FLASK, 40, '~', 0, 1, 20
-    },
-    {
-        "weakness flask", "weakness flasks", "Dousing the living in this vile liquid causes immediate\nand severe physical degeneration.", POCLASS_FLASK, 40, '~', 0, 1, 20
-    },
-    {
-        "teleport scroll", "teleport scrolls", "Reading this scroll will teleport you to a random\nlocation.", POCLASS_SCROLL, 40, '?', 0, 1, 1
-    },
-    {
-        "fire scroll", "fire scrolls", "Reading this scroll will engulf all nearby creatures\n(including you) in flames.", POCLASS_SCROLL, 30, '?', 0, 1, 1
-    },
-    {
-        "protection scroll", "protection scrolls", "Reading this scroll will dispel any curses afflicting\nyou and protect you from curses for a time.", POCLASS_SCROLL, 80, '?', 0, 1, 8
-    },
-    {
-        "leather armour", "suits of leather armour", "A heavy leather jerkin and breeches, providing some\nprotection.", POCLASS_ARMOUR, 25, '[', 3, 1, 1
-    },
-    {
-        "chainmail", "suits of chainmail", "A suit of interlocking metal rings, providing better\nprotection than leather.", POCLASS_ARMOUR, 30, '[', 6, 1, 3
-    },
-    {
-        "plate armour", "suits of plate armour", "A suit of steel plates, providing better protection than\nchainmail.", POCLASS_ARMOUR, 40, '[', 10, 1, 6
-    },
-    {
-        "mage armour", "suits of mage armour", "A suit of glowing steel plates bearing enchantments of\ndefence.", POCLASS_ARMOUR, 70, '[', 15, 1, 12
-    },
-    {
-        "mundane robe", "mundane robes", "A simple woolen robe. It's better protection than your\nskin, but not by much.", POCLASS_ARMOUR, 50, '[', 2, 1, 1
-    },
-    {
-        "robe of swiftness", "robes of swiftness", "A simple woolen robe that bears a potent enchantment,\nprotecting the wearer and making him unnaturally swift.", POCLASS_ARMOUR, 70, '[', 8, 1, 8
-    },
-    {
-        "robe of shadows", "robes of shadows", "A simple woolen robe that bears an awesome enchantment,\nprotecting the wearer better than steel plate.", POCLASS_ARMOUR, 90, '[', 14, 1, 18
-    },
-    {
-        "dragonhide armour", "suits of dragonhide armour", "The skin of a dragon, formed into a jerkin and breeches;\nit turns blows like steel plate and turns away\nflames.", POCLASS_ARMOUR, 90, '[', 12, 1, 21
-    },
-    {
-        "meteoric plate armour", "suits of meteoric plate armour", "This plate armour has been forged out of metal taken from\na fallen star.", POCLASS_ARMOUR, 90, '[', 18, 1, 27
-    },
-    {
-        "sacred chainmail", "suits of sacred chainmail", "This suit of interlocking rings has been consecrated to\nthe gods of the Light.", POCLASS_ARMOUR, 90, '[', 15, 1, 24
-    },
-    {
-        "ragged shift", "ragged shifts", "This sorry-looking collection of rags is all that remains\nof a battle ballgown.", POCLASS_ARMOUR, 100, '[', 1, 0, 1  
-    },
-    {
-        "battle ballgown", "battle ballgowns", "Partially armoured dresses such as this are a\ntraditional part of a princess's wardrobe.", POCLASS_ARMOUR, 95, '[', 3, 1, 1
-    },
-    {
-        "imperatrix gown", "imperatrix gowns", "This armoured, enchanted, and elaborately decorated dress\nwould be worthy of an empress regnant.", POCLASS_ARMOUR, 95, '[', 15, 1, 24
-    },
-    {
-        /* inspired by DoomRL's Necroarmor and my own creepiness. */
-        "set of ribbons", "sets of ribbons", "These ribbons, arranged as if to form an alleged\ngarment, make your fingers tingle with magic.", POCLASS_ARMOUR, 90, '[', 15, 1, 30
-    },
-    {
-        "regeneration ring", "regeneration rings", "This magical ring increases the wearer's healing rate,\nbut also increases the rate at which they must consume\nfood.", POCLASS_RING, 70, '=', 0, 1, 1
-    },
-    {
-        "fire ring", "fire rings", "This magical ring protects the wearer from mundane and\nmagical fire, and imbues their blows in combat with the\npower of fire.", POCLASS_RING, 50, '=', 0, 1, 1
-    },
-    {
-        "vampire ring", "vampire rings", "This magical ring protects the wearer from necromantic\nenergies, and imbues their blows in combat with such\nenergies as well.", POCLASS_RING, 90, '=', 0, 1, 12
-    },
-    {
-        "frost ring", "frost rings", "This magical ring protects the wearer from mundane and\nmagical cold, and imbues their blows in combat with the\npower of cold. Rumour suggests it might also allow walking\non water.\n", POCLASS_RING, 40, '=', 0, 1, 1
-    },
-    {
-        "teleport ring", "teleport rings", "This magical ring allows the wearer to teleport for a\nmodest cost in nutrition.", POCLASS_RING, 70, '=', 0, 1, 1
-    },
-    {
-        "iron ration", "iron rations", "A parcel of hardtack and beef jerky. Dull but nutritious.", POCLASS_FOOD, 75, '%', 0, 1, 1
-    },
-    {
-        "parcel of dried fruit", "parcels of dried fruit", "A parcel of mixed dried fruit. It sure beats hardtack\nand beef jerky.", POCLASS_FOOD, 75, '%', 0, 1, 1
-    },
-    {
-        "round of elven waybread", "rounds of elven waybread", "A tasty, filling, nutritious piece of elven waybread.", POCLASS_FOOD, 85, '%', 0, 1, 1
-    },
-    {
-        "devil spleen", "devil spleens", "A weirdly pulsing organ ripped from the torso of a devil.", POCLASS_FOOD, 100, '%', 0, 1, 1
-    }
+struct permobj permobjs[NUM_OF_PERMOBJS] =
+{
+    { "dagger", "daggers", "A long knife, designed for stabbing.", POCLASS_WEAPON, 25, ')', ")", 4, 1 },
+    { "long sword", "long swords", "A steel sword of simple but sturdy construction; the\nblade is three feet long.", POCLASS_WEAPON, 30, ')', ")", 10, 4 },
+    { "mace", "maces", "A flanged lump of iron on an iron haft.", POCLASS_WEAPON, 30, ')', ")", 7, 2 },
+    { "runesword", "runeswords", "An eerily glowing sword engraved with many strange\nrunes.", POCLASS_WEAPON, 80, ')', ")", 20, 12 },
+    { "bow", "bows", "A recurve composite bow.", POCLASS_WEAPON, 45, '(', "(", 8, 1 },
+    { "crossbow", "crossbows", "A crossbow.", POCLASS_WEAPON, 70, '(', "(", 16, 6 },
+    { "thunderbow", "thunderbows", "A recurve composite bow decorated with eldritch signs.\nArrows fired with this bow strike with staggering force.", POCLASS_WEAPON, 70, '(', "(", 16, 30 },
+     { "tormentor's lash", "tormentor's lash", "A bone-handled whip that crackles with malefic energies.", POCLASS_WEAPON, 80, ')', ")", 20, 30 },
+    { "staff of fire", "staff of fire", "A jet-black staff with a glowing ruby in its headpiece.", POCLASS_WEAPON, 80, ')', ")", 10, 20 },
+    { "healing potion", "healing potions", "This magic elixir restores some lost hit points.", POCLASS_POTION, 10, '!', "!", 0, 1 },
+    { "body potion", "body potions", "This magic elixir will improve your physique.", POCLASS_POTION, 70, '!', "!", 0, 5 },
+    { "agility potion", "agility potions", "This magic elixir will sharpen your reflexes.", POCLASS_POTION, 70, '!', "!", 0, 5 },
+    { "restoration potion", "restoration potions", "This magic elixir cures temporary damage to one's\nabilities.", POCLASS_POTION, 70, '!', "!", 0, 1 },
+    { "poison flask", "poison flask", "This fragile bottle is full of contact poison.", POCLASS_FLASK, 10, '~', "~", 0, 1 },
+    { "fire flask", "fire flasks", "The volatile, phosphorus-laced liquid in this sealed\nflask will ignite spontaneously when exposed to the air.", POCLASS_FLASK, 40, '~', "~", 0, 20 },
+    { "weakness flask", "weakness flasks", "Dousing the living in this vile liquid causes immediate\nand severe physical degeneration.", POCLASS_FLASK, 40, '~', "~", 0, 20 },
+    { "teleport scroll", "teleport scrolls", "Reading this scroll will teleport you to a random\nlocation.", POCLASS_SCROLL, 40, '?', "?", 0, 1 },
+    { "fire scroll", "fire scrolls", "Reading this scroll will engulf all nearby creatures\n(including you) in flames.", POCLASS_SCROLL, 30, '?', "?", 0, 1 },
+    { "protection scroll", "protection scrolls", "Reading this scroll will dispel any curses afflicting\nyou and protect you from curses for a time.", POCLASS_SCROLL, 80, '?', "?", 0, 8 },
+    { "leather armour", "suits of leather armour", "A heavy leather jerkin and breeches, providing some\nprotection.", POCLASS_ARMOUR, 25, '[', "[", 3, 1 },
+    { "chainmail", "suits of chainmail", "A suit of interlocking metal rings, providing better\nprotection than leather.", POCLASS_ARMOUR, 30, '[', "[", 6, 3 },
+    { "plate armour", "suits of plate armour", "A suit of steel plates, providing better protection than\nchainmail.", POCLASS_ARMOUR, 40, '[', "[", 10, 6 },
+    { "mage armour", "suits of mage armour", "A suit of glowing steel plates bearing enchantments of\ndefence.", POCLASS_ARMOUR, 70, '[', "[", 15, 12 },
+    { "mundane robe", "mundane robes", "A simple woolen robe. It's better protection than your\nskin, but not by much.", POCLASS_ARMOUR, 50, '[', "[", 2, 1 },
+    { "robe of swiftness", "robes of swiftness", "A simple woolen robe that bears a potent enchantment,\nprotecting the wearer and making him unnaturally swift.", POCLASS_ARMOUR, 70, '[', "[", 8, 8 },
+    { "robe of shadows", "robes of shadows", "A simple woolen robe that bears an awesome enchantment,\nprotecting the wearer better than steel plate.", POCLASS_ARMOUR, 90, '[', "[", 14, 18 },
+    { "dragonhide armour", "suits of dragonhide armour", "The skin of a dragon, formed into a jerkin and breeches;\nit turns blows like steel plate and turns away\nflames.", POCLASS_ARMOUR, 90, '[', "[", 12, 21 },
+    { "meteoric plate armour", "suits of meteoric plate armour", "This plate armour has been forged out of metal taken from\na fallen star.", POCLASS_ARMOUR, 90, '[', "[", 18, 27 },
+    { "sacred chainmail", "suits of sacred chainmail", "This suit of interlocking rings has been consecrated to\nthe gods of the Light.", POCLASS_ARMOUR, 90, '[', "[", 15, 24 },
+    { "ragged shift", "ragged shifts", "This sorry-looking collection of rags is all that remains\nof an imposing armoured dress.", POCLASS_ARMOUR, 100, '[', "[", 1, 1  },
+    { "battle ballgown", "battle ballgowns", "Partially armoured dresses such as this are a\ntraditional part of a princess's wardrobe.", POCLASS_ARMOUR, 95, '[', "[", 3, 1 },
+    { "imperatrix gown", "imperatrix gowns", "This armoured, enchanted, and elaborately decorated dress\nwould be worthy of an empress regnant.", POCLASS_ARMOUR, 95, '[', "[", 15, 24 },
+    { "set of ribbons", "sets of ribbons", "These ribbons, arranged as if to form an alleged\ngarment, make your fingers tingle with magic.", POCLASS_ARMOUR, 90, '[', "[", 15, 30 },
+    { "regeneration ring", "regeneration rings", "This magical ring increases the wearer's healing rate,\nbut also increases the rate at which they must consume\nfood.", POCLASS_RING, 70, '=', "=", 0, 1 },
+    { "fire ring", "fire rings", "This magical ring protects the wearer from mundane and\nmagical fire, and imbues their blows in combat with the\npower of fire.", POCLASS_RING, 50, '=', "=", 0, 1 },
+    { "vampire ring", "vampire rings", "This magical ring protects the wearer from necromantic\nenergies, and imbues their blows in combat with such\nenergies as well.", POCLASS_RING, 90, '=', "=", 0, 12 },
+    { "frost ring", "frost rings", "This magical ring protects the wearer from mundane and\nmagical cold, and imbues their blows in combat with the\npower of cold. Rumour suggests it might also allow walking\non water.\n", POCLASS_RING, 40, '=', "=", 0, 1 },
+    { "teleport ring", "teleport rings", "This magical ring allows the wearer to teleport for a\nmodest cost in nutrition.", POCLASS_RING, 70, '=', "=", 0, 1 },
+    { "iron ration", "iron rations", "A parcel of hardtack and beef jerky. Dull but nutritious.", POCLASS_FOOD, 75, '%', "%", 0, 1 },
+    { "parcel of dried fruit", "parcels of dried fruit", "A parcel of mixed dried fruit. It sure beats hardtack\nand beef jerky.", POCLASS_FOOD, 75, '%', "%", 0, 1 },
+    { "round of elven waybread", "rounds of elven waybread", "A tasty, filling, nutritious piece of elven waybread.", POCLASS_FOOD, 85, '%', "%", 0, 1 },
+    { "devil spleen", "devil spleens", "A weirdly pulsing organ ripped from the torso of a devil.", POCLASS_FOOD, 100, '%', "%", 0, 1 }
 };
 
 /* permobj.c */
diff --git a/rng.cc b/rng.cc
index 2f5777f..7448079 100644 (file)
--- a/rng.cc
+++ b/rng.cc
@@ -51,8 +51,8 @@ void rng_init(void)
 {
     int i;
     /* To make manipulating the RNG by monitoring the system time
-     * harder, we use PID and UID to perturb the return value of time()
-     * used to initialise the libc RNG.
+     * marginally harder, we use PID and UID to perturb the return value of
+     * time() used to initialise the libc RNG.
      *
      * Yes, I am aware that the libc RNG on many platforms is a steaming
      * pile of shite. However, I need *something* with which to populate
diff --git a/u.cc b/u.cc
index dda7516..9b7d23a 100644 (file)
--- a/u.cc
+++ b/u.cc
@@ -82,13 +82,13 @@ void recalc_defence(void)
     display_update();
 }
 
-int move_player(int dy, int dx)
+Action_cost move_player(int dy, int dx)
 {
     if ((u.y + dy < 0) || (u.y + dy >= DUN_HEIGHT) ||
         (u.x + dx < 0) || (u.x + dx >= DUN_WIDTH))
     {
         print_msg("Attempted move out of bounds.\n");
-        return 0;       /* No movement. */
+        return Cost_none;       /* No movement. */
     }
     if (lvl.mons[u.y + dy][u.x + dx] != NO_MON)
     {
@@ -98,7 +98,7 @@ int move_player(int dy, int dx)
                 (objects[u.weapon].obj_id == PO_CROSSBOW))
             {
                 print_msg("You can't use that weapon in melee!\n");
-                return 0;
+                return Cost_none;
             }
         }
         return player_attack(dy, dx);
@@ -108,13 +108,13 @@ int move_player(int dy, int dx)
     case WALL:
     case HARDWALL:
         print_msg("You cannot go there.\n");
-        return 0;
+        return Cost_none;
     case FLOOR:
     case DOOR:
     case STAIRS:
     case ALTAR:
         reloc_player(u.y + dy, u.x + dx);
-        return 1;
+        return Cost_std;
     case LAVA:
         if (u.resistances[DT_FIRE])
         {
@@ -123,12 +123,12 @@ int move_player(int dy, int dx)
                 print_msg("You walk on the lava.\n");
             }
             reloc_player(u.y + dy, u.x + dx);
-            return 1;
+            return Cost_std;
         }
         else
         {
             print_msg("The fierce heat of the molten rock repels you.\n");
-            return 0;
+            return Cost_none;
         }
     case WATER:
         if ((u.ring != NO_OBJ) && (objects[u.ring].obj_id == PO_RING_FROST))
@@ -138,18 +138,18 @@ int move_player(int dy, int dx)
                 print_msg("You walk on the water.\n");
             }
             reloc_player(u.y + dy, u.x + dx);
-            return 1;
+            return Cost_std;
         }
         else
         {
             print_msg("The idiot who raised you never taught you to swim.\n");
-            return 0;
+            return Cost_none;
         }
     }
-    return 0;
+    return Cost_none;
 }
 
-int reloc_player(int y, int x)
+void reloc_player(int y, int x)
 {
     int oy, ox;
 
@@ -169,7 +169,6 @@ int reloc_player(int y, int x)
         print_obj_name(lvl.objs[y][x]);
         print_msg(".\n");
     }
-    return 0;
 }
 
 int gain_body(int amount, int loud)
@@ -556,7 +555,7 @@ void gain_experience(int amount)
     }
 }
 
-int teleport_u(void)
+Pass_fail teleport_u(void)
 {
     int cell_try;
     int y, x;
@@ -568,11 +567,11 @@ int teleport_u(void)
         {
             print_msg("You are whisked away!\n");
             reloc_player(y, x);
-            return 0;
+            return You_pass;
         }
     }
     print_msg("You feel briefly dislocated.\n");
-    return -1;
+    return You_fail;
 }
 
 void update_player(void)
@@ -595,20 +594,20 @@ void update_player(void)
     if (((game_tick % 10) == 5) &&
         (objects[u.ring].obj_id == PO_RING_REGEN) &&
         (u.hpcur < ((u.food >= 0) ? u.hpmax : ((u.hpmax * 3) / 4))) &&
-        (u.food >= -1950))
+        (u.food > MIN_FOOD))
     {
         /* Heal player for 1d3 hit points; do not allow HP gain,
          * and don't say anything apart from the regen ring message. */
         print_msg("Your ring pulses soothingly.\n");
         heal_u(one_die(3), 0, 0);
     }
-    if (u.food >= -1950)
+    if (u.food > MIN_FOOD)
     {
         int food_use = 1;
         int squeal = 0;
-        if ((objects[u.ring].obj_id == PO_RING_REGEN) && !(game_tick % 2) && (u.food >= -1950))
+        if ((objects[u.ring].obj_id == PO_RING_REGEN) && !(game_tick % 2) && (u.food > MIN_FOOD))
         {
-            /* If you are still less hungry than -1950 nutrition,
+            /* If you are still less hungry than MIN_FOOD nutrition,
              * use one more food every second tick if you are
              * wearing a ring of regeneration. */
             food_use++;
index f2da191..d428518 100644 (file)
--- a/vector.cc
+++ b/vector.cc
@@ -33,8 +33,8 @@ void compute_directions(int y1, int x1, int y2, int x2, int *pdy, int *pdx, int
     int dy, dx, sy, sx;
     dy = y1 - y2;
     dx = x1 - x2;
-    sy = dy > 0 ? 1 : (dy < 0 ? -1 : 0);
-    sx = dx > 0 ? 1 : (dx < 0 ? -1 : 0);
+    sy = mysign(dy);
+    sx = mysign(dx);
     if (pdy)
     {
         *pdy = dy;
index 93504a7..ccf0dfc 100644 (file)
 #include "coord.hh"
 #endif
 
+enum Pass_fail
+{
+    You_fail = -1,
+    You_pass = 0
+};
+
+enum Action_cost
+{
+    Cost_none = 0,
+    Cost_std = 1
+};
+
 /* change WIZARD_MODE to 1 if you want the wizard mode commands. */
 #define WIZARD_MODE 0
 
@@ -125,6 +137,10 @@ struct Player {
     bool resists(Damtyp dtype) const;
 };
 
+#define MIN_FOOD (-1950)
+#define SLOT_CANCEL (-1)
+#define SLOT_NOTHING (-2)
+
 #ifndef MONSTERS_HH
 #include "monsters.hh"
 #endif
@@ -151,7 +167,7 @@ extern int inclusive_flat(int lower, int upper); /* l ... u */
 extern int one_die(int sides);  /* 1..n */
 extern int dice(int count, int sides);
 extern int zero_die(int sides); /* 0..n-1 */
-extern int do_command(enum game_cmd command);
+extern Action_cost do_command(enum game_cmd command);
 extern uint32_t convert_range(int dy, int dx);
 extern int game_finished;
 extern int game_tick;
@@ -163,12 +179,12 @@ extern const char *damtype_names[DT_COUNT];
 extern int quaff_potion(int obj);
 extern int eat_food(int obj);
 extern void attempt_pickup(void);
-extern int po_is_stackable(int po);
+extern bool po_is_stackable(int po);
 extern void damage_obj(int obj);
 extern int evasion_penalty(int obj);
-extern int magic_ring(void);
-extern int emanate_armour(void);
-extern int zap_weapon(void);
+extern Action_cost magic_ring(void);
+extern Action_cost emanate_armour(void);
+extern Action_cost zap_weapon(void);
 
 /* XXX rng.c data and funcs */
 #define RNG_MAX 0xFFFFFFFFu
@@ -192,10 +208,10 @@ extern int drain_body(int amount, const char *what, int permanent);
 extern int drain_agility(int amount, const char *what, int permanent);
 extern void gain_experience(int amount);
 extern int lev_threshold(int level);
-extern int move_player(int dy, int dx);
-extern int reloc_player(int y, int x);
+extern Action_cost move_player(int dy, int dx);
+extern void reloc_player(int y, int x);
 extern void recalc_defence(void);
-extern int teleport_u(void);
+extern Pass_fail teleport_u(void);
 extern void update_player(void);
 
 extern struct Player u;