--- angband-master/src/monster/mon-lore.c Tue Dec 24 06:58:50 2013 @@ -385,7 +385,7 @@ /** * Determine if the player knows the AC of the given monster. */ -static bool know_armour(const monster_race *r_ptr, const monster_lore *l_ptr) +bool know_armour(const monster_race *r_ptr, const monster_lore *l_ptr) { assert(l_ptr); return l_ptr->tkills > 0; --- angband-master/src/monster/mon-lore.h Tue Dec 24 06:58:50 2013 @@ -30,6 +30,7 @@ /** Variables **/ /** Functions **/ +bool know_armour(const monster_race *r_ptr, const monster_lore *l_ptr); void cheat_monster_lore(const monster_race *r_ptr, monster_lore *l_ptr); void wipe_monster_lore(const monster_race *r_ptr, monster_lore *l_ptr); void lore_do_probe(struct monster *m); --- angband-master/src/object/obj-info.c Tue Dec 24 06:58:50 2013 @@ -25,6 +25,8 @@ #include "z-textblock.h" #include "object/slays.h" #include "object/pval.h" +#include "monster/mon-util.h" +#include "monster/mon-lore.h" /* * Describes a flag-name pair. @@ -759,6 +761,66 @@ } + +/* + * Describe hit chance vs most recently recalled monster. + */ +static bool describe_hitchance(textblock *tb, const object_type *o_ptr, + player_state state, bitflag f[OF_SIZE], oinfo_detail_t mode) +{ + bool weapon = (wield_slot(o_ptr) == INVEN_WIELD); + bool have_knowledge = FALSE; + monster_lore *lore; + long chance = 0, chance2 = 0; + monster_race *race = p_ptr->monster_race; + + if (!weapon) + { + return FALSE; + } + + textblock_append(tb, "\n"); + + if (race) + { + lore = get_lore(race); + if (know_armour(race, lore)) + { + have_knowledge = TRUE; + + /* Player's chance to hit it */ + chance = py_attack_hit_chance(o_ptr); + + /* The following calculations are based on test_hit(); make sure to keep it in sync */ + /* Avoid division by zero errors, and starting higher on the scale */ + if (chance < 9) + chance = 9; + + chance2 = 90 * (chance - (race->ac * 2 / 3)) / chance + 5; + + /* There is always a 12 percent chance to hit */ + if (chance2 < 12) chance2 = 12; + + /* TODO: add better grammer */ + textblock_append(tb, "Chance to hit "); + textblock_append(tb, race->name); + textblock_append(tb, ": "); + textblock_append_c(tb, TERM_L_BLUE, " %d", chance2); + textblock_append(tb, "%%"); + } + } + + if (!have_knowledge) + { + textblock_append_c(tb, TERM_L_DARK, "Use monster recall to select a known subject for a hit chance calculation."); + } + + textblock_append(tb, "\n"); + + return TRUE; +} + + /* * Describe combat advantages. */ @@ -829,6 +891,9 @@ /* Describe damage */ describe_damage(tb, o_ptr, state, f, mode); + /* Describe hitchance */ + describe_hitchance(tb, o_ptr, state, f, mode); + /* Note the impact flag */ if (of_has(f, OF_IMPACT)) textblock_append(tb, "Sometimes creates earthquakes on impact.\n");