AdventureMapShortcuts.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. #include "../../lib/mapObjectConstructors/CObjectClassesHandler.h"
  37. AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
  38. : owner(owner)
  39. , state(EAdventureState::NOT_INITIALIZED)
  40. , mapLevel(0)
  41. {}
  42. void AdventureMapShortcuts::setState(EAdventureState newState)
  43. {
  44. state = newState;
  45. }
  46. EAdventureState AdventureMapShortcuts::getState() const
  47. {
  48. return state;
  49. }
  50. void AdventureMapShortcuts::onMapViewMoved(const Rect & visibleArea, int newMapLevel)
  51. {
  52. mapLevel = newMapLevel;
  53. }
  54. std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
  55. {
  56. std::vector<AdventureMapShortcutState> result = {
  57. { EShortcut::ADVENTURE_KINGDOM_OVERVIEW, optionInMapView(), [this]() { this->showOverview(); } },
  58. { EShortcut::ADVENTURE_EXIT_WORLD_VIEW, optionInWorldView(), [this]() { this->worldViewBack(); } },
  59. { EShortcut::ADVENTURE_VIEW_WORLD, optionInMapView(), [this]() { this->worldViewScale1x(); } },
  60. { EShortcut::ADVENTURE_VIEW_WORLD_X1, optionInWorldView(), [this]() { this->worldViewScale1x(); } },
  61. { EShortcut::ADVENTURE_VIEW_WORLD_X2, optionInWorldView(), [this]() { this->worldViewScale2x(); } },
  62. { EShortcut::ADVENTURE_VIEW_WORLD_X4, optionInWorldView(), [this]() { this->worldViewScale4x(); } },
  63. { EShortcut::ADVENTURE_TOGGLE_MAP_LEVEL, optionCanToggleLevel(), [this]() { this->switchMapLevel(); } },
  64. { EShortcut::ADVENTURE_QUEST_LOG, optionCanViewQuests(), [this]() { this->showQuestlog(); } },
  65. { EShortcut::ADVENTURE_TOGGLE_SLEEP, optionHeroSelected(), [this]() { this->toggleSleepWake(); } },
  66. { EShortcut::ADVENTURE_TOGGLE_GRID, optionInMapView(), [this]() { this->toggleGrid(); } },
  67. { EShortcut::ADVENTURE_TOGGLE_VISITABLE, optionInMapView(), [this]() { this->toggleVisitable(); } },
  68. { EShortcut::ADVENTURE_TOGGLE_BLOCKED, optionInMapView(), [this]() { this->toggleBlocked(); } },
  69. { EShortcut::ADVENTURE_TRACK_HERO, optionInMapView(), [this]() { this->toggleTrackHero(); } },
  70. { EShortcut::ADVENTURE_SET_HERO_ASLEEP, optionHeroAwake(), [this]() { this->setHeroSleeping(); } },
  71. { EShortcut::ADVENTURE_SET_HERO_AWAKE, optionHeroSleeping(), [this]() { this->setHeroAwake(); } },
  72. { EShortcut::ADVENTURE_MOVE_HERO, optionHeroCanMove(), [this]() { this->moveHeroAlongPath(); } },
  73. { EShortcut::ADVENTURE_CAST_SPELL, optionHeroSelected(), [this]() { this->showSpellbook(); } },
  74. { EShortcut::ADVENTURE_GAME_OPTIONS, optionInMapView(), [this]() { this->adventureOptions(); } },
  75. { EShortcut::GLOBAL_OPTIONS, optionInMapView(), [this]() { this->systemOptions(); } },
  76. { EShortcut::ADVENTURE_FIRST_HERO, optionInMapView(), [this]() { this->firstHero(); } },
  77. { EShortcut::ADVENTURE_NEXT_HERO, optionHasNextHero(), [this]() { this->nextHero(); } },
  78. { EShortcut::ADVENTURE_END_TURN, optionCanEndTurn(), [this]() { this->endTurn(); } },
  79. { EShortcut::ADVENTURE_THIEVES_GUILD, optionInMapView(), [this]() { this->showThievesGuild(); } },
  80. { EShortcut::ADVENTURE_VIEW_SCENARIO, optionInMapView(), [this]() { this->showScenarioInfo(); } },
  81. { EShortcut::ADVENTURE_QUIT_GAME, optionInMapView(), [this]() { this->quitGame(); } },
  82. { EShortcut::ADVENTURE_TO_MAIN_MENU, optionInMapView(), [this]() { this->toMainMenu(); } },
  83. { EShortcut::ADVENTURE_SAVE_GAME, optionInMapView(), [this]() { this->saveGame(); } },
  84. { EShortcut::ADVENTURE_NEW_GAME, optionInMapView(), [this]() { this->newGame(); } },
  85. { EShortcut::ADVENTURE_LOAD_GAME, optionInMapView(), [this]() { this->loadGame(); } },
  86. { EShortcut::ADVENTURE_RESTART_GAME, optionInMapView(), [this]() { this->restartGame(); } },
  87. { EShortcut::ADVENTURE_DIG_GRAIL, optionHeroSelected(), [this]() { this->digGrail(); } },
  88. { EShortcut::ADVENTURE_VIEW_PUZZLE, optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } },
  89. { EShortcut::ADVENTURE_VISIT_OBJECT, optionCanVisitObject(), [this]() { this->visitObject(); } },
  90. { EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } },
  91. { EShortcut::ADVENTURE_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } },
  92. { EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+10); } },
  93. { EShortcut::ADVENTURE_ZOOM_OUT, optionSidePanelActive(),[this]() { this->zoom(-10); } },
  94. { EShortcut::ADVENTURE_ZOOM_RESET, optionSidePanelActive(),[this]() { this->zoom( 0); } },
  95. { EShortcut::ADVENTURE_FIRST_TOWN, optionInMapView(), [this]() { this->firstTown(); } },
  96. { EShortcut::ADVENTURE_NEXT_TOWN, optionInMapView(), [this]() { this->nextTown(); } },
  97. { EShortcut::ADVENTURE_NEXT_OBJECT, optionInMapView(), [this]() { this->nextObject(); } },
  98. { EShortcut::ADVENTURE_MOVE_HERO_SW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, +1}); } },
  99. { EShortcut::ADVENTURE_MOVE_HERO_SS, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, +1}); } },
  100. { EShortcut::ADVENTURE_MOVE_HERO_SE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, +1}); } },
  101. { EShortcut::ADVENTURE_MOVE_HERO_WW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, 0}); } },
  102. { EShortcut::ADVENTURE_MOVE_HERO_EE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, 0}); } },
  103. { EShortcut::ADVENTURE_MOVE_HERO_NW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, -1}); } },
  104. { EShortcut::ADVENTURE_MOVE_HERO_NN, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, -1}); } },
  105. { EShortcut::ADVENTURE_MOVE_HERO_NE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, -1}); } },
  106. { EShortcut::ADVENTURE_SEARCH, optionSidePanelActive(),[this]() { this->search(); } }
  107. };
  108. return result;
  109. }
  110. void AdventureMapShortcuts::showOverview()
  111. {
  112. GH.windows().createAndPushWindow<CKingdomInterface>();
  113. }
  114. void AdventureMapShortcuts::worldViewBack()
  115. {
  116. owner.hotkeyExitWorldView();
  117. auto hero = LOCPLINT->localState->getCurrentHero();
  118. if (hero)
  119. owner.centerOnObject(hero);
  120. }
  121. void AdventureMapShortcuts::worldViewScale1x()
  122. {
  123. // TODO set corresponding scale button to "selected" mode
  124. owner.openWorldView(7);
  125. }
  126. void AdventureMapShortcuts::worldViewScale2x()
  127. {
  128. owner.openWorldView(11);
  129. }
  130. void AdventureMapShortcuts::worldViewScale4x()
  131. {
  132. owner.openWorldView(16);
  133. }
  134. void AdventureMapShortcuts::switchMapLevel()
  135. {
  136. int maxLevels = LOCPLINT->cb->getMapSize().z;
  137. if (maxLevels < 2)
  138. return;
  139. owner.hotkeySwitchMapLevel();
  140. }
  141. void AdventureMapShortcuts::showQuestlog()
  142. {
  143. LOCPLINT->showQuestLog();
  144. }
  145. void AdventureMapShortcuts::toggleTrackHero()
  146. {
  147. Settings s = settings.write["session"];
  148. s["adventureTrackHero"].Bool() = !settings["session"]["adventureTrackHero"].Bool();
  149. }
  150. void AdventureMapShortcuts::toggleGrid()
  151. {
  152. Settings s = settings.write["gameTweaks"];
  153. s["showGrid"].Bool() = !settings["gameTweaks"]["showGrid"].Bool();
  154. }
  155. void AdventureMapShortcuts::toggleVisitable()
  156. {
  157. Settings s = settings.write["session"];
  158. s["showVisitable"].Bool() = !settings["session"]["showVisitable"].Bool();
  159. }
  160. void AdventureMapShortcuts::toggleBlocked()
  161. {
  162. Settings s = settings.write["session"];
  163. s["showBlocked"].Bool() = !settings["session"]["showBlocked"].Bool();
  164. }
  165. void AdventureMapShortcuts::toggleSleepWake()
  166. {
  167. if (!optionHeroSelected())
  168. return;
  169. if (optionHeroAwake())
  170. setHeroSleeping();
  171. else
  172. setHeroAwake();
  173. }
  174. void AdventureMapShortcuts::setHeroSleeping()
  175. {
  176. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  177. if (h)
  178. {
  179. LOCPLINT->localState->setHeroAsleep(h);
  180. owner.onHeroChanged(h);
  181. nextHero();
  182. }
  183. }
  184. void AdventureMapShortcuts::setHeroAwake()
  185. {
  186. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  187. if (h)
  188. {
  189. LOCPLINT->localState->setHeroAwaken(h);
  190. owner.onHeroChanged(h);
  191. }
  192. }
  193. void AdventureMapShortcuts::moveHeroAlongPath()
  194. {
  195. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  196. if (!h || !LOCPLINT->localState->hasPath(h))
  197. return;
  198. LOCPLINT->moveHero(h, LOCPLINT->localState->getPath(h));
  199. }
  200. void AdventureMapShortcuts::showSpellbook()
  201. {
  202. if (!LOCPLINT->localState->getCurrentHero())
  203. return;
  204. owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
  205. GH.windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
  206. }
  207. void AdventureMapShortcuts::adventureOptions()
  208. {
  209. GH.windows().createAndPushWindow<AdventureOptions>();
  210. }
  211. void AdventureMapShortcuts::systemOptions()
  212. {
  213. GH.windows().createAndPushWindow<SettingsMainWindow>();
  214. }
  215. void AdventureMapShortcuts::firstHero()
  216. {
  217. if (!LOCPLINT->localState->getWanderingHeroes().empty())
  218. {
  219. const auto * hero = LOCPLINT->localState->getWanderingHero(0);
  220. LOCPLINT->localState->setSelection(hero);
  221. owner.centerOnObject(hero);
  222. }
  223. }
  224. void AdventureMapShortcuts::nextHero()
  225. {
  226. const auto * currHero = LOCPLINT->localState->getCurrentHero();
  227. const auto * nextHero = LOCPLINT->localState->getNextWanderingHero(currHero);
  228. if (nextHero)
  229. {
  230. LOCPLINT->localState->setSelection(nextHero);
  231. owner.centerOnObject(nextHero);
  232. }
  233. }
  234. void AdventureMapShortcuts::endTurn()
  235. {
  236. if(!LOCPLINT->makingTurn)
  237. return;
  238. if(settings["adventure"]["heroReminder"].Bool())
  239. {
  240. for(auto hero : LOCPLINT->localState->getWanderingHeroes())
  241. {
  242. if(!LOCPLINT->localState->isHeroSleeping(hero) && hero->movementPointsRemaining() > 0)
  243. {
  244. // Only show hero reminder if conditions met:
  245. // - There still movement points
  246. // - Hero don't have a path or there not points for first step on path
  247. LOCPLINT->localState->verifyPath(hero);
  248. if(!LOCPLINT->localState->hasPath(hero))
  249. {
  250. LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
  251. return;
  252. }
  253. auto path = LOCPLINT->localState->getPath(hero);
  254. if (path.nodes.size() < 2 || path.nodes[path.nodes.size() - 2].turns)
  255. {
  256. LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
  257. return;
  258. }
  259. }
  260. }
  261. }
  262. owner.hotkeyEndingTurn();
  263. }
  264. void AdventureMapShortcuts::showThievesGuild()
  265. {
  266. //find first town with tavern
  267. auto itr = range::find_if(LOCPLINT->localState->getOwnedTowns(), [](const CGTownInstance * town)
  268. {
  269. return town->hasBuilt(BuildingID::TAVERN);
  270. });
  271. if(itr != LOCPLINT->localState->getOwnedTowns().end())
  272. LOCPLINT->showThievesGuildWindow(*itr);
  273. else
  274. LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithTavern"));
  275. }
  276. void AdventureMapShortcuts::showScenarioInfo()
  277. {
  278. AdventureOptions::showScenarioInfo();
  279. }
  280. void AdventureMapShortcuts::toMainMenu()
  281. {
  282. LOCPLINT->showYesNoDialog(
  283. CGI->generaltexth->allTexts[578],
  284. []()
  285. {
  286. CSH->endGameplay();
  287. CMM->menu->switchToTab("main");
  288. },
  289. 0
  290. );
  291. }
  292. void AdventureMapShortcuts::newGame()
  293. {
  294. LOCPLINT->showYesNoDialog(
  295. CGI->generaltexth->allTexts[578],
  296. []()
  297. {
  298. CSH->endGameplay();
  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::search()
  402. {
  403. LOCPLINT->showInfoDialog("search");
  404. std::vector<ObjectInstanceID> visitableObjInstances;
  405. int3 mapSizes = LOCPLINT->cb->getMapSize();
  406. for(int x = 0; x < mapSizes.x; x++)
  407. for(int y = 0; y < mapSizes.y; y++)
  408. for(int z = 0; z < mapSizes.z; z++)
  409. for(auto & obj : LOCPLINT->cb->getVisitableObjs(int3(x, y, z), false))
  410. visitableObjInstances.push_back(obj->id);
  411. // count of elements for each group
  412. std::map<MapObjectID, int> mapObjCount;
  413. for(auto & obj : visitableObjInstances)
  414. mapObjCount[LOCPLINT->cb->getObjInstance(obj)->getObjGroupIndex()]++;
  415. // sort by name
  416. std::vector<std::pair<int, int>> mapObjCountList;
  417. for (auto itr = mapObjCount.begin(); itr != mapObjCount.end(); ++itr)
  418. mapObjCountList.push_back(*itr);
  419. std::sort(mapObjCountList.begin(), mapObjCountList.end(),
  420. [=](std::pair<int, int>& a, std::pair<int, int>& b)
  421. {
  422. return VLC->objtypeh->getObjectName(a.first, 0) < VLC->objtypeh->getObjectName(b.first, 0);
  423. }
  424. );
  425. //TODO show table as popup
  426. for(auto & obj : mapObjCountList)
  427. std::cout << VLC->objtypeh->getObjectName(obj.first, 0) << " " << obj.second << "\n";
  428. }
  429. void AdventureMapShortcuts::nextObject()
  430. {
  431. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
  432. const CGTownInstance *t = LOCPLINT->localState->getCurrentTown();
  433. if(h)
  434. nextHero();
  435. if(t)
  436. nextTown();
  437. }
  438. void AdventureMapShortcuts::moveHeroDirectional(const Point & direction)
  439. {
  440. const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); //selected hero
  441. if(!h)
  442. return;
  443. if (CGI->mh->hasOngoingAnimations())
  444. return;
  445. int3 dst = h->visitablePos() + int3(direction.x, direction.y, 0);
  446. if (!CGI->mh->isInMap((dst)))
  447. return;
  448. if ( !LOCPLINT->localState->setPath(h, dst))
  449. return;
  450. const CGPath & path = LOCPLINT->localState->getPath(h);
  451. if (path.nodes.size() > 2)
  452. owner.onHeroChanged(h);
  453. else
  454. if(path.nodes[0].turns == 0)
  455. LOCPLINT->moveHero(h, path);
  456. }
  457. bool AdventureMapShortcuts::optionCanViewQuests()
  458. {
  459. return optionInMapView() && !CGI->mh->getMap()->quests.empty();
  460. }
  461. bool AdventureMapShortcuts::optionCanToggleLevel()
  462. {
  463. return optionSidePanelActive() && LOCPLINT->cb->getMapSize().z > 1;
  464. }
  465. bool AdventureMapShortcuts::optionMapLevelSurface()
  466. {
  467. return mapLevel == 0;
  468. }
  469. bool AdventureMapShortcuts::optionHeroSleeping()
  470. {
  471. const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
  472. return optionInMapView() && hero && LOCPLINT->localState->isHeroSleeping(hero);
  473. }
  474. bool AdventureMapShortcuts::optionHeroAwake()
  475. {
  476. const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
  477. return optionInMapView() && hero && !LOCPLINT->localState->isHeroSleeping(hero);
  478. }
  479. bool AdventureMapShortcuts::optionCanVisitObject()
  480. {
  481. if (!optionHeroSelected())
  482. return false;
  483. auto * hero = LOCPLINT->localState->getCurrentHero();
  484. auto objects = LOCPLINT->cb->getVisitableObjs(hero->visitablePos());
  485. return objects.size() > 1; // there is object other than our hero
  486. }
  487. bool AdventureMapShortcuts::optionHeroSelected()
  488. {
  489. return optionInMapView() && LOCPLINT->localState->getCurrentHero() != nullptr;
  490. }
  491. bool AdventureMapShortcuts::optionHeroCanMove()
  492. {
  493. const auto * hero = LOCPLINT->localState->getCurrentHero();
  494. return optionInMapView() && hero && LOCPLINT->localState->hasPath(hero) && LOCPLINT->localState->getPath(hero).nextNode().turns == 0;
  495. }
  496. bool AdventureMapShortcuts::optionHasNextHero()
  497. {
  498. const auto * hero = LOCPLINT->localState->getCurrentHero();
  499. const auto * nextSuitableHero = LOCPLINT->localState->getNextWanderingHero(hero);
  500. return optionInMapView() && nextSuitableHero != nullptr;
  501. }
  502. bool AdventureMapShortcuts::optionCanEndTurn()
  503. {
  504. return optionInMapView() && LOCPLINT->makingTurn;
  505. }
  506. bool AdventureMapShortcuts::optionSpellcasting()
  507. {
  508. return state == EAdventureState::CASTING_SPELL;
  509. }
  510. bool AdventureMapShortcuts::optionInMapView()
  511. {
  512. return state == EAdventureState::MAKING_TURN;
  513. }
  514. bool AdventureMapShortcuts::optionInWorldView()
  515. {
  516. return state == EAdventureState::WORLD_VIEW;
  517. }
  518. bool AdventureMapShortcuts::optionSidePanelActive()
  519. {
  520. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW;
  521. }
  522. bool AdventureMapShortcuts::optionMapScrollingActive()
  523. {
  524. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW;
  525. }
  526. bool AdventureMapShortcuts::optionMapViewActive()
  527. {
  528. return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::CASTING_SPELL;
  529. }