1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Moved ArtifactLocation to a separate file

This commit is contained in:
Ivan Savenko 2023-10-23 16:38:05 +03:00
parent ae92bdfb51
commit 5523f05284
27 changed files with 116 additions and 96 deletions

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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)

View File

@ -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)

View File

@ -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"

View File

@ -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),

View File

@ -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<ArtPlacePtr> Backpack,
std::shared_ptr<CButton> leftScroll, std::shared_ptr<CButton> rightScroll)

View File

@ -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)
{

View File

@ -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"

View File

@ -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)

View File

@ -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;

View File

@ -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)
{

View File

@ -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),

View File

@ -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

View File

@ -13,7 +13,7 @@
#include "ArtifactUtils.h"
#include "CArtHandler.h"
#include "networkPacks/NetPacksBase.h"
#include "networkPacks/ArtifactLocation.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -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 <boost/crc.hpp>

View File

@ -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<CGHeroInstance>, ConstTransitivePtr<CStackInstance>>;
struct ArtifactLocation
{
TArtHolder artHolder;//TODO: identify holder by id
ArtifactPosition slot = ArtifactPosition::PRE_FIRST;
ArtifactLocation()
: artHolder(ConstTransitivePtr<CGHeroInstance>())
{
}
template<typename T>
ArtifactLocation(const T * ArtHolder, ArtifactPosition Slot)
: artHolder(const_cast<T *>(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 <typename T>
bool isHolder(const T *t) const
{
if(auto ptrToT = std::get<ConstTransitivePtr<T>>(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 <typename Handler> void serialize(Handler &h, const int version)
{
h & artHolder;
h & slot;
}
};
VCMI_LIB_NAMESPACE_END

View File

@ -12,7 +12,7 @@
#include "PacksForClient.h"
#include "PacksForClientBattle.h"
#include "PacksForServer.h"
#include "NetPacksLobby.h"
#include "PacksForLobby.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@ -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<CGHeroInstance>, ConstTransitivePtr<CStackInstance>>;
struct ArtifactLocation
{
TArtHolder artHolder;//TODO: identify holder by id
ArtifactPosition slot = ArtifactPosition::PRE_FIRST;
ArtifactLocation()
: artHolder(ConstTransitivePtr<CGHeroInstance>())
{
}
template<typename T>
ArtifactLocation(const T * ArtHolder, ArtifactPosition Slot)
: artHolder(const_cast<T *>(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 <typename T>
bool isHolder(const T *t) const
{
if(auto ptrToT = std::get<ConstTransitivePtr<T>>(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 <typename Handler> void serialize(Handler &h, const int version)
{
h & artHolder;
h & slot;
}
void visitBasic(ICPackVisitor & cpackVisitor) override;
};
VCMI_LIB_NAMESPACE_END

View File

@ -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"

View File

@ -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"

View File

@ -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;

View File

@ -1,5 +1,5 @@
/*
* NetPacksLobby.h, part of VCMI engine
* PacksForLobby.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*

View File

@ -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"

View File

@ -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"

View File

@ -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;