BattleFieldController.cpp 19 KB

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