CConsoleHandler.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. break;
  66. }
  67. case 'T': //test rect
  68. readed>>src;
  69. for(int g=0; g<8; ++g)
  70. {
  71. for(int v=0; v<8; ++v)
  72. {
  73. int3 csrc = src;
  74. csrc.y+=g;
  75. csrc.x+=v;
  76. if(CGI->mh->getObjDescriptions(csrc).size())
  77. std::cout<<'x';
  78. else
  79. std::cout<<'o';
  80. }
  81. std::cout<<std::endl;
  82. }
  83. break;
  84. case 'A': //hide everything from map
  85. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  86. {
  87. CGI->mh->hideObject(CGI->objh->objInstances[c]);
  88. }
  89. break;
  90. case 'R': //restora all objects after A has been pressed
  91. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  92. {
  93. CGI->mh->printObject(CGI->objh->objInstances[c]);
  94. }
  95. break;
  96. }
  97. //SDL_Delay(100);
  98. }
  99. return -1;
  100. }
  101. void CConsoleHandler::runConsole()
  102. {
  103. SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
  104. }