CCreatureHandler.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CCreatureHandler.h"
  4. #include "CLodHandler.h"
  5. #include <sstream>
  6. #include <boost/assign/std/set.hpp>
  7. #include <boost/assign/std/vector.hpp>
  8. #include <boost/assign/std/list.hpp>
  9. #include <boost/assign/list_of.hpp>
  10. #include <boost/algorithm/string.hpp>
  11. #include <boost/algorithm/string/find.hpp>
  12. #include <boost/algorithm/string/replace.hpp>
  13. #include "../lib/VCMI_Lib.h"
  14. #include "../lib/CGameState.h"
  15. using namespace boost::assign;
  16. extern CLodHandler * bitmaph;
  17. /*
  18. * CCreatureHandler.cpp, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. static std::vector<int> getMindSpells()
  27. {
  28. std::vector<int> ret;
  29. ret.push_back(50); //sorrow
  30. ret.push_back(59); //berserk
  31. ret.push_back(60); //hypnotize
  32. ret.push_back(61); //forgetfulness
  33. ret.push_back(62); //blind
  34. return ret;
  35. }
  36. CCreatureHandler::CCreatureHandler()
  37. {
  38. VLC->creh = this;
  39. // Set the faction alignments to the defaults:
  40. // Good: Castle, Rampart, Tower // Evil: Inferno, Necropolis, Dungeon
  41. // Neutral: Stronghold, Fortess, Conflux
  42. factionAlignments += 1, 1, 1, -1, -1, -1, 0, 0, 0;
  43. }
  44. int CCreature::getQuantityID(const int & quantity)
  45. {
  46. if (quantity<5)
  47. return 0;
  48. if (quantity<10)
  49. return 1;
  50. if (quantity<20)
  51. return 2;
  52. if (quantity<50)
  53. return 3;
  54. if (quantity<100)
  55. return 4;
  56. if (quantity<250)
  57. return 5;
  58. if (quantity<500)
  59. return 5;
  60. if (quantity<1000)
  61. return 6;
  62. if (quantity<4000)
  63. return 7;
  64. return 8;
  65. }
  66. bool CCreature::isDoubleWide() const
  67. {
  68. return doubleWide;
  69. }
  70. bool CCreature::isFlying() const
  71. {
  72. return vstd::contains(bonuses, Bonus::FLYING);
  73. }
  74. bool CCreature::isShooting() const
  75. {
  76. return vstd::contains(bonuses, Bonus::SHOOTER);
  77. }
  78. bool CCreature::isUndead() const
  79. {
  80. return vstd::contains(bonuses, Bonus::UNDEAD);
  81. }
  82. /**
  83. * Determines if the creature is of a good alignment.
  84. * @return true if the creture is good, false otherwise.
  85. */
  86. bool CCreature::isGood () const
  87. {
  88. return VLC->creh->isGood(faction);
  89. }
  90. /**
  91. * Determines if the creature is of an evil alignment.
  92. * @return true if the creature is evil, false otherwise.
  93. */
  94. bool CCreature::isEvil () const
  95. {
  96. return VLC->creh->isEvil(faction);
  97. }
  98. si32 CCreature::maxAmount(const std::vector<si32> &res) const //how many creatures can be bought
  99. {
  100. int ret = 2147483645;
  101. int resAmnt = std::min(res.size(),cost.size());
  102. for(int i=0;i<resAmnt;i++)
  103. if(cost[i])
  104. ret = std::min(ret,(int)(res[i]/cost[i]));
  105. return ret;
  106. }
  107. CCreature::CCreature()
  108. {
  109. doubleWide = false;
  110. nodeType = CBonusSystemNode::CREATURE;
  111. }
  112. ui32 CCreature::getMinDamage() const
  113. {
  114. return damageMin + valOfBonuses(Bonus::CREATURE_DAMAGE, 0) + valOfBonuses(Bonus::CREATURE_DAMAGE, 1);
  115. }
  116. ui32 CCreature::getMaxDamage() const
  117. {
  118. return damageMax + valOfBonuses(Bonus::CREATURE_DAMAGE, 0) + valOfBonuses(Bonus::CREATURE_DAMAGE, 2);
  119. }
  120. void CCreature::addBonus(int val, int type, int subtype /*= -1*/)
  121. {
  122. Bonus added(Bonus::PERMANENT, type, Bonus::CREATURE_ABILITY, val, idNumber, subtype, Bonus::BASE_NUMBER);
  123. bonuses.push_back(added);
  124. }
  125. void CCreature::getParents(TCNodes &out, const CBonusSystemNode *root /*= NULL*/) const
  126. {
  127. out.insert (VLC->creh->globalEffects);
  128. }
  129. bool CCreature::isMyUpgrade(const CCreature *anotherCre) const
  130. {
  131. //TODO upgrade of upgrade?
  132. return vstd::contains(upgrades, anotherCre->idNumber);
  133. }
  134. int readNumber(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadCreatures() and loadUnitAnimInfo()
  135. {
  136. befi=i;
  137. for(i; i<andame; ++i)
  138. {
  139. if(buf[i]=='\t')
  140. break;
  141. }
  142. std::string tmp = buf.substr(befi, i-befi);
  143. int ret = atoi(buf.substr(befi, i-befi).c_str());
  144. ++i;
  145. return ret;
  146. }
  147. float readFloat(int & befi, int & i, int andame, std::string & buf) //helper function for void CCreatureHandler::loadUnitAnimInfo()
  148. {
  149. befi=i;
  150. for(i; i<andame; ++i)
  151. {
  152. if(buf[i]=='\t')
  153. break;
  154. }
  155. std::string tmp = buf.substr(befi, i-befi);
  156. float ret = atof(buf.substr(befi, i-befi).c_str());
  157. ++i;
  158. return ret;
  159. }
  160. /**
  161. * Determines if a faction is good.
  162. * @param ID of the faction.
  163. * @return true if the faction is good, false otherwise.
  164. */
  165. bool CCreatureHandler::isGood (si8 faction) const
  166. {
  167. return faction != -1 && factionAlignments[faction] == 1;
  168. }
  169. /**
  170. * Determines if a faction is evil.
  171. * @param ID of the faction.
  172. * @return true if the faction is evil, false otherwise.
  173. */
  174. bool CCreatureHandler::isEvil (si8 faction) const
  175. {
  176. return faction != -1 && factionAlignments[faction] == -1;
  177. }
  178. void CCreatureHandler::loadCreatures()
  179. {
  180. notUsedMonsters += 122,124,126,128,145,146,147,148,149,160,161,162,163,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191;
  181. tlog5 << "\t\tReading config/cr_abils.txt and ZCRTRAIT.TXT" << std::endl;
  182. bool useCreAbilsFromZCRTRAIT = true;
  183. ////////////reading cr_abils.txt ///////////////////
  184. std::ifstream abils(DATA_DIR "/config/cr_abils.txt", std::ios::in | std::ios::binary); //this file is not in lod
  185. const int MAX_LINE_SIZE = 1000;
  186. char abilLine[MAX_LINE_SIZE+1];
  187. for(int i=0; i<5; ++i) //removing 5 comment lines
  188. {
  189. abils.getline(abilLine, MAX_LINE_SIZE);
  190. }
  191. //reading first line (determining if we should use creature abilities from ZCRTRAIT.TXT)
  192. abils.getline(abilLine, MAX_LINE_SIZE);
  193. useCreAbilsFromZCRTRAIT = atoi(abilLine);
  194. ////////////reading ZCRTRAIT.TXT ///////////////////
  195. std::string buf = bitmaph->getTextFile("ZCRTRAIT.TXT");
  196. int andame = buf.size();
  197. int i=0; //buf iterator
  198. int hmcr=0;
  199. for(i; i<andame; ++i)
  200. {
  201. if(buf[i]=='\r')
  202. ++hmcr;
  203. if(hmcr==2)
  204. break;
  205. }
  206. i+=2;
  207. while(i<buf.size())
  208. {
  209. CCreature &ncre = *new CCreature;
  210. ncre.idNumber = creatures.size();
  211. ncre.cost.resize(RESOURCE_QUANTITY);
  212. ncre.level=0;
  213. int befi=i;
  214. for(i; i<andame; ++i)
  215. {
  216. if(buf[i]=='\t')
  217. break;
  218. }
  219. ncre.nameSing = buf.substr(befi, i-befi);
  220. ++i;
  221. befi=i;
  222. for(i; i<andame; ++i)
  223. {
  224. if(buf[i]=='\t')
  225. break;
  226. }
  227. ncre.namePl = buf.substr(befi, i-befi);
  228. ++i;
  229. for(int v=0; v<7; ++v)
  230. {
  231. ncre.cost[v] = readNumber(befi, i, andame, buf);
  232. }
  233. ncre.fightValue = readNumber(befi, i, andame, buf);
  234. ncre.AIValue = readNumber(befi, i, andame, buf);
  235. ncre.growth = readNumber(befi, i, andame, buf);
  236. ncre.hordeGrowth = readNumber(befi, i, andame, buf);
  237. ncre.hitPoints = readNumber(befi, i, andame, buf);
  238. ncre.addBonus(ncre.hitPoints, Bonus::STACK_HEALTH);
  239. ncre.speed = readNumber(befi, i, andame, buf);
  240. ncre.addBonus(ncre.speed, Bonus::STACKS_SPEED);
  241. ncre.attack = readNumber(befi, i, andame, buf);
  242. ncre.addBonus(ncre.attack, Bonus::PRIMARY_SKILL, PrimarySkill::ATTACK);
  243. ncre.defence = readNumber(befi, i, andame, buf);
  244. ncre.addBonus(ncre.defence, Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE);
  245. ncre.damageMin = readNumber(befi, i, andame, buf);
  246. ncre.damageMax = readNumber(befi, i, andame, buf);
  247. ncre.shots = readNumber(befi, i, andame, buf);
  248. ncre.spells = readNumber(befi, i, andame, buf);
  249. ncre.ammMin = readNumber(befi, i, andame, buf);
  250. ncre.ammMax = readNumber(befi, i, andame, buf);
  251. befi=i;
  252. for(i; i<andame; ++i)
  253. {
  254. if(buf[i]=='\t')
  255. break;
  256. }
  257. ncre.abilityText = buf.substr(befi, i-befi);
  258. ++i;
  259. befi=i;
  260. for(i; i<andame; ++i)
  261. {
  262. if(buf[i]=='\r')
  263. break;
  264. }
  265. ncre.abilityRefs = buf.substr(befi, i-befi);
  266. i+=2;
  267. if(useCreAbilsFromZCRTRAIT)
  268. { //adding abilities from ZCRTRAIT.TXT
  269. if(boost::algorithm::find_first(ncre.abilityRefs, "DOUBLE_WIDE"))
  270. ncre.doubleWide = true;
  271. if(boost::algorithm::find_first(ncre.abilityRefs, "FLYING_ARMY"))
  272. ncre.addBonus(0, Bonus::FLYING);
  273. if(boost::algorithm::find_first(ncre.abilityRefs, "SHOOTING_ARMY"))
  274. ncre.addBonus(0, Bonus::SHOOTER);
  275. if(boost::algorithm::find_first(ncre.abilityRefs, "SIEGE_WEAPON"))
  276. ncre.addBonus(0, Bonus::SIEGE_WEAPON);
  277. if(boost::algorithm::find_first(ncre.abilityRefs, "const_two_attacks"))
  278. ncre.addBonus(1, Bonus::ADDITIONAL_ATTACK);
  279. if(boost::algorithm::find_first(ncre.abilityRefs, "const_free_attack"))
  280. ncre.addBonus(0, Bonus::BLOCKS_RETALIATION);
  281. if(boost::algorithm::find_first(ncre.abilityRefs, "IS_UNDEAD"))
  282. ncre.addBonus(0, Bonus::UNDEAD);
  283. if(boost::algorithm::find_first(ncre.abilityRefs, "const_no_melee_penalty"))
  284. ncre.addBonus(0, Bonus::NO_MELEE_PENALTY);
  285. if(boost::algorithm::find_first(ncre.abilityRefs, "const_jousting"))
  286. ncre.addBonus(0, Bonus::JOUSTING);
  287. if(boost::algorithm::find_first(ncre.abilityRefs, "const_raises_morale"))
  288. {
  289. ncre.addBonus(+1, Bonus::MORALE);;
  290. ncre.bonuses.back().effectRange = Bonus::ONLY_ALLIED_ARMY;
  291. }
  292. if(boost::algorithm::find_first(ncre.abilityRefs, "const_lowers_morale"))
  293. {
  294. ncre.addBonus(-1, Bonus::MORALE);;
  295. ncre.bonuses.back().effectRange = Bonus::ONLY_ENEMY_ARMY;
  296. }
  297. if(boost::algorithm::find_first(ncre.abilityRefs, "KING_1"))
  298. ncre.addBonus(0, Bonus::KING1);
  299. if(boost::algorithm::find_first(ncre.abilityRefs, "KING_2"))
  300. ncre.addBonus(0, Bonus::KING2);
  301. if(boost::algorithm::find_first(ncre.abilityRefs, "KING_3"))
  302. ncre.addBonus(0, Bonus::KING3);
  303. if(boost::algorithm::find_first(ncre.abilityRefs, "const_no_wall_penalty"))
  304. ncre.addBonus(0, Bonus::NO_WALL_PENALTY);
  305. if(boost::algorithm::find_first(ncre.abilityRefs, "CATAPULT"))
  306. ncre.addBonus(0, Bonus::CATAPULT);
  307. if(boost::algorithm::find_first(ncre.abilityRefs, "MULTI_HEADED"))
  308. ncre.addBonus(0, Bonus::ATTACKS_ALL_ADJACENT);
  309. if(boost::algorithm::find_first(ncre.abilityRefs, "IMMUNE_TO_MIND_SPELLS"))
  310. {
  311. std::vector<int> mindSpells = getMindSpells();
  312. for(int g=0; g<mindSpells.size(); ++g)
  313. ncre.addBonus(0, Bonus::SPELL_IMMUNITY, mindSpells[g]); //giants are immune to mind spells
  314. }
  315. if(boost::algorithm::find_first(ncre.abilityRefs, "IMMUNE_TO_FIRE_SPELLS"))
  316. ncre.addBonus(0, Bonus::FIRE_IMMUNITY);
  317. if(boost::algorithm::find_first(ncre.abilityRefs, "HAS_EXTENDED_ATTACK"))
  318. ncre.addBonus(0, Bonus::TWO_HEX_ATTACK_BREATH);;
  319. }
  320. if(ncre.nameSing!=std::string("") && ncre.namePl!=std::string(""))
  321. {
  322. ncre.idNumber = creatures.size();
  323. creatures.push_back(&ncre);
  324. }
  325. }
  326. ////second part of reading cr_abils.txt////
  327. bool contReading = true;
  328. while(contReading) //main reading loop
  329. {
  330. abils.getline(abilLine, MAX_LINE_SIZE);
  331. std::istringstream reader(abilLine);
  332. char command;
  333. reader >> command;
  334. switch(command)
  335. {
  336. case '+': //add new ability
  337. {
  338. int creatureID;
  339. Bonus nsf;
  340. si32 buf;
  341. std::string type;
  342. reader >> creatureID;
  343. reader >> type;
  344. std::map<std::string, int>::const_iterator it = bonusNameMap.find(type);
  345. CCreature *cre = creatures[creatureID];
  346. if (it == bonusNameMap.end())
  347. {
  348. if(type == "DOUBLE_WIDE")
  349. cre->doubleWide = true;
  350. else if(type == "ENEMY_MORALE_DECREASING")
  351. {
  352. cre->addBonus(-1, Bonus::MORALE);;
  353. cre->bonuses.back().effectRange = Bonus::ONLY_ENEMY_ARMY;
  354. }
  355. else if(type == "ENEMY_LUCK_DECREASING")
  356. {
  357. cre->addBonus(-1, Bonus::LUCK);;
  358. cre->bonuses.back().effectRange = Bonus::ONLY_ENEMY_ARMY;
  359. }
  360. else
  361. tlog1 << "Error: invalid type " << type << " in cr_abils.txt" << std::endl;
  362. break;
  363. }
  364. nsf.type = it->second;
  365. reader >> buf; nsf.val = buf;
  366. reader >> buf; nsf.subtype = buf;
  367. reader >> buf; nsf.additionalInfo = buf;
  368. nsf.source = Bonus::CREATURE_ABILITY;
  369. nsf.id = cre->idNumber;
  370. nsf.duration = Bonus::ONE_BATTLE;
  371. nsf.turnsRemain = 0;
  372. cre->bonuses += nsf;
  373. break;
  374. }
  375. case '-': //remove ability
  376. {
  377. int creatureID;
  378. std::string type;
  379. reader >> creatureID;
  380. reader >> type;
  381. std::map<std::string, int>::const_iterator it = bonusNameMap.find(type);
  382. if (it == bonusNameMap.end())
  383. {
  384. if(type == "DOUBLE_WIDE")
  385. creatures[creatureID]->doubleWide = false;
  386. else
  387. tlog1 << "Error: invalid type " << type << " in cr_abils.txt" << std::endl;
  388. break;
  389. }
  390. int typeNo = it->second;
  391. Bonus::BonusType ecf = static_cast<Bonus::BonusType>(typeNo);
  392. creatures[creatureID]->bonuses -= ecf;
  393. break;
  394. }
  395. case '0': //end reading
  396. {
  397. contReading = false;
  398. break;
  399. }
  400. default: //invalid command
  401. {
  402. tlog1 << "Parse error in file config/cr_abils.txt" << std::endl;
  403. break;
  404. }
  405. }
  406. }
  407. abils.close();
  408. tlog5 << "\t\tReading config/crerefnam.txt" << std::endl;
  409. //loading reference names
  410. std::ifstream ifs(DATA_DIR "/config/crerefnam.txt");
  411. int tempi;
  412. std::string temps;
  413. for (;;)
  414. {
  415. ifs >> tempi >> temps;
  416. if (tempi>=creatures.size())
  417. break;
  418. boost::assign::insert(nameToID)(temps,tempi);
  419. creatures[tempi]->nameRef=temps;
  420. }
  421. ifs.close();
  422. ifs.clear();
  423. for(int i=1;i<=10;i++)
  424. levelCreatures.insert(std::pair<int,std::vector<CCreature*> >(i,std::vector<CCreature*>()));
  425. tlog5 << "\t\tReading config/monsters.txt" << std::endl;
  426. ifs.open(DATA_DIR "/config/monsters.txt");
  427. {
  428. while(!ifs.eof())
  429. {
  430. int id, lvl;
  431. ifs >> id >> lvl;
  432. if(lvl>0)
  433. {
  434. creatures[id]->level = lvl;
  435. levelCreatures[lvl].push_back(creatures[id]);
  436. }
  437. }
  438. }
  439. ifs.close();
  440. ifs.clear();
  441. tlog5 << "\t\tReading config/cr_factions.txt" << std::endl;
  442. ifs.open(DATA_DIR "/config/cr_factions.txt");
  443. while(!ifs.eof())
  444. {
  445. int id, fact;
  446. ifs >> id >> fact;
  447. creatures[id]->faction = fact;
  448. }
  449. ifs.close();
  450. ifs.clear();
  451. tlog5 << "\t\tReading config/cr_upgrade_list.txt" << std::endl;
  452. ifs.open(DATA_DIR "/config/cr_upgrade_list.txt");
  453. while(!ifs.eof())
  454. {
  455. int id, up;
  456. ifs >> id >> up;
  457. creatures[id]->upgrades.insert(up);
  458. }
  459. ifs.close();
  460. ifs.clear();
  461. //loading unit animation def names
  462. tlog5 << "\t\tReading config/CREDEFS.TXT" << std::endl;
  463. std::ifstream inp(DATA_DIR "/config/CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod
  464. inp.seekg(0,std::ios::end); // na koniec
  465. int andame2 = inp.tellg(); // read length
  466. inp.seekg(0,std::ios::beg); // wracamy na poczatek
  467. char * bufor = new char[andame2+1]; // allocate memory
  468. inp.read((char*)bufor, andame2); // read map file to buffer
  469. inp.close();
  470. bufor[andame2] = 0;
  471. buf = std::string(bufor);
  472. delete [] bufor;
  473. i = 0; //buf iterator
  474. hmcr = 0;
  475. for(i; i<andame2; ++i) //omitting rubbish
  476. {
  477. if(buf[i]=='\r')
  478. break;
  479. }
  480. i+=2;
  481. tlog5 << "We have "<<creatures.size() << " creatures\n";
  482. for(int s=0; s<creatures.size(); ++s)
  483. {
  484. //tlog5 <<"\t\t\t" << s <<". Reading defname. \n";
  485. int befi=i;
  486. std::string rub;
  487. for(i; i<andame2; ++i)
  488. {
  489. if(buf[i]==' ')
  490. break;
  491. }
  492. rub = buf.substr(befi, i-befi);
  493. ++i;
  494. befi=i;
  495. for(i; i<andame2; ++i)
  496. {
  497. if(buf[i]=='\r')
  498. break;
  499. }
  500. std::string defName = buf.substr(befi, i-befi);
  501. creatures[s]->animDefName = defName;
  502. }
  503. tlog5 << "\t\tReading CRANIM.TXT.txt" << std::endl;
  504. loadAnimationInfo();
  505. //loading id to projectile mapping
  506. tlog5 << "\t\tReading config/cr_shots.txt" << std::endl;
  507. std::ifstream inp2(DATA_DIR "/config/cr_shots.txt", std::ios::in | std::ios::binary); //this file is not in lod
  508. char dump [200];
  509. inp2.getline(dump, 200);
  510. while(true)
  511. {
  512. int id;
  513. std::string name;
  514. bool spin;
  515. inp2>>id;
  516. if(id == -1)
  517. break;
  518. inp2>>name;
  519. idToProjectile[id] = name;
  520. inp2>>spin;
  521. idToProjectileSpin[id] = spin;
  522. }
  523. inp2.close();
  524. //reading factionToTurretCreature
  525. tlog5 << "\t\tReading config/cr_to_turret.txt" << std::endl;
  526. std::ifstream inp3(DATA_DIR "/config/cr_to_turret.txt", std::ios::in | std::ios::binary); //this file is not in lod
  527. std::string dump2;
  528. inp3 >> dump2 >> dump2;
  529. for(int g=0; g<F_NUMBER; ++g)
  530. {
  531. inp3 >> factionToTurretCreature[g];
  532. }
  533. inp3.close();
  534. }
  535. void CCreatureHandler::loadAnimationInfo()
  536. {
  537. std::string buf = bitmaph->getTextFile("CRANIM.TXT");
  538. int andame = buf.size();
  539. int i=0; //buf iterator
  540. int hmcr=0;
  541. for(i; i<andame; ++i)
  542. {
  543. if(buf[i]=='\r')
  544. ++hmcr;
  545. if(hmcr==2)
  546. break;
  547. }
  548. i+=2;
  549. for(int dd=0; dd<creatures.size(); ++dd)
  550. {
  551. //tlog5 << "\t\t\tReading animation info for creature " << dd << std::endl;
  552. loadUnitAnimInfo(*creatures[dd], buf, i);
  553. }
  554. return;
  555. }
  556. void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int & i)
  557. {
  558. int befi=i;
  559. unit.timeBetweenFidgets = readFloat(befi, i, src.size(), src);
  560. while(unit.timeBetweenFidgets == 0.0)
  561. {
  562. for(i; i<src.size(); ++i)
  563. {
  564. if(src[i]=='\r')
  565. break;
  566. }
  567. i+=2;
  568. unit.timeBetweenFidgets = readFloat(befi, i, src.size(), src);
  569. }
  570. unit.walkAnimationTime = readFloat(befi, i, src.size(), src);
  571. unit.attackAnimationTime = readFloat(befi, i, src.size(), src);
  572. unit.flightAnimationDistance = readFloat(befi, i, src.size(), src);
  573. ///////////////////////
  574. unit.upperRightMissleOffsetX = readNumber(befi, i, src.size(), src);
  575. unit.upperRightMissleOffsetY = readNumber(befi, i, src.size(), src);
  576. unit.rightMissleOffsetX = readNumber(befi, i, src.size(), src);
  577. unit.rightMissleOffsetY = readNumber(befi, i, src.size(), src);
  578. unit.lowerRightMissleOffsetX = readNumber(befi, i, src.size(), src);
  579. unit.lowerRightMissleOffsetY = readNumber(befi, i, src.size(), src);
  580. ///////////////////////
  581. for(int jjj=0; jjj<12; ++jjj)
  582. {
  583. unit.missleFrameAngles[jjj] = readFloat(befi, i, src.size(), src);
  584. }
  585. unit.troopCountLocationOffset= readNumber(befi, i, src.size(), src);
  586. unit.attackClimaxFrame = readNumber(befi, i, src.size(), src);
  587. for(i; i<src.size(); ++i)
  588. {
  589. if(src[i]=='\r')
  590. break;
  591. }
  592. i+=2;
  593. }
  594. CCreatureHandler::~CCreatureHandler()
  595. {
  596. }
  597. int CCreatureHandler::pickRandomMonster(const boost::function<int()> &randGen) const
  598. {
  599. int r = 0;
  600. do
  601. {
  602. if(randGen)
  603. r = randGen();
  604. else
  605. r = rand();
  606. r %= 197;
  607. } while (vstd::contains(VLC->creh->notUsedMonsters,r));
  608. return r;
  609. }