CPreGameTextHandler.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "../stdafx.h"
  2. #include "CPreGameTextHandler.h"
  3. #include "../CGameInfo.h"
  4. #include "CLodHandler.h"
  5. #include <boost/algorithm/string.hpp>
  6. #include <boost/algorithm/string/replace.hpp>
  7. std::string CPreGameTextHandler::getTitle(std::string text)
  8. {
  9. std::string ret;
  10. int i=0;
  11. while ((text[i++]!='{'));
  12. while ((text[i]!='}') && (i<text.length()))
  13. ret+=text[i++];
  14. return ret;
  15. }
  16. std::string CPreGameTextHandler::getDescr(std::string text)
  17. {
  18. std::string ret;
  19. int i=0;
  20. while ((text[i++]!='}'));
  21. i+=2;
  22. while ((text[i]!='"') && (i<text.length()))
  23. ret+=text[i++];
  24. return ret;
  25. }
  26. void CPreGameTextHandler::loadTexts()
  27. {
  28. std::string buf1 = CGI->bitmaph->getTextFile("ZELP.TXT");
  29. int itr=0, eol=-1, eolnext=-1, pom;
  30. eolnext = buf1.find_first_of('\r',itr);
  31. while(itr<buf1.size())
  32. {
  33. eol = eolnext; //end of this line
  34. eolnext = buf1.find_first_of('\r',eol+1); //end of the next line
  35. pom=buf1.find_first_of('\t',itr); //upcoming tab
  36. if(eol<0 || pom<0)
  37. break;
  38. if(pom>eol) //in current line there is not tab
  39. zelp.push_back(std::pair<std::string,std::string>());
  40. else
  41. {
  42. zelp.push_back
  43. (std::pair<std::string,std::string>
  44. (buf1.substr(itr,pom-itr),
  45. buf1.substr(pom+1,eol-pom-1)));
  46. boost::algorithm::replace_all(zelp[zelp.size()-1].first,"\t","");
  47. boost::algorithm::replace_all(zelp[zelp.size()-1].second,"\t","");
  48. }
  49. itr=eol+2;
  50. }
  51. std::string buf = CGI->bitmaph->getTextFile("VCDESC.TXT");
  52. int andame = buf.size();
  53. int i=0; //buf iterator
  54. for(int gg=0; gg<14; ++gg)
  55. {
  56. int befi=i;
  57. for(i; i<andame; ++i)
  58. {
  59. if(buf[i]=='\r')
  60. break;
  61. }
  62. victoryConditions[gg] = buf.substr(befi, i-befi);
  63. i+=2;
  64. }
  65. buf = CGI->bitmaph->getTextFile("LCDESC.TXT");
  66. andame = buf.size();
  67. i=0; //buf iterator
  68. for(int gg=0; gg<4; ++gg)
  69. {
  70. int befi=i;
  71. for(i; i<andame; ++i)
  72. {
  73. if(buf[i]=='\r')
  74. break;
  75. }
  76. lossCondtions[gg] = buf.substr(befi, i-befi);
  77. i+=2;
  78. }
  79. }