CGameInterface.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. char temp[50];
  26. dllname = "AI/"+dllname;
  27. CGlobalAI * ret=NULL;
  28. CGlobalAI*(*getAI)();
  29. void(*getName)(char*);
  30. #ifdef _WIN32
  31. HINSTANCE dll = LoadLibraryA(dllname.c_str());
  32. if (!dll)
  33. {
  34. tlog1 << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
  35. throw new std::string("Cannot open AI library");
  36. }
  37. //int len = dllname.size()+1;
  38. getName = (void(*)(char*))GetProcAddress(dll,"GetAiName");
  39. getAI = (CGlobalAI*(*)())GetProcAddress(dll,"GetNewAI");
  40. getName(temp);
  41. #else
  42. ; //TODO: handle AI library on Linux
  43. #endif
  44. tlog0 << "Loaded .dll with AI named " << temp << std::endl;
  45. #if _WIN32
  46. ret = getAI();
  47. #else
  48. //ret = new CEmptyAI();
  49. #endif
  50. return ret;
  51. }
  52. //CGlobalAI::CGlobalAI()
  53. //{
  54. //}