CConsoleHandler.cpp 2.5 KB

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