CConsoleHandler.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "stdafx.h"
  2. #include "CConsoleHandler.h"
  3. #include "CAdvmapInterface.h"
  4. #include "CPlayerInterface.h"
  5. #include "SDL.h"
  6. #include "SDL_thread.h"
  7. #include "CGameInfo.h"
  8. #include "global.h"
  9. #include "CGameState.h"
  10. #include "CCallback.h"
  11. #include "CPathfinder.h"
  12. #include "mapHandler.h"
  13. #include <sstream>
  14. #include "SDL_Extensions.h"
  15. #include "hch/CHeroHandler.h"
  16. int internalFunc(void * callback)
  17. {
  18. CCallback * cb = (CCallback*)callback;
  19. char * usersMessage = new char[500];
  20. std::string readed;
  21. while(true)
  22. {
  23. std::cin.getline(usersMessage, 500);
  24. std::istringstream readed;
  25. std::string pom(usersMessage);
  26. readed.str(pom);
  27. std::string cn; //command name
  28. readed >> cn;
  29. int3 src, dst;
  30. int heronum;
  31. int3 dest;
  32. if(pom==std::string("die, fool"))
  33. exit(0);
  34. switch (*cn.c_str())
  35. {
  36. case 'P':
  37. std::cout<<"Policzyc sciezke."<<std::endl;
  38. readed>>src>>dst;
  39. LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  40. break;
  41. case 'm': //number of heroes
  42. std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  43. break;
  44. case 'H': //position of hero
  45. readed>>heronum;
  46. std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
  47. break;
  48. case 'M': //move heroa
  49. {
  50. readed>>heronum>>dest;
  51. const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
  52. CPath * path = CGI->pathf->getPath(hero->getPosition(false),dest,hero);
  53. cb->moveHero(heronum, path, 0, 0);
  54. delete path;
  55. break;
  56. }
  57. case 'D': //pos description
  58. readed>>src;
  59. CGI->mh->getObjDescriptions(src);
  60. break;
  61. case 'I':
  62. {
  63. SDL_Surface * temp = LOCPLINT->infoWin(NULL);
  64. blitAtWR(temp,605,389);
  65. SDL_FreeSurface(temp);
  66. break;
  67. }
  68. case 'T': //test rect
  69. readed>>src;
  70. for(int g=0; g<8; ++g)
  71. {
  72. for(int v=0; v<8; ++v)
  73. {
  74. int3 csrc = src;
  75. csrc.y+=g;
  76. csrc.x+=v;
  77. if(CGI->mh->getObjDescriptions(csrc).size())
  78. std::cout<<'x';
  79. else
  80. std::cout<<'o';
  81. }
  82. std::cout<<std::endl;
  83. }
  84. break;
  85. case 'A': //hide everything from map
  86. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  87. {
  88. CGI->mh->hideObject(CGI->objh->objInstances[c]);
  89. }
  90. break;
  91. case 'R': //restora all objects after A has been pressed
  92. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  93. {
  94. CGI->mh->printObject(CGI->objh->objInstances[c]);
  95. }
  96. break;
  97. }
  98. //SDL_Delay(100);
  99. }
  100. return -1;
  101. }
  102. void CConsoleHandler::runConsole()
  103. {
  104. SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
  105. }