CCreatureHandler.cpp 18 KB

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