BattleFieldController.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. /*
  2. * BattleFieldController.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "BattleFieldController.h"
  12. #include "BattleInterface.h"
  13. #include "BattleActionsController.h"
  14. #include "BattleInterfaceClasses.h"
  15. #include "BattleEffectsController.h"
  16. #include "BattleSiegeController.h"
  17. #include "BattleStacksController.h"
  18. #include "BattleObstacleController.h"
  19. #include "BattleProjectileController.h"
  20. #include "BattleRenderer.h"
  21. #include "../CGameInfo.h"
  22. #include "../CPlayerInterface.h"
  23. #include "../render/Canvas.h"
  24. #include "../render/IImage.h"
  25. #include "../renderSDL/SDL_Extensions.h"
  26. #include "../gui/CGuiHandler.h"
  27. #include "../gui/CursorHandler.h"
  28. #include "../adventureMap/CInGameConsole.h"
  29. #include "../../CCallback.h"
  30. #include "../../lib/BattleFieldHandler.h"
  31. #include "../../lib/CConfigHandler.h"
  32. #include "../../lib/CStack.h"
  33. #include "../../lib/spells/ISpellMechanics.h"
  34. BattleFieldController::BattleFieldController(BattleInterface & owner):
  35. owner(owner)
  36. {
  37. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  38. strongInterest = true;
  39. //preparing cells and hexes
  40. cellBorder = IImage::createFromFile("CCELLGRD.BMP", EImageBlitMode::COLORKEY);
  41. cellShade = IImage::createFromFile("CCELLSHD.BMP");
  42. cellUnitMovementHighlight = IImage::createFromFile("UnitMovementHighlight.PNG", EImageBlitMode::COLORKEY);
  43. cellUnitMaxMovementHighlight = IImage::createFromFile("UnitMaxMovementHighlight.PNG", EImageBlitMode::COLORKEY);
  44. if(!owner.siegeController)
  45. {
  46. auto bfieldType = owner.curInt->cb->battleGetBattlefieldType();
  47. if(bfieldType == BattleField::NONE)
  48. logGlobal->error("Invalid battlefield returned for current battle");
  49. else
  50. background = IImage::createFromFile(bfieldType.getInfo()->graphics, EImageBlitMode::OPAQUE);
  51. }
  52. else
  53. {
  54. std::string backgroundName = owner.siegeController->getBattleBackgroundName();
  55. background = IImage::createFromFile(backgroundName, EImageBlitMode::OPAQUE);
  56. }
  57. pos.w = background->width();
  58. pos.h = background->height();
  59. backgroundWithHexes = std::make_unique<Canvas>(Point(background->width(), background->height()));
  60. updateAccessibleHexes();
  61. addUsedEvents(LCLICK | RCLICK | MOVE);
  62. LOCPLINT->cingconsole->pos = this->pos;
  63. }
  64. void BattleFieldController::createHeroes()
  65. {
  66. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  67. // create heroes as part of our constructor for correct positioning inside battlefield
  68. if(owner.attackingHeroInstance)
  69. owner.attackingHero = std::make_shared<BattleHero>(owner, owner.attackingHeroInstance, false);
  70. if(owner.defendingHeroInstance)
  71. owner.defendingHero = std::make_shared<BattleHero>(owner, owner.defendingHeroInstance, true);
  72. }
  73. void BattleFieldController::mouseMoved(const Point & cursorPosition)
  74. {
  75. if (!pos.isInside(cursorPosition))
  76. {
  77. owner.actionsController->onHoverEnded();
  78. return;
  79. }
  80. BattleHex selectedHex = getHoveredHex();
  81. owner.actionsController->onHexHovered(selectedHex);
  82. }
  83. void BattleFieldController::clickLeft(tribool down, bool previousState)
  84. {
  85. if(!down)
  86. {
  87. BattleHex selectedHex = getHoveredHex();
  88. if (selectedHex != BattleHex::INVALID)
  89. owner.actionsController->onHexLeftClicked(selectedHex);
  90. }
  91. }
  92. void BattleFieldController::clickRight(tribool down, bool previousState)
  93. {
  94. if(down)
  95. {
  96. BattleHex selectedHex = getHoveredHex();
  97. if (selectedHex != BattleHex::INVALID)
  98. owner.actionsController->onHexRightClicked(selectedHex);
  99. }
  100. }
  101. void BattleFieldController::renderBattlefield(Canvas & canvas)
  102. {
  103. Canvas clippedCanvas(canvas, pos);
  104. showBackground(clippedCanvas);
  105. BattleRenderer renderer(owner);
  106. renderer.execute(clippedCanvas);
  107. owner.projectilesController->showProjectiles(clippedCanvas);
  108. }
  109. void BattleFieldController::showBackground(Canvas & canvas)
  110. {
  111. if (owner.stacksController->getActiveStack() != nullptr ) //&& creAnims[stacksController->getActiveStack()->unitId()]->isIdle() //show everything with range
  112. showBackgroundImageWithHexes(canvas);
  113. else
  114. showBackgroundImage(canvas);
  115. showHighlightedHexes(canvas);
  116. }
  117. void BattleFieldController::showBackgroundImage(Canvas & canvas)
  118. {
  119. canvas.draw(background, Point(0, 0));
  120. owner.obstacleController->showAbsoluteObstacles(canvas);
  121. if ( owner.siegeController )
  122. owner.siegeController->showAbsoluteObstacles(canvas);
  123. if (settings["battle"]["cellBorders"].Bool())
  124. {
  125. for (int i=0; i<GameConstants::BFIELD_SIZE; ++i)
  126. {
  127. if ( i % GameConstants::BFIELD_WIDTH == 0)
  128. continue;
  129. if ( i % GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_WIDTH - 1)
  130. continue;
  131. canvas.draw(cellBorder, hexPositionLocal(i).topLeft());
  132. }
  133. }
  134. }
  135. void BattleFieldController::showBackgroundImageWithHexes(Canvas & canvas)
  136. {
  137. canvas.draw(*backgroundWithHexes.get(), Point(0, 0));
  138. }
  139. void BattleFieldController::redrawBackgroundWithHexes()
  140. {
  141. const CStack *activeStack = owner.stacksController->getActiveStack();
  142. std::vector<BattleHex> attackableHexes;
  143. if(activeStack)
  144. occupiableHexes = owner.curInt->cb->battleGetAvailableHexes(activeStack, false, true, &attackableHexes);
  145. // prepare background graphic with hexes and shaded hexes
  146. backgroundWithHexes->draw(background, Point(0,0));
  147. owner.obstacleController->showAbsoluteObstacles(*backgroundWithHexes);
  148. if(owner.siegeController)
  149. owner.siegeController->showAbsoluteObstacles(*backgroundWithHexes);
  150. // show shaded hexes for active's stack valid movement and the hexes that it can attack
  151. if(settings["battle"]["stackRange"].Bool())
  152. {
  153. std::vector<BattleHex> hexesToShade = occupiableHexes;
  154. hexesToShade.insert(hexesToShade.end(), attackableHexes.begin(), attackableHexes.end());
  155. for(BattleHex hex : hexesToShade)
  156. {
  157. showHighlightedHex(*backgroundWithHexes, cellShade, hex, false);
  158. }
  159. }
  160. // draw cell borders
  161. if(settings["battle"]["cellBorders"].Bool())
  162. {
  163. for(int i=0; i<GameConstants::BFIELD_SIZE; ++i)
  164. {
  165. if(i % GameConstants::BFIELD_WIDTH == 0)
  166. continue;
  167. if(i % GameConstants::BFIELD_WIDTH == GameConstants::BFIELD_WIDTH - 1)
  168. continue;
  169. backgroundWithHexes->draw(cellBorder, hexPositionLocal(i).topLeft());
  170. }
  171. }
  172. }
  173. void BattleFieldController::showHighlightedHex(Canvas & canvas, std::shared_ptr<IImage> highlight, BattleHex hex, bool darkBorder)
  174. {
  175. Point hexPos = hexPositionLocal(hex).topLeft();
  176. canvas.draw(highlight, hexPos);
  177. if(!darkBorder && settings["battle"]["cellBorders"].Bool())
  178. canvas.draw(cellBorder, hexPos);
  179. }
  180. std::set<BattleHex> BattleFieldController::getHighlightedHexesForActiveStack()
  181. {
  182. std::set<BattleHex> result;
  183. if(!owner.stacksController->getActiveStack())
  184. return result;
  185. if(!settings["battle"]["stackRange"].Bool())
  186. return result;
  187. auto hoveredHex = getHoveredHex();
  188. std::set<BattleHex> set = owner.curInt->cb->battleGetAttackedHexes(owner.stacksController->getActiveStack(), hoveredHex, attackingHex);
  189. for(BattleHex hex : set)
  190. result.insert(hex);
  191. return result;
  192. }
  193. std::set<BattleHex> BattleFieldController::getMovementRangeForHoveredStack()
  194. {
  195. std::set<BattleHex> result;
  196. if (!owner.stacksController->getActiveStack())
  197. return result;
  198. if (!settings["battle"]["movementHighlightOnHover"].Bool() && !GH.isKeyboardShiftDown())
  199. return result;
  200. auto hoveredHex = getHoveredHex();
  201. // add possible movement hexes for stack under mouse
  202. const CStack * const hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
  203. if(hoveredStack)
  204. {
  205. std::vector<BattleHex> v = owner.curInt->cb->battleGetAvailableHexes(hoveredStack, true, true, nullptr);
  206. for(BattleHex hex : v)
  207. result.insert(hex);
  208. }
  209. return result;
  210. }
  211. std::set<BattleHex> BattleFieldController::getHighlightedHexesForSpellRange()
  212. {
  213. std::set<BattleHex> result;
  214. auto hoveredHex = getHoveredHex();
  215. if(!settings["battle"]["mouseShadow"].Bool())
  216. return result;
  217. const spells::Caster *caster = nullptr;
  218. const CSpell *spell = nullptr;
  219. spells::Mode mode = owner.actionsController->getCurrentCastMode();
  220. spell = owner.actionsController->getCurrentSpell(hoveredHex);
  221. caster = owner.actionsController->getCurrentSpellcaster();
  222. if(caster && spell) //when casting spell
  223. {
  224. // printing shaded hex(es)
  225. spells::BattleCast event(owner.curInt->cb.get(), caster, mode, spell);
  226. auto shadedHexes = spell->battleMechanics(&event)->rangeInHexes(hoveredHex);
  227. for(BattleHex shadedHex : shadedHexes)
  228. {
  229. if((shadedHex.getX() != 0) && (shadedHex.getX() != GameConstants::BFIELD_WIDTH - 1))
  230. result.insert(shadedHex);
  231. }
  232. }
  233. return result;
  234. }
  235. std::set<BattleHex> BattleFieldController::getHighlightedHexesForMovementTarget()
  236. {
  237. const CStack * stack = owner.stacksController->getActiveStack();
  238. auto hoveredHex = getHoveredHex();
  239. if(!stack)
  240. return {};
  241. std::vector<BattleHex> availableHexes = owner.curInt->cb->battleGetAvailableHexes(stack, false, false, nullptr);
  242. auto hoveredStack = owner.curInt->cb->battleGetStackByPos(hoveredHex, true);
  243. if(owner.curInt->cb->battleCanAttack(stack, hoveredStack, hoveredHex))
  244. {
  245. if(isTileAttackable(hoveredHex))
  246. {
  247. BattleHex attackFromHex = fromWhichHexAttack(hoveredHex);
  248. if(stack->doubleWide())
  249. return {attackFromHex, stack->occupiedHex(attackFromHex)};
  250. else
  251. return {attackFromHex};
  252. }
  253. }
  254. if(vstd::contains(availableHexes, hoveredHex))
  255. {
  256. if(stack->doubleWide())
  257. return {hoveredHex, stack->occupiedHex(hoveredHex)};
  258. else
  259. return {hoveredHex};
  260. }
  261. if(stack->doubleWide())
  262. {
  263. for(auto const & hex : availableHexes)
  264. {
  265. if(stack->occupiedHex(hex) == hoveredHex)
  266. return {hoveredHex, hex};
  267. }
  268. }
  269. return {};
  270. }
  271. void BattleFieldController::showHighlightedHexes(Canvas & canvas)
  272. {
  273. std::set<BattleHex> hoveredStackMovementRangeHexes = getMovementRangeForHoveredStack();
  274. std::set<BattleHex> hoveredSpellHexes = getHighlightedHexesForSpellRange();
  275. std::set<BattleHex> hoveredMoveHexes = getHighlightedHexesForMovementTarget();
  276. if(getHoveredHex() == BattleHex::INVALID)
  277. return;
  278. auto const & hoveredMouseHexes = owner.actionsController->currentActionSpellcasting(getHoveredHex()) ? hoveredSpellHexes : hoveredMoveHexes;
  279. for(int hex = 0; hex < GameConstants::BFIELD_SIZE; ++hex)
  280. {
  281. bool stackMovement = hoveredStackMovementRangeHexes.count(hex);
  282. bool mouse = hoveredMouseHexes.count(hex);
  283. if(stackMovement && mouse) // area where hovered stackMovement can move shown with highlight. Because also affected by mouse cursor, shade as well
  284. {
  285. showHighlightedHex(canvas, cellUnitMovementHighlight, hex, false);
  286. showHighlightedHex(canvas, cellShade, hex, true);
  287. }
  288. if(!stackMovement && mouse) // hexes affected only at mouse cursor shown as shaded
  289. {
  290. showHighlightedHex(canvas, cellShade, hex, true);
  291. }
  292. if(stackMovement && !mouse) // hexes where hovered stackMovement can move shown with highlight
  293. {
  294. showHighlightedHex(canvas, cellUnitMovementHighlight, hex, false);
  295. }
  296. }
  297. }
  298. Rect BattleFieldController::hexPositionLocal(BattleHex hex) const
  299. {
  300. int x = 14 + ((hex.getY())%2==0 ? 22 : 0) + 44*hex.getX();
  301. int y = 86 + 42 *hex.getY();
  302. int w = cellShade->width();
  303. int h = cellShade->height();
  304. return Rect(x, y, w, h);
  305. }
  306. Rect BattleFieldController::hexPositionAbsolute(BattleHex hex) const
  307. {
  308. return hexPositionLocal(hex) + pos.topLeft();
  309. }
  310. bool BattleFieldController::isPixelInHex(Point const & position)
  311. {
  312. return !cellShade->isTransparent(position);
  313. }
  314. BattleHex BattleFieldController::getHoveredHex()
  315. {
  316. Point hoverPos = GH.getCursorPosition();
  317. if (owner.attackingHero)
  318. {
  319. if (owner.attackingHero->pos.isInside(hoverPos))
  320. return BattleHex::HERO_ATTACKER;
  321. }
  322. if (owner.defendingHero)
  323. {
  324. if (owner.attackingHero->pos.isInside(hoverPos))
  325. return BattleHex::HERO_DEFENDER;
  326. }
  327. for (int h = 0; h < GameConstants::BFIELD_SIZE; ++h)
  328. {
  329. Rect hexPosition = hexPositionAbsolute(h);
  330. if (!hexPosition.isInside(hoverPos))
  331. continue;
  332. if (isPixelInHex(hoverPos - hexPosition.topLeft()))
  333. return h;
  334. }
  335. return BattleHex::INVALID;
  336. }
  337. void BattleFieldController::setBattleCursor(BattleHex myNumber)
  338. {
  339. Point cursorPos = CCS->curh->position();
  340. std::vector<Cursor::Combat> sectorCursor = {
  341. Cursor::Combat::HIT_SOUTHEAST,
  342. Cursor::Combat::HIT_SOUTHWEST,
  343. Cursor::Combat::HIT_WEST,
  344. Cursor::Combat::HIT_NORTHWEST,
  345. Cursor::Combat::HIT_NORTHEAST,
  346. Cursor::Combat::HIT_EAST,
  347. Cursor::Combat::HIT_SOUTH,
  348. Cursor::Combat::HIT_NORTH,
  349. };
  350. auto direction = static_cast<size_t>(selectAttackDirection(myNumber, cursorPos));
  351. assert(direction != -1);
  352. if (direction != -1)
  353. CCS->curh->set(sectorCursor[direction]);
  354. }
  355. BattleHex::EDir BattleFieldController::selectAttackDirection(BattleHex myNumber, const Point & cursorPos)
  356. {
  357. const bool doubleWide = owner.stacksController->getActiveStack()->doubleWide();
  358. auto neighbours = myNumber.allNeighbouringTiles();
  359. // 0 1
  360. // 5 x 2
  361. // 4 3
  362. // if true - our current stack can move into this hex (and attack)
  363. std::array<bool, 8> attackAvailability;
  364. if (doubleWide)
  365. {
  366. // For double-hexes we need to ensure that both hexes needed for this direction are occupyable:
  367. // | -0- | -1- | -2- | -3- | -4- | -5- | -6- | -7-
  368. // | o o - | - o o | - - | - - | - - | - - | o o | - -
  369. // | - x - | - x - | - x o o| - x - | - x - |o o x - | - x - | - x -
  370. // | - - | - - | - - | - o o | o o - | - - | - - | o o
  371. for (size_t i : { 1, 2, 3})
  372. attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]) && vstd::contains(occupiableHexes, neighbours[i].cloneInDirection(BattleHex::RIGHT, false));
  373. for (size_t i : { 4, 5, 0})
  374. attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]) && vstd::contains(occupiableHexes, neighbours[i].cloneInDirection(BattleHex::LEFT, false));
  375. attackAvailability[6] = vstd::contains(occupiableHexes, neighbours[0]) && vstd::contains(occupiableHexes, neighbours[1]);
  376. attackAvailability[7] = vstd::contains(occupiableHexes, neighbours[3]) && vstd::contains(occupiableHexes, neighbours[4]);
  377. }
  378. else
  379. {
  380. for (size_t i = 0; i < 6; ++i)
  381. attackAvailability[i] = vstd::contains(occupiableHexes, neighbours[i]);
  382. attackAvailability[6] = false;
  383. attackAvailability[7] = false;
  384. }
  385. // Zero available tiles to attack from
  386. if ( vstd::find(attackAvailability, true) == attackAvailability.end())
  387. {
  388. logGlobal->error("Error: cannot find a hex to attack hex %d from!", myNumber);
  389. return BattleHex::NONE;
  390. }
  391. // For each valid direction, select position to test against
  392. std::array<Point, 8> testPoint;
  393. for (size_t i = 0; i < 6; ++i)
  394. if (attackAvailability[i])
  395. testPoint[i] = hexPositionAbsolute(neighbours[i]).center();
  396. // For bottom/top directions select central point, but move it a bit away from true center to reduce zones allocated to them
  397. if (attackAvailability[6])
  398. testPoint[6] = (hexPositionAbsolute(neighbours[0]).center() + hexPositionAbsolute(neighbours[1]).center()) / 2 + Point(0, -5);
  399. if (attackAvailability[7])
  400. testPoint[7] = (hexPositionAbsolute(neighbours[3]).center() + hexPositionAbsolute(neighbours[4]).center()) / 2 + Point(0, 5);
  401. // Compute distance between tested position & cursor position and pick nearest
  402. std::array<int, 8> distance2;
  403. for (size_t i = 0; i < 8; ++i)
  404. if (attackAvailability[i])
  405. distance2[i] = (testPoint[i].y - cursorPos.y)*(testPoint[i].y - cursorPos.y) + (testPoint[i].x - cursorPos.x)*(testPoint[i].x - cursorPos.x);
  406. size_t nearest = -1;
  407. for (size_t i = 0; i < 8; ++i)
  408. if (attackAvailability[i] && (nearest == -1 || distance2[i] < distance2[nearest]) )
  409. nearest = i;
  410. assert(nearest != -1);
  411. return BattleHex::EDir(nearest);
  412. }
  413. BattleHex BattleFieldController::fromWhichHexAttack(BattleHex attackTarget)
  414. {
  415. BattleHex::EDir direction = selectAttackDirection(attackTarget, CCS->curh->position());
  416. const CStack * attacker = owner.stacksController->getActiveStack();
  417. assert(direction != BattleHex::NONE);
  418. assert(attacker);
  419. if (!attacker->doubleWide())
  420. {
  421. assert(direction != BattleHex::BOTTOM);
  422. assert(direction != BattleHex::TOP);
  423. return attackTarget.cloneInDirection(direction);
  424. }
  425. else
  426. {
  427. // We need to find position of right hex of double-hex creature (or left for defending side)
  428. // | TOP_LEFT |TOP_RIGHT | RIGHT |BOTTOM_RIGHT|BOTTOM_LEFT| LEFT | TOP |BOTTOM
  429. // | o o - | - o o | - - | - - | - - | - - | o o | - -
  430. // | - x - | - x - | - x o o| - x - | - x - |o o x - | - x - | - x -
  431. // | - - | - - | - - | - o o | o o - | - - | - - | o o
  432. switch (direction)
  433. {
  434. case BattleHex::TOP_LEFT:
  435. case BattleHex::LEFT:
  436. case BattleHex::BOTTOM_LEFT:
  437. {
  438. if ( attacker->unitSide() == BattleSide::ATTACKER )
  439. return attackTarget.cloneInDirection(direction);
  440. else
  441. return attackTarget.cloneInDirection(direction).cloneInDirection(BattleHex::LEFT);
  442. }
  443. case BattleHex::TOP_RIGHT:
  444. case BattleHex::RIGHT:
  445. case BattleHex::BOTTOM_RIGHT:
  446. {
  447. if ( attacker->unitSide() == BattleSide::ATTACKER )
  448. return attackTarget.cloneInDirection(direction).cloneInDirection(BattleHex::RIGHT);
  449. else
  450. return attackTarget.cloneInDirection(direction);
  451. }
  452. case BattleHex::TOP:
  453. {
  454. if ( attacker->unitSide() == BattleSide::ATTACKER )
  455. return attackTarget.cloneInDirection(BattleHex::TOP_RIGHT);
  456. else
  457. return attackTarget.cloneInDirection(BattleHex::TOP_LEFT);
  458. }
  459. case BattleHex::BOTTOM:
  460. {
  461. if ( attacker->unitSide() == BattleSide::ATTACKER )
  462. return attackTarget.cloneInDirection(BattleHex::BOTTOM_RIGHT);
  463. else
  464. return attackTarget.cloneInDirection(BattleHex::BOTTOM_LEFT);
  465. }
  466. default:
  467. assert(0);
  468. return BattleHex::INVALID;
  469. }
  470. }
  471. }
  472. bool BattleFieldController::isTileAttackable(const BattleHex & number) const
  473. {
  474. for (auto & elem : occupiableHexes)
  475. {
  476. if (BattleHex::mutualPosition(elem, number) != -1 || elem == number)
  477. return true;
  478. }
  479. return false;
  480. }
  481. void BattleFieldController::updateAccessibleHexes()
  482. {
  483. auto accessibility = owner.curInt->cb->getAccesibility();
  484. for(int i = 0; i < accessibility.size(); i++)
  485. stackCountOutsideHexes[i] = (accessibility[i] == EAccessibility::ACCESSIBLE || (accessibility[i] == EAccessibility::SIDE_COLUMN));
  486. }
  487. bool BattleFieldController::stackCountOutsideHex(const BattleHex & number) const
  488. {
  489. return stackCountOutsideHexes[number];
  490. }
  491. void BattleFieldController::showAll(SDL_Surface * to)
  492. {
  493. show(to);
  494. }
  495. void BattleFieldController::show(SDL_Surface * to)
  496. {
  497. updateAccessibleHexes();
  498. owner.stacksController->update();
  499. owner.obstacleController->update();
  500. Canvas canvas(to);
  501. CSDL_Ext::CClipRectGuard guard(to, pos);
  502. renderBattlefield(canvas);
  503. }