From e337eb681db62549054fe2153afa39752e8bccc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 15 Dec 2011 23:50:35 +0000 Subject: [PATCH] =?UTF-8?q?[programming=20challenge]=20Added=20battleGetDi?= =?UTF-8?q?stancesFromHex=20as=20a=20fixed=20variant=20of=20battleGetDista?= =?UTF-8?q?nces=20(that=20uses=20its=20second=20argument=20=E2=80=94=20hex?= =?UTF-8?q?).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/IGameCallback.cpp | 10 +++++++--- lib/IGameCallback.h | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 4472c6945..98fd54c6e 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -55,6 +55,11 @@ si8 CBattleInfoCallback::battleCanTeleportTo(const CStack * stack, THex destHex, } std::vector CBattleInfoCallback::battleGetDistances(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/) +{ + return battleGetDistancesFromHex(stack, stack->position, predecessors); +} + +std::vector CBattleInfoCallback::battleGetDistancesFromHex(const CStack * stack, THex hex /*= THex::INVALID*/, THex * predecessors /*= NULL*/) { if(!hex.isValid()) hex = stack->position; @@ -65,7 +70,7 @@ std::vector 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 CBattleInfoCallback::battleGetDistances(const CStack * stack, T return ret; } + std::set 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; diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 9c0fbc093..fdc7ce5a9 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -120,9 +120,12 @@ public: /// returns numbers of hexes reachable by creature with id ID std::vector battleGetAvailableHexes(const CStack * stack, bool addOccupiable, std::vector * 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 battleGetDistances(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); + /// returns vector of distances to [dest hex number] + std::vector battleGetDistancesFromHex(const CStack * stack, THex hex = THex::INVALID, THex * predecessors = NULL); + std::set 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);