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

fixed wrong battle result

This commit is contained in:
AlexVinS 2017-07-14 23:43:03 +03:00
parent 2fb531b6d0
commit df13851176
3 changed files with 21 additions and 5 deletions

View File

@ -264,12 +264,15 @@ void CHealth::toInfo(CHealthInfo & info) const
void CHealth::takeResurrected() void CHealth::takeResurrected()
{ {
int64_t totalHealth = total(); if(resurrected != 0)
{
int64_t totalHealth = available();
totalHealth -= resurrected * owner->unitMaxHealth(); totalHealth -= resurrected * owner->unitMaxHealth();
vstd::amax(totalHealth, 0); vstd::amax(totalHealth, 0);
setFromTotal(totalHealth); setFromTotal(totalHealth);
resurrected = 0; resurrected = 0;
}
} }
///CStack ///CStack

View File

@ -6429,6 +6429,7 @@ CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance * _army, Battl
} }
else if(st->base && !army->slotEmpty(st->slot)) else if(st->base && !army->slotEmpty(st->slot))
{ {
logGlobal->debug("Count: %d; base count: %d", st->getCount(), army->getStackCount(st->slot));
if(st->getCount() == 0 || !st->alive()) if(st->getCount() == 0 || !st->alive())
{ {
logGlobal->debug("Stack has been destroyed."); logGlobal->debug("Stack has been destroyed.");

View File

@ -166,6 +166,18 @@ BOOST_FIXTURE_TEST_CASE(resurrectOneBattle, CUnitHealthInfoMock)
health.init(); health.init();
checkNormalDamage(health, UNIT_HEALTH);
BOOST_CHECK_EQUAL(health.getCount(), UNIT_AMOUNT - 1);
BOOST_CHECK_EQUAL(health.getFirstHPleft(), UNIT_HEALTH);
BOOST_CHECK_EQUAL(health.getResurrected(), 0);
health.takeResurrected();
BOOST_CHECK_EQUAL(health.getCount(), UNIT_AMOUNT - 1);
BOOST_CHECK_EQUAL(health.getFirstHPleft(), UNIT_HEALTH);
BOOST_CHECK_EQUAL(health.getResurrected(), 0);
health.init();
checkNormalDamage(health, UNIT_HEALTH * UNIT_AMOUNT); checkNormalDamage(health, UNIT_HEALTH * UNIT_AMOUNT);
checkEmptyHealth(health, *this); checkEmptyHealth(health, *this);