CConsoleHandler.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #include "hch/CLodHandler.h"
  17. #include "boost/filesystem/operations.hpp"
  18. #include <boost/algorithm/string.hpp>
  19. #ifdef WIN32
  20. #include <conio.h>
  21. #else
  22. #endif
  23. bool continueReadingConsole = true;
  24. int internalFunc(void * callback)
  25. {
  26. CCallback * cb = (CCallback*)callback;
  27. char * usersMessage = new char[500];
  28. std::string readed;
  29. while(true)
  30. {
  31. #ifdef WIN32
  32. if(continueReadingConsole && kbhit())
  33. #else
  34. #endif
  35. {
  36. std::cin.getline(usersMessage, 500);
  37. std::istringstream readed;
  38. std::string pom(usersMessage);
  39. readed.str(pom);
  40. std::string cn; //command name
  41. readed >> cn;
  42. int3 src, dst;
  43. int heronum;
  44. int3 dest;
  45. if(pom==std::string("die, fool"))
  46. exit(0);
  47. else if(pom==std::string("get txt"))
  48. {
  49. boost::filesystem::create_directory("Extracted_txts");
  50. std::cout<<"Command accepted. Opening .lod file...\t";
  51. CLodHandler * txth = new CLodHandler;
  52. txth->init(std::string("Data\\H3bitmap.lod"),"data");
  53. std::cout<<"done.\nScanning .lod file\n";
  54. int curp=0;
  55. std::string pattern = ".TXT";
  56. for(int i=0;i<txth->entries.size(); i++)
  57. {
  58. std::string pom = txth->entries[i].nameStr;
  59. if(boost::algorithm::find_last(pom,pattern))
  60. {
  61. txth->extractFile(std::string("Extracted_txts\\")+pom,pom);
  62. }
  63. int p2 = ((float)i/(float)txth->entries.size())*(float)100;
  64. if(p2!=curp)
  65. {
  66. curp = p2;
  67. std::cout<<"\r"<<curp<<"%";
  68. }
  69. }
  70. std::cout<<"\rExtracting done :)\n";
  71. }
  72. vector<Coordinate>* p;
  73. switch (*cn.c_str())
  74. {
  75. //case 'P':
  76. // std::cout<<"Policzyc sciezke."<<std::endl;
  77. // readed>>src>>dst;
  78. //
  79. // p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]);
  80. // LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p);
  81. // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  82. // break;
  83. //case 'm': //number of heroes
  84. // std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  85. // break;
  86. //case 'H': //position of hero
  87. // readed>>heronum;
  88. // std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
  89. // break;
  90. //case 'M': //move heroa
  91. // {
  92. // readed>>heronum>>dest;
  93. // const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
  94. // p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
  95. // cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
  96. // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  97. // break;
  98. // }
  99. //case 'D': //pos description
  100. // readed>>src;
  101. // CGI->mh->getObjDescriptions(src);
  102. // break;
  103. //case 'I':
  104. // {
  105. // SDL_Surface * temp = LOCPLINT->infoWin(NULL);
  106. // blitAtWR(temp,605,389);
  107. // SDL_FreeSurface(temp);
  108. // break;
  109. // }
  110. //case 'T': //test rect
  111. // readed>>src;
  112. // for(int g=0; g<8; ++g)
  113. // {
  114. // for(int v=0; v<8; ++v)
  115. // {
  116. // int3 csrc = src;
  117. // csrc.y+=g;
  118. // csrc.x+=v;
  119. // if(CGI->mh->getObjDescriptions(csrc).size())
  120. // std::cout<<'x';
  121. // else
  122. // std::cout<<'o';
  123. // }
  124. // std::cout<<std::endl;
  125. // }
  126. // break;
  127. //case 'A': //hide everything from map
  128. // for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  129. // {
  130. // CGI->mh->hideObject(CGI->objh->objInstances[c]);
  131. // }
  132. // break;
  133. //case 'R': //restora all objects after A has been pressed
  134. // for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  135. // {
  136. // CGI->mh->printObject(CGI->objh->objInstances[c]);
  137. // }
  138. // break;
  139. }
  140. //SDL_Delay(100);
  141. //delete p;
  142. }
  143. }
  144. return -1;
  145. }
  146. SDL_Thread * consoleReadingThread;
  147. void CConsoleHandler::runConsole()
  148. {
  149. consoleReadingThread = SDL_CreateThread(&internalFunc, cb);
  150. }