CGameInterface.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "stdafx.h"
  2. #include "CGameInterface.h"
  3. #include "CAdvmapInterface.h"
  4. #include "CMessage.h"
  5. #include "mapHandler.h"
  6. #include "SDL_Extensions.h"
  7. #include "SDL_framerate.h"
  8. #include "CCursorHandler.h"
  9. #include "CCallback.h"
  10. #include "SDL_Extensions.h"
  11. #include "hch/CLodHandler.h"
  12. #include "CPathfinder.h"
  13. #include <sstream>
  14. #include "hch/CHeroHandler.h"
  15. #include "SDL_framerate.h"
  16. #include "AI/EmptyAI/CEmptyAI.h"
  17. #ifdef _WIN32
  18. #include <windows.h> //for .dll libs
  19. #else
  20. #include <dlfcn.h>
  21. #endif
  22. using namespace CSDL_Ext;
  23. CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
  24. {
  25. dllname = "AI/"+dllname;
  26. CGlobalAI * ret=NULL;
  27. CGlobalAI*(*getAI)();
  28. void(*getName)(char*);
  29. #ifdef _WIN32
  30. HINSTANCE dll = LoadLibraryA(dllname.c_str());
  31. if (!dll)
  32. {
  33. tlog1 << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
  34. #ifdef _MSC_VER
  35. throw new std::exception("Cannot open AI library");
  36. #endif
  37. throw new std::exception();
  38. }
  39. //int len = dllname.size()+1;
  40. getName = (void(*)(char*))GetProcAddress(dll,"GetAiName");
  41. getAI = (CGlobalAI*(*)())GetProcAddress(dll,"GetNewAI");
  42. #else
  43. ; //TODO: handle AI library on Linux
  44. #endif
  45. char * temp = new char[50];
  46. #if _WIN32
  47. getName(temp);
  48. #endif
  49. tlog0 << "Loaded .dll with AI named " << temp << std::endl;
  50. delete temp;
  51. #if _WIN32
  52. ret = getAI();
  53. ret->init(cb);
  54. #else
  55. //ret = new CEmptyAI();
  56. #endif
  57. return ret;
  58. }
  59. //CGlobalAI::CGlobalAI()
  60. //{
  61. //}