2023-05-02 15:09:36 +02:00
|
|
|
/*
|
|
|
|
* AdventureMapShortcuts.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "AdventureMapShortcuts.h"
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
2023-06-26 20:51:10 +02:00
|
|
|
#include "../CServerHandler.h"
|
2023-05-04 18:04:36 +02:00
|
|
|
#include "../PlayerLocalState.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/Shortcut.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2023-05-04 18:04:36 +02:00
|
|
|
#include "../lobby/CSavingScreen.h"
|
|
|
|
#include "../mapView/mapHandler.h"
|
2023-05-02 15:09:36 +02:00
|
|
|
#include "../windows/CKingdomInterface.h"
|
|
|
|
#include "../windows/CSpellWindow.h"
|
2024-02-03 13:26:24 +02:00
|
|
|
#include "../windows/CMarketWindow.h"
|
2023-05-04 18:04:36 +02:00
|
|
|
#include "../windows/settings/SettingsMainWindow.h"
|
2023-05-08 14:18:34 +02:00
|
|
|
#include "AdventureMapInterface.h"
|
|
|
|
#include "AdventureOptions.h"
|
2023-05-05 14:48:43 +02:00
|
|
|
#include "AdventureState.h"
|
2023-05-02 15:09:36 +02:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/mapObjects/CGHeroInstance.h"
|
|
|
|
#include "../../lib/mapObjects/CGTownInstance.h"
|
2023-05-04 18:04:36 +02:00
|
|
|
#include "../../lib/mapping/CMap.h"
|
2023-06-21 12:46:09 +02:00
|
|
|
#include "../../lib/pathfinder/CGPathNode.h"
|
2023-05-02 15:09:36 +02:00
|
|
|
|
2023-05-08 14:18:34 +02:00
|
|
|
AdventureMapShortcuts::AdventureMapShortcuts(AdventureMapInterface & owner)
|
2023-05-05 14:48:43 +02:00
|
|
|
: owner(owner)
|
|
|
|
, state(EAdventureState::NOT_INITIALIZED)
|
|
|
|
, mapLevel(0)
|
2023-05-02 15:09:36 +02:00
|
|
|
{}
|
|
|
|
|
2023-05-05 14:48:43 +02:00
|
|
|
void AdventureMapShortcuts::setState(EAdventureState newState)
|
|
|
|
{
|
|
|
|
state = newState;
|
|
|
|
}
|
|
|
|
|
2024-05-14 22:21:18 +02:00
|
|
|
EAdventureState AdventureMapShortcuts::getState()
|
|
|
|
{
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2023-05-05 14:48:43 +02:00
|
|
|
void AdventureMapShortcuts::onMapViewMoved(const Rect & visibleArea, int newMapLevel)
|
|
|
|
{
|
|
|
|
mapLevel = newMapLevel;
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
std::vector<AdventureMapShortcutState> AdventureMapShortcuts::getShortcuts()
|
|
|
|
{
|
|
|
|
std::vector<AdventureMapShortcutState> result = {
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_KINGDOM_OVERVIEW, optionInMapView(), [this]() { this->showOverview(); } },
|
|
|
|
{ EShortcut::ADVENTURE_EXIT_WORLD_VIEW, optionInWorldView(), [this]() { this->worldViewBack(); } },
|
|
|
|
{ EShortcut::ADVENTURE_VIEW_WORLD, optionInMapView(), [this]() { this->worldViewScale1x(); } },
|
|
|
|
{ EShortcut::ADVENTURE_VIEW_WORLD_X1, optionInWorldView(), [this]() { this->worldViewScale1x(); } },
|
|
|
|
{ EShortcut::ADVENTURE_VIEW_WORLD_X2, optionInWorldView(), [this]() { this->worldViewScale2x(); } },
|
|
|
|
{ EShortcut::ADVENTURE_VIEW_WORLD_X4, optionInWorldView(), [this]() { this->worldViewScale4x(); } },
|
2023-05-07 00:34:11 +02:00
|
|
|
{ EShortcut::ADVENTURE_TOGGLE_MAP_LEVEL, optionCanToggleLevel(), [this]() { this->switchMapLevel(); } },
|
|
|
|
{ EShortcut::ADVENTURE_QUEST_LOG, optionCanViewQuests(), [this]() { this->showQuestlog(); } },
|
2023-05-04 18:04:36 +02:00
|
|
|
{ EShortcut::ADVENTURE_TOGGLE_SLEEP, optionHeroSelected(), [this]() { this->toggleSleepWake(); } },
|
2024-04-30 18:10:10 +02:00
|
|
|
{ EShortcut::ADVENTURE_TOGGLE_GRID, optionInMapView(), [this]() { this->toggleGrid(); } },
|
|
|
|
{ EShortcut::ADVENTURE_TRACK_HERO, optionInMapView(), [this]() { this->toggleTrackHero(); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_SET_HERO_ASLEEP, optionHeroAwake(), [this]() { this->setHeroSleeping(); } },
|
2023-05-04 18:04:36 +02:00
|
|
|
{ EShortcut::ADVENTURE_SET_HERO_AWAKE, optionHeroSleeping(), [this]() { this->setHeroAwake(); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO, optionHeroCanMove(), [this]() { this->moveHeroAlongPath(); } },
|
|
|
|
{ EShortcut::ADVENTURE_CAST_SPELL, optionHeroSelected(), [this]() { this->showSpellbook(); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_GAME_OPTIONS, optionInMapView(), [this]() { this->adventureOptions(); } },
|
|
|
|
{ EShortcut::GLOBAL_OPTIONS, optionInMapView(), [this]() { this->systemOptions(); } },
|
2023-05-04 18:04:36 +02:00
|
|
|
{ EShortcut::ADVENTURE_NEXT_HERO, optionHasNextHero(), [this]() { this->nextHero(); } },
|
2023-09-19 18:50:07 +02:00
|
|
|
{ EShortcut::GAME_END_TURN, optionCanEndTurn(), [this]() { this->endTurn(); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_THIEVES_GUILD, optionInMapView(), [this]() { this->showThievesGuild(); } },
|
|
|
|
{ EShortcut::ADVENTURE_VIEW_SCENARIO, optionInMapView(), [this]() { this->showScenarioInfo(); } },
|
|
|
|
{ EShortcut::GAME_SAVE_GAME, optionInMapView(), [this]() { this->saveGame(); } },
|
|
|
|
{ EShortcut::GAME_LOAD_GAME, optionInMapView(), [this]() { this->loadGame(); } },
|
2023-05-04 18:04:36 +02:00
|
|
|
{ EShortcut::ADVENTURE_DIG_GRAIL, optionHeroSelected(), [this]() { this->digGrail(); } },
|
2023-05-07 00:34:11 +02:00
|
|
|
{ EShortcut::ADVENTURE_VIEW_PUZZLE, optionSidePanelActive(),[this]() { this->viewPuzzleMap(); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::GAME_RESTART_GAME, optionInMapView(), [this]() { this->restartGame(); } },
|
2023-09-19 18:51:31 +02:00
|
|
|
{ EShortcut::ADVENTURE_VISIT_OBJECT, optionCanVisitObject(), [this]() { this->visitObject(); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_VIEW_SELECTED, optionInMapView(), [this]() { this->openObject(); } },
|
|
|
|
{ EShortcut::GAME_OPEN_MARKETPLACE, optionInMapView(), [this]() { this->showMarketplace(); } },
|
2023-05-16 22:42:51 +02:00
|
|
|
{ EShortcut::ADVENTURE_ZOOM_IN, optionSidePanelActive(),[this]() { this->zoom(+1); } },
|
|
|
|
{ EShortcut::ADVENTURE_ZOOM_OUT, optionSidePanelActive(),[this]() { this->zoom(-1); } },
|
2023-05-17 13:54:19 +02:00
|
|
|
{ EShortcut::ADVENTURE_ZOOM_RESET, optionSidePanelActive(),[this]() { this->zoom( 0); } },
|
2023-05-05 14:48:43 +02:00
|
|
|
{ EShortcut::ADVENTURE_NEXT_TOWN, optionInMapView(), [this]() { this->nextTown(); } },
|
|
|
|
{ EShortcut::ADVENTURE_NEXT_OBJECT, optionInMapView(), [this]() { this->nextObject(); } },
|
2023-05-04 18:04:36 +02:00
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_SW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, +1}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_SS, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, +1}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_SE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, +1}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_WW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, 0}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_EE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, 0}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_NW, optionHeroSelected(), [this]() { this->moveHeroDirectional({-1, -1}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_NN, optionHeroSelected(), [this]() { this->moveHeroDirectional({ 0, -1}); } },
|
|
|
|
{ EShortcut::ADVENTURE_MOVE_HERO_NE, optionHeroSelected(), [this]() { this->moveHeroDirectional({+1, -1}); } }
|
2023-05-02 15:09:36 +02:00
|
|
|
};
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showOverview()
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CKingdomInterface>();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::worldViewBack()
|
|
|
|
{
|
|
|
|
owner.hotkeyExitWorldView();
|
|
|
|
|
|
|
|
auto hero = LOCPLINT->localState->getCurrentHero();
|
|
|
|
if (hero)
|
|
|
|
owner.centerOnObject(hero);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::worldViewScale1x()
|
|
|
|
{
|
|
|
|
// TODO set corresponding scale button to "selected" mode
|
|
|
|
owner.openWorldView(7);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::worldViewScale2x()
|
|
|
|
{
|
|
|
|
owner.openWorldView(11);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::worldViewScale4x()
|
|
|
|
{
|
|
|
|
owner.openWorldView(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::switchMapLevel()
|
|
|
|
{
|
|
|
|
int maxLevels = LOCPLINT->cb->getMapSize().z;
|
|
|
|
if (maxLevels < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
owner.hotkeySwitchMapLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showQuestlog()
|
|
|
|
{
|
|
|
|
LOCPLINT->showQuestLog();
|
|
|
|
}
|
|
|
|
|
2024-04-30 18:10:10 +02:00
|
|
|
void AdventureMapShortcuts::toggleTrackHero()
|
|
|
|
{
|
|
|
|
Settings s = settings.write["session"];
|
|
|
|
s["adventureTrackHero"].Bool() = !settings["session"]["adventureTrackHero"].Bool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::toggleGrid()
|
|
|
|
{
|
|
|
|
Settings s = settings.write["gameTweaks"];
|
|
|
|
s["showGrid"].Bool() = !settings["gameTweaks"]["showGrid"].Bool();
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:09:36 +02:00
|
|
|
void AdventureMapShortcuts::toggleSleepWake()
|
|
|
|
{
|
2023-05-08 16:30:02 +02:00
|
|
|
if (!optionHeroSelected())
|
2023-05-02 15:09:36 +02:00
|
|
|
return;
|
|
|
|
|
2023-05-08 16:30:02 +02:00
|
|
|
if (optionHeroAwake())
|
|
|
|
setHeroSleeping();
|
2023-05-02 15:09:36 +02:00
|
|
|
else
|
2023-05-08 16:30:02 +02:00
|
|
|
setHeroAwake();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::setHeroSleeping()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
LOCPLINT->localState->setHeroAsleep(h);
|
|
|
|
owner.onHeroChanged(h);
|
|
|
|
nextHero();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::setHeroAwake()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
if (h)
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
LOCPLINT->localState->setHeroAwaken(h);
|
2023-05-02 15:09:36 +02:00
|
|
|
owner.onHeroChanged(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::moveHeroAlongPath()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
if (!h || !LOCPLINT->localState->hasPath(h))
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOCPLINT->moveHero(h, LOCPLINT->localState->getPath(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showSpellbook()
|
|
|
|
{
|
2023-05-08 16:30:02 +02:00
|
|
|
if (!LOCPLINT->localState->getCurrentHero())
|
2023-05-02 15:09:36 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
owner.centerOnObject(LOCPLINT->localState->getCurrentHero());
|
|
|
|
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CSpellWindow>(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false);
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::adventureOptions()
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<AdventureOptions>();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::systemOptions()
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<SettingsMainWindow>();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::nextHero()
|
|
|
|
{
|
|
|
|
const auto * currHero = LOCPLINT->localState->getCurrentHero();
|
|
|
|
const auto * nextHero = LOCPLINT->localState->getNextWanderingHero(currHero);
|
|
|
|
|
|
|
|
if (nextHero)
|
|
|
|
{
|
|
|
|
LOCPLINT->localState->setSelection(nextHero);
|
|
|
|
owner.centerOnObject(nextHero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::endTurn()
|
|
|
|
{
|
|
|
|
if(!LOCPLINT->makingTurn)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(settings["adventure"]["heroReminder"].Bool())
|
|
|
|
{
|
|
|
|
for(auto hero : LOCPLINT->localState->getWanderingHeroes())
|
|
|
|
{
|
2023-06-21 19:38:26 +02:00
|
|
|
if(!LOCPLINT->localState->isHeroSleeping(hero) && hero->movementPointsRemaining() > 0)
|
2023-05-02 15:09:36 +02:00
|
|
|
{
|
|
|
|
// Only show hero reminder if conditions met:
|
|
|
|
// - There still movement points
|
|
|
|
// - Hero don't have a path or there not points for first step on path
|
|
|
|
LOCPLINT->localState->verifyPath(hero);
|
|
|
|
|
|
|
|
if(!LOCPLINT->localState->hasPath(hero))
|
|
|
|
{
|
|
|
|
LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto path = LOCPLINT->localState->getPath(hero);
|
|
|
|
if (path.nodes.size() < 2 || path.nodes[path.nodes.size() - 2].turns)
|
|
|
|
{
|
|
|
|
LOCPLINT->showYesNoDialog( CGI->generaltexth->allTexts[55], [this](){ owner.hotkeyEndingTurn(); }, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
owner.hotkeyEndingTurn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showThievesGuild()
|
|
|
|
{
|
|
|
|
//find first town with tavern
|
|
|
|
auto itr = range::find_if(LOCPLINT->localState->getOwnedTowns(), [](const CGTownInstance * town)
|
|
|
|
{
|
|
|
|
return town->hasBuilt(BuildingID::TAVERN);
|
|
|
|
});
|
|
|
|
|
|
|
|
if(itr != LOCPLINT->localState->getOwnedTowns().end())
|
|
|
|
LOCPLINT->showThievesGuildWindow(*itr);
|
|
|
|
else
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithTavern"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showScenarioInfo()
|
|
|
|
{
|
2023-05-08 14:18:34 +02:00
|
|
|
AdventureOptions::showScenarioInfo();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::saveGame()
|
|
|
|
{
|
2023-05-16 15:20:35 +02:00
|
|
|
GH.windows().createAndPushWindow<CSavingScreen>();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::loadGame()
|
|
|
|
{
|
|
|
|
LOCPLINT->proposeLoadingGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::digGrail()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
|
|
|
|
if(h && LOCPLINT->makingTurn)
|
2023-07-13 21:56:53 +02:00
|
|
|
LOCPLINT->tryDigging(h);
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::viewPuzzleMap()
|
|
|
|
{
|
|
|
|
LOCPLINT->showPuzzleMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::restartGame()
|
|
|
|
{
|
2023-06-26 20:51:10 +02:00
|
|
|
LOCPLINT->showYesNoDialog(
|
|
|
|
CGI->generaltexth->translate("vcmi.adventureMap.confirmRestartGame"),
|
|
|
|
[]()
|
|
|
|
{
|
|
|
|
GH.dispatchMainThread(
|
|
|
|
[]()
|
|
|
|
{
|
|
|
|
CSH->sendRestartGame();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
nullptr
|
|
|
|
);
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::visitObject()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
|
|
|
|
if(h)
|
2024-04-18 14:13:16 +02:00
|
|
|
LOCPLINT->cb->moveHero(h, h->pos, false);
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::openObject()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
const CGTownInstance *t = LOCPLINT->localState->getCurrentTown();
|
|
|
|
if(h)
|
|
|
|
LOCPLINT->openHeroWindow(h);
|
|
|
|
|
|
|
|
if(t)
|
|
|
|
LOCPLINT->openTownWindow(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::showMarketplace()
|
|
|
|
{
|
|
|
|
//check if we have any marketplace
|
|
|
|
const CGTownInstance *townWithMarket = nullptr;
|
|
|
|
for(const CGTownInstance *t : LOCPLINT->cb->getTownsInfo())
|
|
|
|
{
|
|
|
|
if(t->hasBuilt(BuildingID::MARKETPLACE))
|
|
|
|
{
|
|
|
|
townWithMarket = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(townWithMarket) //if any town has marketplace, open window
|
2024-02-03 13:26:24 +02:00
|
|
|
GH.windows().createAndPushWindow<CMarketWindow>(townWithMarket, nullptr, nullptr, EMarketMode::RESOURCE_RESOURCE);
|
2023-05-02 15:09:36 +02:00
|
|
|
else //if not - complain
|
|
|
|
LOCPLINT->showInfoDialog(CGI->generaltexth->translate("vcmi.adventureMap.noTownWithMarket"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::nextTown()
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
owner.hotkeyNextTown();
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-16 22:42:51 +02:00
|
|
|
void AdventureMapShortcuts::zoom( int distance)
|
|
|
|
{
|
|
|
|
owner.hotkeyZoom(distance);
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
void AdventureMapShortcuts::nextObject()
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero();
|
|
|
|
const CGTownInstance *t = LOCPLINT->localState->getCurrentTown();
|
|
|
|
if(h)
|
|
|
|
nextHero();
|
|
|
|
|
|
|
|
if(t)
|
|
|
|
nextTown();
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdventureMapShortcuts::moveHeroDirectional(const Point & direction)
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); //selected hero
|
|
|
|
|
|
|
|
if(!h)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (CGI->mh->hasOngoingAnimations())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int3 dst = h->visitablePos() + int3(direction.x, direction.y, 0);
|
|
|
|
|
|
|
|
if (!CGI->mh->isInMap((dst)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( !LOCPLINT->localState->setPath(h, dst))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const CGPath & path = LOCPLINT->localState->getPath(h);
|
|
|
|
|
|
|
|
if (path.nodes.size() > 2)
|
|
|
|
owner.onHeroChanged(h);
|
|
|
|
else
|
|
|
|
if(path.nodes[0].turns == 0)
|
|
|
|
LOCPLINT->moveHero(h, path);
|
2023-05-02 15:09:36 +02:00
|
|
|
}
|
2023-05-04 18:04:36 +02:00
|
|
|
|
2023-05-07 00:34:11 +02:00
|
|
|
bool AdventureMapShortcuts::optionCanViewQuests()
|
2023-05-04 18:04:36 +02:00
|
|
|
{
|
2023-08-24 18:10:39 +02:00
|
|
|
return optionInMapView() && !CGI->mh->getMap()->quests.empty();
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-07 00:34:11 +02:00
|
|
|
bool AdventureMapShortcuts::optionCanToggleLevel()
|
2023-05-04 18:04:36 +02:00
|
|
|
{
|
2023-09-11 17:10:57 +02:00
|
|
|
return optionSidePanelActive() && LOCPLINT->cb->getMapSize().z > 1;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionMapLevelSurface()
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
return mapLevel == 0;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionHeroSleeping()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
|
2023-05-07 00:34:11 +02:00
|
|
|
return optionInMapView() && hero && LOCPLINT->localState->isHeroSleeping(hero);
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-05 14:48:43 +02:00
|
|
|
bool AdventureMapShortcuts::optionHeroAwake()
|
|
|
|
{
|
|
|
|
const CGHeroInstance *hero = LOCPLINT->localState->getCurrentHero();
|
2023-05-07 00:34:11 +02:00
|
|
|
return optionInMapView() && hero && !LOCPLINT->localState->isHeroSleeping(hero);
|
2023-05-05 14:48:43 +02:00
|
|
|
}
|
|
|
|
|
2023-09-19 18:51:31 +02:00
|
|
|
bool AdventureMapShortcuts::optionCanVisitObject()
|
|
|
|
{
|
|
|
|
if (!optionHeroSelected())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto * hero = LOCPLINT->localState->getCurrentHero();
|
|
|
|
auto objects = LOCPLINT->cb->getVisitableObjs(hero->visitablePos());
|
|
|
|
|
|
|
|
assert(vstd::contains(objects,hero));
|
|
|
|
return objects.size() > 1; // there is object other than our hero
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
bool AdventureMapShortcuts::optionHeroSelected()
|
|
|
|
{
|
2023-05-07 00:34:11 +02:00
|
|
|
return optionInMapView() && LOCPLINT->localState->getCurrentHero() != nullptr;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionHeroCanMove()
|
|
|
|
{
|
|
|
|
const auto * hero = LOCPLINT->localState->getCurrentHero();
|
2024-05-13 19:25:20 +02:00
|
|
|
return optionInMapView() && hero && LOCPLINT->localState->hasPath(hero) && LOCPLINT->localState->getPath(hero).nextNode().turns == 0;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionHasNextHero()
|
|
|
|
{
|
|
|
|
const auto * hero = LOCPLINT->localState->getCurrentHero();
|
|
|
|
const auto * nextSuitableHero = LOCPLINT->localState->getNextWanderingHero(hero);
|
|
|
|
|
2023-05-07 00:34:11 +02:00
|
|
|
return optionInMapView() && nextSuitableHero != nullptr;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-09-19 18:50:07 +02:00
|
|
|
bool AdventureMapShortcuts::optionCanEndTurn()
|
|
|
|
{
|
|
|
|
return optionInMapView() && LOCPLINT->makingTurn;
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
bool AdventureMapShortcuts::optionSpellcasting()
|
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
return state == EAdventureState::CASTING_SPELL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionInMapView()
|
|
|
|
{
|
|
|
|
return state == EAdventureState::MAKING_TURN;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-05 14:48:43 +02:00
|
|
|
bool AdventureMapShortcuts::optionInWorldView()
|
2023-05-04 18:04:36 +02:00
|
|
|
{
|
2023-05-05 14:48:43 +02:00
|
|
|
return state == EAdventureState::WORLD_VIEW;
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
2023-05-07 00:34:11 +02:00
|
|
|
|
|
|
|
bool AdventureMapShortcuts::optionSidePanelActive()
|
|
|
|
{
|
2024-04-27 11:40:22 +02:00
|
|
|
return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
|
2023-05-07 00:34:11 +02:00
|
|
|
}
|
|
|
|
|
2023-07-26 21:20:11 +02:00
|
|
|
bool AdventureMapShortcuts::optionMapScrollingActive()
|
|
|
|
{
|
2024-04-27 11:40:22 +02:00
|
|
|
return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
|
2023-07-26 21:20:11 +02:00
|
|
|
}
|
|
|
|
|
2023-05-07 00:34:11 +02:00
|
|
|
bool AdventureMapShortcuts::optionMapViewActive()
|
|
|
|
{
|
2023-07-26 21:20:11 +02:00
|
|
|
return state == EAdventureState::MAKING_TURN || state == EAdventureState::WORLD_VIEW || state == EAdventureState::CASTING_SPELL
|
2024-04-27 11:40:22 +02:00
|
|
|
|| state == EAdventureState::OTHER_HUMAN_PLAYER_TURN;
|
2023-05-07 00:34:11 +02:00
|
|
|
}
|