CHeroHandler.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "stdafx.h"
  2. #include "CHeroHandler.h"
  3. void CHeroHandler::loadHeroes()
  4. {
  5. std::ifstream inp("H3bitmap.lod\\HOTRAITS.TXT", std::ios::in);
  6. std::string dump;
  7. for(int i=0; i<25; ++i)
  8. {
  9. inp>>dump;
  10. }
  11. inp.ignore();
  12. while(!inp.eof())
  13. {
  14. CHero nher;
  15. std::string base;
  16. char * tab = new char[500];
  17. int iit = 0;
  18. inp.getline(tab, 500);
  19. base = std::string(tab);
  20. if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
  21. {
  22. loadSpecialAbilities();
  23. loadBiographies();
  24. return;
  25. }
  26. while(base[iit]!='\t')
  27. {
  28. ++iit;
  29. }
  30. nher.name = base.substr(0, iit);
  31. ++iit;
  32. for(int i=iit; i<iit+100; ++i)
  33. {
  34. if(base[i]==(char)(10) || base[i]==(char)(9))
  35. {
  36. nher.low1stack = atoi(base.substr(iit, i).c_str());
  37. iit=i+1;
  38. break;
  39. }
  40. }
  41. for(int i=iit; i<iit+100; ++i)
  42. {
  43. if(base[i]==(char)(10) || base[i]==(char)(9))
  44. {
  45. nher.high1stack = atoi(base.substr(iit, i).c_str());
  46. iit=i+1;
  47. break;
  48. }
  49. }
  50. int ipom=iit;
  51. while(base[ipom]!='\t')
  52. {
  53. ++ipom;
  54. }
  55. nher.refType1stack = base.substr(iit, ipom-iit);
  56. iit=ipom+1;
  57. for(int i=iit; i<iit+100; ++i)
  58. {
  59. if(base[i]==(char)(10) || base[i]==(char)(9))
  60. {
  61. nher.low2stack = atoi(base.substr(iit, i-iit).c_str());
  62. iit=i+1;
  63. break;
  64. }
  65. }
  66. for(int i=iit; i<iit+100; ++i)
  67. {
  68. if(base[i]==(char)(10) || base[i]==(char)(9))
  69. {
  70. nher.high2stack = atoi(base.substr(iit, i-iit).c_str());
  71. iit=i+1;
  72. break;
  73. }
  74. }
  75. ipom=iit;
  76. while(base[ipom]!='\t')
  77. {
  78. ++ipom;
  79. }
  80. nher.refType2stack = base.substr(iit, ipom-iit);
  81. iit=ipom+1;
  82. for(int i=iit; i<iit+100; ++i)
  83. {
  84. if(base[i]==(char)(10) || base[i]==(char)(9))
  85. {
  86. nher.low3stack = atoi(base.substr(iit, i-iit).c_str());
  87. iit=i+1;
  88. break;
  89. }
  90. }
  91. for(int i=iit; i<iit+100; ++i)
  92. {
  93. if(base[i]==(char)(10) || base[i]==(char)(9))
  94. {
  95. nher.high3stack = atoi(base.substr(iit, i-iit).c_str());
  96. iit=i+1;
  97. break;
  98. }
  99. }
  100. nher.refType3stack = base.substr(iit, base.size()-iit);
  101. heroes.push_back(nher);
  102. delete[500] tab;
  103. }
  104. loadSpecialAbilities();
  105. }
  106. void CHeroHandler::loadSpecialAbilities()
  107. {
  108. std::ifstream inp("H3bitmap.lod\\HEROSPEC.txt", std::ios::in);
  109. std::string dump;
  110. for(int i=0; i<7; ++i)
  111. {
  112. inp>>dump;
  113. }
  114. inp.ignore();
  115. int whHero=0;
  116. while(!inp.eof() && whHero<heroes.size())
  117. {
  118. std::string base;
  119. char * tab = new char[500];
  120. int iitBef = 0;
  121. int iit = 0;
  122. inp.getline(tab, 500);
  123. base = std::string(tab);
  124. if(base.size()<2) //ended, but some rubbish could still stay end we have something useless
  125. {
  126. return; //add counter
  127. }
  128. while(base[iit]!='\t')
  129. {
  130. ++iit;
  131. }
  132. heroes[whHero].bonusName = base.substr(0, iit);
  133. ++iit;
  134. iitBef=iit;
  135. if(heroes[whHero].bonusName == std::string("Ogry"))
  136. {
  137. char * tab2 = new char[500];
  138. inp.getline(tab2, 500);
  139. base += std::string(tab2);
  140. delete [500] tab2;
  141. }
  142. while(base[iit]!='\t')
  143. {
  144. ++iit;
  145. }
  146. heroes[whHero].shortBonus = base.substr(iitBef, iit-iitBef);
  147. ++iit;
  148. iitBef=iit;
  149. while(base[iit]!='\t' && iit<base.size())
  150. {
  151. ++iit;
  152. }
  153. heroes[whHero].longBonus = base.substr(iitBef, iit-iitBef);
  154. ++whHero;
  155. delete [500] tab;
  156. }
  157. }
  158. void CHeroHandler::loadBiographies()
  159. {
  160. std::ifstream inp("H3bitmap.lod\\HEROBIOS.TXT", std::ios::in | std::ios::binary);
  161. inp.seekg(0,std::ios::end); // na koniec
  162. int andame = inp.tellg(); // read length
  163. inp.seekg(0,std::ios::beg); // wracamy na poczatek
  164. char * bufor = new char[andame]; // allocate memory
  165. inp.read((char*)bufor, andame); // read map file to buffer
  166. std::string buf = std::string(bufor);
  167. delete [andame] bufor;
  168. int i = 0; //buf iterator
  169. for(int q=0; q<heroes.size(); ++q)
  170. {
  171. int befi=i;
  172. for(i; i<andame; ++i)
  173. {
  174. if(buf[i]=='\r')
  175. break;
  176. }
  177. heroes[q].biography = buf.substr(befi, i-befi);
  178. i+=2;
  179. }
  180. }