diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 32698ad0b..e0be8e0d8 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -1231,13 +1231,13 @@ void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const Bonus void CPlayerInterface::saveGame( BinarySerializer & h, const int version ) { EVENT_HANDLER_CALLED_BY_CLIENT; - h & localState; + localState->serialize(h, version); } void CPlayerInterface::loadGame( BinaryDeserializer & h, const int version ) { EVENT_HANDLER_CALLED_BY_CLIENT; - h & localState; + localState->serialize(h, version); firstCall = -1; } @@ -1325,6 +1325,12 @@ void CPlayerInterface::requestRealized( PackageApplied *pa ) } } + +void CPlayerInterface::showHeroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2) +{ + heroExchangeStarted(hero1, hero2, QueryID(-1)); +} + void CPlayerInterface::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query) { EVENT_HANDLER_CALLED_BY_CLIENT; @@ -2075,3 +2081,9 @@ void CPlayerInterface::showWorldViewEx(const std::vector& objectP EVENT_HANDLER_CALLED_BY_CLIENT; adventureInt->openWorldView(objectPositions, showTerrain ); } + +void CPlayerInterface::setSelection(const CArmedInstance *sel, bool centerView) +{ + localState->setSelection(sel); + adventureInt->onSelectionChanged(sel, centerView); +} diff --git a/client/CPlayerInterface.h b/client/CPlayerInterface.h index 552c119b2..6c640984d 100644 --- a/client/CPlayerInterface.h +++ b/client/CPlayerInterface.h @@ -58,6 +58,10 @@ namespace boost /// Central class for managing user interface logic class CPlayerInterface : public CGameInterface, public IUpdateable { + bool duringMovement; + bool ignoreEvents; + size_t numOfMovedArts; + // -1 - just loaded game; 1 - just started game; 0 otherwise int firstCall; int autosaveCount; @@ -92,14 +96,12 @@ public: // TODO: make private std::shared_ptr autofightingAI; //AI that makes decisions bool isAutoFightOn; //Flag, switch it to stop quick combat. Don't touch if there is no battle interface. -public: +protected: // Call-ins from server, should not be called directly, but only via GameInterface + void update() override; - void initializeHeroTownList(); - int getLastIndex(std::string namePrefix); + void initGameInterface(std::shared_ptr ENV, std::shared_ptr CB) override; - //overridden funcs from CGameInterface void garrisonsChanged(ObjectInstanceID id1, ObjectInstanceID id2) override; - void buildChanged(const CGTownInstance *town, BuildingID buildingID, int what) override; //what: 1 - built, 2 - demolished void artifactPut(const ArtifactLocation &al) override; @@ -124,19 +126,13 @@ public: void receivedResource() override; void showInfoDialog(EInfoWindowMode type, const std::string & text, const std::vector & components, int soundID) override; void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level) override; - void showShipyardDialog(const IShipyard *obj) override; //obj may be town or shipyard; void showBlockingDialog(const std::string &text, const std::vector &components, QueryID askID, const int soundID, bool selection, bool cancel) override; //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID. void showTeleportDialog(TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) override; void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, QueryID queryID) override; void showMapObjectSelectDialog(QueryID askID, const Component & icon, const MetaString & title, const MetaString & description, const std::vector & objects) override; - void showPuzzleMap() override; - void viewWorldMap() override; void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor) override; void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor) override; void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor) override; - void showTavernWindow(const CGObjectInstance *townOrTavern) override; - void showThievesGuildWindow (const CGObjectInstance * obj) override; - void showQuestLog() override; void advmapSpellCast(const CGHeroInstance * caster, int spellID) override; //called when a hero casts a spell void tileHidden(const std::unordered_set &pos) override; //called when given tiles become hidden under fog of war void tileRevealed(const std::unordered_set &pos) override; //called when fog of war disappears from given tiles @@ -182,18 +178,23 @@ public: void yourTacticPhase(int distance) override; void forceEndTacticPhase() override; - //-------------// +public: // public interface for use by client via LOCPLINT access + + // part of GameInterface that is also used by client code + void showPuzzleMap() override; + void viewWorldMap() override; + void showQuestLog() override; + void showThievesGuildWindow (const CGObjectInstance * obj) override; + void showTavernWindow(const CGObjectInstance *townOrTavern) override; + void showShipyardDialog(const IShipyard *obj) override; //obj may be town or shipyard; + + void showHeroExchange(ObjectInstanceID hero1, ObjectInstanceID hero2); void showArtifactAssemblyDialog(const Artifact * artifact, const Artifact * assembledArtifact, CFunctionList onYes); - void garrisonsChanged(std::vector objs); - void heroKilled(const CGHeroInstance* hero); void waitWhileDialog(bool unlockPim = true); void waitForAllDialogs(bool unlockPim = true); - void redrawHeroWin(const CGHeroInstance * hero); void openTownWindow(const CGTownInstance * town); //shows townscreen void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero - void initGameInterface(std::shared_ptr ENV, std::shared_ptr CB) override; - // show dialogs void showInfoDialog(const std::string &text, std::shared_ptr component); void showInfoDialog(const std::string &text, const std::vector> & components = std::vector>(), int soundID = 0); void showInfoDialogAndWait(std::vector & components, const MetaString & text); @@ -202,12 +203,13 @@ public: void stopMovement(); void moveHero(const CGHeroInstance *h, const CGPath& path); - void acceptTurn(); //used during hot seat after your turn message is close void tryDiggging(const CGHeroInstance *h); void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard; - void requestReturningToMainMenu(bool won); void proposeLoadingGame(); + /// Changes currently selected object + void setSelection(const CArmedInstance *sel, bool centerView = true); + ///returns true if all events are processed internally bool capturedAllEvents(); @@ -229,10 +231,12 @@ private: }; - bool duringMovement; - bool ignoreEvents; - size_t numOfMovedArts; - + void heroKilled(const CGHeroInstance* hero); + void garrisonsChanged(std::vector objs); + void requestReturningToMainMenu(bool won); + void acceptTurn(); //used during hot seat after your turn message is close + void initializeHeroTownList(); + int getLastIndex(std::string namePrefix); void doMoveHero(const CGHeroInstance *h, CGPath path); void setMovementStatus(bool value); @@ -240,4 +244,5 @@ private: void performAutosave(); }; +/// Provides global access to instance of interface of currently active player extern CPlayerInterface * LOCPLINT; diff --git a/client/ClientCommandManager.cpp b/client/ClientCommandManager.cpp index 959e0b588..b2c999286 100644 --- a/client/ClientCommandManager.cpp +++ b/client/ClientCommandManager.cpp @@ -15,6 +15,7 @@ #include "adventureMap/CInGameConsole.h" #include "adventureMap/CAdventureMapInterface.h" #include "CPlayerInterface.h" +#include "PlayerLocalState.h" #include "CServerHandler.h" #include "gui/CGuiHandler.h" #include "../lib/NetPacks.h" @@ -387,12 +388,12 @@ void ClientCommandManager::handleBonusesCommand(std::istringstream & singleWordB ss << b; return ss.str(); }; - printCommandMessage("Bonuses of " + adventureInt->getCurrentArmy()->getObjectName() + "\n"); - printCommandMessage(format(adventureInt->getCurrentArmy()->getBonusList()) + "\n"); + printCommandMessage("Bonuses of " + LOCPLINT->localState->getCurrentArmy()->getObjectName() + "\n"); + printCommandMessage(format(LOCPLINT->localState->getCurrentArmy()->getBonusList()) + "\n"); printCommandMessage("\nInherited bonuses:\n"); TCNodes parents; - adventureInt->getCurrentArmy()->getParents(parents); + LOCPLINT->localState->getCurrentArmy()->getParents(parents); for(const CBonusSystemNode *parent : parents) { printCommandMessage(std::string("\nBonuses from ") + typeid(*parent).name() + "\n" + format(*parent->getAllBonuses(Selector::all, Selector::all)) + "\n"); diff --git a/client/PlayerLocalState.cpp b/client/PlayerLocalState.cpp index 531b22fb5..ffcc7c94b 100644 --- a/client/PlayerLocalState.cpp +++ b/client/PlayerLocalState.cpp @@ -13,18 +13,13 @@ #include "../CCallback.h" #include "../lib/CPathfinder.h" #include "../lib/mapObjects/CGHeroInstance.h" +#include "../lib/mapObjects/CGTownInstance.h" #include "CPlayerInterface.h" #include "adventureMap/CAdventureMapInterface.h" -PlayerLocalState::PlayerLocalState() - : owner(*LOCPLINT) -{ - // should never be called, method required for serializer methods template instantiations - throw std::runtime_error("Can not create PlayerLocalState without interface!"); -} - PlayerLocalState::PlayerLocalState(CPlayerInterface & owner) : owner(owner) + , currentSelection(nullptr) { } @@ -103,3 +98,32 @@ void PlayerLocalState::verifyPath(const CGHeroInstance * h) return; setPath(h, getPath(h).endPos()); } + +const CGHeroInstance * PlayerLocalState::getCurrentHero() const +{ + if(currentSelection && currentSelection->ID == Obj::HERO) + return dynamic_cast(currentSelection); + else + return nullptr; +} + +const CGTownInstance * PlayerLocalState::getCurrentTown() const +{ + if(currentSelection && currentSelection->ID == Obj::TOWN) + return dynamic_cast(currentSelection); + else + return nullptr; +} + +const CArmedInstance * PlayerLocalState::getCurrentArmy() const +{ + if (currentSelection) + return dynamic_cast(currentSelection); + else + return nullptr; +} + +void PlayerLocalState::setSelection(const CArmedInstance *selection) +{ + currentSelection = selection; +} diff --git a/client/PlayerLocalState.h b/client/PlayerLocalState.h index 3da5330cd..b6511fcc6 100644 --- a/client/PlayerLocalState.h +++ b/client/PlayerLocalState.h @@ -13,6 +13,7 @@ VCMI_LIB_NAMESPACE_BEGIN class CGHeroInstance; class CGTownInstance; +class CArmedInstance; struct CGPath; class int3; @@ -25,6 +26,9 @@ class PlayerLocalState { CPlayerInterface & owner; + /// Currently selected object, can be town, hero or null + const CArmedInstance * currentSelection; + std::map paths; //maps hero => selected path in adventure map void saveHeroPaths(std::map & paths); @@ -51,7 +55,6 @@ public: std::vector ownedTowns; //our towns on the adventure map std::vector sleepingHeroes; //if hero is in here, he's sleeping - PlayerLocalState(); explicit PlayerLocalState(CPlayerInterface & owner); void setPath(const CGHeroInstance *h, const CGPath & path); @@ -64,6 +67,14 @@ public: void erasePath(const CGHeroInstance *h); void verifyPath(const CGHeroInstance *h); + /// Returns currently selected object + const CGHeroInstance * getCurrentHero() const; + const CGTownInstance * getCurrentTown() const; + const CArmedInstance * getCurrentArmy() const; + + /// Changes currently selected object + void setSelection(const CArmedInstance *selection); + template void serialize( Handler &h, int version ) { diff --git a/client/adventureMap/CAdventureMapInterface.cpp b/client/adventureMap/CAdventureMapInterface.cpp index 9181a9aaf..1a4b0e0ef 100644 --- a/client/adventureMap/CAdventureMapInterface.cpp +++ b/client/adventureMap/CAdventureMapInterface.cpp @@ -229,7 +229,7 @@ void CAdventureMapInterface::fworldViewBack() { exitWorldView(); - auto hero = getCurrentHero(); + auto hero = LOCPLINT->localState->getCurrentHero(); if (hero) centerOnObject(hero); } @@ -288,7 +288,7 @@ void CAdventureMapInterface::fshowQuestlog() void CAdventureMapInterface::fsleepWake() { - const CGHeroInstance *h = getCurrentHero(); + const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); if (!h) return; bool newSleep = !isHeroSleeping(h); @@ -309,7 +309,7 @@ void CAdventureMapInterface::fsleepWake() void CAdventureMapInterface::fmoveHero() { - const CGHeroInstance *h = getCurrentHero(); + const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); if (!h || !LOCPLINT->localState->hasPath(h) || CGI->mh->hasOngoingAnimations()) return; @@ -318,12 +318,12 @@ void CAdventureMapInterface::fmoveHero() void CAdventureMapInterface::fshowSpellbok() { - if (!getCurrentHero()) //checking necessary values + if (!LOCPLINT->localState->getCurrentHero()) //checking necessary values return; centerOnObject(currentSelection); - GH.pushIntT(getCurrentHero(), LOCPLINT, false); + GH.pushIntT(LOCPLINT->localState->getCurrentHero(), LOCPLINT, false); } void CAdventureMapInterface::fadventureOPtions() @@ -342,7 +342,7 @@ void CAdventureMapInterface::fnextHero() int next = getNextHeroIndex(vstd::find_pos(LOCPLINT->localState->wanderingHeroes, hero)); if (next < 0) return; - setSelection(LOCPLINT->localState->wanderingHeroes[next], true); + LOCPLINT->setSelection(LOCPLINT->localState->wanderingHeroes[next], true); } void CAdventureMapInterface::fendTurn() @@ -420,7 +420,7 @@ void CAdventureMapInterface::onHeroChanged(const CGHeroInstance *h) { heroList->update(h); - if (h == getCurrentHero()) + if (h == LOCPLINT->localState->getCurrentHero()) infoBar->showSelection(); int start = vstd::find_pos(LOCPLINT->localState->wanderingHeroes, h); @@ -657,7 +657,7 @@ void CAdventureMapInterface::selectionChanged() { const CGTownInstance *to = LOCPLINT->localState->ownedTowns[townList->getSelectedIndex()]; if (currentSelection != to) - setSelection(to); + LOCPLINT->setSelection(to); } void CAdventureMapInterface::centerOnTile(int3 on) @@ -675,8 +675,8 @@ void CAdventureMapInterface::keyPressed(const SDL_Keycode & key) if (state != EGameState::MAKING_TURN) return; - const CGHeroInstance *h = getCurrentHero(); //selected hero - const CGTownInstance *t = getCurrentTown(); //selected town + const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero(); //selected hero + const CGTownInstance *t = LOCPLINT->localState->getCurrentTown(); //selected town switch(key) { @@ -856,7 +856,7 @@ std::optional CAdventureMapInterface::keyToMoveDirection(const SDL_Keycod return std::nullopt; } -void CAdventureMapInterface::setSelection(const CArmedInstance *sel, bool centerView) +void CAdventureMapInterface::onSelectionChanged(const CArmedInstance *sel, bool centerView) { assert(sel); if(currentSelection != sel) @@ -993,12 +993,12 @@ void CAdventureMapInterface::onPlayerTurnStarted(PlayerColor playerID) //select first hero if available. if (heroToSelect != nullptr) { - setSelection(heroToSelect, centerView); + LOCPLINT->setSelection(heroToSelect, centerView); } else if (LOCPLINT->localState->ownedTowns.size()) - setSelection(LOCPLINT->localState->ownedTowns.front(), centerView); + LOCPLINT->setSelection(LOCPLINT->localState->ownedTowns.front(), centerView); else - setSelection(LOCPLINT->localState->wanderingHeroes.front()); + LOCPLINT->setSelection(LOCPLINT->localState->wanderingHeroes.front()); //show new day animation and sound on infobar infoBar->showDate(); @@ -1084,9 +1084,9 @@ void CAdventureMapInterface::onTileLeftClicked(const int3 &mapPos) if(currentSelection == topBlocking) //selected town clicked LOCPLINT->openTownWindow(static_cast(topBlocking)); else if(canSelect) - setSelection(static_cast(topBlocking), false); + LOCPLINT->setSelection(static_cast(topBlocking), false); } - else if(const CGHeroInstance * currentHero = getCurrentHero()) //hero is selected + else if(const CGHeroInstance * currentHero = LOCPLINT->localState->getCurrentHero()) //hero is selected { isHero = true; @@ -1098,7 +1098,7 @@ void CAdventureMapInterface::onTileLeftClicked(const int3 &mapPos) } else if(canSelect && pn->turns == 255 ) //selectable object at inaccessible tile { - setSelection(static_cast(topBlocking), false); + LOCPLINT->setSelection(static_cast(topBlocking), false); return; } else //still here? we need to move hero if we clicked end of already selected path or calculate a new path otherwise @@ -1148,7 +1148,7 @@ void CAdventureMapInterface::onTileHovered(const int3 &mapPos) if(objAtTile) { objRelations = LOCPLINT->cb->getPlayerRelations(LOCPLINT->playerID, objAtTile->tempOwner); - std::string text = getCurrentHero() ? objAtTile->getHoverText(getCurrentHero()) : objAtTile->getHoverText(LOCPLINT->playerID); + std::string text = LOCPLINT->localState->getCurrentHero() ? objAtTile->getHoverText(LOCPLINT->localState->getCurrentHero()) : objAtTile->getHoverText(LOCPLINT->playerID); boost::replace_all(text,"\n"," "); statusbar->write(text); } @@ -1195,7 +1195,7 @@ void CAdventureMapInterface::onTileHovered(const int3 &mapPos) else CCS->curh->set(Cursor::Map::POINTER); } - else if(const CGHeroInstance * hero = getCurrentHero()) + else if(const CGHeroInstance * hero = LOCPLINT->localState->getCurrentHero()) { std::array cursorMove = { Cursor::Map::T1_MOVE, Cursor::Map::T2_MOVE, Cursor::Map::T3_MOVE, Cursor::Map::T4_MOVE, }; std::array cursorAttack = { Cursor::Map::T1_ATTACK, Cursor::Map::T2_ATTACK, Cursor::Map::T3_ATTACK, Cursor::Map::T4_ATTACK, }; @@ -1348,35 +1348,11 @@ void CAdventureMapInterface::leaveCastingMode(const int3 & dest) abortCastingMode(); // if(cast) - LOCPLINT->cb->castSpell(getCurrentHero(), id, dest); + LOCPLINT->cb->castSpell(LOCPLINT->localState->getCurrentHero(), id, dest); // else // LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[731]); //Spell cancelled } -const CGHeroInstance * CAdventureMapInterface::getCurrentHero() const -{ - if(currentSelection && currentSelection->ID == Obj::HERO) - return dynamic_cast(currentSelection); - else - return nullptr; -} - -const CGTownInstance * CAdventureMapInterface::getCurrentTown() const -{ - if(currentSelection && currentSelection->ID == Obj::TOWN) - return dynamic_cast(currentSelection); - else - return nullptr; -} - -const CArmedInstance * CAdventureMapInterface::getCurrentArmy() const -{ - if (currentSelection) - return dynamic_cast(currentSelection); - else - return nullptr; -} - Rect CAdventureMapInterface::terrainAreaPixels() const { return terrain->pos; diff --git a/client/adventureMap/CAdventureMapInterface.h b/client/adventureMap/CAdventureMapInterface.h index e3c3ad396..93ffe8c4c 100644 --- a/client/adventureMap/CAdventureMapInterface.h +++ b/client/adventureMap/CAdventureMapInterface.h @@ -182,6 +182,9 @@ public: /// Called by PlayerInterface when town state changed and town list must be updated void onTownChanged(const CGTownInstance * town); + /// Changes currently selected object + void onSelectionChanged(const CArmedInstance *sel, bool centerView = true); + /// Called when map audio should be paused, e.g. on combat or town screen access void onAudioPaused(); @@ -191,9 +194,6 @@ public: /// Requests to display provided information inside infobox void showInfoBoxMessage(const std::vector & components, std::string message, int timer); - /// Changes currently selected object - void setSelection(const CArmedInstance *sel, bool centerView = true); - /// Changes position on map to center selected location void centerOnTile(int3 on); void centerOnObject(const CGObjectInstance *obj); @@ -215,10 +215,6 @@ public: void leaveCastingMode(const int3 & castTarget); void abortCastingMode(); - const CGHeroInstance * getCurrentHero() const; - const CGTownInstance * getCurrentTown() const; - const CArmedInstance * getCurrentArmy() const; - /// returns area of screen covered by terrain (main game area) Rect terrainAreaPixels() const; diff --git a/client/adventureMap/CAdventureOptions.cpp b/client/adventureMap/CAdventureOptions.cpp index 843b0be84..238ecf487 100644 --- a/client/adventureMap/CAdventureOptions.cpp +++ b/client/adventureMap/CAdventureOptions.cpp @@ -15,6 +15,7 @@ #include "../CGameInfo.h" #include "../CPlayerInterface.h" +#include "../PlayerLocalState.h" #include "../lobby/CCampaignInfoScreen.h" #include "../lobby/CScenarioInfoScreen.h" #include "../gui/CGuiHandler.h" @@ -41,7 +42,7 @@ CAdventureOptions::CAdventureOptions() puzzle->addCallback(std::bind(&CPlayerInterface::showPuzzleMap, LOCPLINT)); dig = std::make_shared(Point(24, 139), "ADVDIG.DEF", CButton::tooltip(), [&](){ close(); }, SDLK_d); - if(const CGHeroInstance *h = adventureInt->getCurrentHero()) + if(const CGHeroInstance *h = LOCPLINT->localState->getCurrentHero()) dig->addCallback(std::bind(&CPlayerInterface::tryDiggging, LOCPLINT, h)); else dig->block(true); diff --git a/client/adventureMap/CInGameConsole.cpp b/client/adventureMap/CInGameConsole.cpp index cc711adf1..27ac0b257 100644 --- a/client/adventureMap/CInGameConsole.cpp +++ b/client/adventureMap/CInGameConsole.cpp @@ -14,6 +14,7 @@ #include "../CGameInfo.h" #include "../CMusicHandler.h" #include "../CPlayerInterface.h" +#include "../PlayerLocalState.h" #include "../ClientCommandManager.h" #include "../adventureMap/CAdventureMapInterface.h" #include "../gui/CGuiHandler.h" @@ -259,7 +260,7 @@ void CInGameConsole::endEnteringText(bool processEnteredText) clientCommandThread.detach(); } else - LOCPLINT->cb->sendMessage(txt, adventureInt->getCurrentArmy()); + LOCPLINT->cb->sendMessage(txt, LOCPLINT->localState->getCurrentArmy()); } enteredText.clear(); diff --git a/client/adventureMap/CInfoBar.cpp b/client/adventureMap/CInfoBar.cpp index 83c8befe5..14759f99c 100644 --- a/client/adventureMap/CInfoBar.cpp +++ b/client/adventureMap/CInfoBar.cpp @@ -238,15 +238,15 @@ void CInfoBar::reset() void CInfoBar::showSelection() { OBJECT_CONSTRUCTION_CUSTOM_CAPTURING(255-DISPOSE); - if(adventureInt->getCurrentHero()) + if(LOCPLINT->localState->getCurrentHero()) { - showHeroSelection(adventureInt->getCurrentHero()); + showHeroSelection(LOCPLINT->localState->getCurrentHero()); return; } - if(adventureInt->getCurrentTown()) + if(LOCPLINT->localState->getCurrentTown()) { - showTownSelection(adventureInt->getCurrentTown()); + showTownSelection(LOCPLINT->localState->getCurrentTown()); return; } diff --git a/client/adventureMap/CList.cpp b/client/adventureMap/CList.cpp index 18d8d341d..f9957df8b 100644 --- a/client/adventureMap/CList.cpp +++ b/client/adventureMap/CList.cpp @@ -204,8 +204,8 @@ std::shared_ptr CHeroList::CHeroItem::genSelection() void CHeroList::CHeroItem::select(bool on) { - if(on && adventureInt->getCurrentHero() != hero) - adventureInt->setSelection(hero); + if(on && LOCPLINT->localState->getCurrentHero() != hero) + LOCPLINT->setSelection(hero); } void CHeroList::CHeroItem::open() @@ -255,8 +255,8 @@ void CHeroList::update(const CGHeroInstance * hero) //simplest solution for now: reset list and restore selection listBox->resize(LOCPLINT->localState->wanderingHeroes.size()); - if (adventureInt->getCurrentHero()) - select(adventureInt->getCurrentHero()); + if (LOCPLINT->localState->getCurrentHero()) + select(LOCPLINT->localState->getCurrentHero()); CList::update(); } @@ -293,8 +293,8 @@ void CTownList::CTownItem::update() void CTownList::CTownItem::select(bool on) { - if (on && adventureInt->getCurrentTown() != town) - adventureInt->setSelection(town); + if (on && LOCPLINT->localState->getCurrentTown() != town) + LOCPLINT->localState->setSelection(town); } void CTownList::CTownItem::open() @@ -327,8 +327,8 @@ void CTownList::update(const CGTownInstance *) //simplest solution for now: reset list and restore selection listBox->resize(LOCPLINT->localState->ownedTowns.size()); - if (adventureInt->getCurrentTown()) - select(adventureInt->getCurrentTown()); + if (LOCPLINT->localState->getCurrentTown()) + select(LOCPLINT->localState->getCurrentTown()); CList::update(); } diff --git a/client/mapView/MapRendererContext.cpp b/client/mapView/MapRendererContext.cpp index 7c79a1dfd..442cdbc67 100644 --- a/client/mapView/MapRendererContext.cpp +++ b/client/mapView/MapRendererContext.cpp @@ -74,9 +74,9 @@ bool MapRendererBaseContext::isActiveHero(const CGObjectInstance * obj) const if(obj->ID == Obj::HERO) { assert(dynamic_cast(obj) != nullptr); - if(adventureInt->getCurrentHero() != nullptr) + if(LOCPLINT->localState->getCurrentHero() != nullptr) { - if(obj->id == adventureInt->getCurrentHero()->id) + if(obj->id == LOCPLINT->localState->getCurrentHero()->id) return true; } } @@ -207,7 +207,7 @@ MapRendererAdventureContext::MapRendererAdventureContext(const MapRendererContex const CGPath * MapRendererAdventureContext::currentPath() const { - const auto * hero = adventureInt->getCurrentHero(); + const auto * hero = LOCPLINT->localState->getCurrentHero(); if(!hero) return nullptr; diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 5f573a74a..1d4d6080a 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -496,7 +496,7 @@ void HeroSlots::splitClicked() { if(!!town->visitingHero && town->garrisonHero && (visitingHero->isSelected() || garrisonedHero->isSelected())) { - LOCPLINT->heroExchangeStarted(town->visitingHero->id, town->garrisonHero->id, QueryID(-1)); + LOCPLINT->showHeroExchange(town->visitingHero->id, town->garrisonHero->id); } } @@ -1230,9 +1230,9 @@ void CCastleInterface::close() if(town->tempOwner == LOCPLINT->playerID) //we may have opened window for an allied town { if(town->visitingHero && town->visitingHero->tempOwner == LOCPLINT->playerID) - adventureInt->setSelection(town->visitingHero); + LOCPLINT->setSelection(town->visitingHero); else - adventureInt->setSelection(town); + LOCPLINT->setSelection(town); } CWindowObject::close(); } @@ -1240,7 +1240,7 @@ void CCastleInterface::close() void CCastleInterface::castleTeleport(int where) { const CGTownInstance * dest = LOCPLINT->cb->getTown(ObjectInstanceID(where)); - adventureInt->setSelection(town->visitingHero);//according to assert(ho == adventureInt->selection) in the eraseCurrentPathOf + LOCPLINT->localState->setSelection(town->visitingHero);//according to assert(ho == adventureInt->selection) in the eraseCurrentPathOf LOCPLINT->cb->teleportHero(town->visitingHero, dest); LOCPLINT->localState->erasePath(town->visitingHero); } diff --git a/client/windows/InfoWindows.cpp b/client/windows/InfoWindows.cpp index f6fd72a7f..a1955a681 100644 --- a/client/windows/InfoWindows.cpp +++ b/client/windows/InfoWindows.cpp @@ -11,6 +11,7 @@ #include "InfoWindows.h" #include "../CGameInfo.h" +#include "../PlayerLocalState.h" #include "../CPlayerInterface.h" #include "../CMusicHandler.h" @@ -332,8 +333,8 @@ void CRClickPopup::createAndPush(const CGObjectInstance * obj, const Point & p, } else { - if(adventureInt->getCurrentHero()) - CRClickPopup::createAndPush(obj->getHoverText(adventureInt->getCurrentHero())); + if(LOCPLINT->localState->getCurrentHero()) + CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->localState->getCurrentHero())); else CRClickPopup::createAndPush(obj->getHoverText(LOCPLINT->playerID)); } @@ -376,7 +377,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGTownInstance * town) : CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position)) { InfoAboutTown iah; - LOCPLINT->cb->getTownInfo(town, iah, adventureInt->getCurrentTown()); //todo: should this be nearest hero? + LOCPLINT->cb->getTownInfo(town, iah, LOCPLINT->localState->getCurrentTown()); //todo: should this be nearest hero? OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); tooltip = std::make_shared(Point(9, 10), iah); @@ -386,7 +387,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero) : CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "HEROQVBK", toScreen(position)) { InfoAboutHero iah; - LOCPLINT->cb->getHeroInfo(hero, iah, adventureInt->getCurrentHero());//todo: should this be nearest hero? + LOCPLINT->cb->getHeroInfo(hero, iah, LOCPLINT->localState->getCurrentHero());//todo: should this be nearest hero? OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); tooltip = std::make_shared(Point(9, 10), iah); @@ -405,7 +406,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr) std::shared_ptr CRClickPopup::createInfoWin(Point position, const CGObjectInstance * specific) //specific=0 => draws info about selected town/hero { if(nullptr == specific) - specific = adventureInt->getCurrentArmy(); + specific = LOCPLINT->localState->getCurrentArmy(); if(nullptr == specific) {