BattleFieldController.cpp 19 KB

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