mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
[programming challenge] Added battleGetDistancesFromHex as a fixed variant of battleGetDistances (that uses its second argument — hex).
This commit is contained in:
@ -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*/)
|
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())
|
if(!hex.isValid())
|
||||||
hex = stack->position;
|
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);
|
gs->curB->getAccessibilityMap(ac, stack->doubleWide(), stack->attackerOwned, false, occupyable, stack->hasBonusOfType(Bonus::FLYING), stack);
|
||||||
THex pr[BFIELD_SIZE];
|
THex pr[BFIELD_SIZE];
|
||||||
int dist[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)
|
for(int i=0; i<BFIELD_SIZE; ++i)
|
||||||
{
|
{
|
||||||
@ -82,6 +87,7 @@ std::vector<int> CBattleInfoCallback::battleGetDistances(const CStack * stack, T
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<THex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos /*= THex::INVALID*/)
|
std::set<THex> CBattleInfoCallback::battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos /*= THex::INVALID*/)
|
||||||
{
|
{
|
||||||
if(!gs->curB)
|
if(!gs->curB)
|
||||||
@ -370,8 +376,6 @@ const CGHeroInstance * CBattleInfoCallback::battleGetFightingHero(ui8 side) cons
|
|||||||
return gs->curB->heroes[side];
|
return gs->curB->heroes[side];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CGameState *const CPrivilagedInfoCallback::gameState ()
|
CGameState *const CPrivilagedInfoCallback::gameState ()
|
||||||
{
|
{
|
||||||
return gs;
|
return gs;
|
||||||
|
@ -120,9 +120,12 @@ public:
|
|||||||
/// returns numbers of hexes reachable by creature with id ID
|
/// returns numbers of hexes reachable by creature with id ID
|
||||||
std::vector<THex> battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector<THex> * attackable = NULL);
|
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);
|
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);
|
std::set<THex> battleGetAttackedHexes(const CStack* attacker, THex destinationTile, THex attackerPos = THex::INVALID);
|
||||||
/// returns true if unit with id ID can shoot to dest
|
/// returns true if unit with id ID can shoot to dest
|
||||||
bool battleCanShoot(const CStack * stack, THex dest);
|
bool battleCanShoot(const CStack * stack, THex dest);
|
||||||
|
Reference in New Issue
Block a user