CHeroHandler.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CHeroHandler.h"
  4. #include <sstream>
  5. #include "CLodHandler.h"
  6. extern CLodHandler * bitmaph;
  7. void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
  8. CHeroHandler::~CHeroHandler()
  9. {}
  10. void CHeroHandler::loadPortraits()
  11. {
  12. std::string strs = bitmaph->getTextFile("PRISKILL.TXT");
  13. int itr=0;
  14. for (int i=0; i<PRIMARY_SKILLS; i++)
  15. {
  16. std::string tmp;
  17. loadToIt(tmp, strs, itr, 3);
  18. pskillsn.push_back(tmp);
  19. }
  20. }
  21. void CHeroHandler::loadHeroes()
  22. {
  23. int ID=0;
  24. std::string buf = bitmaph->getTextFile("HOTRAITS.TXT");
  25. int it=0;
  26. std::string dump;
  27. for(int i=0; i<2; ++i)
  28. {
  29. loadToIt(dump,buf,it,3);
  30. }
  31. int numberOfCurrentClassHeroes = 0;
  32. int currentClass = 0;
  33. int additHero = 0;
  34. EHeroClasses addTab[12];
  35. addTab[0] = HERO_KNIGHT;
  36. addTab[1] = HERO_WITCH;
  37. addTab[2] = HERO_KNIGHT;
  38. addTab[3] = HERO_WIZARD;
  39. addTab[4] = HERO_RANGER;
  40. addTab[5] = HERO_BARBARIAN;
  41. addTab[6] = HERO_DEATHKNIGHT;
  42. addTab[7] = HERO_WARLOCK;
  43. addTab[8] = HERO_KNIGHT;
  44. addTab[9] = HERO_WARLOCK;
  45. addTab[10] = HERO_BARBARIAN;
  46. addTab[11] = HERO_DEMONIAC;
  47. for (int i=0; i<HEROES_QUANTITY; i++)
  48. {
  49. CHero * nher = new CHero;
  50. if(currentClass<18)
  51. {
  52. nher->heroType = (EHeroClasses)currentClass;
  53. ++numberOfCurrentClassHeroes;
  54. if(numberOfCurrentClassHeroes==8)
  55. {
  56. numberOfCurrentClassHeroes = 0;
  57. ++currentClass;
  58. }
  59. }
  60. else
  61. {
  62. nher->heroType = addTab[additHero++];
  63. }
  64. std::string pom ;
  65. loadToIt(nher->name,buf,it,4);
  66. for(int x=0;x<3;x++)
  67. {
  68. loadToIt(pom,buf,it,4);
  69. nher->lowStack[x] = atoi(pom.c_str());
  70. loadToIt(pom,buf,it,4);
  71. nher->highStack[x] = atoi(pom.c_str());
  72. loadToIt(nher->refTypeStack[x],buf,it,(x==2) ? (3) : (4));
  73. int hlp = nher->refTypeStack[x].find_first_of(' ',0);
  74. if(hlp>=0)
  75. nher->refTypeStack[x].replace(hlp,1,"");
  76. }
  77. nher->ID = heroes.size();
  78. heroes.push_back(nher);
  79. }
  80. loadSpecialAbilities();
  81. loadBiographies();
  82. loadHeroClasses();
  83. initHeroClasses();
  84. expPerLevel.push_back(0);
  85. expPerLevel.push_back(1000);
  86. expPerLevel.push_back(2000);
  87. expPerLevel.push_back(3200);
  88. expPerLevel.push_back(4500);
  89. expPerLevel.push_back(6000);
  90. expPerLevel.push_back(7700);
  91. expPerLevel.push_back(9000);
  92. expPerLevel.push_back(11000);
  93. expPerLevel.push_back(13200);
  94. expPerLevel.push_back(15500);
  95. expPerLevel.push_back(18500);
  96. expPerLevel.push_back(22100);
  97. expPerLevel.push_back(26420);
  98. expPerLevel.push_back(31604);
  99. return;
  100. }
  101. void CHeroHandler::loadSpecialAbilities()
  102. {
  103. std::string buf = bitmaph->getTextFile("HEROSPEC.TXT");
  104. int it=0;
  105. std::string dump;
  106. for(int i=0; i<2; ++i)
  107. {
  108. loadToIt(dump,buf,it,3);
  109. }
  110. for (int i=0;i<heroes.size();i++)
  111. {
  112. loadToIt(heroes[i]->bonusName,buf,it,4);
  113. loadToIt(heroes[i]->shortBonus,buf,it,4);
  114. loadToIt(heroes[i]->longBonus,buf,it,3);
  115. }
  116. }
  117. void CHeroHandler::loadBiographies()
  118. {
  119. std::string buf = bitmaph->getTextFile("HEROBIOS.TXT");
  120. int it=0;
  121. for (int i=0;i<heroes.size();i++)
  122. {
  123. loadToIt(heroes[i]->biography,buf,it,3);
  124. }
  125. }
  126. void CHeroHandler::loadHeroClasses()
  127. {
  128. std::string buf = bitmaph->getTextFile("HCTRAITS.TXT");
  129. int andame = buf.size();
  130. for(int y=0; y<andame; ++y)
  131. if(buf[y]==',')
  132. buf[y]='.';
  133. int i = 0; //buf iterator
  134. int hmcr = 0;
  135. for(i; i<andame; ++i) //omitting rubbish
  136. {
  137. if(buf[i]=='\r')
  138. ++hmcr;
  139. if(hmcr==2)
  140. break;
  141. }
  142. i+=2;
  143. for(int ss=0; ss<18; ++ss) //18 classes of hero (including conflux)
  144. {
  145. CHeroClass * hc = new CHeroClass;
  146. int befi=i;
  147. for(i; i<andame; ++i)
  148. {
  149. if(buf[i]=='\t')
  150. break;
  151. }
  152. hc->name = buf.substr(befi, i-befi);
  153. ++i;
  154. befi=i;
  155. for(i; i<andame; ++i)
  156. {
  157. if(buf[i]=='\t')
  158. break;
  159. }
  160. hc->aggression = atof(buf.substr(befi, i-befi).c_str());
  161. ++i;
  162. befi=i;
  163. for(i; i<andame; ++i)
  164. {
  165. if(buf[i]=='\t')
  166. break;
  167. }
  168. hc->initialAttack = atoi(buf.substr(befi, i-befi).c_str());
  169. ++i;
  170. befi=i;
  171. for(i; i<andame; ++i)
  172. {
  173. if(buf[i]=='\t')
  174. break;
  175. }
  176. hc->initialDefence = atoi(buf.substr(befi, i-befi).c_str());
  177. ++i;
  178. befi=i;
  179. for(i; i<andame; ++i)
  180. {
  181. if(buf[i]=='\t')
  182. break;
  183. }
  184. hc->initialPower = atoi(buf.substr(befi, i-befi).c_str());
  185. ++i;
  186. befi=i;
  187. for(i; i<andame; ++i)
  188. {
  189. if(buf[i]=='\t')
  190. break;
  191. }
  192. hc->initialKnowledge = atoi(buf.substr(befi, i-befi).c_str());
  193. ++i;
  194. hc->primChance.resize(PRIMARY_SKILLS);
  195. for(int x=0;x<PRIMARY_SKILLS;x++)
  196. {
  197. befi=i;
  198. for(i; i<andame; ++i)
  199. {
  200. if(buf[i]=='\t')
  201. break;
  202. }
  203. hc->primChance[x].first = atoi(buf.substr(befi, i-befi).c_str());
  204. ++i;
  205. }
  206. for(int x=0;x<PRIMARY_SKILLS;x++)
  207. {
  208. befi=i;
  209. for(i; i<andame; ++i)
  210. {
  211. if(buf[i]=='\t')
  212. break;
  213. }
  214. hc->primChance[x].second = atoi(buf.substr(befi, i-befi).c_str());
  215. ++i;
  216. }
  217. //CHero kkk = heroes[0];
  218. for(int dd=0; dd<SKILL_QUANTITY; ++dd)
  219. {
  220. befi=i;
  221. for(i; i<andame; ++i)
  222. {
  223. if(buf[i]=='\t')
  224. break;
  225. }
  226. int buff = atoi(buf.substr(befi, i-befi).c_str());
  227. ++i;
  228. hc->proSec.push_back(buff);
  229. }
  230. for(int dd=0; dd<9; ++dd)
  231. {
  232. befi=i;
  233. for(i; i<andame; ++i)
  234. {
  235. if(buf[i]=='\t' || buf[i]=='\r')
  236. break;
  237. }
  238. hc->selectionProbability[dd] = atoi(buf.substr(befi, i-befi).c_str());
  239. ++i;
  240. }
  241. ++i;
  242. heroClasses.push_back(hc);
  243. }
  244. }
  245. void CHeroHandler::initHeroClasses()
  246. {
  247. for(int gg=0; gg<heroes.size(); ++gg)
  248. {
  249. heroes[gg]->heroClass = heroClasses[heroes[gg]->heroType];
  250. }
  251. initTerrainCosts();
  252. }
  253. unsigned int CHeroHandler::level(unsigned int experience)
  254. {
  255. int add=0;
  256. while(experience>=expPerLevel[expPerLevel.size()-1])
  257. {
  258. experience/=1.2;
  259. add+=1;
  260. }
  261. for(int i=expPerLevel.size()-1; i>=0; --i)
  262. {
  263. if(experience>=expPerLevel[i])
  264. return i+add;
  265. }
  266. return -1;
  267. }
  268. unsigned int CHeroHandler::reqExp(unsigned int level)
  269. {
  270. level-=1;
  271. if(level<=expPerLevel.size())
  272. return expPerLevel[level];
  273. else
  274. {
  275. unsigned int exp = expPerLevel[expPerLevel.size()-1];
  276. level-=expPerLevel.size();
  277. while(level>0)
  278. {
  279. --level;
  280. exp*=1.2;
  281. }
  282. }
  283. return -1;
  284. }
  285. void CHeroHandler::initTerrainCosts()
  286. {
  287. std::ifstream inp;
  288. inp.open("config\\TERCOSTS.TXT", std::ios_base::in|std::ios_base::binary);
  289. int tynum;
  290. inp>>tynum;
  291. for(int i=0; i<2*tynum; i+=2)
  292. {
  293. int catNum;
  294. inp>>catNum;
  295. for(int k=0; k<catNum; ++k)
  296. {
  297. int curCost;
  298. inp>>curCost;
  299. heroClasses[i]->terrCosts.push_back(curCost);
  300. heroClasses[i+1]->terrCosts.push_back(curCost);
  301. }
  302. }
  303. inp.close();
  304. }