diff --git a/client/LobbyClientNetPackVisitors.h b/client/LobbyClientNetPackVisitors.h index 0c4af1aa0..7e19e614b 100644 --- a/client/LobbyClientNetPackVisitors.h +++ b/client/LobbyClientNetPackVisitors.h @@ -10,8 +10,10 @@ #pragma once #include "../lib/networkPacks/NetPackVisitor.h" +#include "../lib/networkPacks/PacksForLobby.h" class CClient; +class CLobbyScreen; VCMI_LIB_NAMESPACE_BEGIN class CGameState; VCMI_LIB_NAMESPACE_END diff --git a/client/lobby/CLobbyScreen.cpp b/client/lobby/CLobbyScreen.cpp index d8c739370..fc0333f37 100644 --- a/client/lobby/CLobbyScreen.cpp +++ b/client/lobby/CLobbyScreen.cpp @@ -25,7 +25,7 @@ #include "../../CCallback.h" #include "../CGameInfo.h" -#include "../../lib/networkPacks/NetPacksLobby.h" +#include "../../lib/networkPacks/PacksForLobby.h" #include "../../lib/CGeneralTextHandler.h" #include "../../lib/campaign/CampaignHandler.h" #include "../../lib/mapping/CMapInfo.h" diff --git a/client/lobby/OptionsTab.cpp b/client/lobby/OptionsTab.cpp index de17abd5b..72e3817f3 100644 --- a/client/lobby/OptionsTab.cpp +++ b/client/lobby/OptionsTab.cpp @@ -34,7 +34,7 @@ #include "../eventsSDL/InputHandler.h" #include "../../lib/filesystem/Filesystem.h" -#include "../../lib/networkPacks/NetPacksLobby.h" +#include "../../lib/networkPacks/PacksForLobby.h" #include "../../lib/CGeneralTextHandler.h" #include "../../lib/CArtHandler.h" #include "../../lib/CTownHandler.h" diff --git a/client/widgets/CArtifactHolder.cpp b/client/widgets/CArtifactHolder.cpp index 40f186332..a3b72d320 100644 --- a/client/widgets/CArtifactHolder.cpp +++ b/client/widgets/CArtifactHolder.cpp @@ -26,7 +26,7 @@ #include "../../lib/CGeneralTextHandler.h" #include "../../lib/ArtifactUtils.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/CConfigHandler.h" void CArtPlace::setInternals(const CArtifactInstance * artInst) diff --git a/client/widgets/CArtifactsOfHeroAltar.cpp b/client/widgets/CArtifactsOfHeroAltar.cpp index 672b4df60..737b05f9c 100644 --- a/client/widgets/CArtifactsOfHeroAltar.cpp +++ b/client/widgets/CArtifactsOfHeroAltar.cpp @@ -16,7 +16,7 @@ #include "../../lib/ArtifactUtils.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" CArtifactsOfHeroAltar::CArtifactsOfHeroAltar(const Point & position) : visibleArtSet(ArtBearer::ArtBearer::HERO) diff --git a/client/widgets/CArtifactsOfHeroBackpack.cpp b/client/widgets/CArtifactsOfHeroBackpack.cpp index 4d2e426f6..f95d5cf65 100644 --- a/client/widgets/CArtifactsOfHeroBackpack.cpp +++ b/client/widgets/CArtifactsOfHeroBackpack.cpp @@ -18,7 +18,7 @@ #include "../CPlayerInterface.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../CCallback.h" diff --git a/client/widgets/CArtifactsOfHeroBase.cpp b/client/widgets/CArtifactsOfHeroBase.cpp index d66772eb7..769da2258 100644 --- a/client/widgets/CArtifactsOfHeroBase.cpp +++ b/client/widgets/CArtifactsOfHeroBase.cpp @@ -22,7 +22,7 @@ #include "../../lib/ArtifactUtils.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" CArtifactsOfHeroBase::CArtifactsOfHeroBase() : backpackPos(0), diff --git a/client/widgets/CArtifactsOfHeroKingdom.cpp b/client/widgets/CArtifactsOfHeroKingdom.cpp index c2043bd94..67e702b5f 100644 --- a/client/widgets/CArtifactsOfHeroKingdom.cpp +++ b/client/widgets/CArtifactsOfHeroKingdom.cpp @@ -15,7 +15,7 @@ #include "../CPlayerInterface.h" #include "../../CCallback.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" CArtifactsOfHeroKingdom::CArtifactsOfHeroKingdom(ArtPlaceMap ArtWorn, std::vector Backpack, std::shared_ptr leftScroll, std::shared_ptr rightScroll) diff --git a/client/widgets/CArtifactsOfHeroMain.cpp b/client/widgets/CArtifactsOfHeroMain.cpp index 2681f5a9c..46b5329ca 100644 --- a/client/widgets/CArtifactsOfHeroMain.cpp +++ b/client/widgets/CArtifactsOfHeroMain.cpp @@ -13,7 +13,7 @@ #include "../CPlayerInterface.h" #include "../../CCallback.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" CArtifactsOfHeroMain::CArtifactsOfHeroMain(const Point & position) { diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index 52ca984ec..3942da8a0 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -30,7 +30,7 @@ #include "../../lib/CCreatureHandler.h" #include "../../lib/CConfigHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/TextOperations.h" #include "../../lib/gameState/CGameState.h" diff --git a/client/widgets/CWindowWithArtifacts.cpp b/client/widgets/CWindowWithArtifacts.cpp index b3c2c2700..8c6d2b7c9 100644 --- a/client/widgets/CWindowWithArtifacts.cpp +++ b/client/widgets/CWindowWithArtifacts.cpp @@ -29,7 +29,7 @@ #include "../../lib/ArtifactUtils.h" #include "../../lib/CGeneralTextHandler.h" #include "../../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/CConfigHandler.h" void CWindowWithArtifacts::addSet(CArtifactsOfHeroPtr artSet) diff --git a/client/windows/CCreatureWindow.cpp b/client/windows/CCreatureWindow.cpp index 8c91103a5..bece268cf 100644 --- a/client/windows/CCreatureWindow.cpp +++ b/client/windows/CCreatureWindow.cpp @@ -33,7 +33,7 @@ #include "../../lib/GameSettings.h" #include "../../lib/CHeroHandler.h" #include "../../lib/gameState/CGameState.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" #include "../../lib/TextOperations.h" class CCreatureArtifactInstance; diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index 890504063..7d05fe38a 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -39,7 +39,7 @@ #include "../lib/CHeroHandler.h" #include "../lib/CSkillHandler.h" #include "../lib/mapObjects/CGHeroInstance.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" void CHeroSwitcher::clickPressed(const Point & cursorPosition) { diff --git a/client/windows/CTradeWindow.cpp b/client/windows/CTradeWindow.cpp index c87db89b7..8a1d3672a 100644 --- a/client/windows/CTradeWindow.cpp +++ b/client/windows/CTradeWindow.cpp @@ -35,7 +35,7 @@ #include "../../lib/mapObjects/CGHeroInstance.h" #include "../../lib/mapObjects/CGTownInstance.h" #include "../../lib/mapObjects/CGMarket.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" CTradeWindow::CTradeableItem::CTradeableItem(Point pos, EType Type, int ID, bool Left, int Serial) : CIntObject(LCLICK | HOVER | SHOW_POPUP, pos), diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index 998bf074b..1d7ac1aa2 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -476,16 +476,17 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) ${MAIN_LIB_DIR}/modding/ModScope.h ${MAIN_LIB_DIR}/modding/ModUtility.h + ${MAIN_LIB_DIR}/networkPacks/ArtifactLocation.h ${MAIN_LIB_DIR}/networkPacks/BattleChanges.h ${MAIN_LIB_DIR}/networkPacks/Component.h ${MAIN_LIB_DIR}/networkPacks/EInfoWindowMode.h ${MAIN_LIB_DIR}/networkPacks/EntityChanges.h ${MAIN_LIB_DIR}/networkPacks/EOpenWindowMode.h ${MAIN_LIB_DIR}/networkPacks/NetPacksBase.h - ${MAIN_LIB_DIR}/networkPacks/NetPacksLobby.h ${MAIN_LIB_DIR}/networkPacks/NetPackVisitor.h ${MAIN_LIB_DIR}/networkPacks/PacksForClient.h ${MAIN_LIB_DIR}/networkPacks/PacksForClientBattle.h + ${MAIN_LIB_DIR}/networkPacks/PacksForLobby.h ${MAIN_LIB_DIR}/networkPacks/PacksForServer.h ${MAIN_LIB_DIR}/networkPacks/StackLocation.h diff --git a/lib/CArtifactInstance.cpp b/lib/CArtifactInstance.cpp index 754831590..d80373251 100644 --- a/lib/CArtifactInstance.cpp +++ b/lib/CArtifactInstance.cpp @@ -13,7 +13,7 @@ #include "ArtifactUtils.h" #include "CArtHandler.h" -#include "networkPacks/NetPacksBase.h" +#include "networkPacks/ArtifactLocation.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 8152ed991..800dc4d55 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -37,7 +37,7 @@ #include "../mapObjects/ObjectTemplate.h" #include "../modding/ModScope.h" #include "../networkPacks/Component.h" -#include "../networkPacks/NetPacksBase.h" +#include "../networkPacks/ArtifactLocation.h" #include "../spells/CSpellHandler.h" #include diff --git a/lib/networkPacks/ArtifactLocation.h b/lib/networkPacks/ArtifactLocation.h new file mode 100644 index 000000000..777a1fdf5 --- /dev/null +++ b/lib/networkPacks/ArtifactLocation.h @@ -0,0 +1,76 @@ +/* + * ArtifactLocation.h, 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 + * + */ +#pragma once + +#include "../ConstTransitivePtr.h" +#include "../constants/EntityIdentifiers.h" + +VCMI_LIB_NAMESPACE_BEGIN + +class CGHeroInstance; +class CStackInstance; +class CArmedInstance; +class CArtifactSet; +class CBonusSystemNode; +struct ArtSlotInfo; + +using TArtHolder = std::variant, ConstTransitivePtr>; + +struct ArtifactLocation +{ + TArtHolder artHolder;//TODO: identify holder by id + ArtifactPosition slot = ArtifactPosition::PRE_FIRST; + + ArtifactLocation() + : artHolder(ConstTransitivePtr()) + { + } + template + ArtifactLocation(const T * ArtHolder, ArtifactPosition Slot) + : artHolder(const_cast(ArtHolder)) //we are allowed here to const cast -> change will go through one of our packages... do not abuse! + , slot(Slot) + { + } + ArtifactLocation(TArtHolder ArtHolder, const ArtifactPosition & Slot) + : artHolder(std::move(std::move(ArtHolder))) + , slot(Slot) + { + } + + template + bool isHolder(const T *t) const + { + if(auto ptrToT = std::get>(artHolder)) + { + return ptrToT == t; + } + return false; + } + + DLL_LINKAGE void removeArtifact(); // BE CAREFUL, this operation modifies holder (gs) + + DLL_LINKAGE const CArmedInstance *relatedObj() const; //hero or the stack owner + DLL_LINKAGE PlayerColor owningPlayer() const; + DLL_LINKAGE CArtifactSet *getHolderArtSet(); + DLL_LINKAGE CBonusSystemNode *getHolderNode(); + DLL_LINKAGE CArtifactSet *getHolderArtSet() const; + DLL_LINKAGE const CBonusSystemNode *getHolderNode() const; + + DLL_LINKAGE const CArtifactInstance *getArt() const; + DLL_LINKAGE CArtifactInstance *getArt(); + DLL_LINKAGE const ArtSlotInfo *getSlot() const; + template void serialize(Handler &h, const int version) + { + h & artHolder; + h & slot; + } +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/networkPacks/NetPackVisitor.h b/lib/networkPacks/NetPackVisitor.h index 73b090b4a..08f7c13e0 100644 --- a/lib/networkPacks/NetPackVisitor.h +++ b/lib/networkPacks/NetPackVisitor.h @@ -12,7 +12,7 @@ #include "PacksForClient.h" #include "PacksForClientBattle.h" #include "PacksForServer.h" -#include "NetPacksLobby.h" +#include "PacksForLobby.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/networkPacks/NetPacksBase.h b/lib/networkPacks/NetPacksBase.h index 295594c46..dc22af57e 100644 --- a/lib/networkPacks/NetPacksBase.h +++ b/lib/networkPacks/NetPacksBase.h @@ -9,26 +9,12 @@ */ #pragma once -#include "../ConstTransitivePtr.h" -#include "../GameConstants.h" - -class CClient; -class CGameHandler; -class CLobbyScreen; -class CServerHandler; -class CVCMIServer; +#include "../constants/EntityIdentifiers.h" VCMI_LIB_NAMESPACE_BEGIN class CGameState; class CConnection; -class CStackBasicDescriptor; -class CGHeroInstance; -class CStackInstance; -class CArmedInstance; -class CArtifactSet; -class CBonusSystemNode; -struct ArtSlotInfo; class ICPackVisitor; @@ -65,7 +51,7 @@ protected: struct DLL_LINKAGE CPackForClient : public CPack { protected: - virtual void visitBasic(ICPackVisitor & cpackVisitor) override; + void visitBasic(ICPackVisitor & cpackVisitor) override; }; struct DLL_LINKAGE Query : public CPackForClient @@ -85,7 +71,7 @@ struct DLL_LINKAGE CPackForServer : public CPack } protected: - virtual void visitBasic(ICPackVisitor & cpackVisitor) override; + void visitBasic(ICPackVisitor & cpackVisitor) override; }; struct DLL_LINKAGE CPackForLobby : public CPack @@ -93,59 +79,7 @@ struct DLL_LINKAGE CPackForLobby : public CPack virtual bool isForServer() const; protected: - virtual void visitBasic(ICPackVisitor & cpackVisitor) override; -}; - -using TArtHolder = std::variant, ConstTransitivePtr>; - -struct ArtifactLocation -{ - TArtHolder artHolder;//TODO: identify holder by id - ArtifactPosition slot = ArtifactPosition::PRE_FIRST; - - ArtifactLocation() - : artHolder(ConstTransitivePtr()) - { - } - template - ArtifactLocation(const T * ArtHolder, ArtifactPosition Slot) - : artHolder(const_cast(ArtHolder)) //we are allowed here to const cast -> change will go through one of our packages... do not abuse! - , slot(Slot) - { - } - ArtifactLocation(TArtHolder ArtHolder, const ArtifactPosition & Slot) - : artHolder(std::move(std::move(ArtHolder))) - , slot(Slot) - { - } - - template - bool isHolder(const T *t) const - { - if(auto ptrToT = std::get>(artHolder)) - { - return ptrToT == t; - } - return false; - } - - DLL_LINKAGE void removeArtifact(); // BE CAREFUL, this operation modifies holder (gs) - - DLL_LINKAGE const CArmedInstance *relatedObj() const; //hero or the stack owner - DLL_LINKAGE PlayerColor owningPlayer() const; - DLL_LINKAGE CArtifactSet *getHolderArtSet(); - DLL_LINKAGE CBonusSystemNode *getHolderNode(); - DLL_LINKAGE CArtifactSet *getHolderArtSet() const; - DLL_LINKAGE const CBonusSystemNode *getHolderNode() const; - - DLL_LINKAGE const CArtifactInstance *getArt() const; - DLL_LINKAGE CArtifactInstance *getArt(); - DLL_LINKAGE const ArtSlotInfo *getSlot() const; - template void serialize(Handler &h, const int version) - { - h & artHolder; - h & slot; - } + void visitBasic(ICPackVisitor & cpackVisitor) override; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index 508379a18..251c39180 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -13,7 +13,7 @@ #include "PacksForClientBattle.h" #include "PacksForServer.h" #include "StackLocation.h" -#include "NetPacksLobby.h" +#include "PacksForLobby.h" #include "NetPackVisitor.h" #include "CGeneralTextHandler.h" #include "CArtHandler.h" diff --git a/lib/networkPacks/PacksForClient.h b/lib/networkPacks/PacksForClient.h index b37551cd7..31bc4752e 100644 --- a/lib/networkPacks/PacksForClient.h +++ b/lib/networkPacks/PacksForClient.h @@ -1,5 +1,5 @@ /* - * NetPacks.h, part of VCMI engine + * PacksForClient.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -9,11 +9,12 @@ */ #pragma once -#include "NetPacksBase.h" +#include "ArtifactLocation.h" #include "Component.h" -#include "EOpenWindowMode.h" #include "EInfoWindowMode.h" +#include "EOpenWindowMode.h" #include "EntityChanges.h" +#include "NetPacksBase.h" #include "../CCreatureSet.h" #include "../MetaString.h" diff --git a/lib/networkPacks/PacksForClientBattle.h b/lib/networkPacks/PacksForClientBattle.h index 4e87f8a39..d52ea6483 100644 --- a/lib/networkPacks/PacksForClientBattle.h +++ b/lib/networkPacks/PacksForClientBattle.h @@ -1,5 +1,5 @@ /* - * NetPacks.h, part of VCMI engine + * PacksForClientBattle.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -14,8 +14,12 @@ #include "../MetaString.h" #include "../battle/BattleAction.h" +class CClient; + VCMI_LIB_NAMESPACE_BEGIN +class CGHeroInstance; +class CArmedInstance; class IBattleState; class BattleInfo; diff --git a/lib/networkPacks/NetPacksLobby.h b/lib/networkPacks/PacksForLobby.h similarity index 99% rename from lib/networkPacks/NetPacksLobby.h rename to lib/networkPacks/PacksForLobby.h index 4e819d98f..ef55fe054 100644 --- a/lib/networkPacks/NetPacksLobby.h +++ b/lib/networkPacks/PacksForLobby.h @@ -1,5 +1,5 @@ /* - * NetPacksLobby.h, part of VCMI engine + * PacksForLobby.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * diff --git a/lib/networkPacks/PacksForServer.h b/lib/networkPacks/PacksForServer.h index d71681450..9911d1ba8 100644 --- a/lib/networkPacks/PacksForServer.h +++ b/lib/networkPacks/PacksForServer.h @@ -1,5 +1,5 @@ /* - * NetPacks.h, part of VCMI engine + * PacksForServer.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -9,7 +9,9 @@ */ #pragma once +#include "ArtifactLocation.h" #include "NetPacksBase.h" + #include "../int3.h" #include "../battle/BattleAction.h" diff --git a/lib/registerTypes/RegisterTypes.h b/lib/registerTypes/RegisterTypes.h index 4f375148f..7f5c086dc 100644 --- a/lib/registerTypes/RegisterTypes.h +++ b/lib/registerTypes/RegisterTypes.h @@ -12,7 +12,7 @@ #include "../networkPacks/PacksForClient.h" #include "../networkPacks/PacksForClientBattle.h" #include "../networkPacks/PacksForServer.h" -#include "../networkPacks/NetPacksLobby.h" +#include "../networkPacks/PacksForLobby.h" #include "../VCMI_Lib.h" #include "../CArtHandler.h" #include "../CCreatureSet.h" diff --git a/server/battles/BattleResultProcessor.h b/server/battles/BattleResultProcessor.h index 88d4bb11a..7616c1775 100644 --- a/server/battles/BattleResultProcessor.h +++ b/server/battles/BattleResultProcessor.h @@ -11,7 +11,7 @@ #include "../../lib/GameConstants.h" #include "../../lib/networkPacks/StackLocation.h" -#include "../../lib/networkPacks/NetPacksBase.h" +#include "../../lib/networkPacks/ArtifactLocation.h" VCMI_LIB_NAMESPACE_BEGIN struct SideInBattle;