CGeneralTextHandler.cpp 8.8 KB

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