CGameInterface.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. 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. #if !defined(__amigaos4__) && !defined(__unix__)
  44. getName(temp);
  45. #endif
  46. std::cout << "Loaded .dll with AI named " << temp << std::endl;
  47. delete temp;
  48. #if !defined(__amigaos4__) && !defined(__unix__)
  49. ret = getAI();
  50. ret->init(cb);
  51. #else
  52. //ret = new CEmptyAI();
  53. #endif
  54. return ret;
  55. }
  56. //CGlobalAI::CGlobalAI()
  57. //{
  58. //}