From 1d59a2553c02ba153eea53c1e46b2f712814b0ea Mon Sep 17 00:00:00 2001 From: Martin Read Date: Mon, 30 Sep 2013 23:49:07 +0100 Subject: [PATCH] More elimination of magic numbers; also, store evasion penalty in the item database. --- mon2.cc | 24 ++++++++-------- monsters.cc | 17 +++++++---- monsters.hh | 4 +-- objects.cc | 35 ++++------------------- objects.hh | 1 + permobj.cc | 84 +++++++++++++++++++++++++++---------------------------- victrix-abyssi.hh | 7 +++++ 7 files changed, 80 insertions(+), 92 deletions(-) diff --git a/mon2.cc b/mon2.cc index 8b37d16..8d36354 100644 --- a/mon2.cc +++ b/mon2.cc @@ -33,6 +33,7 @@ #include "monsters.hh" #include "combat.hh" +#define AI_REALLY_HATE (-10000) /* AI map cell descriptor. */ struct ai_cell { int y, x; @@ -45,7 +46,7 @@ static void get_naive_prefs(int y, int x, int dy, int dx, int *pref_y, int *pref static void get_seeking_prefs(int y, int x, int dy, int dx, int *pref_y, int *pref_x); static void get_drunk_prefs(int y, int x, int dy, int dx, int *pref_y, int *pref_x); static void build_ai_cells(struct ai_cell *cells, int y, int x); -static int ai_cell_compare(struct ai_cell *cell, int dy, int dx); +static Comparison ai_cell_compare(struct ai_cell *cell, int dy, int dx); static void get_dodger_prefs(int y, int x, int dy, int dx, int *pref_y, int *pref_x); static void get_chase_prefs(int mon, int *pref_y, int *pref_x); @@ -243,7 +244,7 @@ static void get_seeking_prefs(int y, int x, int dy, int dx, int *pref_y, int *pr int i; int ady, adx; int j; - int highest_score = -10000; + int highest_score = AI_REALLY_HATE; int tryct; *pref_y = y; *pref_x = x; @@ -262,7 +263,7 @@ static void get_seeking_prefs(int y, int x, int dy, int dx, int *pref_y, int *pr { /* Square impassable to this monster. Set score WAY * out of bounds and continue. */ - ai_cells[i].score = -10000; + ai_cells[i].score = AI_REALLY_HATE; continue; } if ((ai_cells[i].y == u.y) || (ai_cells[i].x == u.x)) @@ -283,7 +284,7 @@ static void get_seeking_prefs(int y, int x, int dy, int dx, int *pref_y, int *pr highest_score = ai_cells[i].score; } } - if (highest_score == -10000) + if (highest_score == AI_REALLY_HATE) { /* No good targets. */ return; @@ -411,20 +412,19 @@ static void build_ai_cells(struct ai_cell *cells, int y, int x) * * Find relative range of cell compared to monster's current range. */ -static int ai_cell_compare(struct ai_cell *cell, int dy, int dx) +static Comparison ai_cell_compare(struct ai_cell *cell, int dy, int dx) { - /* returns -1 for closer, 0 for same range, +1 for further. */ int pointrange = convert_range(dy, dx); int cellrange = convert_range(cell->dy, cell->dx); if (cellrange < pointrange) { - return -1; + return Lesser; } else if (cellrange > pointrange) { - return 1; + return Greater; } - return 0; + return Equal; } /* XXX get_dodger_prefs() @@ -445,7 +445,7 @@ static void get_dodger_prefs(int y, int x, int dy, int dx, int *pref_y, int *pre int i; int ady, adx; int j; - int highest_score = -10000; + int highest_score = AI_REALLY_HATE; int tryct; *pref_y = y; *pref_x = x; @@ -473,7 +473,7 @@ static void get_dodger_prefs(int y, int x, int dy, int dx, int *pref_y, int *pre { /* Square impassable. Set score WAY out of bounds * and continue. */ - ai_cells[i].score = -10000; + ai_cells[i].score = AI_REALLY_HATE; continue; } /* Cardinality */ @@ -502,7 +502,7 @@ static void get_dodger_prefs(int y, int x, int dy, int dx, int *pref_y, int *pre highest_score = ai_cells[i].score; } } - if (highest_score == -10000) + if (highest_score == AI_REALLY_HATE) { /* No good targets. */ return; diff --git a/monsters.cc b/monsters.cc index 1b0acd3..c65b731 100644 --- a/monsters.cc +++ b/monsters.cc @@ -33,6 +33,11 @@ Mon monsters[100]; static int reject_mon(int pm); +/*! \brief Summon some monsters + * + * \return Number of monsters summoned + * \param how_many Maximum number of monsters to summon + */ int summoning(int y, int x, int how_many) { int i; @@ -362,7 +367,7 @@ int reject_mon(int pm) return 0; } -int teleport_mon_to_you(int mon) +Pass_fail teleport_mon_to_you(int mon) { int tryct; int dy, dx; @@ -385,14 +390,14 @@ int teleport_mon_to_you(int mon) reloc_mon(mon, y, x); print_mon_name(mon, 2); print_msg(" appears in a puff of smoke.\n"); - return 1; + return You_pass; } - return 0; + return You_fail; } -int teleport_mon(int mon) +Pass_fail teleport_mon(int mon) { - int rval = -1; + Pass_fail rval = You_fail; int cell_try; int y, x; for (cell_try = 0; cell_try < 200; cell_try++) @@ -402,7 +407,7 @@ int teleport_mon(int mon) 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; + rval = You_pass; break; } } diff --git a/monsters.hh b/monsters.hh index 3c7883c..5b1df9c 100644 --- a/monsters.hh +++ b/monsters.hh @@ -126,8 +126,8 @@ 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); -extern int teleport_mon(int mon); /* Randomly relocate monster. */ -extern int teleport_mon_to_you(int mon); /* Relocate monster to your vicinity. */ +extern Pass_fail teleport_mon(int mon); /* Randomly relocate monster. */ +extern Pass_fail teleport_mon_to_you(int mon); /* Relocate monster to your vicinity. */ extern void heal_mon(int mon, int amount, int cansee); extern bool mon_resists_cold(int mon); extern bool mon_resists_fire(int mon); diff --git a/objects.cc b/objects.cc index 0d9b5e7..f539cfc 100644 --- a/objects.cc +++ b/objects.cc @@ -695,38 +695,13 @@ void describe_object(int obj) int evasion_penalty(int obj) { - switch (objects[obj].obj_id) + if (permobjs[objects[obj].obj_id].poclass == POCLASS_ARMOUR) { - case PO_ROBE: - return 5; - - case PO_LEATHER_ARMOUR: - case PO_DRAGON_ARMOUR: - case PO_BATTLE_BALLGOWN: - return 10; - - case PO_CHAINMAIL: - case PO_SACRED_MAIL: - return 25; - - case PO_PLATE_ARMOUR: - case PO_MAGE_ARMOUR: - case PO_METEOR_ARMOUR: - return 40; - - case PO_ROBE_SWIFTNESS: - return 0; - - case PO_ROBE_SHADOWS: - case PO_RIBBONS: - return -15; /* This is a bonus. */ - - default: - /* If you've somehow managed to wear a non-armour, you're abusing - * a bug; get a 100% penalty to evasion. */ - print_msg("Trying to find evasion penalty of non-armour!\n"); - return 100; + return permobjs[objects[obj].obj_id].power2; } + /* Haxx0r. Or maybe a bug. */ + print_msg("Trying to find evasion penalty of non-armour!\n"); + return 100; } Action_cost magic_ring(void) diff --git a/objects.hh b/objects.hh index e9e4dd2..f667fa9 100644 --- a/objects.hh +++ b/objects.hh @@ -88,6 +88,7 @@ struct permobj { const char *unicode; /* UTF-8 */ int power; /* AC for armour; damage for weapons; colour/title for * scrolls and potions and rings and such. */ + int power2; /* evasion for armour */ int depth; /* If greater than 1, this item cannot be given out * by get_random_pobj() before the specified depth. */ }; diff --git a/permobj.cc b/permobj.cc index 9959ed7..8c2d1cf 100644 --- a/permobj.cc +++ b/permobj.cc @@ -30,48 +30,48 @@ 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 } + { "dagger", "daggers", "A long knife, designed for stabbing.", POCLASS_WEAPON, 25, ')', ")", 4, 0, 1 }, + { "long sword", "long swords", "A steel sword of simple but sturdy construction; the\nblade is three feet long.", POCLASS_WEAPON, 30, ')', ")", 10, 0, 4 }, + { "mace", "maces", "A flanged lump of iron on an iron haft.", POCLASS_WEAPON, 30, ')', ")", 7, 0, 2 }, + { "runesword", "runeswords", "An eerily glowing sword engraved with many strange\nrunes.", POCLASS_WEAPON, 80, ')', ")", 20, 0, 12 }, + { "bow", "bows", "A recurve composite bow.", POCLASS_WEAPON, 45, '(', "(", 8, 0, 1 }, + { "crossbow", "crossbows", "A crossbow.", POCLASS_WEAPON, 70, '(', "(", 16, 0, 6 }, + { "thunderbow", "thunderbows", "A recurve composite bow decorated with eldritch signs.\nArrows fired with this bow strike with staggering force.", POCLASS_WEAPON, 70, '(', "(", 16, 0, 30 }, + { "tormentor's lash", "tormentor's lash", "A bone-handled whip that crackles with malefic energies.", POCLASS_WEAPON, 80, ')', ")", 20, 0, 30 }, + { "staff of fire", "staff of fire", "A jet-black staff with a glowing ruby in its headpiece.", POCLASS_WEAPON, 80, ')', ")", 10, 0, 20 }, + { "healing potion", "healing potions", "This magic elixir restores some lost hit points.", POCLASS_POTION, 10, '!', "!", 0, 0, 1 }, + { "body potion", "body potions", "This magic elixir will improve your physique.", POCLASS_POTION, 70, '!', "!", 0, 0, 5 }, + { "agility potion", "agility potions", "This magic elixir will sharpen your reflexes.", POCLASS_POTION, 70, '!', "!", 0, 0, 5 }, + { "restoration potion", "restoration potions", "This magic elixir cures temporary damage to one's\nabilities.", POCLASS_POTION, 70, '!', "!", 0, 0, 1 }, + { "poison flask", "poison flask", "This fragile bottle is full of contact poison.", POCLASS_FLASK, 10, '~', "~", 0, 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, 0, 20 }, + { "weakness flask", "weakness flasks", "Dousing the living in this vile liquid causes immediate\nand severe physical degeneration.", POCLASS_FLASK, 40, '~', "~", 0, 0, 20 }, + { "teleport scroll", "teleport scrolls", "Reading this scroll will teleport you to a random\nlocation.", POCLASS_SCROLL, 40, '?', "?", 0, 0, 1 }, + { "fire scroll", "fire scrolls", "Reading this scroll will engulf all nearby creatures\n(including you) in flames.", POCLASS_SCROLL, 30, '?', "?", 0, 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, 0, 8 }, + { "leather armour", "suits of leather armour", "A heavy leather jerkin and breeches, providing some\nprotection.", POCLASS_ARMOUR, 25, '[', "[", 3, 10, 1 }, + { "chainmail", "suits of chainmail", "A suit of interlocking metal rings, providing better\nprotection than leather.", POCLASS_ARMOUR, 30, '[', "[", 6, 25, 3 }, + { "plate armour", "suits of plate armour", "A suit of steel plates, providing better protection than\nchainmail.", POCLASS_ARMOUR, 40, '[', "[", 10, 40, 6 }, + { "mage armour", "suits of mage armour", "A suit of glowing steel plates bearing enchantments of\ndefence.", POCLASS_ARMOUR, 70, '[', "[", 15, 40, 12 }, + { "mundane robe", "mundane robes", "A simple woolen robe. It's better protection than your\nskin, but not by much.", POCLASS_ARMOUR, 50, '[', "[", 2, 5, 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, 0, 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, -15, 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, 10, 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, 40, 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, 25, 24 }, + { "ragged shift", "ragged shifts", "This sorry-looking collection of rags is all that remains\nof an imposing armoured dress.", 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, 10, 1 }, + { "imperatrix gown", "imperatrix gowns", "This armoured, enchanted, and elaborately decorated dress\nwould be worthy of an empress regnant.", POCLASS_ARMOUR, 95, '[', "[", 15, 10, 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, -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, 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, 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, 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, 0, 1 }, + { "teleport ring", "teleport rings", "This magical ring allows the wearer to teleport for a\nmodest cost in nutrition.", POCLASS_RING, 70, '=', "=", 0, 0, 1 }, + { "iron ration", "iron rations", "A parcel of hardtack and beef jerky. Dull but nutritious.", POCLASS_FOOD, 75, '%', "%", 0, 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, 0, 1 }, + { "round of elven waybread", "rounds of elven waybread", "A tasty, filling, nutritious piece of elven waybread.", POCLASS_FOOD, 85, '%', "%", 0, 0, 1 }, + { "devil spleen", "devil spleens", "A weirdly pulsing organ ripped from the torso of a devil.", POCLASS_FOOD, 100, '%', "%", 0, 0, 1 } }; /* permobj.c */ diff --git a/victrix-abyssi.hh b/victrix-abyssi.hh index 0779fc2..e176527 100644 --- a/victrix-abyssi.hh +++ b/victrix-abyssi.hh @@ -42,6 +42,13 @@ #include "coord.hh" #endif +enum Comparison +{ + Lesser = -1, + Equal = 0, + Greater = 1 +}; + enum Pass_fail { You_fail = -1, -- 2.11.0