CGeneralTextHandler.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. if(i < mines.size())
  228. mines[i++].second = temp;
  229. else
  230. tlog2 << "Warning - too much entries in MINEEVNT. Omitting this one: " << temp << std::endl;
  231. }
  232. tlog5 << "\t\tReading RESTYPES \n";
  233. buf = bitmaph->getTextFile("RESTYPES.TXT");
  234. it=0;
  235. while (it<buf.length()-1)
  236. {
  237. loadToIt(temp,buf,it,3);
  238. restypes.push_back(temp);
  239. }
  240. tlog5 << "\t\tReading ZCRGN1 \n";
  241. buf = bitmaph->getTextFile("ZCRGN1.TXT");
  242. it=0;
  243. while (it<buf.length()-1)
  244. {
  245. loadToIt(temp,buf,it,3);
  246. creGens.push_back(temp);
  247. }
  248. buf = bitmaph->getTextFile("GENRLTXT.TXT");
  249. std::string tmp;
  250. andame = buf.size();
  251. i=0; //buf iterator
  252. for(i; i<andame; ++i)
  253. {
  254. if(buf[i]=='\r')
  255. break;
  256. }
  257. i+=2;
  258. std::string buflet;
  259. for(int jj=0; jj<764; ++jj)
  260. {
  261. loadToIt(buflet, buf, i, 2);
  262. if(buflet[0] == '"' && buflet[buflet.size()-1] == '"')
  263. buflet = buflet.substr(1,buflet.size()-2);
  264. allTexts.push_back(buflet);
  265. }
  266. std::string strs = bitmaph->getTextFile("ARRAYTXT.TXT");
  267. itr=0;
  268. while(itr<strs.length()-1)
  269. {
  270. loadToIt(tmp, strs, itr, 3);
  271. if(tmp[0] == '"' && tmp[tmp.size()-1] == '"')
  272. tmp = tmp.substr(1,tmp.size()-2);
  273. arraytxt.push_back(tmp);
  274. }
  275. itr = 0;
  276. std::string strin = bitmaph->getTextFile("PRISKILL.TXT");
  277. for(int hh=0; hh<4; ++hh)
  278. {
  279. loadToIt(tmp, strin, itr, 3);
  280. primarySkillNames.push_back(tmp);
  281. }
  282. itr = 0;
  283. std::string strin2 = bitmaph->getTextFile("JKTEXT.TXT");
  284. for(int hh=0; hh<45; ++hh)
  285. {
  286. loadToIt(tmp, strin2, itr, 3);
  287. jktexts.push_back(tmp);
  288. }
  289. itr = 0;
  290. std::string strin3 = bitmaph->getTextFile("HEROSCRN.TXT");
  291. for(int hh=0; hh<33; ++hh)
  292. {
  293. loadToIt(tmp, strin3, itr, 3);
  294. heroscrn.push_back(tmp);
  295. }
  296. strin3 = bitmaph->getTextFile("ARTEVENT.TXT");
  297. for(itr = 0; itr<strin3.size();itr++)
  298. {
  299. loadToIt(tmp, strin3, itr, 3);
  300. artifEvents.push_back(tmp);
  301. }
  302. buf = bitmaph->getTextFile("SSTRAITS.TXT");
  303. it=0;
  304. for(int i=0; i<2; ++i)
  305. loadToIt(dump,buf,it,3);
  306. skillName.resize(SKILL_QUANTITY);
  307. skillInfoTexts.resize(SKILL_QUANTITY);
  308. for (int i=0; i<SKILL_QUANTITY; i++)
  309. {
  310. skillInfoTexts[i].resize(3);
  311. loadToIt(skillName[i],buf,it,4);
  312. loadToIt(skillInfoTexts[i][0],buf,it,4);
  313. loadToIt(skillInfoTexts[i][1],buf,it,4);
  314. loadToIt(skillInfoTexts[i][2],buf,it,3);
  315. }
  316. buf = bitmaph->getTextFile("SKILLLEV.TXT");
  317. it=0;
  318. for(int i=0; i<6; ++i)
  319. {
  320. std::string buffo;
  321. loadToIt(buffo,buf,it,3);
  322. levels.push_back(buffo);
  323. }
  324. }
  325. std::string CGeneralTextHandler::getTitle(std::string text)
  326. {
  327. std::string ret;
  328. int i=0;
  329. while ((text[i++]!='{'));
  330. while ((text[i]!='}') && (i<text.length()))
  331. ret+=text[i++];
  332. return ret;
  333. }
  334. std::string CGeneralTextHandler::getDescr(std::string text)
  335. {
  336. std::string ret;
  337. int i=0;
  338. while ((text[i++]!='}'));
  339. i+=2;
  340. while ((text[i]!='"') && (i<text.length()))
  341. ret+=text[i++];
  342. return ret;
  343. }
  344. CGeneralTextHandler::CGeneralTextHandler()
  345. {
  346. }