1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

* Moved CConfigHandler from client to lib, CMake/Makefile need updating. I believe other projects besides client also need access to settings. (surprisingly there was a "server" category used only by client... and now VCAI.)

* It is possible to set the battle ai that'll be used by neutrals by typing in VCMI console:
setBattleAI <AIName>
VCAI also respects that setting and uses given AI as its battle back-end.
This commit is contained in:
Michał W. Urbańczyk
2012-09-29 10:59:43 +00:00
parent 74cd2e77fe
commit f8a27a9fdb
28 changed files with 73 additions and 43 deletions

View File

@ -2,6 +2,7 @@
#include "VCAI.h" #include "VCAI.h"
#include "../../lib/UnlockGuard.h" #include "../../lib/UnlockGuard.h"
#include "../../lib/CObjectHandler.h" #include "../../lib/CObjectHandler.h"
#include "../../lib/CConfigHandler.h"
#define I_AM_ELEMENTAR return CGoal(*this).setisElementar(true) #define I_AM_ELEMENTAR return CGoal(*this).setisElementar(true)
CLogger &aiLogger = tlog6; CLogger &aiLogger = tlog6;
@ -436,7 +437,6 @@ VCAI::VCAI(void)
{ {
LOG_ENTRY; LOG_ENTRY;
myCb = NULL; myCb = NULL;
battleAIName = "StupidAI";
makingTurn = NULL; makingTurn = NULL;
} }
@ -2538,6 +2538,14 @@ void VCAI::requestSent(const CPackForServer *pack, int requestID)
} }
} }
std::string VCAI::getBattleAIName() const
{
if(settings["server"]["neutralAI"].getType() == JsonNode::DATA_STRING)
return settings["server"]["neutralAI"].String();
else
return "StupidAI";
}
AIStatus::AIStatus() AIStatus::AIStatus()
{ {
battle = NO_BATTLE; battle = NO_BATTLE;

View File

@ -269,8 +269,10 @@ public:
int3 explorationNewPoint(int radius, HeroPtr h, std::vector<std::vector<int3> > &tiles); int3 explorationNewPoint(int radius, HeroPtr h, std::vector<std::vector<int3> > &tiles);
void recruitHero(); void recruitHero();
virtual void init(CCallback * CB); virtual std::string getBattleAIName() const OVERRIDE;
virtual void yourTurn();
virtual void init(CCallback * CB) OVERRIDE;
virtual void yourTurn() OVERRIDE;
virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, int queryID) OVERRIDE; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, int queryID) OVERRIDE; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, int queryID) OVERRIDE; //TODO virtual void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, int queryID) OVERRIDE; //TODO

View File

@ -17,7 +17,7 @@
#include "CCreatureAnimation.h" #include "CCreatureAnimation.h"
#include "../Graphics.h" #include "../Graphics.h"
#include "../CSpellWindow.h" #include "../CSpellWindow.h"
#include "../CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include "../../lib/CondSh.h" #include "../../lib/CondSh.h"
#include "../../lib/NetPacks.h" #include "../../lib/NetPacks.h"
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"

View File

@ -10,7 +10,7 @@
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../CSpellWindow.h" #include "../CSpellWindow.h"
#include "../Graphics.h" #include "../Graphics.h"
#include "../CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include "../UIFramework/CGuiHandler.h" #include "../UIFramework/CGuiHandler.h"
#include "../UIFramework/CIntObjectClasses.h" #include "../UIFramework/CIntObjectClasses.h"
#include "../../lib/CGeneralTextHandler.h" #include "../../lib/CGeneralTextHandler.h"

View File

@ -11,7 +11,7 @@
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "UIFramework/SDL_Extensions.h" #include "UIFramework/SDL_Extensions.h"
#include "CBitmapHandler.h" #include "CBitmapHandler.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CSpellWindow.h" #include "CSpellWindow.h"
#include "Graphics.h" #include "Graphics.h"
#include "CDefHandler.h" #include "CDefHandler.h"

View File

@ -13,7 +13,7 @@
#include "CDefHandler.h" #include "CDefHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CAnimation.h" #include "CAnimation.h"
#include "../lib/CGameState.h" #include "../lib/CGameState.h"

View File

@ -13,7 +13,7 @@
#include "CBitmapHandler.h" #include "CBitmapHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "CSpellWindow.h" #include "CSpellWindow.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "../lib/CArtHandler.h" #include "../lib/CArtHandler.h"

View File

@ -11,7 +11,7 @@
#include "CAnimation.h" //CAnimImage #include "CAnimation.h" //CAnimImage
#include "CAdvmapInterface.h" //CResDataBar #include "CAdvmapInterface.h" //CResDataBar
#include "CCastleInterface.h" //various town-specific classes #include "CCastleInterface.h" //various town-specific classes
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "CPlayerInterface.h" //LOCPLINT #include "CPlayerInterface.h" //LOCPLINT
#include "UIFramework/CGuiHandler.h" #include "UIFramework/CGuiHandler.h"

View File

@ -27,7 +27,7 @@
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "Client.h" #include "Client.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "../lib/Connection.h" #include "../lib/Connection.h"
#include "../lib/VCMI_Lib.h" #include "../lib/VCMI_Lib.h"
#include "../lib/VCMIDirs.h" #include "../lib/VCMIDirs.h"
@ -595,6 +595,23 @@ void processCommand(const std::string &message)
if(mxname == "pim" && LOCPLINT) if(mxname == "pim" && LOCPLINT)
LOCPLINT->pim->unlock(); LOCPLINT->pim->unlock();
} }
else if(cn == "setBattleAI")
{
std::string fname;
readed >> fname;
tlog0 << "Will try loading that AI to see if it is correct name...\n";
if(auto ai = CDynLibHandler::getNewBattleAI(fname)) //test that given AI is indeed available... heavy but it is easy to make a typo and break the game
{
delete ai;
Settings neutralAI = settings.write["server"]["neutralAI"];
neutralAI->String() = fname;
tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\n";
}
else
{
tlog3 << "Setting not changes, no such AI found!\n";
}
}
else if(client && client->serv && client->serv->connected && LOCPLINT) //send to server else if(client && client->serv && client->serv->connected && LOCPLINT) //send to server
{ {
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim); boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);

View File

@ -9,7 +9,7 @@
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "GUIClasses.h" #include "GUIClasses.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CBitmapHandler.h" #include "CBitmapHandler.h"
#include "UIFramework/CIntObjectClasses.h" #include "UIFramework/CIntObjectClasses.h"

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CSoundBase.h" #include "CSoundBase.h"
#include "../lib/CCreatureHandler.h" #include "../lib/CCreatureHandler.h"

View File

@ -15,7 +15,7 @@
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
//#include "UIFramework/SDL_Extensions.h" //#include "UIFramework/SDL_Extensions.h"
#include "UIFramework/SDL_Extensions.h" #include "UIFramework/SDL_Extensions.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "BattleInterface/CCreatureAnimation.h" #include "BattleInterface/CCreatureAnimation.h"
#include "Graphics.h" #include "Graphics.h"
#include "../lib/CArtHandler.h" #include "../lib/CArtHandler.h"

View File

@ -37,7 +37,7 @@
#include "../lib/NetPacks.h" #include "../lib/NetPacks.h"
#include "../lib/RegisterTypes.h" #include "../lib/RegisterTypes.h"
#include "../lib/CThreadHelper.h" #include "../lib/CThreadHelper.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
#include "UIFramework/CGuiHandler.h" #include "UIFramework/CGuiHandler.h"
#include "UIFramework/CIntObjectClasses.h" #include "UIFramework/CIntObjectClasses.h"

View File

@ -11,7 +11,7 @@
#include "CDefHandler.h" #include "CDefHandler.h"
#include "Graphics.h" #include "Graphics.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "../lib/CGameState.h" #include "../lib/CGameState.h"
#include "../lib/CArtHandler.h" #include "../lib/CArtHandler.h"

View File

@ -26,7 +26,7 @@
#include "../lib/map.h" #include "../lib/map.h"
#include "../lib/JsonNode.h" #include "../lib/JsonNode.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "Client.h" #include "Client.h"
#include "CPreGame.h" #include "CPreGame.h"
#include "BattleInterface/CBattleInterface.h" #include "BattleInterface/CBattleInterface.h"

View File

@ -12,8 +12,7 @@
#include "CGameInfo.h" #include "CGameInfo.h"
#include "CHeroWindow.h" #include "CHeroWindow.h"
#include "CMessage.h" #include "CMessage.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "CConfigHandler.h"
#include "BattleInterface/CCreatureAnimation.h" #include "BattleInterface/CCreatureAnimation.h"
#include "CPlayerInterface.h" #include "CPlayerInterface.h"
#include "Graphics.h" #include "Graphics.h"

View File

@ -19,7 +19,7 @@
#include "CSoundBase.h" #include "CSoundBase.h"
#include "mapHandler.h" #include "mapHandler.h"
#include "GUIClasses.h" #include "GUIClasses.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "UIFramework/SDL_Extensions.h" #include "UIFramework/SDL_Extensions.h"
#include "BattleInterface/CBattleInterface.h" #include "BattleInterface/CBattleInterface.h"
#include "../lib/CCampaignHandler.h" #include "../lib/CCampaignHandler.h"

View File

@ -6,7 +6,7 @@
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "CCursorHandler.h" #include "CCursorHandler.h"
#include "../../lib/CThreadHelper.h" #include "../../lib/CThreadHelper.h"
#include "../CConfigHandler.h" #include "../../lib/CConfigHandler.h"
extern SDL_Surface * screenBuf, * screen2, * screen; extern SDL_Surface * screenBuf, * screen2, * screen;
extern std::queue<SDL_Event> events; extern std::queue<SDL_Event> events;

View File

@ -9,7 +9,7 @@
#include "CCursorHandler.h" #include "CCursorHandler.h"
#include "../CGameInfo.h" #include "../CGameInfo.h"
#include "../../CCallback.h" #include "../../CCallback.h"
#include "../CConfigHandler.h" #include "../../lib/CConfigHandler.h"
#include "../BattleInterface/CBattleInterface.h" #include "../BattleInterface/CBattleInterface.h"
#include "../BattleInterface/CBattleInterfaceClasses.h" #include "../BattleInterface/CBattleInterfaceClasses.h"
#include "../CPlayerInterface.h" #include "../CPlayerInterface.h"

View File

@ -235,7 +235,6 @@
<ClCompile Include="..\CCallback.cpp" /> <ClCompile Include="..\CCallback.cpp" />
<ClCompile Include="CBitmapHandler.cpp" /> <ClCompile Include="CBitmapHandler.cpp" />
<ClCompile Include="CCastleInterface.cpp" /> <ClCompile Include="CCastleInterface.cpp" />
<ClCompile Include="CConfigHandler.cpp" />
<ClCompile Include="CCreatureWindow.cpp" /> <ClCompile Include="CCreatureWindow.cpp" />
<ClCompile Include="CDefHandler.cpp" /> <ClCompile Include="CDefHandler.cpp" />
<ClCompile Include="CGameInfo.cpp" /> <ClCompile Include="CGameInfo.cpp" />
@ -280,7 +279,6 @@
<ClInclude Include="CBitmapHandler.h" /> <ClInclude Include="CBitmapHandler.h" />
<ClInclude Include="..\CCallback.h" /> <ClInclude Include="..\CCallback.h" />
<ClInclude Include="CCastleInterface.h" /> <ClInclude Include="CCastleInterface.h" />
<ClInclude Include="CConfigHandler.h" />
<ClInclude Include="CCreatureWindow.h" /> <ClInclude Include="CCreatureWindow.h" />
<ClInclude Include="CDefHandler.h" /> <ClInclude Include="CDefHandler.h" />
<ClInclude Include="CGameInfo.h" /> <ClInclude Include="CGameInfo.h" />

View File

@ -11,7 +11,6 @@
<ClCompile Include="..\CCallback.cpp" /> <ClCompile Include="..\CCallback.cpp" />
<ClCompile Include="CBitmapHandler.cpp" /> <ClCompile Include="CBitmapHandler.cpp" />
<ClCompile Include="CCastleInterface.cpp" /> <ClCompile Include="CCastleInterface.cpp" />
<ClCompile Include="CConfigHandler.cpp" />
<ClCompile Include="CCreatureWindow.cpp" /> <ClCompile Include="CCreatureWindow.cpp" />
<ClCompile Include="CDefHandler.cpp" /> <ClCompile Include="CDefHandler.cpp" />
<ClCompile Include="CGameInfo.cpp" /> <ClCompile Include="CGameInfo.cpp" />
@ -50,7 +49,6 @@
<ClInclude Include="CBitmapHandler.h" /> <ClInclude Include="CBitmapHandler.h" />
<ClInclude Include="..\CCallback.h" /> <ClInclude Include="..\CCallback.h" />
<ClInclude Include="CCastleInterface.h" /> <ClInclude Include="CCastleInterface.h" />
<ClInclude Include="CConfigHandler.h" />
<ClInclude Include="CCreatureWindow.h" /> <ClInclude Include="CCreatureWindow.h" />
<ClInclude Include="CDefHandler.h" /> <ClInclude Include="CDefHandler.h" />
<ClInclude Include="CGameInfo.h" /> <ClInclude Include="CGameInfo.h" />

View File

@ -11,7 +11,7 @@
#include "../lib/CObjectHandler.h" #include "../lib/CObjectHandler.h"
#include "../lib/map.h" #include "../lib/map.h"
#include "CDefHandler.h" #include "CDefHandler.h"
#include "CConfigHandler.h" #include "../lib/CConfigHandler.h"
#include "../lib/CGeneralTextHandler.h" #include "../lib/CGeneralTextHandler.h"
#include "../lib/GameConstants.h" #include "../lib/GameConstants.h"
#include "../lib/CStopWatch.h" #include "../lib/CStopWatch.h"

View File

@ -168,9 +168,9 @@ JsonNode& Settings::operator [](std::string value)
{ {
return node[value]; return node[value];
} }
//
template struct SettingsStorage::NodeAccessor<SettingsListener>; // template DLL_LINKAGE struct SettingsStorage::NodeAccessor<SettingsListener>;
template struct SettingsStorage::NodeAccessor<Settings>; // template DLL_LINKAGE struct SettingsStorage::NodeAccessor<Settings>;
static void setButton(ButtonInfo &button, const JsonNode &g) static void setButton(ButtonInfo &button, const JsonNode &g)
{ {

View File

@ -15,11 +15,11 @@ class Settings;
class SettingsListener; class SettingsListener;
/// Main storage of game settings /// Main storage of game settings
class SettingsStorage class DLL_LINKAGE SettingsStorage
{ {
//Helper struct to access specific node either via chain of operator[] or with one operator() (vector) //Helper struct to access specific node either via chain of operator[] or with one operator() (vector)
template<typename Accessor> template<typename Accessor>
struct NodeAccessor struct DLL_LINKAGE NodeAccessor
{ {
SettingsStorage & parent; SettingsStorage & parent;
std::vector<std::string> path; std::vector<std::string> path;
@ -57,7 +57,7 @@ public:
}; };
/// Class for listening changes in specific part of configuration (e.g. change of music volume) /// Class for listening changes in specific part of configuration (e.g. change of music volume)
class SettingsListener class DLL_LINKAGE SettingsListener
{ {
SettingsStorage &parent; SettingsStorage &parent;
// Path to this node // Path to this node
@ -81,7 +81,7 @@ public:
}; };
/// System options, provides write access to config tree with auto-saving on change /// System options, provides write access to config tree with auto-saving on change
class Settings class DLL_LINKAGE Settings
{ {
SettingsStorage &parent; SettingsStorage &parent;
//path to this node //path to this node
@ -109,7 +109,7 @@ public:
namespace config namespace config
{ {
struct ButtonInfo struct DLL_LINKAGE ButtonInfo
{ {
std::string defName; std::string defName;
std::vector<std::string> additionalDefs; std::vector<std::string> additionalDefs;
@ -117,7 +117,7 @@ namespace config
bool playerColoured; //if true button will be colored to main player's color (works properly only for appropriate 8bpp graphics) bool playerColoured; //if true button will be colored to main player's color (works properly only for appropriate 8bpp graphics)
}; };
/// Struct which holds data about position of several GUI elements at the adventure map screen /// Struct which holds data about position of several GUI elements at the adventure map screen
struct AdventureMapConfig struct DLL_LINKAGE AdventureMapConfig
{ {
//minimap properties //minimap properties
int minimapX, minimapY, minimapW, minimapH; int minimapX, minimapY, minimapW, minimapH;
@ -153,12 +153,12 @@ namespace config
int overviewPics, overviewSize; //pic count in def and count of visible slots int overviewPics, overviewSize; //pic count in def and count of visible slots
std::string overviewBg; //background name std::string overviewBg; //background name
}; };
struct GUIOptions struct DLL_LINKAGE GUIOptions
{ {
AdventureMapConfig ac; AdventureMapConfig ac;
}; };
/// Handles adventure map screen settings /// Handles adventure map screen settings
class CConfigHandler class DLL_LINKAGE CConfigHandler
{ {
GUIOptions *current; // pointer to current gui options GUIOptions *current; // pointer to current gui options
@ -176,5 +176,10 @@ namespace config
}; };
} }
extern SettingsStorage settings; extern DLL_LINKAGE SettingsStorage settings;
extern config::CConfigHandler conf; extern DLL_LINKAGE config::CConfigHandler conf;
// Force instantiation of the SettingsStorage::NodeAccessor class template.
// That way method definitions can sit in the cpp file
template struct SettingsStorage::NodeAccessor<SettingsListener>;
template struct SettingsStorage::NodeAccessor<Settings>;

View File

@ -127,7 +127,7 @@ void CAdventureAI::battleStart(const CCreatureSet *army1, const CCreatureSet *ar
{ {
assert(!battleAI); assert(!battleAI);
assert(cbc); assert(cbc);
battleAI = CDynLibHandler::getNewBattleAI(battleAIName); battleAI = CDynLibHandler::getNewBattleAI(getBattleAIName());
battleAI->init(cbc); battleAI->init(cbc);
battleAI->battleStart(army1, army2, tile, hero1, hero2, side); battleAI->battleStart(army1, army2, tile, hero1, hero2, side);
} }

View File

@ -111,12 +111,12 @@ class DLL_LINKAGE CAdventureAI : public CGlobalAI
{ {
public: public:
CAdventureAI() : battleAI(NULL), cbc(NULL) {}; CAdventureAI() : battleAI(NULL), cbc(NULL) {};
CAdventureAI(const std::string &BattleAIName) : battleAIName(BattleAIName), battleAI(NULL), cbc(NULL) {};
std::string battleAIName;
CBattleGameInterface *battleAI; CBattleGameInterface *battleAI;
CBattleCallback *cbc; CBattleCallback *cbc;
virtual std::string getBattleAIName() const = 0; //has to return name of the battle AI to be used
//battle interface //battle interface
virtual BattleAction activeStack(const CStack * stack); virtual BattleAction activeStack(const CStack * stack);
virtual void yourTacticPhase(int distance); virtual void yourTacticPhase(int distance);

View File

@ -12,6 +12,7 @@
#include <boost/type_traits/remove_pointer.hpp> #include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/remove_const.hpp> #include <boost/type_traits/remove_const.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/mpl/eval_if.hpp> #include <boost/mpl/eval_if.hpp>
#include <boost/mpl/equal_to.hpp> #include <boost/mpl/equal_to.hpp>
@ -24,7 +25,7 @@
#include "CObjectHandler.h" //for CArmedInstance #include "CObjectHandler.h" //for CArmedInstance
#include "CCampaignHandler.h" //for CCampaignState #include "CCampaignHandler.h" //for CCampaignState
const ui32 version = 732; const ui32 version = 733;
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2; const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
class CConnection; class CConnection;

View File

@ -226,6 +226,7 @@
<ClCompile Include="CArtHandler.cpp" /> <ClCompile Include="CArtHandler.cpp" />
<ClCompile Include="CBuildingHandler.cpp" /> <ClCompile Include="CBuildingHandler.cpp" />
<ClCompile Include="CCampaignHandler.cpp" /> <ClCompile Include="CCampaignHandler.cpp" />
<ClCompile Include="CConfigHandler.cpp" />
<ClCompile Include="CConsoleHandler.cpp" /> <ClCompile Include="CConsoleHandler.cpp" />
<ClCompile Include="CCreatureHandler.cpp" /> <ClCompile Include="CCreatureHandler.cpp" />
<ClCompile Include="CCreatureSet.cpp" /> <ClCompile Include="CCreatureSet.cpp" />
@ -278,6 +279,7 @@
<ClInclude Include="CArtHandler.h" /> <ClInclude Include="CArtHandler.h" />
<ClInclude Include="CBuildingHandler.h" /> <ClInclude Include="CBuildingHandler.h" />
<ClInclude Include="CCampaignHandler.h" /> <ClInclude Include="CCampaignHandler.h" />
<ClInclude Include="CConfigHandler.h" />
<ClInclude Include="CConsoleHandler.h" /> <ClInclude Include="CConsoleHandler.h" />
<ClInclude Include="CCreatureHandler.h" /> <ClInclude Include="CCreatureHandler.h" />
<ClInclude Include="CCreatureSet.h" /> <ClInclude Include="CCreatureSet.h" />