2
0

CGameInterface.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "CScreenHandler.h"
  9. #include "CCursorHandler.h"
  10. #include "CCallback.h"
  11. #include "SDL_Extensions.h"
  12. #include "hch/CLodHandler.h"
  13. #include "CPathfinder.h"
  14. #include <sstream>
  15. #include "hch/CHeroHandler.h"
  16. #include "SDL_framerate.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. std::cout << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
  34. throw new std::exception("Cannot open AI library");
  35. }
  36. //int len = dllname.size()+1;
  37. getName = (void(*)(char*))GetProcAddress(dll,"GetAiName");
  38. getAI = (CGlobalAI*(*)())GetProcAddress(dll,"GetNewAI");
  39. #else
  40. ; //TODO: handle AI library on Linux
  41. #endif
  42. char * temp = new char[50];
  43. getName(temp);
  44. std::cout << "Loaded .dll with AI named " << temp << std::endl;
  45. delete temp;
  46. ret = getAI();
  47. ret->init(cb);
  48. return ret;
  49. }
  50. //CGlobalAI::CGlobalAI()
  51. //{
  52. //}