1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Mod Handler class. It is connected with engine, but doesn't do anything yet.

This commit is contained in:
DjWarmonger
2012-08-10 13:07:53 +00:00
parent d72c44e4c3
commit 289b7b68d9
14 changed files with 183 additions and 9 deletions

View File

@@ -80,7 +80,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)\AI\</OutDir>
<OutDir>..\..\..\AI</OutDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
@@ -90,7 +90,7 @@
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='RD|Win32'">
<OutDir>$(SolutionDir)$(Configuration)\bin\AI\</OutDir>
<OutDir>..\..\..\RD\AI</OutDir>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
@@ -111,7 +111,7 @@
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)..;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>../..;../../../libs;../../..;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)EmptyAI.dll</OutputFile>
</Link>
</ItemDefinitionGroup>
@@ -147,7 +147,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)..;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>G:\Programowanie\VCMI\RD;../../../libs;../../;E:\vcmi\rep - assembla\trunk;E:\C++\lua bin;E:\C++\boost_1_43_0\lib;E:\C++\SDL_mixer-1.2.7\lib;E:\C++\SDL_ttf-2.0.8\lib;E:\C++\zlib 1.2.3 binaries\lib;E:\C++\SDL-1.2.11\devlibs - visual\SDL-1.2.11\lib;F:\C++\SDL_Image 1.2.5\SDL_image-1.2.5\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<OutputFile>$(OutDir)EmptyAI.dll</OutputFile>
</Link>
</ItemDefinitionGroup>

View File

@@ -23,6 +23,7 @@ CGameInfo::CGameInfo()
void CGameInfo::setFromLib()
{
modh = VLC->modh;
generaltexth = VLC->generaltexth;
arth = VLC->arth;
creh = VLC->creh;

View File

@@ -13,6 +13,7 @@
*
*/
class CModHandler;
class CMapHandler;
class CArtHandler;
class CHeroHandler;
@@ -51,6 +52,7 @@ class CGameInfo
{
ConstTransitivePtr<CGameState> state; //don't touch it in client's code
public:
ConstTransitivePtr<CModHandler> modh; //public?
ConstTransitivePtr<CArtHandler> arth;
ConstTransitivePtr<CHeroHandler> heroh;
ConstTransitivePtr<CCreatureHandler> creh;

View File

@@ -9,6 +9,7 @@
#include "CPlayerInterface.h"
#include "../lib/StartInfo.h"
#include "../lib/BattleState.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CDefObjInfoHandler.h"
#include "../lib/CGeneralTextHandler.h"

View File

@@ -23,7 +23,6 @@
<ClCompile Include="CMusicHandler.cpp" />
<ClCompile Include="CPlayerInterface.cpp" />
<ClCompile Include="CPreGame.cpp" />
<ClCompile Include="CSndHandler.cpp" />
<ClCompile Include="CSpellWindow.cpp" />
<ClCompile Include="CVideoHandler.cpp" />
<ClCompile Include="Graphics.cpp" />
@@ -63,11 +62,9 @@
<ClInclude Include="Client.h" />
<ClInclude Include="CMessage.h" />
<ClInclude Include="..\hch\CObjectHandler.h" />
<ClInclude Include="CMusicBase.h" />
<ClInclude Include="CMusicHandler.h" />
<ClInclude Include="CPlayerInterface.h" />
<ClInclude Include="CPreGame.h" />
<ClInclude Include="CSndHandler.h" />
<ClInclude Include="CSoundBase.h" />
<ClInclude Include="CSpellWindow.h" />
<ClInclude Include="..\hch\CVideoHandler.h" />
@@ -97,7 +94,6 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\ChangeLog" />
<None Include="vcmi.ico" />
</ItemGroup>
</Project>

View File

@@ -12,6 +12,7 @@
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "CModHandler.h"
#include "VCMI_Lib.h"
#include "Connection.h"
#include "map.h"

71
lib/CModHandler.cpp Normal file
View File

@@ -0,0 +1,71 @@
#include "StdInc.h"
#include "CModHandler.h"
/*
* CModHandler.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
*
*/
class CArtHandler;
class CHeroHandler;
class CCreatureHandler;
class CSpellHandler;
class CBuildingHandler;
class CObjectHandler;
class CDefObjInfoHandler;
class CTownHandler;
class CGeneralTextHandler;
CModHandler::CModHandler()
{
VLC->modh = this;
//CResourceHandler::loadModsFilesystems(); //scan for all mods
//TODO: mod filesystem is already initialized at LibClasses launch
//TODO: load default (last?) config
}
artID CModHandler::addNewArtifact (CArtifact * art)
{
int id = artifacts.size();
artifacts.push_back (art);
return id;
}
creID CModHandler::addNewCreature (CCreature * cre)
{
int id = creatures.size();
creatures.push_back (cre);
return id;
}
void CModHandler::loadConfigFromFile (std::string name)
{}
void CModHandler::saveConfigToFile (std::string name)
{}
void CModHandler::recreateHandlers()
{
//TODO: consider some template magic to unify all handlers?
VLC->arth->artifacts.clear();
VLC->creh->creatures.clear(); //TODO: what about items from original game?
BOOST_FOREACH (auto mod, activeMods)
{
BOOST_FOREACH (auto art, allMods[mod].artifacts)
{
VLC->arth->artifacts.push_back (artifacts[art]);
}
BOOST_FOREACH (auto creature, allMods[mod].creatures)
{
VLC->creh->creatures.push_back (creatures[creature]);
}
}
}
CModHandler::~CModHandler()
{
}

86
lib/CModHandler.h Normal file
View File

@@ -0,0 +1,86 @@
#include "Filesystem\CResourceLoader.h"
#include "VCMI_Lib.h"
#include "CCreatureHandler.h"
#include "CArtHandler.h"
/*
* CModHandler.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
*
*/
class CModHandler;
class CModIndentifier;
class CModInfo;
typedef si32 artID;
typedef si32 creID;
class DLL_LINKAGE CModIdentifier
{
//TODO? are simple integer identifiers enough?
int id;
public:
// int operator ()() {return 0;};
bool operator < (CModIdentifier rhs) const {return true;}; //for map
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id;
}
};
class DLL_LINKAGE CModInfo
{
public:
std::vector <CModIdentifier> requirements;
std::vector <ResourceID> usedFiles;
//TODO: config options?
//items added by this mod
std::vector <artID> artifacts;
std::vector <creID> creatures;
//TODO: some additional scripts?
template <typename Handler> void serialize(Handler &h, const int version)
{
h & requirements & artifacts & creatures;
//h & usedFiles; //TODO: make seralizable?
}
};
class DLL_LINKAGE CModHandler
{
public:
std::string currentConfig; //save settings in this file
//list of all possible objects in game, including inactive mods or not allowed
std::vector <ConstTransitivePtr<CCreature> > creatures;
std::vector <ConstTransitivePtr<CArtifact> > artifacts;
std::map <CModIdentifier, CModInfo> allMods;
std::set <CModIdentifier> activeMods;
//create unique object indentifier
artID addNewArtifact (CArtifact * art);
creID addNewCreature (CCreature * cre);
void loadConfigFromFile (std::string name);
void saveConfigToFile (std::string name);
void recreateHandlers();
CModHandler();
~CModHandler();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & creatures & artifacts;
h & allMods & activeMods;
}
};

View File

@@ -11,6 +11,7 @@
#include "BattleState.h"
#include "CGameState.h"
#include "map.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"

View File

@@ -8,6 +8,7 @@
#include "CGameState.h"
#include "CHeroHandler.h"
#include "CTownHandler.h"
//#include "CModHandler.h" //needed?
/*
* RegisterTypes.h, part of VCMI engine
@@ -83,6 +84,9 @@ void registerTypes1(Serializer &s)
s.template registerType<RankRangeLimiter>();
s.template registerType<StackOwnerLimiter>();
s.template registerType<CModInfo>();
s.template registerType<CModIdentifier>();
s.template registerType<CBonusSystemNode>();
s.template registerType<CArtifact>();
s.template registerType<CGrowingArtifact>();

View File

@@ -11,6 +11,7 @@
#include "CBuildingHandler.h"
#include "CSpellHandler.h"
#include "CGeneralTextHandler.h"
#include "CModHandler.h"
#include "IGameEventsReceiver.h"
#include "CStopWatch.h"
#include "VCMIDirs.h"
@@ -179,6 +180,9 @@ void LibClasses::init()
{
CStopWatch pomtime;
modh = new CModHandler; //TODO: all handlers should use mod handler to manage objects
tlog0<<"\tMod handler: "<<pomtime.getDiff()<<std::endl;
generaltexth = new CGeneralTextHandler;
generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDiff()<<std::endl;
@@ -231,6 +235,7 @@ void LibClasses::clear()
delete dobjinfo;
delete buildh;
delete spellh;
delete modh;
makeNull();
}
@@ -245,6 +250,7 @@ void LibClasses::makeNull()
dobjinfo = NULL;
buildh = NULL;
spellh = NULL;
modh = NULL;
}
LibClasses::LibClasses()
@@ -258,6 +264,7 @@ void LibClasses::callWhenDeserializing()
generaltexth = new CGeneralTextHandler;
generaltexth->load();
arth->loadArtifacts(true);
modh->loadConfigFromFile ("default"); //TODO: remember last saved config
}
LibClasses::~LibClasses()

View File

@@ -19,6 +19,7 @@ class CObjectHandler;
class CDefObjInfoHandler;
class CTownHandler;
class CGeneralTextHandler;
class CModHandler;
/// Loads and constructs several handlers
class DLL_LINKAGE LibClasses
@@ -34,6 +35,7 @@ public:
CDefObjInfoHandler * dobjinfo;
CTownHandler * townh;
CGeneralTextHandler * generaltexth;
CModHandler * modh;
LibClasses(); //c-tor, loads .lods and NULLs handlers
~LibClasses();
@@ -46,7 +48,7 @@ public:
void callWhenDeserializing(); //should be called only by serialize !!!
template <typename Handler> void serialize(Handler &h, const int version)
{
h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh & IS_AI_ENABLED;;
h & heroh & arth & creh & townh & objh & dobjinfo & buildh & spellh & modh & IS_AI_ENABLED;;
if(!h.saving)
{
callWhenDeserializing();

View File

@@ -5,6 +5,7 @@
#include "../lib/int3.h"
#include "../lib/CCampaignHandler.h"
#include "../lib/StartInfo.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CBuildingHandler.h"
#include "../lib/CDefObjInfoHandler.h"

View File

@@ -4,6 +4,7 @@
#include "../lib/CCampaignHandler.h"
#include "../lib/CThreadHelper.h"
#include "../lib/Connection.h"
#include "../lib/CModHandler.h"
#include "../lib/CArtHandler.h"
#include "../lib/CDefObjInfoHandler.h"
#include "../lib/CGeneralTextHandler.h"