From 57a0efea3ac85e10c522afcaaae4307c0c6efcd9 Mon Sep 17 00:00:00 2001 From: Tangles Date: Wed, 27 Sep 2017 00:20:17 +1000 Subject: [PATCH] bugfix - dieroll fix based on barthouse contribution to 3.6.x barthouse commits: 0f2fe57c79b99b86e822a567ab60db211f27ea5e 583f99a4d4a9fa9c97295c1e164b63e0ad3d067a 04290ca8a81fefcea204ad72cdbbf829b5203c2d --- include/extern.h | 2 +- src/ball.c | 5 +++-- src/do.c | 3 ++- src/dothrow.c | 16 +++++++++------- src/uhitm.c | 32 ++++++++++++++++++-------------- 5 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/extern.h b/include/extern.h index e3c66040..bd71ed42 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2110,7 +2110,7 @@ E boolean FDECL(attack_checks, (struct monst *,struct obj *)); E void FDECL(check_caitiff, (struct monst *)); E schar FDECL(find_roll_to_hit, (struct monst *)); E boolean FDECL(attack, (struct monst *)); -E boolean FDECL(hmon, (struct monst *,struct obj *,int)); +E boolean FDECL(hmon, (struct monst *,struct obj *,int,int)); E int FDECL(damageum, (struct monst *,struct attack *)); E void FDECL(missum, (struct monst *,struct attack *)); E int FDECL(passive, (struct monst *,BOOLEAN_P,int,UCHAR_P)); diff --git a/src/ball.c b/src/ball.c index 5d972445..f077792b 100644 --- a/src/ball.c +++ b/src/ball.c @@ -581,11 +581,12 @@ boolean allow_drag; You("are jerked back by the iron ball!"); if ((victim = m_at(uchain->ox, uchain->oy)) != 0) { int tmp; + int dieroll = rnd(20); tmp = -2 + Luck + find_mac(victim); tmp += omon_adj(victim, uball, TRUE); - if (tmp >= rnd(20)) - (void) hmon(victim,uball,1); + if (tmp >= dieroll) + (void) hmon(victim,uball,1,dieroll); else miss(xname(uball), victim); diff --git a/src/do.c b/src/do.c index 15e1aa21..49d428ab 100644 --- a/src/do.c +++ b/src/do.c @@ -159,7 +159,8 @@ const char *verb; if (mtmp) { if (!passes_walls(mtmp->data) && !throws_rocks(mtmp->data)) { - if (hmon(mtmp, obj, TRUE) && !is_whirly(mtmp->data)) + int dieroll = rnd(20); + if (hmon(mtmp, obj, TRUE, dieroll) && !is_whirly(mtmp->data)) return FALSE; /* still alive */ } mtmp->mtrapped = 0; diff --git a/src/dothrow.c b/src/dothrow.c index 290cec63..de209000 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -1192,6 +1192,7 @@ register struct obj *obj; register int disttmp; /* distance modifier */ int otyp = obj->otyp; boolean guaranteed_hit = (u.uswallow && mon == u.ustuck); + int dieroll; /* Differences from melee weapons: * @@ -1282,6 +1283,7 @@ register struct obj *obj; return(0); } + dieroll = rnd(20); if (obj->oclass == WEAPON_CLASS || is_weptool(obj) || obj->oclass == GEM_CLASS) { if (is_ammo(obj)) { @@ -1318,8 +1320,8 @@ register struct obj *obj; tmp += weapon_hit_bonus(obj); } - if (tmp >= rnd(20)) { - if (hmon(mon,obj,1)) { /* mon still alive */ + if (tmp >= dieroll) { + if (hmon(mon,obj,1,dieroll)) { /* mon still alive */ cutworm(mon, bhitpos.x, bhitpos.y, obj); } exercise(A_DEX, TRUE); @@ -1355,11 +1357,11 @@ register struct obj *obj; } else if (otyp == HEAVY_IRON_BALL) { exercise(A_STR, TRUE); - if (tmp >= rnd(20)) { + if (tmp >= dieroll) { int was_swallowed = guaranteed_hit; exercise(A_DEX, TRUE); - if (!hmon(mon,obj,1)) { /* mon killed */ + if (!hmon(mon,obj,1,dieroll)) { /* mon killed */ if (was_swallowed && !u.uswallow && obj == uball) return 1; /* already did placebc() */ } @@ -1369,9 +1371,9 @@ register struct obj *obj; } else if (otyp == BOULDER) { exercise(A_STR, TRUE); - if (tmp >= rnd(20)) { + if (tmp >= dieroll) { exercise(A_DEX, TRUE); - (void) hmon(mon,obj,1); + (void) hmon(mon,obj,1,dieroll); } else { tmiss(obj, mon); } @@ -1379,7 +1381,7 @@ register struct obj *obj; } else if ((otyp == EGG || otyp == CREAM_PIE || otyp == BLINDING_VENOM || otyp == ACID_VENOM) && (guaranteed_hit || ACURR(A_DEX) > rnd(25))) { - (void) hmon(mon, obj, 1); + (void) hmon(mon, obj, 1, dieroll); return 1; /* hmon used it up */ } else if (obj->oclass == POTION_CLASS && diff --git a/src/uhitm.c b/src/uhitm.c index 64f20655..95320361 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -4,10 +4,10 @@ #include "hack.h" -STATIC_DCL boolean FDECL(known_hitum, (struct monst *,int *,struct attack *)); +STATIC_DCL boolean FDECL(known_hitum, (struct monst *,int *,struct attack *,int)); STATIC_DCL void FDECL(steal_it, (struct monst *, struct attack *)); STATIC_DCL boolean FDECL(hitum, (struct monst *,int,struct attack *)); -STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *,struct obj *,int)); +STATIC_DCL boolean FDECL(hmon_hitmon, (struct monst *,struct obj *,int,int)); #ifdef STEED STATIC_DCL int FDECL(joust, (struct monst *,struct obj *)); #endif @@ -22,8 +22,7 @@ STATIC_DCL void FDECL(nohandglow, (struct monst *)); STATIC_DCL boolean FDECL(shade_aware, (struct obj *)); extern boolean notonhead; /* for long worms */ -/* The below might become a parameter instead if we use it a lot */ -static int dieroll; + /* Used to flag attacks caused by Stormbringer's maliciousness. */ static boolean override_confirmation = FALSE; @@ -427,10 +426,11 @@ register struct monst *mtmp; } STATIC_OVL boolean -known_hitum(mon, mhit, uattk) /* returns TRUE if monster still lives */ +known_hitum(mon, mhit, uattk, dieroll) /* returns TRUE if monster still lives */ register struct monst *mon; register int *mhit; struct attack *uattk; +int dieroll; { register boolean malive = TRUE; @@ -453,11 +453,11 @@ struct attack *uattk; /* we hit the monster; be careful: it might die or be knocked into a different location */ notonhead = (mon->mx != x || mon->my != y); - malive = hmon(mon, uwep, 0); + malive = hmon(mon, uwep, 0, dieroll); /* this assumes that Stormbringer was uwep not uswapwep */ if (malive && u.twoweap && !override_confirmation && m_at(x, y) == mon) - malive = hmon(mon, uswapwep, 0); + malive = hmon(mon, uswapwep, 0, dieroll); if (malive) { /* monster still alive */ if(!rn2(25) && mon->mhp < mon->mhpmax/2 @@ -493,19 +493,21 @@ int tmp; struct attack *uattk; { boolean malive; - int mhit = (tmp > (dieroll = rnd(20)) || u.uswallow); + int dieroll = rnd(20); + int mhit = (tmp > dieroll || u.uswallow); if(tmp > dieroll) exercise(A_DEX, TRUE); - malive = known_hitum(mon, &mhit, uattk); + malive = known_hitum(mon, &mhit, uattk, dieroll); (void) passive(mon, mhit, malive, AT_WEAP); return(malive); } boolean /* general "damage monster" routine */ -hmon(mon, obj, thrown) /* return TRUE if mon still alive */ +hmon(mon, obj, thrown, dieroll) /* return TRUE if mon still alive */ struct monst *mon; struct obj *obj; int thrown; +int dieroll; { boolean result, anger_guards; @@ -513,7 +515,7 @@ int thrown; (mon->ispriest || mon->isshk || mon->data == &mons[PM_WATCHMAN] || mon->data == &mons[PM_WATCH_CAPTAIN])); - result = hmon_hitmon(mon, obj, thrown); + result = hmon_hitmon(mon, obj, thrown, dieroll); if (mon->ispriest && !rn2(2)) ghod_hitsu(mon); if (anger_guards) (void)angry_guards(!flags.soundok); return result; @@ -521,10 +523,11 @@ int thrown; /* guts of hmon() */ STATIC_OVL boolean -hmon_hitmon(mon, obj, thrown) +hmon_hitmon(mon, obj, thrown, dieroll) struct monst *mon; struct obj *obj; int thrown; +int dieroll; { int tmp; struct permonst *mdat = mon->data; @@ -1955,6 +1958,7 @@ register int tmp; int i, sum[NATTK], hittmp = 0; int nsum = 0; int dhit = 0; + int dieroll; for(i = 0; i < NATTK; i++) { @@ -1981,7 +1985,7 @@ register int tmp; /* KMH -- Don't accumulate to-hit bonuses */ if (uwep) tmp -= hittmp; /* Enemy dead, before any special abilities used */ - if (!known_hitum(mon,&dhit,mattk)) { + if (!known_hitum(mon,&dhit,mattk,dieroll)) { sum[i] = 2; break; } else sum[i] = dhit; @@ -2010,7 +2014,7 @@ register int tmp; case AT_BUTT: case AT_TENT: if (i==0 && uwep && (youmonst.data->mlet==S_LICH)) goto use_weapon; - if ((dhit = (tmp > rnd(20) || u.uswallow)) != 0) { + if ((dhit = (tmp > (dieroll = rnd(20)) || u.uswallow)) != 0) { int compat; if (!u.uswallow &&