--------------------------------------------- AI MODULE ----------------------------------------------
| 322 | |
| 323 | //--------------------------------------------- AI MODULE ---------------------------------------------- |
| 324 | void GameImpl::initializeAIModule() |
| 325 | { |
| 326 | // Declare typedefs for function pointers |
| 327 | typedef void (*PFNGameInit)(Game *); |
| 328 | typedef AIModule* (*PFNCreateA1)(); |
| 329 | |
| 330 | // Connect to external module if it exists |
| 331 | externalModuleConnected = false; |
| 332 | std::string moduleName("<Nothing>"); |
| 333 | if ( server.isConnected() ) //check to see if the server is connected to the client |
| 334 | { |
| 335 | // assign a blank AI module to our variable |
| 336 | this->client = new AIModule(); |
| 337 | // Hide success strings in tournament mode |
| 338 | if ( !hTournamentModule ) |
| 339 | Broodwar << "BWAPI: Connected to AI Client process" << std::endl; |
| 340 | // Set the module string |
| 341 | moduleName = "<Client Connection>"; |
| 342 | externalModuleConnected = true; |
| 343 | } |
| 344 | else // if not, load the AI module DLL |
| 345 | { |
| 346 | // declare/assign variables |
| 347 | hAIModule = nullptr; |
| 348 | |
| 349 | std::string dll; |
| 350 | std::string aicfg = LoadConfigString("ai", BUILD_DEBUG ? "ai_dbg" : "ai", "_NULL"); |
| 351 | if (aicfg == "_NULL") |
| 352 | { |
| 353 | BWAPIError("Could not find %s under ai in \"%s\".", BUILD_DEBUG ? "ai_dbg" : "ai", configPath().c_str()); |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | std::stringstream aiList(aicfg); |
| 358 | |
| 359 | // Get DLL name |
| 360 | dll = aicfg.substr(0, aicfg.find_first_of(',')); |
| 361 | |
| 362 | // Skip to current intended instance |
| 363 | for (int i = 0; i < (int)gdwProcNum && aiList; ++i) |
| 364 | std::getline(aiList, dll, ','); |
| 365 | |
| 366 | // trim whitespace outside quotations and then the quotations |
| 367 | Util::trim(dll, Util::is_whitespace_or_newline); |
| 368 | Util::trim(dll, [](char c) { return c == '"'; }); |
| 369 | |
| 370 | hAIModule = LoadLibraryA(dll.c_str()); |
| 371 | } |
| 372 | |
| 373 | if ( !hAIModule ) |
| 374 | { |
| 375 | //if hAIModule is nullptr, there there was a problem when trying to load the AI Module |
| 376 | this->client = new AIModule(); |
| 377 | |
| 378 | // enable flags to allow interaction |
| 379 | Broodwar->enableFlag(Flag::CompleteMapInformation); |
| 380 | Broodwar->enableFlag(Flag::UserInput); |
| 381 |
no test coverage detected