CGameInterface.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #include "AI/EmptyAI/CEmptyAI.h"
  18. #ifdef _WIN32
  19. #include <windows.h> //for .dll libs
  20. #else
  21. #include <dlfcn.h>
  22. #endif
  23. using namespace CSDL_Ext;
  24. CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
  25. {
  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. std::cout << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
  35. throw new std::exception("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. #else
  41. ; //TODO: handle AI library on Linux
  42. #endif
  43. char * temp = new char[50];
  44. #if !defined(__amigaos4__) && !defined(__unix__)
  45. getName(temp);
  46. #endif
  47. std::cout << "Loaded .dll with AI named " << temp << std::endl;
  48. delete temp;
  49. #if !defined(__amigaos4__) && !defined(__unix__)
  50. ret = getAI();
  51. ret->init(cb);
  52. #else
  53. //ret = new CEmptyAI();
  54. #endif
  55. return ret;
  56. }
  57. //CGlobalAI::CGlobalAI()
  58. //{
  59. //}