1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-01 00:45:26 +02:00

[programming challenge] Added battleGetDistancesFromHex as a fixed variant of battleGetDistances (that uses its second argument — hex).

This commit is contained in:
Michał W. Urbańczyk
2011-12-15 23:50:35 +00:00
parent 8e10d315ed
commit e337eb681d
2 changed files with 11 additions and 4 deletions

View File

@ -55,6 +55,11 @@ si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, THex destHex,
}
std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
{
return battleGetDistancesFromHex(stack, stack->position, predecessors);
}
std::vector<int> CBattleInfoCallback::battleGetDistancesFromHex(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/)
{
if(!hex.isValid())
hex = stack->position;
@ -65,7 +70,7 @@ std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, T
gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack);
THex pr[BFIELD_SIZE];
int dist[BFIELD_SIZE];
gs->curB->makeBFS(stack->position, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
gs->curB->makeBFS(hex, ac, pr, dist, stack->doubleWide(), stack->attackerOwned, stack->hasBonusOfType(Bonus::FLYING), false);
for(int i=0; i<BFIELD_SIZE; ++i)
{
@ -82,6 +87,7 @@ std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, T
return ret;
}
std::set<THex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos /*= THex::INVALID*/)
{
if(!gs->curB)
@ -370,8 +376,6 @@ const CGHeroInstance * CBattleInfoCallback::battleGetFightingHero(ui8 side) cons
return gs->curB->heroes[side];
}
CGameState *const CPrivilagedInfoCallback::gameState ()
{
return gs;