فهرست منبع

"More stable" opening AI.

Michał W. Urbańczyk 12 سال پیش
والد
کامیت
5b919d88eb
3فایلهای تغییر یافته به همراه23 افزوده شده و 10 حذف شده
  1. 6 3
      AI/BattleAI/BattleAI.cpp
  2. 11 7
      client/CMT.cpp
  3. 6 0
      lib/CGameInterface.cpp

+ 6 - 3
AI/BattleAI/BattleAI.cpp

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

+ 11 - 7
client/CMT.cpp

@@ -616,16 +616,20 @@ void processCommand(const std::string &message)
 		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
+		try
 		{
-			delete ai;
-			Settings neutralAI = settings.write["server"]["neutralAI"];
-			neutralAI->String() = fname;
-			tlog0 << "Setting changed, from now the battle ai will be " << fname << "!\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
+		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

+ 6 - 0
lib/CGameInterface.cpp

@@ -51,6 +51,12 @@ rett * createAny(std::string dllname, std::string methodName)
 		tlog1 << "Cannot open dynamic library ("<<dllname<<"). Throwing..."<<std::endl;
 		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);
 	tlog0 << "Loaded " << temp << std::endl;