Explorar o código

Moved current selection to local state class

Ivan Savenko %!s(int64=2) %!d(string=hai) anos
pai
achega
6a46138617

+ 14 - 2
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<ObjectPosInfo>& 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);
+}

+ 28 - 23
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<CBattleGameInterface> 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<Environment> ENV, std::shared_ptr<CCallback> 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<Component> & 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<Component> &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<ObjectInstanceID> & 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<int3> &pos) override; //called when given tiles become hidden under fog of war
 	void tileRevealed(const std::unordered_set<int3> &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<bool()> onYes);
-	void garrisonsChanged(std::vector<const CGObjectInstance *> 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<Environment> ENV, std::shared_ptr<CCallback> CB) override;
 
-	// show dialogs
 	void showInfoDialog(const std::string &text, std::shared_ptr<CComponent> component);
 	void showInfoDialog(const std::string &text, const std::vector<std::shared_ptr<CComponent>> & components = std::vector<std::shared_ptr<CComponent>>(), int soundID = 0);
 	void showInfoDialogAndWait(std::vector<Component> & 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<const CGObjectInstance *> 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;

+ 4 - 3
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");

+ 31 - 7
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<const CGHeroInstance *>(currentSelection);
+	else
+		return nullptr;
+}
+
+const CGTownInstance * PlayerLocalState::getCurrentTown() const
+{
+	if(currentSelection && currentSelection->ID == Obj::TOWN)
+		return dynamic_cast<const CGTownInstance *>(currentSelection);
+	else
+		return nullptr;
+}
+
+const CArmedInstance * PlayerLocalState::getCurrentArmy() const
+{
+	if (currentSelection)
+		return dynamic_cast<const CArmedInstance *>(currentSelection);
+	else
+		return nullptr;
+}
+
+void PlayerLocalState::setSelection(const CArmedInstance *selection)
+{
+	currentSelection = selection;
+}

+ 12 - 1
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<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
 
 	void saveHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
@@ -51,7 +55,6 @@ public:
 	std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
 	std::vector<const CGHeroInstance *> 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 <typename Handler>
 	void serialize( Handler &h, int version )
 	{

+ 20 - 44
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<CSpellWindow>(getCurrentHero(), LOCPLINT, false);
+	GH.pushIntT<CSpellWindow>(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<Point> 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<const CGTownInstance*>(topBlocking));
 		else if(canSelect)
-			setSelection(static_cast<const CArmedInstance*>(topBlocking), false);
+			LOCPLINT->setSelection(static_cast<const CArmedInstance*>(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<const CArmedInstance*>(topBlocking), false);
+			LOCPLINT->setSelection(static_cast<const CArmedInstance*>(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<Cursor::Map, 4> cursorMove      = { Cursor::Map::T1_MOVE,       Cursor::Map::T2_MOVE,       Cursor::Map::T3_MOVE,       Cursor::Map::T4_MOVE,       };
 		std::array<Cursor::Map, 4> 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<const CGHeroInstance *>(currentSelection);
-	else
-		return nullptr;
-}
-
-const CGTownInstance * CAdventureMapInterface::getCurrentTown() const
-{
-	if(currentSelection && currentSelection->ID == Obj::TOWN)
-		return dynamic_cast<const CGTownInstance *>(currentSelection);
-	else
-		return nullptr;
-}
-
-const CArmedInstance * CAdventureMapInterface::getCurrentArmy() const
-{
-	if (currentSelection)
-		return dynamic_cast<const CArmedInstance *>(currentSelection);
-	else
-		return nullptr;
-}
-
 Rect CAdventureMapInterface::terrainAreaPixels() const
 {
 	return terrain->pos;

+ 3 - 7
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<Component> & 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;
 

+ 2 - 1
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<CButton>(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);

+ 2 - 1
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();
 

+ 4 - 4
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;
 	}
 

+ 8 - 8
client/adventureMap/CList.cpp

@@ -204,8 +204,8 @@ std::shared_ptr<CIntObject> 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();
 }

+ 3 - 3
client/mapView/MapRendererContext.cpp

@@ -74,9 +74,9 @@ bool MapRendererBaseContext::isActiveHero(const CGObjectInstance * obj) const
 	if(obj->ID == Obj::HERO)
 	{
 		assert(dynamic_cast<const CGHeroInstance *>(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;

+ 4 - 4
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);
 }

+ 6 - 5
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<CTownTooltip>(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<CHeroTooltip>(Point(9, 10), iah);
@@ -405,7 +406,7 @@ CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr)
 std::shared_ptr<WindowBase> 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)
 	{