BUG 2378: Fix magic armor resistance calculation.

Use frac_one constant where applicable.
This commit is contained in:
Enno Rehling 2017-10-29 18:55:43 +01:00
parent 1866b95e14
commit 5af5daa355
4 changed files with 6 additions and 5 deletions

View file

@ -1141,7 +1141,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
const weapon_type *dwtype = NULL; const weapon_type *dwtype = NULL;
const weapon_type *awtype = NULL; const weapon_type *awtype = NULL;
const weapon *weapon; const weapon *weapon;
variant res = frac_make(1, 1); variant res = frac_one;
int rda, sk = 0, sd; int rda, sk = 0, sd;
bool magic = false; bool magic = false;
@ -1185,6 +1185,7 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
} }
if (magic) { if (magic) {
res = frac_sub(frac_one, res);
res = frac_mul(frac_make(da, 1), res); res = frac_mul(frac_make(da, 1), res);
da = res.sa[0] / res.sa[1]; da = res.sa[0] / res.sa[1];
} }

View file

@ -76,7 +76,7 @@ int *casualties)
killed += terminate(dt, *at, AT_SPELL, damage, 1); killed += terminate(dt, *at, AT_SPELL, damage, 1);
} }
} while (force && killed < enemies); } while (force && killed < enemies);
if (casualties) if (killed > 0 && casualties)
*casualties = killed; *casualties = killed;
return true; return true;
} }

View file

@ -405,7 +405,7 @@ static int required(int size, int msize, int maxneed)
static int matmod(const unit * u, const resource_type * rtype, int value) static int matmod(const unit * u, const resource_type * rtype, int value)
{ {
if (rtype->modifiers) { if (rtype->modifiers) {
variant save = frac_make(1, 1); variant save = frac_one;
const struct building_type *btype = NULL; const struct building_type *btype = NULL;
const struct race *rc = u_race(u); const struct race *rc = u_race(u);
resource_mod *mod; resource_mod *mod;

View file

@ -106,8 +106,8 @@ damage_unit(unit * u, const char *dam, bool physical, bool magic)
int damage = dice_rand(dam); int damage = dice_rand(dam);
if (magic) { if (magic) {
variant magres = magic_resistance(u); variant magres = magic_resistance(u);
magres = frac_sub(frac_make(1, 1), magres); int save = magres.sa[0] / magres.sa[1];
damage = damage * magres.sa[0] / magres.sa[1]; damage -= damage * save;
} }
if (physical) { if (physical) {
damage -= nb_armor(u, i); damage -= nb_armor(u, i);