MCPcopy Index your code
hub / github.com/NetHack/NetHack / thitmonst

Function thitmonst

src/dothrow.c:2010–2304  ·  view source on GitHub ↗

* Object thrown by player arrives at monster's location. * Return 1 if obj has disappeared or otherwise been taken care of, * 0 if caller must take care of it. * Also used for kicked objects and for polearms/grapnel applied at range. */

Source from the content-addressed store, hash-verified

2008 * Also used for kicked objects and for polearms/grapnel applied at range.
2009 */
2010int
2011thitmonst(
2012 struct monst *mon,
2013 struct obj *obj) /* gt.thrownobj or gk.kickedobj or uwep */
2014{
2015 int tmp; /* Base chance to hit */
2016 int disttmp; /* distance modifier */
2017 int otyp = obj->otyp, hmode;
2018 boolean guaranteed_hit = engulfing_u(mon);
2019 int dieroll;
2020
2021 hmode = (obj == uwep) ? HMON_APPLIED
2022 : (obj == gk.kickedobj) ? HMON_KICKED
2023 : HMON_THROWN;
2024
2025 /* Differences from melee weapons:
2026 *
2027 * Dex still gives a bonus, but strength does not.
2028 * Polymorphed players lacking attacks may still throw.
2029 * There's a base -1 to hit.
2030 * No bonuses for fleeing or stunned targets (they don't dodge
2031 * melee blows as readily, but dodging arrows is hard anyway).
2032 * Not affected by traps, etc.
2033 * Certain items which don't in themselves do damage ignore 'tmp'.
2034 * Distance and monster size affect chance to hit.
2035 */
2036 tmp = -1 + Luck + find_mac(mon) + u.uhitinc
2037 + maybe_polyd(gy.youmonst.data->mlevel, u.ulevel);
2038 if (ACURR(A_DEX) < 4)
2039 tmp -= 3;
2040 else if (ACURR(A_DEX) < 6)
2041 tmp -= 2;
2042 else if (ACURR(A_DEX) < 8)
2043 tmp -= 1;
2044 else if (ACURR(A_DEX) >= 14)
2045 tmp += (ACURR(A_DEX) - 14);
2046
2047 /* Modify to-hit depending on distance; but keep it sane.
2048 * Polearms get a distance penalty even when wielded; it's
2049 * hard to hit at a distance.
2050 */
2051 disttmp = 3 - distmin(u.ux, u.uy, mon->mx, mon->my);
2052 if (disttmp < -4)
2053 disttmp = -4;
2054 tmp += disttmp;
2055
2056 /* gloves are a hindrance to proper use of bows */
2057 if (uarmg && uwep && objects[uwep->otyp].oc_skill == P_BOW) {
2058 switch (uarmg->otyp) {
2059 case GAUNTLETS_OF_POWER: /* metal */
2060 tmp -= 2;
2061 break;
2062 case GAUNTLETS_OF_FUMBLING:
2063 tmp -= 3;
2064 break;
2065 case LEATHER_GLOVES:
2066 case GAUNTLETS_OF_DEXTERITY:
2067 break;

Callers 4

throwit_mon_hitFunction · 0.85
really_kick_objectFunction · 0.85
use_poleFunction · 0.85
use_grappleFunction · 0.85

Calls 15

find_macFunction · 0.85
distminFunction · 0.85
omon_adjFunction · 0.85
tmissFunction · 0.85
MonnamFunction · 0.85
theFunction · 0.85
xnameFunction · 0.85
gem_acceptFunction · 0.85
Some_MonnamFunction · 0.85
fully_identify_objFunction · 0.85
verbalizeFunction · 0.85
s_suffixFunction · 0.85

Tested by

no test coverage detected