mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Client: add onlyAI option support for saved games
When --onlyAI option used all human players will be replaced with AIs during loading.
This commit is contained in:
parent
f7f7fe1d32
commit
d95c74941b
@ -333,10 +333,11 @@ int main(int argc, char** argv)
|
||||
preinitDLL(::console);
|
||||
settings.init();
|
||||
Settings session = settings.write["session"];
|
||||
session["onlyai"].Bool() = vm.count("onlyAI");
|
||||
if(vm.count("headless"))
|
||||
{
|
||||
session["headless"].Bool() = true;
|
||||
vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
|
||||
session["onlyai"].Bool() = true;
|
||||
}
|
||||
|
||||
// Init special testing settings
|
||||
@ -581,6 +582,20 @@ void printInfoAboutIntObject(const CIntObject *obj, int level)
|
||||
printInfoAboutIntObject(child, level+1);
|
||||
}
|
||||
|
||||
void removeGUI()
|
||||
{
|
||||
// CClient::endGame
|
||||
GH.curInt = nullptr;
|
||||
if(GH.topInt())
|
||||
GH.topInt()->deactivate();
|
||||
GH.listInt.clear();
|
||||
GH.objsToBlit.clear();
|
||||
GH.statusbar = nullptr;
|
||||
logGlobal->infoStream() << "Removed GUI.";
|
||||
|
||||
LOCPLINT = nullptr;
|
||||
};
|
||||
|
||||
void processCommand(const std::string &message)
|
||||
{
|
||||
std::istringstream readed;
|
||||
@ -701,10 +716,6 @@ void processCommand(const std::string &message)
|
||||
*ptr = 666;
|
||||
//disaster!
|
||||
}
|
||||
else if(cn == "onlyai")
|
||||
{
|
||||
vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
|
||||
}
|
||||
else if(cn == "mp" && adventureInt)
|
||||
{
|
||||
if(const CGHeroInstance *h = dynamic_cast<const CGHeroInstance *>(adventureInt->selection))
|
||||
@ -840,20 +851,6 @@ void processCommand(const std::string &message)
|
||||
}
|
||||
}
|
||||
|
||||
auto removeGUI = [&]()
|
||||
{
|
||||
// CClient::endGame
|
||||
GH.curInt = nullptr;
|
||||
if(GH.topInt())
|
||||
GH.topInt()->deactivate();
|
||||
GH.listInt.clear();
|
||||
GH.objsToBlit.clear();
|
||||
GH.statusbar = nullptr;
|
||||
logNetwork->infoStream() << "Removed GUI.";
|
||||
|
||||
LOCPLINT = nullptr;
|
||||
|
||||
};
|
||||
auto giveTurn = [&](PlayerColor player)
|
||||
{
|
||||
YourTurn yt;
|
||||
@ -1302,7 +1299,7 @@ void startGame(StartInfo * options, CConnection *serv/* = nullptr*/)
|
||||
serverAlive.setn(true);
|
||||
}
|
||||
|
||||
if(vm.count("onlyAI"))
|
||||
if(settings["session"]["onlyai"].Bool())
|
||||
{
|
||||
auto ais = vm.count("ai") ? vm["ai"].as<std::vector<std::string>>() : std::vector<std::string>();
|
||||
|
||||
|
@ -11,9 +11,7 @@ extern SDL_Surface *screen; // main screen surface
|
||||
extern SDL_Surface *screen2; // and hlp surface (used to store not-active interfaces layer)
|
||||
extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
|
||||
|
||||
|
||||
extern bool gNoGUI; //if true there is no client window and game is silently played between AIs
|
||||
|
||||
extern CondSh<bool> serverAlive; //used to prevent game start from executing if server is already running
|
||||
|
||||
void removeGUI();
|
||||
void handleQuit(bool ask = true);
|
||||
|
@ -642,6 +642,18 @@ void CClient::serialize(BinaryDeserializer & h, const int version, const std::se
|
||||
installNewPlayerInterface(nInt, pid);
|
||||
|
||||
nInt->loadGame(h, version);
|
||||
if(settings["session"]["onlyai"].Bool() && isHuman)
|
||||
{
|
||||
removeGUI();
|
||||
nInt.reset();
|
||||
dllname = aiNameForPlayer(false);
|
||||
nInt = CDynLibHandler::getNewAI(dllname);
|
||||
nInt->dllName = dllname;
|
||||
nInt->human = false;
|
||||
nInt->playerID = pid;
|
||||
installNewPlayerInterface(nInt, pid);
|
||||
GH.totalRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
if(playerIDs.count(PlayerColor::NEUTRAL))
|
||||
@ -922,6 +934,11 @@ std::string CClient::aiNameForPlayer(const PlayerSettings &ps, bool battleAI)
|
||||
return ps.name;
|
||||
}
|
||||
|
||||
return aiNameForPlayer(battleAI);
|
||||
}
|
||||
|
||||
std::string CClient::aiNameForPlayer(bool battleAI)
|
||||
{
|
||||
const int sensibleAILimit = settings["session"]["oneGoodAI"].Bool() ? 1 : PlayerColor::PLAYER_LIMIT_I;
|
||||
std::string goodAI = battleAI ? settings["server"]["neutralAI"].String() : settings["server"]["playerAI"].String();
|
||||
std::string badAI = battleAI ? "StupidAI" : "EmptyAI";
|
||||
|
@ -151,6 +151,7 @@ public:
|
||||
void installNewPlayerInterface(std::shared_ptr<CGameInterface> gameInterface, boost::optional<PlayerColor> color);
|
||||
void installNewBattleInterface(std::shared_ptr<CBattleGameInterface> battleInterface, boost::optional<PlayerColor> color, bool needCallback = true);
|
||||
std::string aiNameForPlayer(const PlayerSettings &ps, bool battleAI); //empty means no AI -> human
|
||||
std::string aiNameForPlayer(bool battleAI);
|
||||
|
||||
void endGame(bool closeConnection = true);
|
||||
void stopConnection();
|
||||
|
Loading…
Reference in New Issue
Block a user