CConsoleHandler.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_DIR "Data" PATHSEPARATOR "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. int heroX;
  74. int heroY;
  75. int heroZ;
  76. switch (*cn.c_str())
  77. {
  78. //case 'P':
  79. // std::cout<<"Policzyc sciezke."<<std::endl;
  80. // readed>>src>>dst;
  81. //
  82. // p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]);
  83. // LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p);
  84. // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  85. // break;
  86. //case 'm': //number of heroes
  87. // std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
  88. // break;
  89. //case 'H': //position of hero
  90. // readed>>heronum;
  91. // std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
  92. // break;
  93. //case 'M': //move heroa
  94. // {
  95. // readed>>heronum>>dest;
  96. // const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
  97. // p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
  98. // cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
  99. // //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
  100. // break;
  101. // }
  102. //case 'D': //pos description
  103. // readed>>src;
  104. // CGI->mh->getObjDescriptions(src);
  105. // break;
  106. //case 'I':
  107. // {
  108. // SDL_Surface * temp = LOCPLINT->infoWin(NULL);
  109. // blitAtWR(temp,605,389);
  110. // SDL_FreeSurface(temp);
  111. // break;
  112. // }
  113. //case 'T': //test rect
  114. // readed>>src;
  115. // for(int g=0; g<8; ++g)
  116. // {
  117. // for(int v=0; v<8; ++v)
  118. // {
  119. // int3 csrc = src;
  120. // csrc.y+=g;
  121. // csrc.x+=v;
  122. // if(CGI->mh->getObjDescriptions(csrc).size())
  123. // std::cout<<'x';
  124. // else
  125. // std::cout<<'o';
  126. // }
  127. // std::cout<<std::endl;
  128. // }
  129. // break;
  130. //case 'A': //hide everything from map
  131. // for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  132. // {
  133. // CGI->mh->hideObject(CGI->objh->objInstances[c]);
  134. // }
  135. // break;
  136. //case 'R': //restora all objects after A has been pressed
  137. // for(int c=0; c<CGI->objh->objInstances.size(); ++c)
  138. // {
  139. // CGI->mh->printObject(CGI->objh->objInstances[c]);
  140. // }
  141. // break;
  142. }
  143. //SDL_Delay(100);
  144. //delete p;
  145. }
  146. SDL_Delay(10);
  147. }
  148. return -1;
  149. }
  150. SDL_Thread * consoleReadingThread;
  151. void CConsoleHandler::runConsole()
  152. {
  153. consoleReadingThread = SDL_CreateThread(&internalFunc, cb);
  154. }