MCPcopy Create free account
hub / github.com/NetHack/NetHack / omon_adj

Function omon_adj

src/dothrow.c:1912–1947  ·  view source on GitHub ↗

an object may hit a monster; various factors adjust chance of hitting */

Source from the content-addressed store, hash-verified

1910
1911/* an object may hit a monster; various factors adjust chance of hitting */
1912int
1913omon_adj(struct monst *mon, struct obj *obj, boolean mon_notices)
1914{
1915 int tmp = 0;
1916
1917 /* size of target affects the chance of hitting */
1918 tmp += (mon->data->msize - MZ_MEDIUM); /* -2..+5 */
1919 /* sleeping target is more likely to be hit */
1920 if (mon->msleeping) {
1921 tmp += 2;
1922 }
1923 /* ditto for immobilized target */
1924 if (!mon->mcanmove || !mon->data->mmove) {
1925 tmp += 4;
1926 if (mon_notices && mon->data->mmove && !rn2(10)) {
1927 mon->mcanmove = 1;
1928 mon->mfrozen = 0;
1929 }
1930 }
1931 /* some objects are more likely to hit than others */
1932 switch (obj->otyp) {
1933 case HEAVY_IRON_BALL:
1934 if (obj != uball)
1935 tmp += 2;
1936 break;
1937 case BOULDER:
1938 tmp += 6;
1939 break;
1940 default:
1941 if (obj->oclass == WEAPON_CLASS || is_weptool(obj)
1942 || obj->oclass == GEM_CLASS)
1943 tmp += hitval(obj, mon);
1944 break;
1945 }
1946 return tmp;
1947}
1948
1949/* thrown object misses target monster */
1950staticfn void

Callers 3

drag_ballFunction · 0.85
thitmonstFunction · 0.85
ohitmonFunction · 0.85

Calls 2

rn2Function · 0.85
hitvalFunction · 0.85

Tested by

no test coverage detected