1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +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;

View File

@ -120,9 +120,12 @@ public:
/// returns numbers of hexes reachable by creature with id ID
std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL);
/// returns vector of distances to [dest hex number]
/// returns vector of distances to [dest hex number]; WARNING: second argument is ignored
std::vector<int> battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL);
/// returns vector of distances to [dest hex number]
std::vector<int> battleGetDistancesFromHex(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL);
std::set<THex> battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID);
/// returns true if unit with id ID can shoot to dest
bool battleCanShoot(const CStack * stack, THex dest);