CGeneralTextHandler.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "../lib/VCMI_Lib.h"
  4. #include "CGeneralTextHandler.h"
  5. #include "CLodHandler.h"
  6. #include <boost/algorithm/string.hpp>
  7. #include <boost/algorithm/string/replace.hpp>
  8. #include <fstream>
  9. #include <sstream>
  10. std::string readTo(std::string &in, int &it, char end)
  11. {
  12. int pom = it;
  13. int last = in.find_first_of(end,it);
  14. it+=(1+last-it);
  15. return in.substr(pom,last-pom);
  16. }
  17. void CGeneralTextHandler::load()
  18. {
  19. std::string buf = bitmaph->getTextFile("GENRLTXT.TXT"), tmp;
  20. int andame = buf.size();
  21. int i=0; //buf iterator
  22. for(i; i<andame; ++i)
  23. {
  24. if(buf[i]=='\r')
  25. break;
  26. }
  27. i+=2;
  28. std::string buflet;
  29. for(int jj=0; jj<764; ++jj)
  30. {
  31. loadToIt(buflet, buf, i, 2);
  32. if(buflet[0] == '"' && buflet[buflet.size()-1] == '"')
  33. buflet = buflet.substr(1,buflet.size()-2);
  34. allTexts.push_back(buflet);
  35. }
  36. std::string strs = bitmaph->getTextFile("ARRAYTXT.TXT");
  37. int itr=0;
  38. while(itr<strs.length()-1)
  39. {
  40. loadToIt(tmp, strs, itr, 3);
  41. arraytxt.push_back(tmp);
  42. }
  43. itr = 0;
  44. std::string strin = bitmaph->getTextFile("PRISKILL.TXT");
  45. for(int hh=0; hh<4; ++hh)
  46. {
  47. loadToIt(tmp, strin, itr, 3);
  48. primarySkillNames.push_back(tmp);
  49. }
  50. itr = 0;
  51. std::string strin2 = bitmaph->getTextFile("JKTEXT.TXT");
  52. for(int hh=0; hh<45; ++hh)
  53. {
  54. loadToIt(tmp, strin2, itr, 3);
  55. jktexts.push_back(tmp);
  56. }
  57. itr = 0;
  58. std::string strin3 = bitmaph->getTextFile("HEROSCRN.TXT");
  59. for(int hh=0; hh<33; ++hh)
  60. {
  61. loadToIt(tmp, strin3, itr, 3);
  62. heroscrn.push_back(tmp);
  63. }
  64. strin3 = bitmaph->getTextFile("ARTEVENT.TXT");
  65. for(itr = 0; itr<strin3.size();itr++)
  66. {
  67. loadToIt(tmp, strin3, itr, 3);
  68. artifEvents.push_back(tmp);
  69. }
  70. }
  71. std::string CGeneralTextHandler::getTitle(std::string text)
  72. {
  73. std::string ret;
  74. int i=0;
  75. while ((text[i++]!='{'));
  76. while ((text[i]!='}') && (i<text.length()))
  77. ret+=text[i++];
  78. return ret;
  79. }
  80. std::string CGeneralTextHandler::getDescr(std::string text)
  81. {
  82. std::string ret;
  83. int i=0;
  84. while ((text[i++]!='}'));
  85. i+=2;
  86. while ((text[i]!='"') && (i<text.length()))
  87. ret+=text[i++];
  88. return ret;
  89. }
  90. void CGeneralTextHandler::loadTexts()
  91. {
  92. std::string buf1 = bitmaph->getTextFile("ZELP.TXT");
  93. int itr=0, eol=-1, eolnext=-1, pom;
  94. eolnext = buf1.find_first_of('\r',itr);
  95. while(itr<buf1.size())
  96. {
  97. eol = eolnext; //end of this line
  98. eolnext = buf1.find_first_of('\r',eol+1); //end of the next line
  99. pom=buf1.find_first_of('\t',itr); //upcoming tab
  100. if(eol<0 || pom<0)
  101. break;
  102. if(pom>eol) //in current line there is not tab
  103. zelp.push_back(std::pair<std::string,std::string>());
  104. else
  105. {
  106. zelp.push_back
  107. (std::pair<std::string,std::string>
  108. (buf1.substr(itr,pom-itr),
  109. buf1.substr(pom+1,eol-pom-1)));
  110. boost::algorithm::replace_all(zelp[zelp.size()-1].first,"\t","");
  111. boost::algorithm::replace_all(zelp[zelp.size()-1].second,"\t","");
  112. }
  113. itr=eol+2;
  114. }
  115. std::string buf = bitmaph->getTextFile("VCDESC.TXT");
  116. int andame = buf.size();
  117. int i=0; //buf iterator
  118. for(int gg=0; gg<14; ++gg)
  119. {
  120. int befi=i;
  121. for(i; i<andame; ++i)
  122. {
  123. if(buf[i]=='\r')
  124. break;
  125. }
  126. victoryConditions[gg] = buf.substr(befi, i-befi);
  127. i+=2;
  128. }
  129. buf = bitmaph->getTextFile("LCDESC.TXT");
  130. andame = buf.size();
  131. i=0; //buf iterator
  132. for(int gg=0; gg<4; ++gg)
  133. {
  134. int befi=i;
  135. for(i; i<andame; ++i)
  136. {
  137. if(buf[i]=='\r')
  138. break;
  139. }
  140. lossCondtions[gg] = buf.substr(befi, i-befi);
  141. i+=2;
  142. }
  143. hTxts.resize(HEROES_QUANTITY);
  144. buf = bitmaph->getTextFile("HEROSPEC.TXT");
  145. i=0;
  146. std::string dump;
  147. for(int iii=0; iii<2; ++iii)
  148. {
  149. loadToIt(dump,buf,i,3);
  150. }
  151. for (int iii=0;iii<hTxts.size();iii++)
  152. {
  153. loadToIt(hTxts[iii].bonusName,buf,i,4);
  154. loadToIt(hTxts[iii].shortBonus,buf,i,4);
  155. loadToIt(hTxts[iii].longBonus,buf,i,3);
  156. }
  157. buf = bitmaph->getTextFile("HEROBIOS.TXT");
  158. i=0;
  159. for (int iii=0;iii<hTxts.size();iii++)
  160. {
  161. loadToIt(hTxts[iii].biography,buf,i,3);
  162. }
  163. int it;
  164. buf = bitmaph->getTextFile("BLDGNEUT.TXT");
  165. andame = buf.size(), it=0;
  166. for(int b=0;b<15;b++)
  167. {
  168. std::string name = readTo(buf,it,'\t'),
  169. description = readTo(buf,it,'\n');
  170. for(int fi=0;fi<F_NUMBER;fi++)
  171. {
  172. buildings[fi][b].first = name;
  173. buildings[fi][b].second = description;
  174. }
  175. }
  176. buf1 = readTo(buf,it,'\n');buf1 = readTo(buf,it,'\n');buf1 = readTo(buf,it,'\n');//silo,blacksmith,moat - useless???
  177. //shipyard with the ship
  178. std::string name = readTo(buf,it,'\t'),
  179. description = readTo(buf,it,'\n');
  180. for(int fi=0;fi<F_NUMBER;fi++)
  181. {
  182. buildings[fi][20].first = name;
  183. buildings[fi][20].second = description;
  184. }
  185. for(int fi=0;fi<F_NUMBER;fi++)
  186. {
  187. buildings[fi][16].first = readTo(buf,it,'\t'),
  188. buildings[fi][16].second = readTo(buf,it,'\n');
  189. }
  190. /////done reading "BLDGNEUT.TXT"******************************
  191. buf = bitmaph->getTextFile("BLDGSPEC.TXT");
  192. andame = buf.size(), it=0;
  193. for(int f=0;f<F_NUMBER;f++)
  194. {
  195. for(int b=0;b<9;b++)
  196. {
  197. buildings[f][17+b].first = readTo(buf,it,'\t');
  198. buildings[f][17+b].second = readTo(buf,it,'\n');
  199. }
  200. buildings[f][26].first = readTo(buf,it,'\t');
  201. buildings[f][26].second = readTo(buf,it,'\n');
  202. buildings[f][15].first = readTo(buf,it,'\t'); //resource silo
  203. buildings[f][15].second = readTo(buf,it,'\n');//resource silo
  204. }
  205. /////done reading BLDGSPEC.TXT*********************************
  206. buf = bitmaph->getTextFile("DWELLING.TXT");
  207. andame = buf.size(), it=0;
  208. for(int f=0;f<F_NUMBER;f++)
  209. {
  210. for(int b=0;b<14;b++)
  211. {
  212. buildings[f][30+b].first = readTo(buf,it,'\t');
  213. buildings[f][30+b].second = readTo(buf,it,'\n');
  214. }
  215. }
  216. buf = bitmaph->getTextFile("TCOMMAND.TXT");
  217. itr=0;
  218. while(itr<buf.length()-1)
  219. {
  220. std::string tmp;
  221. loadToIt(tmp, buf, itr, 3);
  222. tcommands.push_back(tmp);
  223. }
  224. buf = bitmaph->getTextFile("HALLINFO.TXT");
  225. itr=0;
  226. while(itr<buf.length()-1)
  227. {
  228. std::string tmp;
  229. loadToIt(tmp, buf, itr, 3);
  230. hcommands.push_back(tmp);
  231. }
  232. std::istringstream ins, namess;
  233. ins.str(bitmaph->getTextFile("TOWNTYPE.TXT"));
  234. namess.str(bitmaph->getTextFile("TOWNNAME.TXT"));
  235. int si=0;
  236. char bufname[75];
  237. while (!ins.eof())
  238. {
  239. ins.getline(bufname,50);
  240. townTypes.push_back(std::string(bufname).substr(0,strlen(bufname)-1));
  241. townNames.resize(si+1);
  242. for (int i=0; i<NAMES_PER_TOWN; i++)
  243. {
  244. namess.getline(bufname,50);
  245. townNames[si].push_back(std::string(bufname).substr(0,strlen(bufname)-1));
  246. }
  247. si++;
  248. }
  249. tlog5 << "\t\tReading OBJNAMES \n";
  250. buf = bitmaph->getTextFile("OBJNAMES.TXT");
  251. it=0; //hope that -1 will not break this
  252. while (it<buf.length()-1)
  253. {
  254. std::string nobj;
  255. loadToIt(nobj, buf, it, 3);
  256. if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9))
  257. {
  258. nobj = nobj.substr(0, nobj.size()-1);
  259. }
  260. names.push_back(nobj);
  261. }
  262. tlog5 << "\t\tReading ADVEVENT \n";
  263. buf = bitmaph->getTextFile("ADVEVENT.TXT");
  264. it=0;
  265. std::string temp;
  266. while (it<buf.length()-1)
  267. {
  268. loadToIt(temp,buf,it,3);
  269. if (temp[0]=='\"')
  270. {
  271. temp = temp.substr(1,temp.length()-2);
  272. }
  273. boost::algorithm::replace_all(temp,"\"\"","\"");
  274. advobtxt.push_back(temp);
  275. }
  276. tlog5 << "\t\tReading XTRAINFO \n";
  277. buf = bitmaph->getTextFile("XTRAINFO.TXT");
  278. it=0;
  279. while (it<buf.length()-1)
  280. {
  281. loadToIt(temp,buf,it,3);
  282. xtrainfo.push_back(temp);
  283. }
  284. tlog5 << "\t\tReading MINENAME \n";
  285. buf = bitmaph->getTextFile("MINENAME.TXT");
  286. it=0;
  287. while (it<buf.length()-1)
  288. {
  289. loadToIt(temp,buf,it,3);
  290. mines.push_back(std::pair<std::string,std::string>(temp,""));
  291. }
  292. tlog5 << "\t\tReading MINEEVNT \n";
  293. buf = bitmaph->getTextFile("MINEEVNT.TXT");
  294. it=0;
  295. i=0;
  296. while (it<buf.length()-1)
  297. {
  298. loadToIt(temp,buf,it,3);
  299. temp = temp.substr(1,temp.length()-2);
  300. mines[i++].second = temp;
  301. }
  302. tlog5 << "\t\tReading RESTYPES \n";
  303. buf = bitmaph->getTextFile("RESTYPES.TXT");
  304. it=0;
  305. while (it<buf.length()-1)
  306. {
  307. loadToIt(temp,buf,it,3);
  308. restypes.push_back(temp);
  309. }
  310. tlog5 << "\t\tReading ZCRGN1 \n";
  311. buf = bitmaph->getTextFile("ZCRGN1.TXT");
  312. it=0;
  313. while (it<buf.length()-1)
  314. {
  315. loadToIt(temp,buf,it,3);
  316. creGens.push_back(temp);
  317. }
  318. }