AdventureMapShortcuts.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * AdventureMapShortcuts.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 "AdventureMapShortcuts.h"
  12. #include "../CGameInfo.h"
  13. #include "../CMT.h"
  14. #include "../CPlayerInterface.h"
  15. #include "../CServerHandler.h"
  16. #include "../PlayerLocalState.h"
  17. #include "../gui/CGuiHandler.h"
  18. #include "../gui/Shortcut.h"
  19. #include "../gui/WindowHandler.h"
  20. #include "../lobby/CSavingScreen.h"
  21. #include "../mapView/mapHandler.h"
  22. #include "../windows/CKingdomInterface.h"
  23. #include "../windows/CSpellWindow.h"
  24. #include "../windows/CMarketWindow.h"
  25. #include "../windows/settings/SettingsMainWindow.h"
  26. #include "AdventureMapInterface.h"
  27. #include "AdventureOptions.h"
  28. #include "AdventureState.h"
  29. #include "../../CCallback.h"
  30. #include "../../lib/CConfigHandler.h"
  31. #include "../../lib/texts/CGeneralTextHandler.h"
  32. #include "../../lib/mapObjects/CGHeroInstance.h"
  33. #include "../../lib/mapObjects/CGTownInstance.h"
  34. #include "../../lib/mapping/CMap.h"
  35. #include "../../lib/pathfinder/CGPathNode.h"
  36. AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
  37. : owner(owner)
  38. , state(EAdventureState::NOT_INITIALIZED)
  39. , mapLevel(0)
  40. {}
  41. void AdventureMapShortcuts::setState(EAdventureState newState)
  42. {
  43. state = newState;
  44. }
  45. EAdventureState AdventureMapShortcuts::getState() const
  46. {
  47. return state;
  48. }
  49. void AdventureMapShortcuts::onMapViewMoved(const Rect & visibleArea, int newMapLevel)
  50. {
  51. mapLevel = newMapLevel;
  52. }
  53. std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
  54. {
  55. std::vector<AdventureMapShortcutState> result = {
  56. { EShortcut::ADVENTURE_KINGDOM_OVERVIEW, optionInMapView(), [this]() { this->showOverview(); } },
  57. { EShortcut::ADVENTURE_EXIT_WORLD_VIEW, optionInWorldView(), [this]() { this->worldViewBack(); } },
  58. { EShortcut::ADVENTURE_VIEW_WORLD, optionInMapView(), [this]() { this->worldViewScale1x(); } },
  59. { EShortcut::ADVENTURE_VIEW_WORLD_X1, optionInWorldView(), [this]() { this->worldViewScale1x(); } },
  60. { EShortcut::ADVENTURE_VIEW_WORLD_X2, optionInWorldView(), [this]() { this->worldViewScale2x(); } },
  61. { EShortcut::ADVENTURE_VIEW_WORLD_X4, optionInWorldView(), [this]() { this->worldViewScale4x(); } },
  62. { EShortcut::ADVENTURE_TOGGLE_MAP_LEVEL, optionCanToggleLevel(), [this]() { this->switchMapLevel(); } },
  63. { EShortcut::ADVENTURE_QUEST_LOG, optionCanViewQuests(), [this]() { this->showQuestlog(); } },
  64. { EShortcut::ADVENTURE_TOGGLE_SLEEP, optionHeroSelected(), [this]() { this->toggleSleepWake(); } },
  65. { EShortcut::ADVENTURE_TOGGLE_GRID, optionInMapView(), [this]() { this->toggleGrid(); } },
  66. { EShortcut::ADVENTURE_TOGGLE_VISITABLE, optionInMapView(), [this]() { this->toggleVisitable(); } },
  67. { EShortcut::ADVENTURE_TOGGLE_BLOCKED, optionInMapView(), [this]() { this->toggleBlocked(); } },
  68. { EShortcut::ADVENTURE_TRACK_HERO, optionInMapView(), [this]() { this->toggleTrackHero(); } },
  69. { EShortcut::ADVENTURE_SET_HERO_ASLEEP, optionHeroAwake(), [this]() { this->setHeroSleeping(); } },
  70. { EShortcut::ADVENTURE_SET_HERO_AWAKE, optionHeroSleeping(), [this]() { this->setHeroAwake(); } },
  71. { EShortcut::ADVENTURE_MOVE_HERO, optionHeroCanMove(), [this]() { this->moveHeroAlongPath(); } },
  72. { EShortcut::ADVENTURE_CAST_SPELL, optionHeroSelected(), [this]() { this->showSpellbook(); } },
  73. { EShortcut::ADVENTURE_GAME_OPTIONS, optionInMapView(), [this]() { this->adventureOptions(); } },
  74. { EShortcut::GLOBAL_OPTIONS, optionInMapView(), [this]() { this->systemOptions(); } },
  75. { EShortcut::ADVENTURE_FIRST_HERO, optionInMapView(), [this]() { this->firstHero(); } },
  76. { EShortcut::ADVENTURE_NEXT_HERO, optionHasNextHero(), [this]() { this->nextHero(); } },
  77. { EShortcut::ADVENTURE_END_TURN, optionCanEndTurn(), [this]() { this->endTurn(); } },
  78. { EShortcut::ADVENTURE_THIEVES_GUILD, optionInMapView(), [this]() { this->showThievesGuild(); } },
  79. { EShortcut::ADVENTURE_VIEW_SCENARIO, optionInMapView(), [this]() { this->showScenarioInfo(); } },
  80. { EShortcut::ADVENTURE_QUIT_GAME, optionInMapView(), [this]() { this->quitGame(); } },
  81. { EShortcut::ADVENTURE_TO_MAIN_MENU, optionInMapView(), [this]() { this->toMainMenu(); } },
  82. { EShortcut::ADVENTURE_SAVE_GAME, optionInMapView(), [this]() { this->saveGame(); } },
  83. { EShortcut::ADVENTURE_NEW_GAME, optionInMapView(), [this]() { this->newGame(); } },
  84. { EShortcut::ADVENTURE_LOAD_GAME, optionInMapView(), [this]() { this->loadGame(); } },
  85. { EShortcut::ADVENTURE_RESTART_GAME, optionInMapView(), [this]() { this->restartGame(); } },
  86. { EShortcut::ADVENTURE_DIG_GRAIL, optionHeroSelected(), [this]() { this->digGrail(); } },
  87. { EShortcut::ADVENTURE_VIEW_PUZZLE, optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } },
  88. { EShortcut::ADVENTURE_VISIT_OBJECT, optionCanVisitObject(), [this]() { this->visitObject(); } },
  89. { EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } },
  90. { EShortcut::ADVENTURE_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } },
  91. { EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+10); } },
  92. { EShortcut::ADVENTURE_ZOOM_OUT, optionSidePanelActive(),[this]() { this->zoom(-10); } },
  93. { EShortcut::ADVENTURE_ZOOM_RESET, optionSidePanelActive(),[this]() { this->zoom( 0); } },
  94. { EShortcut::ADVENTURE_FIRST_TOWN, optionInMapView(), [this]() { this->firstTown(); } },
  95. { EShortcut::ADVENTURE_NEXT_TOWN, optionInMapView(), [this]() { this->nextTown(); } },
  96. { EShortcut::ADVENTURE_NEXT_OBJECT, optionInMapView(), [this]() { this->nextObject(); } },
  97. { EShortcut::ADVENTURE_MOVE_HERO_SW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, +1}); } },
  98. { EShortcut::ADVENTURE_MOVE_HERO_SS, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, +1}); } },
  99. { EShortcut::ADVENTURE_MOVE_HERO_SE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, +1}); } },
  100. { EShortcut::ADVENTURE_MOVE_HERO_WW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, 0}); } },
  101. { EShortcut::ADVENTURE_MOVE_HERO_EE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, 0}); } },
  102. { EShortcut::ADVENTURE_MOVE_HERO_NW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, -1}); } },
  103. { EShortcut::ADVENTURE_MOVE_HERO_NN, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, -1}); } },
  104. { EShortcut::ADVENTURE_MOVE_HERO_NE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, -1}); } }
  105. };
  106. return result;
  107. }
  108. void AdventureMapShortcuts::showOverview()
  109. {
  110. GH.windows().createAndPushWindow<CKingdomInterface>();
  111. }
  112. void AdventureMapShortcuts::worldViewBack()
  113. {
  114. owner.hotkeyExitWorldView();
  115. auto hero = LOCPLINT->localState->getCurrentHero();
  116. if (hero)
  117. owner.centerOnObject(hero);
  118. }
  119. void AdventureMapShortcuts::worldViewScale1x()
  120. {
  121. // TODO set corresponding scale button to "selected" mode
  122. owner.openWorldView(7);
  123. }
  124. void AdventureMapShortcuts::worldViewScale2x()
  125. {
  126. owner.openWorldView(11);
  127. }
  128. void AdventureMapShortcuts::worldViewScale4x()
  129. {
  130. owner.openWorldView(16);
  131. }
  132. void AdventureMapShortcuts::switchMapLevel()
  133. {
  134. int maxLevels = LOCPLINT->cb->getMapSize().z;
  135. if (maxLevels < 2)
  136. return;
  137. owner.hotkeySwitchMapLevel();
  138. }
  139. void AdventureMapShortcuts::showQuestlog()
  140. {
  141. LOCPLINT->showQuestLog();
  142. }
  143. void AdventureMapShortcuts::toggleTrackHero()
  144. {
  145. Settings s = settings.write["session"];
  146. s["adventureTrackHero"].Bool() = !settings["session"]["adventureTrackHero"].Bool();
  147. }
  148. void AdventureMapShortcuts::toggleGrid()
  149. {
  150. Settings s = settings.write["gameTweaks"];
  151. s["showGrid"].Bool() = !settings["gameTweaks"]["showGrid"].Bool();
  152. }
  153. void AdventureMapShortcuts::toggleVisitable()
  154. {
  155. Settings s = settings.write["session"];
  156. s["showVisitable"].Bool() = !settings["session"]["showVisitable"].Bool();
  157. }
  158. void AdventureMapShortcuts::toggleBlocked()
  159. {
  160. Settings s = settings.write["session"];
  161. s["showBlocked"].Bool() = !settings["session"]["showBlocked"].Bool();
  162. }
  163. void AdventureMapShortcuts::toggleSleepWake()
  164. {
  165. if (!optionHeroSelected())
  166. return;
  167. if (optionHeroAwake())
  168. setHeroSleeping();
  169. else
  170. setHeroAwake();
  171. }
  172. void AdventureMapShortcuts::setHeroSleeping()
  173. {
  174. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  175. if (h)
  176. {
  177. LOCPLINT->localState->setHeroAsleep(h);
  178. owner.onHeroChanged(h);
  179. nextHero();
  180. }
  181. }
  182. void AdventureMapShortcuts::setHeroAwake()
  183. {
  184. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  185. if (h)
  186. {
  187. LOCPLINT->localState->setHeroAwaken(h);
  188. owner.onHeroChanged(h);
  189. }
  190. }
  191. void AdventureMapShortcuts::moveHeroAlongPath()
  192. {
  193. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  194. if (!h || !LOCPLINT->localState->hasPath(h))
  195. return;
  196. LOCPLINT->moveHero(h, LOCPLINT->localState->getPath(h));
  197. }
  198. void AdventureMapShortcuts::showSpellbook()
  199. {
  200. if (!LOCPLINT->localState->getCurrentHero())
  201. return;
  202. owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
  203. GH.windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
  204. }
  205. void AdventureMapShortcuts::adventureOptions()
  206. {
  207. GH.windows().createAndPushWindow<AdventureOptions>();
  208. }
  209. void AdventureMapShortcuts::systemOptions()
  210. {
  211. GH.windows().createAndPushWindow<SettingsMainWindow>();
  212. }
  213. void AdventureMapShortcuts::firstHero()
  214. {
  215. if (!LOCPLINT->localState->getWanderingHeroes().empty())
  216. {
  217. const auto * hero = LOCPLINT->localState->getWanderingHero(0);
  218. LOCPLINT->localState->setSelection(hero);
  219. owner.centerOnObject(hero);
  220. }
  221. }
  222. void AdventureMapShortcuts::nextHero()
  223. {
  224. const auto * currHero = LOCPLINT->localState->getCurrentHero();
  225. const auto * nextHero = LOCPLINT->localState->getNextWanderingHero(currHero);
  226. if (nextHero)
  227. {
  228. LOCPLINT->localState->setSelection(nextHero);
  229. owner.centerOnObject(nextHero);
  230. }
  231. }
  232. void AdventureMapShortcuts::endTurn()
  233. {
  234. if(!LOCPLINT->makingTurn)
  235. return;
  236. if(settings["adventure"]["heroReminder"].Bool())
  237. {
  238. for(auto hero : LOCPLINT->localState->getWanderingHeroes())
  239. {
  240. if(!LOCPLINT->localState->isHeroSleeping(hero) && hero->movementPointsRemaining() > 0)
  241. {
  242. // Only show hero reminder if conditions met:
  243. // - There still movement points
  244. // - Hero don't have a path or there not points for first step on path
  245. LOCPLINT->localState->verifyPath(hero);
  246. if(!LOCPLINT->localState->hasPath(hero))
  247. {
  248. LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
  249. return;
  250. }
  251. auto path = LOCPLINT->localState->getPath(hero);
  252. if (path.nodes.size() < 2 || path.nodes[path.nodes.size() - 2].turns)
  253. {
  254. LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
  255. return;
  256. }
  257. }
  258. }
  259. }
  260. owner.hotkeyEndingTurn();
  261. }
  262. void AdventureMapShortcuts::showThievesGuild()
  263. {
  264. //find first town with tavern
  265. auto itr = range::find_if(LOCPLINT->localState->getOwnedTowns(), [](const CGTownInstance * town)
  266. {
  267. return town->hasBuilt(BuildingID::TAVERN);
  268. });
  269. if(itr != LOCPLINT->localState->getOwnedTowns().end())
  270. LOCPLINT->showThievesGuildWindow(*itr);
  271. else
  272. LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithTavern"));
  273. }
  274. void AdventureMapShortcuts::showScenarioInfo()
  275. {
  276. AdventureOptions::showScenarioInfo();
  277. }
  278. void AdventureMapShortcuts::toMainMenu()
  279. {
  280. LOCPLINT->showYesNoDialog(
  281. CGI->generaltexth->allTexts[578],
  282. []()
  283. {
  284. CSH->endGameplay();
  285. GH.defActionsDef = 63;
  286. CMM->menu->switchToTab("main");
  287. },
  288. 0
  289. );
  290. }
  291. void AdventureMapShortcuts::newGame()
  292. {
  293. LOCPLINT->showYesNoDialog(
  294. CGI->generaltexth->allTexts[578],
  295. []()
  296. {
  297. CSH->endGameplay();
  298. GH.defActionsDef = 63;
  299. CMM->menu->switchToTab("new");
  300. },
  301. nullptr
  302. );
  303. }
  304. void AdventureMapShortcuts::quitGame()
  305. {
  306. LOCPLINT->showYesNoDialog(
  307. CGI->generaltexth->allTexts[578],
  308. []()
  309. {
  310. GH.dispatchMainThread( []()
  311. {
  312. handleQuit(false);
  313. });
  314. },
  315. 0
  316. );
  317. }
  318. void AdventureMapShortcuts::saveGame()
  319. {
  320. GH.windows().createAndPushWindow<CSavingScreen>();
  321. }
  322. void AdventureMapShortcuts::loadGame()
  323. {
  324. LOCPLINT->proposeLoadingGame();
  325. }
  326. void AdventureMapShortcuts::digGrail()
  327. {
  328. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  329. if(h && LOCPLINT->makingTurn)
  330. LOCPLINT->tryDigging(h);
  331. }
  332. void AdventureMapShortcuts::viewPuzzleMap()
  333. {
  334. LOCPLINT->showPuzzleMap();
  335. }
  336. void AdventureMapShortcuts::restartGame()
  337. {
  338. LOCPLINT->showYesNoDialog(
  339. CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"),
  340. []()
  341. {
  342. GH.dispatchMainThread(
  343. []()
  344. {
  345. CSH->sendRestartGame();
  346. }
  347. );
  348. },
  349. nullptr
  350. );
  351. }
  352. void AdventureMapShortcuts::visitObject()
  353. {
  354. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  355. if(h)
  356. LOCPLINT->cb->moveHero(h, h->pos, false);
  357. }
  358. void AdventureMapShortcuts::openObject()
  359. {
  360. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  361. const CGTownInstance *t = LOCPLINT->localState->getCurrentTown();
  362. if(h)
  363. LOCPLINT->openHeroWindow(h);
  364. if(t)
  365. LOCPLINT->openTownWindow(t);
  366. }
  367. void AdventureMapShortcuts::showMarketplace()
  368. {
  369. //check if we have any marketplace
  370. const CGTownInstance *townWithMarket = nullptr;
  371. for(const CGTownInstance *t : LOCPLINT->cb->getTownsInfo())
  372. {
  373. if(t->hasBuilt(BuildingID::MARKETPLACE))
  374. {
  375. townWithMarket = t;
  376. break;
  377. }
  378. }
  379. if(townWithMarket) //if any town has marketplace, open window
  380. GH.windows().createAndPushWindow<CMarketWindow>(townWithMarket, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
  381. else //if not - complain
  382. LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
  383. }
  384. void AdventureMapShortcuts::firstTown()
  385. {
  386. if (!LOCPLINT->localState->getOwnedTowns().empty())
  387. {
  388. const auto * town = LOCPLINT->localState->getOwnedTown(0);
  389. LOCPLINT->localState->setSelection(town);
  390. owner.centerOnObject(town);
  391. }
  392. }
  393. void AdventureMapShortcuts::nextTown()
  394. {
  395. owner.hotkeyNextTown();
  396. }
  397. void AdventureMapShortcuts::zoom( int distance)
  398. {
  399. owner.hotkeyZoom(distance, false);
  400. }
  401. void AdventureMapShortcuts::nextObject()
  402. {
  403. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  404. const CGTownInstance *t = LOCPLINT->localState->getCurrentTown();
  405. if(h)
  406. nextHero();
  407. if(t)
  408. nextTown();
  409. }
  410. void AdventureMapShortcuts::moveHeroDirectional(const Point & direction)
  411. {
  412. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); //selected hero
  413. if(!h)
  414. return;
  415. if (CGI->mh->hasOngoingAnimations())
  416. return;
  417. int3 dst = h->visitablePos() + int3(direction.x, direction.y, 0);
  418. if (!CGI->mh->isInMap((dst)))
  419. return;
  420. if ( !LOCPLINT->localState->setPath(h, dst))
  421. return;
  422. const CGPath & path = LOCPLINT->localState->getPath(h);
  423. if (path.nodes.size() > 2)
  424. owner.onHeroChanged(h);
  425. else
  426. if(path.nodes[0].turns == 0)
  427. LOCPLINT->moveHero(h, path);
  428. }
  429. bool AdventureMapShortcuts::optionCanViewQuests()
  430. {
  431. return optionInMapView() && !CGI->mh->getMap()->quests.empty();
  432. }
  433. bool AdventureMapShortcuts::optionCanToggleLevel()
  434. {
  435. return optionSidePanelActive() && LOCPLINT->cb->getMapSize().z > 1;
  436. }
  437. bool AdventureMapShortcuts::optionMapLevelSurface()
  438. {
  439. return mapLevel == 0;
  440. }
  441. bool AdventureMapShortcuts::optionHeroSleeping()
  442. {
  443. const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
  444. return optionInMapView() && hero && LOCPLINT->localState->isHeroSleeping(hero);
  445. }
  446. bool AdventureMapShortcuts::optionHeroAwake()
  447. {
  448. const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
  449. return optionInMapView() && hero && !LOCPLINT->localState->isHeroSleeping(hero);
  450. }
  451. bool AdventureMapShortcuts::optionCanVisitObject()
  452. {
  453. if (!optionHeroSelected())
  454. return false;
  455. auto * hero = LOCPLINT->localState->getCurrentHero();
  456. auto objects = LOCPLINT->cb->getVisitableObjs(hero->visitablePos());
  457. assert(vstd::contains(objects,hero));
  458. return objects.size() > 1; // there is object other than our hero
  459. }
  460. bool AdventureMapShortcuts::optionHeroSelected()
  461. {
  462. return optionInMapView() && LOCPLINT->localState->getCurrentHero() != nullptr;
  463. }
  464. bool AdventureMapShortcuts::optionHeroCanMove()
  465. {
  466. const auto * hero = LOCPLINT->localState->getCurrentHero();
  467. return optionInMapView() && hero && LOCPLINT->localState->hasPath(hero) && LOCPLINT->localState->getPath(hero).nextNode().turns == 0;
  468. }
  469. bool AdventureMapShortcuts::optionHasNextHero()
  470. {
  471. const auto * hero = LOCPLINT->localState->getCurrentHero();
  472. const auto * nextSuitableHero = LOCPLINT->localState->getNextWanderingHero(hero);
  473. return optionInMapView() && nextSuitableHero != nullptr;
  474. }
  475. bool AdventureMapShortcuts::optionCanEndTurn()
  476. {
  477. return optionInMapView() && LOCPLINT->makingTurn;
  478. }
  479. bool AdventureMapShortcuts::optionSpellcasting()
  480. {
  481. return state == EAdventureState::CASTING_SPELL;
  482. }
  483. bool AdventureMapShortcuts::optionInMapView()
  484. {
  485. return state == EAdventureState::MAKING_TURN;
  486. }
  487. bool AdventureMapShortcuts::optionInWorldView()
  488. {
  489. return state == EAdventureState::WORLD_VIEW;
  490. }
  491. bool AdventureMapShortcuts::optionSidePanelActive()
  492. {
  493. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
  494. }
  495. bool AdventureMapShortcuts::optionMapScrollingActive()
  496. {
  497. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
  498. }
  499. bool AdventureMapShortcuts::optionMapViewActive()
  500. {
  501. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::CASTING_SPELL
  502. || state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
  503. }