1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-23 12:08:45 +02:00

"More stable" opening AI.

This commit is contained in:
Michał W. Urbańczyk 2013-01-20 12:06:49 +00:00
parent 0e826915ed
commit 5b919d88eb
3 changed files with 23 additions and 10 deletions

View File

@ -71,10 +71,13 @@ CBattleAI::~CBattleAI(void)
{ {
print("destroyed"); print("destroyed");
if(cb)
{
//Restore previous state of CB - it may be shared with the main AI (like VCAI) //Restore previous state of CB - it may be shared with the main AI (like VCAI)
cb->waitTillRealize = wasWaitingForRealize; cb->waitTillRealize = wasWaitingForRealize;
cb->unlockGsWhenWaiting = wasUnlockingGs; cb->unlockGsWhenWaiting = wasUnlockingGs;
} }
}
void CBattleAI::init( CBattleCallback * CB ) void CBattleAI::init( CBattleCallback * CB )
{ {

View File

@ -616,6 +616,8 @@ void processCommand(const std::string &message)
std::string fname; std::string fname;
readed >> fname; readed >> fname;
tlog0 << "Will try loading that AI to see if it is correct name...\n"; tlog0 << "Will try loading that AI to see if it is correct name...\n";
try
{
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 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; delete ai;
@ -623,9 +625,11 @@ void processCommand(const std::string &message)
neutralAI->String() = fname; neutralAI->String() = fname;
tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\n"; tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\n";
} }
else }
catch(std::exception &e)
{ {
tlog3 << "Setting not changes, no such AI found!\n"; tlog3 << "Failed opening " << fname << ": " << e.what() << std::endl;
tlog3 << "Setting not changes, AI not found or invalid!\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

View File

@ -51,6 +51,12 @@ rett * createAny(std::string dllname, std::string methodName)
tlog1 << "Cannot open dynamic library ("<<dllname<<"). Throwing..."<<std::endl; tlog1 << "Cannot open dynamic library ("<<dllname<<"). Throwing..."<<std::endl;
throw std::runtime_error("Cannot open dynamic library"); throw std::runtime_error("Cannot open dynamic library");
} }
else if(!getName || !getAI)
{
tlog1 << dllname << " does not export method " << methodName << std::endl;
FreeLibrary(dll);
throw std::runtime_error("Cannot find method " + methodName);
}
getName(temp); getName(temp);
tlog0 << "Loaded " << temp << std::endl; tlog0 << "Loaded " << temp << std::endl;