1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixed #1352. Implemented correct death stare algorithm.

This commit is contained in:
DjWarmonger 2013-07-28 08:48:29 +00:00
parent 5f310aa20f
commit abaa5b1c59
2 changed files with 5 additions and 3 deletions

View File

@ -114,6 +114,7 @@
"deathStare" :
{
"type" : "DEATH_STARE",
"subtype" : 0,
"val" : 10
}
},

View File

@ -5332,9 +5332,9 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
{
// mechanics of Death Stare as in H3:
// each gorgon have 10% chance to kill (counted separately in H3) -> binomial distribution
// maximum amount that can be killed is ( gorgons_count / 10 ), rounded up
//original formula x = min(x, (gorgons_count + 9)/10);
double chanceToKill = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100;
double chanceToKill = attacker->valOfBonuses(Bonus::DEATH_STARE, 0) / 100.0f;
vstd::amin(chanceToKill, 1); //cap at 100%
std::binomial_distribution<> distr(attacker->count, chanceToKill);
@ -5342,7 +5342,8 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
int staredCreatures = distr(rng);
int maxToKill = (attacker->count * chanceToKill + 99) / 100;
double cap = 1 / std::max(chanceToKill, (double)(0.01));//don't divide by 0
int maxToKill = (attacker->count + cap - 1) / cap; //not much more than chance * count
vstd::amin(staredCreatures, maxToKill);
staredCreatures += (attacker->level() * attacker->valOfBonuses(Bonus::DEATH_STARE, 1)) / gs->curB->battleGetStackByID(bat.bsa[0].stackAttacked)->level();