From 8e10d315edb15e50616d4fd3601fc183f56d15ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 12 Dec 2011 00:53:27 +0000 Subject: [PATCH] [programming challenge] Implemented battleGetObstaclesAtTile. --- lib/IGameCallback.cpp | 13 ++++++++++--- lib/IGameCallback.h | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 6f46b9a95..4472c6945 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -157,10 +157,17 @@ int CBattleInfoCallback::battleGetBattlefieldType() return gs->curB->battlefieldType; } -int CBattleInfoCallback::battleGetObstaclesAtTile(THex tile) //returns bitfield +int CBattleInfoCallback::battleGetObstaclesAtTile(THex tile) { - //TODO - write - return -1; + std::vector obstacles = battleGetAllObstacles(); + std::set coveredHexes; + for(int b = 0; b < obstacles.size(); ++b) + { + std::vector blocked = VLC->heroh->obstacles.find(obstacles[b].ID)->second.getBlocked(obstacles[b].pos); + for(int w = 0; w < blocked.size(); ++w) + coveredHexes.insert(blocked[w]); + } + return vstd::contains(coveredHexes, tile); } std::vector CBattleInfoCallback::battleGetAllObstacles() diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index c6e5ea0bb..9c0fbc093 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -93,7 +93,7 @@ public: int battleGetBattlefieldType(); -/// returns bitfield +/// returns 1 if there is an obstacle or 0 otherwise int battleGetObstaclesAtTile(THex tile); /// returns all obstacles on the battlefield