diff --git a/Source/missiles.cpp b/Source/missiles.cpp index 4e0e090bc3db..bbf6fe076093 100644 --- a/Source/missiles.cpp +++ b/Source/missiles.cpp @@ -239,7 +239,7 @@ bool MonsterMHit(const Player &player, int monsterId, int mindam, int maxdam, in if (t == MissileID::BoneSpirit) { dam = monster.hitPoints / 3 >> 6; } else { - dam = mindam + GenerateRnd(maxdam - mindam + 1); + dam = RandomIntBetween(mindam, maxdam); } if (missileData.isArrow() && damageType == DamageType::Physical) { @@ -3304,7 +3304,7 @@ void ProcessLightningControl(Missile &missile) dam = (GenerateRnd(2) + GenerateRnd(Players[missile._misource].getCharacterLevel()) + 2) << 6; } else { auto &monster = Monsters[missile._misource]; - dam = 2 * (monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1)); + dam = 2 * RandomIntBetween(monster.minDamage, monster.maxDamage); } SpawnLightning(missile, dam); diff --git a/Source/monster.cpp b/Source/monster.cpp index db36cae3100f..5979e4f5f01a 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -149,7 +149,7 @@ void InitMonster(Monster &monster, Direction rd, size_t typeIndex, Point positio monster.animInfo.tickCounterOfCurrentFrame = GenerateRnd(monster.animInfo.ticksPerFrame - 1); monster.animInfo.currentFrame = GenerateRnd(monster.animInfo.numberOfFrames - 1); - int maxhp = monster.data().hitPointsMinimum + GenerateRnd(monster.data().hitPointsMaximum - monster.data().hitPointsMinimum + 1); + int maxhp = RandomIntBetween(monster.data().hitPointsMinimum, monster.data().hitPointsMaximum); if (monster.type().type == MT_DIABLO && !gbIsHellfire) { maxhp /= 2; } @@ -1086,7 +1086,7 @@ void MonsterAttackMonster(Monster &attacker, Monster &target, int hper, int mind if (hit >= hper) return; - int dam = (mind + GenerateRnd(maxd - mind + 1)) << 6; + int dam = RandomIntBetween(mind, maxd) << 6; ApplyMonsterDamage(DamageType::Physical, target, dam); if (attacker.isPlayerMinion()) { @@ -1191,7 +1191,8 @@ void MonsterAttackPlayer(Monster &monster, Player &player, int hit, int minDam, } } } - int dam = (minDam << 6) + GenerateRnd(((maxDam - minDam) << 6) + 1); + // New method fixes a bug which caused the maximum possible damage value to be 63/64ths too low. + int dam = RandomIntBetween(minDam, maxDam) << 6; dam = std::max(dam + (player._pIGetHit << 6), 64); if (&player == MyPlayer) { if (player.wReflections > 0) { @@ -2650,7 +2651,7 @@ void CounselorAi(Monster &monster) if (distanceToEnemy >= 2) { if (v < 5 * (monster.intelligence + 10) && LineClearMissile(monster.position.tile, monster.enemyPosition)) { constexpr MissileID MissileTypes[4] = { MissileID::Firebolt, MissileID::ChargedBolt, MissileID::LightningControl, MissileID::Fireball }; - StartRangedAttack(monster, MissileTypes[monster.intelligence], monster.minDamage + GenerateRnd(monster.maxDamage - monster.minDamage + 1)); + StartRangedAttack(monster, MissileTypes[monster.intelligence], RandomIntBetween(monster.minDamage, monster.maxDamage)); } else if (GenerateRnd(100) < 30) { monster.goal = MonsterGoal::Move; monster.goalVar1 = 0; diff --git a/Source/player.cpp b/Source/player.cpp index 66261e5861b3..c524369fd6dc 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -600,12 +600,12 @@ bool PlrHitMonst(Player &player, Monster &monster, bool adjacentDamage = false) } if (gbIsHellfire && HasAllOf(player._pIFlags, ItemSpecialEffect::FireDamage | ItemSpecialEffect::LightningDamage)) { - int midam = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam); + int midam = RandomIntBetween(player._pIFMinDam, player._pIFMaxDam); AddMissile(player.position.tile, player.position.temp, player._pdir, MissileID::SpectralArrow, TARGET_MONSTERS, player, midam, 0); } int mind = player._pIMinDam; int maxd = player._pIMaxDam; - int dam = GenerateRnd(maxd - mind + 1) + mind; + int dam = RandomIntBetween(mind, maxd); dam += dam * player._pIBonusDam / 100; dam += player._pIBonusDamMod; int dam2 = dam << 6; @@ -773,7 +773,7 @@ bool PlrHitPlr(Player &attacker, Player &target) int mind = attacker._pIMinDam; int maxd = attacker._pIMaxDam; - int dam = GenerateRnd(maxd - mind + 1) + mind; + int dam = RandomIntBetween(mind, maxd); dam += (dam * attacker._pIBonusDam) / 100; dam += attacker._pIBonusDamMod + attacker._pDamageMod; @@ -920,7 +920,7 @@ bool DoRangeAttack(Player &player) mistype = MissileID::LightningArrow; } if (HasAllOf(player._pIFlags, ItemSpecialEffect::FireArrows | ItemSpecialEffect::LightningArrows)) { - dmg = player._pIFMinDam + GenerateRnd(player._pIFMaxDam - player._pIFMinDam); + dmg = RandomIntBetween(player._pIFMinDam, player._pIFMaxDam); mistype = MissileID::SpectralArrow; }