1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

* estimating damage that will be dealt while choosing stack to attack

This commit is contained in:
mateuszb 2009-08-29 17:09:07 +00:00
parent 4743bff359
commit 8fac12f957
5 changed files with 59 additions and 10 deletions

View File

@ -618,6 +618,29 @@ ui8 CCallback::battleGetWallState(int partOfWall)
return gs->curB->si.wallState[partOfWall];
}
std::pair<ui32, ui32> CCallback::battleEstimateDamage(int attackerID, int defenderID)
{
if(!gs->curB)
return std::make_pair(0, 0);
const CGHeroInstance * attackerHero, * defenderHero;
if(gs->curB->side1 == player)
{
attackerHero = gs->getHero(gs->curB->hero1);
defenderHero = gs->getHero(gs->curB->hero2);
}
else
{
attackerHero = gs->getHero(gs->curB->hero2);
defenderHero = gs->getHero(gs->curB->hero1);
}
const CStack * attacker = gs->curB->stacks[attackerID], * defender = gs->curB->stacks[defenderID];
return BattleInfo::calculateDmgRange(attacker, defender, attackerHero, defenderHero, battleCanShoot(attacker->ID, defender->position), 0);
}
void CCallback::swapGarrisonHero( const CGTownInstance *town )
{
if(town->tempOwner != player) return;

View File

@ -178,6 +178,7 @@ public:
virtual bool battleCanFlee()=0; //returns true if caller can flee from the battle
virtual const CGTownInstance * battleGetDefendedTown()=0; //returns defended town if current battle is a siege, NULL instead
virtual ui8 battleGetWallState(int partOfWall)=0; //for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle
virtual std::pair<ui32, ui32> battleEstimateDamage(int attackerID, int defenderID)=0; //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair <min dmg, max dmg>
};
struct HeroMoveDetails
@ -282,6 +283,7 @@ public:
bool battleCanFlee(); //returns true if caller can flee from the battle
const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead
ui8 battleGetWallState(int partOfWall); //for determining state of a part of the wall; format: parameter [0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; returned value: 1 - intact, 2 - damaged, 3 - destroyed; 0 - no battle
std::pair<ui32, ui32> battleEstimateDamage(int attackerID, int defenderID); //estimates damage dealt by attacker to defender; it may be not precise especially when stack has randomly working bonuses; returns pair <min dmg, max dmg>
//XXX hmmm _tmain on _GNUC_ wtf?
//friends

View File

@ -667,7 +667,12 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
CGI->curh->changeGraphic(1,3);
//setting console text
char buf[500];
sprintf(buf, CGI->generaltexth->allTexts[296].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str(), sactive->shots, "?");
//calculating esimated dmg
std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID);
std::ostringstream estDmg;
estDmg << estimatedDmg.first << " - " << estimatedDmg.second;
//printing
sprintf(buf, CGI->generaltexth->allTexts[296].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str(), sactive->shots, estDmg.str().c_str());
console->alterTxt = buf;
console->whoSetAlter = 0;
}
@ -792,6 +797,17 @@ void CBattleInterface::mouseMoved(const SDL_MouseMotionEvent &sEvent)
while (sectorCursor[(cursorIndex + i)%sectorCursor.size()] == -1)
i = i <= 0 ? 1 - i : -i; // 0, 1, -1, 2, -2, 3, -3 etc..
cursor->changeGraphic(1, sectorCursor[(cursorIndex + i)%sectorCursor.size()]);
//setting console info
char buf[500];
//calculating esimated dmg
std::pair<ui32, ui32> estimatedDmg = LOCPLINT->cb->battleEstimateDamage(sactive->ID, shere->ID);
std::ostringstream estDmg;
estDmg << estimatedDmg.first << " - " << estimatedDmg.second;
//printing
sprintf(buf, CGI->generaltexth->allTexts[36].c_str(), shere->amount == 1 ? shere->creature->nameSing.c_str() : shere->creature->namePl.c_str(), estDmg.str().c_str());
console->alterTxt = buf;
console->whoSetAlter = 0;
}
else //unavailable enemy
{

View File

@ -2064,7 +2064,7 @@ bool CGameState::checkForVisitableDir(const int3 & src, const int3 & dst) const
return true;
}
int BattleInfo::calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge)
std::pair<ui32, ui32> BattleInfo::calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge)
{
int attackDefenseBonus,
minDmg = attacker->creature->damageMin * attacker->amount,
@ -2261,23 +2261,30 @@ int BattleInfo::calculateDmg(const CStack* attacker, const CStack* defender, con
if(attacker->getEffect(42)) //curse handling (rest)
{
minDmg -= VLC->spellh->spells[42].powers[attacker->getEffect(42)->level];
return minDmg;
return std::make_pair(minDmg, minDmg);
}
else if(attacker->getEffect(41)) //bless handling
{
maxDmg += VLC->spellh->spells[41].powers[attacker->getEffect(41)->level];
return maxDmg;
return std::make_pair(maxDmg, maxDmg);
}
else
{
if(minDmg != maxDmg)
return minDmg + rand() % (maxDmg - minDmg + 1);
else
return minDmg;
return std::make_pair(minDmg, maxDmg);
}
tlog1 << "We are too far in calculateDmg...\n";
return -1;
return std::make_pair(0, 0);
}
ui32 BattleInfo::calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge)
{
std::pair<ui32, ui32> range = calculateDmgRange(attacker, defender, attackerHero, defendingHero, shooting, charge);
if(range.first != range.second)
return range.first + rand() % (range.second - range.first + 1);
else
return range.first;
}
void BattleInfo::calculateCasualties( std::set<std::pair<ui32,si32> > *casualties )

View File

@ -148,7 +148,8 @@ struct DLL_EXPORT BattleInfo
bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
static std::vector<int> neighbouringTiles(int hex);
static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge); //charge - number of hexes travelled before attack (for champion's jousting) //TODO: add additional conditions and require necessary data
static ui32 calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge); //charge - number of hexes travelled before attack (for champion's jousting)
static std::pair<ui32, ui32> calculateDmgRange(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting, ui8 charge); //charge - number of hexes travelled before attack (for champion's jousting); returns pair <min dmg, max dmg>
void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
std::set<CStack*> getAttackedCreatures(const CSpell * s, const CGHeroInstance * caster, int destinationTile); //calculates stack affected by given spell
static int calculateSpellDuration(const CSpell * spell, const CGHeroInstance * caster);