CConsoleHandler.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. switch (*cn.c_str())
  33. {
  34. case 'P':
  35. std::cout<<"Policzyc sciezke."<<std::endl;
  36. readed>>src>>dst;
  37. LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  38. break;
  39. case 'm': //number of heroes
  40. std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  41. break;
  42. case 'H': //position of hero
  43. readed>>heronum;
  44. std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
  45. break;
  46. case 'M': //move heroa
  47. {
  48. readed>>heronum>>dest;
  49. const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
  50. CPath * path = CGI->pathf->getPath(hero->getPosition(false),dest,hero);
  51. cb->moveHero(heronum, path, 0, 0);
  52. delete path;
  53. break;
  54. }
  55. case 'D': //pos description
  56. readed>>src;
  57. CGI->mh->getObjDescriptions(src);
  58. break;
  59. case 'I':
  60. {
  61. SDL_Surface * temp = LOCPLINT->infoWin(NULL);
  62. blitAtWR(temp,605,389);
  63. break;
  64. }
  65. case 'T': //test rect
  66. readed>>src;
  67. for(int g=0; g<8; ++g)
  68. {
  69. for(int v=0; v<8; ++v)
  70. {
  71. int3 csrc = src;
  72. csrc.y+=g;
  73. csrc.x+=v;
  74. if(CGI->mh->getObjDescriptions(csrc).size())
  75. std::cout<<'x';
  76. else
  77. std::cout<<'o';
  78. }
  79. std::cout<<std::endl;
  80. }
  81. break;
  82. case 'A': //hide everything from map
  83. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  84. {
  85. CGI->mh->hideObject(CGI->objh->objInstances[c]);
  86. }
  87. break;
  88. case 'R': //restora all objects after A has been pressed
  89. for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  90. {
  91. CGI->mh->printObject(CGI->objh->objInstances[c]);
  92. }
  93. break;
  94. }
  95. //SDL_Delay(100);
  96. }
  97. return -1;
  98. }
  99. void CConsoleHandler::runConsole()
  100. {
  101. SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
  102. }