CConsoleHandler.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 CHeroInstance * 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. }
  81. //SDL_Delay(100);
  82. }
  83. return -1;
  84. }
  85. void CConsoleHandler::runConsole()
  86. {
  87. SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
  88. }