mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +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:
parent
74cd2e77fe
commit
f8a27a9fdb
@ -2,6 +2,7 @@
|
||||
#include "VCAI.h"
|
||||
#include "../../lib/UnlockGuard.h"
|
||||
#include "../../lib/CObjectHandler.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
|
||||
#define I_AM_ELEMENTAR return CGoal(*this).setisElementar(true)
|
||||
CLogger &aiLogger = tlog6;
|
||||
@ -436,7 +437,6 @@ VCAI::VCAI(void)
|
||||
{
|
||||
LOG_ENTRY;
|
||||
myCb = NULL;
|
||||
battleAIName = "StupidAI";
|
||||
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()
|
||||
{
|
||||
battle = NO_BATTLE;
|
||||
|
@ -269,8 +269,10 @@ public:
|
||||
int3 explorationNewPoint(int radius, HeroPtr h, std::vector<std::vector<int3> > &tiles);
|
||||
void recruitHero();
|
||||
|
||||
virtual void init(CCallback * CB);
|
||||
virtual void yourTurn();
|
||||
virtual std::string getBattleAIName() const OVERRIDE;
|
||||
|
||||
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 commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, int queryID) OVERRIDE; //TODO
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "CCreatureAnimation.h"
|
||||
#include "../Graphics.h"
|
||||
#include "../CSpellWindow.h"
|
||||
#include "../CConfigHandler.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/CondSh.h"
|
||||
#include "../../lib/NetPacks.h"
|
||||
#include "../CPlayerInterface.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "../../CCallback.h"
|
||||
#include "../CSpellWindow.h"
|
||||
#include "../Graphics.h"
|
||||
#include "../CConfigHandler.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../UIFramework/CGuiHandler.h"
|
||||
#include "../UIFramework/CIntObjectClasses.h"
|
||||
#include "../../lib/CGeneralTextHandler.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "CPlayerInterface.h"
|
||||
#include "UIFramework/SDL_Extensions.h"
|
||||
#include "CBitmapHandler.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CSpellWindow.h"
|
||||
#include "Graphics.h"
|
||||
#include "CDefHandler.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "CDefHandler.h"
|
||||
#include "Graphics.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CAnimation.h"
|
||||
|
||||
#include "../lib/CGameState.h"
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "CBitmapHandler.h"
|
||||
#include "Graphics.h"
|
||||
#include "CSpellWindow.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CPlayerInterface.h"
|
||||
|
||||
#include "../lib/CArtHandler.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "CAnimation.h" //CAnimImage
|
||||
#include "CAdvmapInterface.h" //CResDataBar
|
||||
#include "CCastleInterface.h" //various town-specific classes
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "CPlayerInterface.h" //LOCPLINT
|
||||
#include "UIFramework/CGuiHandler.h"
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "../lib/CGeneralTextHandler.h"
|
||||
#include "Graphics.h"
|
||||
#include "Client.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "../lib/Connection.h"
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
@ -595,6 +595,23 @@ void processCommand(const std::string &message)
|
||||
if(mxname == "pim" && LOCPLINT)
|
||||
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
|
||||
{
|
||||
boost::unique_lock<boost::recursive_mutex> un(*LOCPLINT->pim);
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "../lib/CGeneralTextHandler.h"
|
||||
#include "Graphics.h"
|
||||
#include "GUIClasses.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CBitmapHandler.h"
|
||||
#include "UIFramework/CIntObjectClasses.h"
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "CSoundBase.h"
|
||||
#include "../lib/CCreatureHandler.h"
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "CPlayerInterface.h"
|
||||
//#include "UIFramework/SDL_Extensions.h"
|
||||
#include "UIFramework/SDL_Extensions.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "BattleInterface/CCreatureAnimation.h"
|
||||
#include "Graphics.h"
|
||||
#include "../lib/CArtHandler.h"
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "../lib/NetPacks.h"
|
||||
#include "../lib/RegisterTypes.h"
|
||||
#include "../lib/CThreadHelper.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "../lib/GameConstants.h"
|
||||
#include "UIFramework/CGuiHandler.h"
|
||||
#include "UIFramework/CIntObjectClasses.h"
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "CDefHandler.h"
|
||||
#include "Graphics.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
|
||||
#include "../lib/CGameState.h"
|
||||
#include "../lib/CArtHandler.h"
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "../lib/map.h"
|
||||
#include "../lib/JsonNode.h"
|
||||
#include "mapHandler.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "Client.h"
|
||||
#include "CPreGame.h"
|
||||
#include "BattleInterface/CBattleInterface.h"
|
||||
|
@ -12,8 +12,7 @@
|
||||
#include "CGameInfo.h"
|
||||
#include "CHeroWindow.h"
|
||||
#include "CMessage.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "BattleInterface/CCreatureAnimation.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "Graphics.h"
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "CSoundBase.h"
|
||||
#include "mapHandler.h"
|
||||
#include "GUIClasses.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "UIFramework/SDL_Extensions.h"
|
||||
#include "BattleInterface/CBattleInterface.h"
|
||||
#include "../lib/CCampaignHandler.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "../CGameInfo.h"
|
||||
#include "CCursorHandler.h"
|
||||
#include "../../lib/CThreadHelper.h"
|
||||
#include "../CConfigHandler.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
|
||||
extern SDL_Surface * screenBuf, * screen2, * screen;
|
||||
extern std::queue<SDL_Event> events;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "CCursorHandler.h"
|
||||
#include "../CGameInfo.h"
|
||||
#include "../../CCallback.h"
|
||||
#include "../CConfigHandler.h"
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../BattleInterface/CBattleInterface.h"
|
||||
#include "../BattleInterface/CBattleInterfaceClasses.h"
|
||||
#include "../CPlayerInterface.h"
|
||||
|
@ -235,7 +235,6 @@
|
||||
<ClCompile Include="..\CCallback.cpp" />
|
||||
<ClCompile Include="CBitmapHandler.cpp" />
|
||||
<ClCompile Include="CCastleInterface.cpp" />
|
||||
<ClCompile Include="CConfigHandler.cpp" />
|
||||
<ClCompile Include="CCreatureWindow.cpp" />
|
||||
<ClCompile Include="CDefHandler.cpp" />
|
||||
<ClCompile Include="CGameInfo.cpp" />
|
||||
@ -280,7 +279,6 @@
|
||||
<ClInclude Include="CBitmapHandler.h" />
|
||||
<ClInclude Include="..\CCallback.h" />
|
||||
<ClInclude Include="CCastleInterface.h" />
|
||||
<ClInclude Include="CConfigHandler.h" />
|
||||
<ClInclude Include="CCreatureWindow.h" />
|
||||
<ClInclude Include="CDefHandler.h" />
|
||||
<ClInclude Include="CGameInfo.h" />
|
||||
|
@ -11,7 +11,6 @@
|
||||
<ClCompile Include="..\CCallback.cpp" />
|
||||
<ClCompile Include="CBitmapHandler.cpp" />
|
||||
<ClCompile Include="CCastleInterface.cpp" />
|
||||
<ClCompile Include="CConfigHandler.cpp" />
|
||||
<ClCompile Include="CCreatureWindow.cpp" />
|
||||
<ClCompile Include="CDefHandler.cpp" />
|
||||
<ClCompile Include="CGameInfo.cpp" />
|
||||
@ -50,7 +49,6 @@
|
||||
<ClInclude Include="CBitmapHandler.h" />
|
||||
<ClInclude Include="..\CCallback.h" />
|
||||
<ClInclude Include="CCastleInterface.h" />
|
||||
<ClInclude Include="CConfigHandler.h" />
|
||||
<ClInclude Include="CCreatureWindow.h" />
|
||||
<ClInclude Include="CDefHandler.h" />
|
||||
<ClInclude Include="CGameInfo.h" />
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "../lib/CObjectHandler.h"
|
||||
#include "../lib/map.h"
|
||||
#include "CDefHandler.h"
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/CConfigHandler.h"
|
||||
#include "../lib/CGeneralTextHandler.h"
|
||||
#include "../lib/GameConstants.h"
|
||||
#include "../lib/CStopWatch.h"
|
||||
|
@ -168,9 +168,9 @@ JsonNode& Settings::operator [](std::string value)
|
||||
{
|
||||
return node[value];
|
||||
}
|
||||
|
||||
template struct SettingsStorage::NodeAccessor<SettingsListener>;
|
||||
template struct SettingsStorage::NodeAccessor<Settings>;
|
||||
//
|
||||
// template DLL_LINKAGE struct SettingsStorage::NodeAccessor<SettingsListener>;
|
||||
// template DLL_LINKAGE struct SettingsStorage::NodeAccessor<Settings>;
|
||||
|
||||
static void setButton(ButtonInfo &button, const JsonNode &g)
|
||||
{
|
@ -15,11 +15,11 @@ class Settings;
|
||||
class SettingsListener;
|
||||
|
||||
/// 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)
|
||||
template<typename Accessor>
|
||||
struct NodeAccessor
|
||||
struct DLL_LINKAGE NodeAccessor
|
||||
{
|
||||
SettingsStorage & parent;
|
||||
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 SettingsListener
|
||||
class DLL_LINKAGE SettingsListener
|
||||
{
|
||||
SettingsStorage &parent;
|
||||
// Path to this node
|
||||
@ -81,7 +81,7 @@ public:
|
||||
};
|
||||
|
||||
/// System options, provides write access to config tree with auto-saving on change
|
||||
class Settings
|
||||
class DLL_LINKAGE Settings
|
||||
{
|
||||
SettingsStorage &parent;
|
||||
//path to this node
|
||||
@ -109,7 +109,7 @@ public:
|
||||
|
||||
namespace config
|
||||
{
|
||||
struct ButtonInfo
|
||||
struct DLL_LINKAGE ButtonInfo
|
||||
{
|
||||
std::string defName;
|
||||
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)
|
||||
};
|
||||
/// Struct which holds data about position of several GUI elements at the adventure map screen
|
||||
struct AdventureMapConfig
|
||||
struct DLL_LINKAGE AdventureMapConfig
|
||||
{
|
||||
//minimap properties
|
||||
int minimapX, minimapY, minimapW, minimapH;
|
||||
@ -153,12 +153,12 @@ namespace config
|
||||
int overviewPics, overviewSize; //pic count in def and count of visible slots
|
||||
std::string overviewBg; //background name
|
||||
};
|
||||
struct GUIOptions
|
||||
struct DLL_LINKAGE GUIOptions
|
||||
{
|
||||
AdventureMapConfig ac;
|
||||
};
|
||||
/// Handles adventure map screen settings
|
||||
class CConfigHandler
|
||||
class DLL_LINKAGE CConfigHandler
|
||||
{
|
||||
GUIOptions *current; // pointer to current gui options
|
||||
|
||||
@ -176,5 +176,10 @@ namespace config
|
||||
};
|
||||
}
|
||||
|
||||
extern SettingsStorage settings;
|
||||
extern config::CConfigHandler conf;
|
||||
extern DLL_LINKAGE SettingsStorage settings;
|
||||
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>;
|
@ -127,7 +127,7 @@ void CAdventureAI::battleStart(const CCreatureSet *army1, const CCreatureSet *ar
|
||||
{
|
||||
assert(!battleAI);
|
||||
assert(cbc);
|
||||
battleAI = CDynLibHandler::getNewBattleAI(battleAIName);
|
||||
battleAI = CDynLibHandler::getNewBattleAI(getBattleAIName());
|
||||
battleAI->init(cbc);
|
||||
battleAI->battleStart(army1, army2, tile, hero1, hero2, side);
|
||||
}
|
||||
|
@ -111,12 +111,12 @@ class DLL_LINKAGE CAdventureAI : public CGlobalAI
|
||||
{
|
||||
public:
|
||||
CAdventureAI() : battleAI(NULL), cbc(NULL) {};
|
||||
CAdventureAI(const std::string &BattleAIName) : battleAIName(BattleAIName), battleAI(NULL), cbc(NULL) {};
|
||||
|
||||
std::string battleAIName;
|
||||
CBattleGameInterface *battleAI;
|
||||
CBattleCallback *cbc;
|
||||
|
||||
virtual std::string getBattleAIName() const = 0; //has to return name of the battle AI to be used
|
||||
|
||||
//battle interface
|
||||
virtual BattleAction activeStack(const CStack * stack);
|
||||
virtual void yourTacticPhase(int distance);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
@ -24,7 +25,7 @@
|
||||
#include "CObjectHandler.h" //for CArmedInstance
|
||||
#include "CCampaignHandler.h" //for CCampaignState
|
||||
|
||||
const ui32 version = 732;
|
||||
const ui32 version = 733;
|
||||
const TSlot COMMANDER_SLOT_PLACEHOLDER = -2;
|
||||
|
||||
class CConnection;
|
||||
|
@ -226,6 +226,7 @@
|
||||
<ClCompile Include="CArtHandler.cpp" />
|
||||
<ClCompile Include="CBuildingHandler.cpp" />
|
||||
<ClCompile Include="CCampaignHandler.cpp" />
|
||||
<ClCompile Include="CConfigHandler.cpp" />
|
||||
<ClCompile Include="CConsoleHandler.cpp" />
|
||||
<ClCompile Include="CCreatureHandler.cpp" />
|
||||
<ClCompile Include="CCreatureSet.cpp" />
|
||||
@ -278,6 +279,7 @@
|
||||
<ClInclude Include="CArtHandler.h" />
|
||||
<ClInclude Include="CBuildingHandler.h" />
|
||||
<ClInclude Include="CCampaignHandler.h" />
|
||||
<ClInclude Include="CConfigHandler.h" />
|
||||
<ClInclude Include="CConsoleHandler.h" />
|
||||
<ClInclude Include="CCreatureHandler.h" />
|
||||
<ClInclude Include="CCreatureSet.h" />
|
||||
|
Loading…
Reference in New Issue
Block a user