CObjectHandler.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. #define VCMI_DLL
  2. #include "../stdafx.h"
  3. #include "CObjectHandler.h"
  4. #include "CDefObjInfoHandler.h"
  5. #include "CLodHandler.h"
  6. #include "CGeneralTextHandler.h"
  7. #include "CDefObjInfoHandler.h"
  8. #include "CHeroHandler.h"
  9. #include "CSpellHandler.h"
  10. #include <boost/algorithm/string/replace.hpp>
  11. #include <boost/random/linear_congruential.hpp>
  12. #include "CTownHandler.h"
  13. #include "CArtHandler.h"
  14. #include "../lib/VCMI_Lib.h"
  15. DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
  16. extern CLodHandler * bitmaph;
  17. extern boost::rand48 ran;
  18. void CObjectHandler::loadObjects()
  19. {
  20. VLC->objh = this;
  21. // int ID=0; //TODO use me
  22. tlog5 << "\t\tReading OBJNAMES \n";
  23. std::string buf = bitmaph->getTextFile("OBJNAMES.TXT");
  24. int it=0; //hope that -1 will not break this
  25. while (it<buf.length()-1)
  26. {
  27. std::string nobj;
  28. loadToIt(nobj, buf, it, 3);
  29. if(nobj.size() && (nobj[nobj.size()-1]==(char)10 || nobj[nobj.size()-1]==(char)13 || nobj[nobj.size()-1]==(char)9)) {
  30. nobj = nobj.substr(0, nobj.size()-1);
  31. }
  32. names.push_back(nobj);
  33. }
  34. tlog5 << "\t\tReading ADVEVENT \n";
  35. buf = bitmaph->getTextFile("ADVEVENT.TXT");
  36. it=0;
  37. std::string temp;
  38. while (it<buf.length()-1)
  39. {
  40. loadToIt(temp,buf,it,3);
  41. if (temp[0]=='\"') {
  42. temp = temp.substr(1,temp.length()-2);
  43. }
  44. boost::algorithm::replace_all(temp,"\"\"","\"");
  45. advobtxt.push_back(temp);
  46. }
  47. tlog5 << "\t\tReading XTRAINFO \n";
  48. buf = bitmaph->getTextFile("XTRAINFO.TXT");
  49. it=0;
  50. while (it<buf.length()-1)
  51. {
  52. loadToIt(temp,buf,it,3);
  53. xtrainfo.push_back(temp);
  54. }
  55. tlog5 << "\t\tReading MINENAME \n";
  56. buf = bitmaph->getTextFile("MINENAME.TXT");
  57. it=0;
  58. while (it<buf.length()-1)
  59. {
  60. loadToIt(temp,buf,it,3);
  61. mines.push_back(std::pair<std::string,std::string>(temp,""));
  62. }
  63. tlog5 << "\t\tReading MINEEVNT \n";
  64. buf = bitmaph->getTextFile("MINEEVNT.TXT");
  65. it=0;
  66. int i=0;
  67. while (it<buf.length()-1)
  68. {
  69. loadToIt(temp,buf,it,3);
  70. temp = temp.substr(1,temp.length()-2);
  71. mines[i++].second = temp;
  72. }
  73. tlog5 << "\t\tReading RESTYPES \n";
  74. buf = bitmaph->getTextFile("RESTYPES.TXT");
  75. it=0;
  76. while (it<buf.length()-1)
  77. {
  78. loadToIt(temp,buf,it,3);
  79. restypes.push_back(temp);
  80. }
  81. tlog5 << "\t\tReading cregens \n";
  82. cregens.resize(110); //TODO: hardcoded value - change
  83. for(size_t i=0; i < cregens.size(); ++i) {
  84. cregens[i]=-1;
  85. }
  86. std::ifstream ifs("config/cregens.txt");
  87. while(!ifs.eof())
  88. {
  89. int dw, cr;
  90. ifs >> dw >> cr;
  91. cregens[dw]=cr;
  92. }
  93. ifs.close();
  94. ifs.clear();
  95. tlog5 << "\t\tReading ZCRGN1 \n";
  96. buf = bitmaph->getTextFile("ZCRGN1.TXT");
  97. it=0;
  98. while (it<buf.length()-1)
  99. {
  100. loadToIt(temp,buf,it,3);
  101. creGens.push_back(temp);
  102. }
  103. tlog5 << "\t\tDone loading objects!\n";
  104. }
  105. bool CGObjectInstance::isHero() const
  106. {
  107. return false;
  108. }
  109. int CGObjectInstance::getOwner() const
  110. {
  111. //if (state)
  112. // return state->owner;
  113. //else
  114. return tempOwner; //won't have owner
  115. }
  116. void CGObjectInstance::setOwner(int ow)
  117. {
  118. //if (state)
  119. // state->owner = ow;
  120. //else
  121. tempOwner = ow;
  122. }
  123. int CGObjectInstance::getWidth() const//returns width of object graphic in tiles
  124. {
  125. return defInfo->width;
  126. }
  127. int CGObjectInstance::getHeight() const //returns height of object graphic in tiles
  128. {
  129. return defInfo->width;
  130. }
  131. bool CGObjectInstance::visitableAt(int x, int y) const //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
  132. {
  133. if(x<0 || y<0 || x>=getWidth() || y>=getHeight() || defInfo==NULL)
  134. return false;
  135. if((defInfo->visitMap[y+6-getHeight()] >> (7-(8-getWidth()+x) )) & 1)
  136. return true;
  137. return false;
  138. }
  139. bool CGObjectInstance::blockingAt(int x, int y) const
  140. {
  141. if(x<0 || y<0 || x>=getWidth() || y>=getHeight() || defInfo==NULL)
  142. return false;
  143. if((defInfo->blockMap[y+6-getHeight()] >> (7-(8-getWidth()+x) )) & 1)
  144. return true;
  145. return false;
  146. }
  147. bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen printing priority comparing
  148. {
  149. if(defInfo->printPriority==1 && cmp.defInfo->printPriority==0)
  150. return true;
  151. if(cmp.defInfo->printPriority==1 && defInfo->printPriority==0)
  152. return false;
  153. if(this->pos.y<cmp.pos.y)
  154. return true;
  155. if(this->pos.y>cmp.pos.y)
  156. return false;
  157. if(cmp.ID==34 && ID!=34)
  158. return true;
  159. if(cmp.ID!=34 && ID==34)
  160. return false;
  161. if(!defInfo->isVisitable() && cmp.defInfo->isVisitable())
  162. return true;
  163. if(!cmp.defInfo->isVisitable() && defInfo->isVisitable())
  164. return false;
  165. if(this->pos.x<cmp.pos.x)
  166. return true;
  167. return false;
  168. }
  169. bool CGHeroInstance::isHero() const
  170. {
  171. return true;
  172. }
  173. unsigned int CGHeroInstance::getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const
  174. {
  175. unsigned int ret = type->heroClass->terrCosts[ttype];
  176. //applying pathfinding skill
  177. switch(getSecSkillLevel(0))
  178. {
  179. case 1: //basic
  180. switch(ttype)
  181. {
  182. case rough:
  183. ret = 100;
  184. break;
  185. case sand: case snow:
  186. if(ret>125)
  187. ret = 125;
  188. break;
  189. case swamp:
  190. if(ret>150)
  191. ret = 150;
  192. break;
  193. default:
  194. //TODO do something nasty here throw maybe? or some def value asing
  195. break;
  196. }
  197. break;
  198. case 2: //advanced
  199. switch(ttype)
  200. {
  201. case rough:
  202. case sand:
  203. case snow:
  204. ret = 100;
  205. break;
  206. case swamp:
  207. if(ret>125)
  208. ret = 125;
  209. break;
  210. default:
  211. //TODO look up
  212. break;
  213. }
  214. break;
  215. case 3: //expert
  216. ret = 100;
  217. break;
  218. default:
  219. //TODO look up
  220. break;
  221. }
  222. //calculating road influence
  223. switch(rdtype)
  224. {
  225. case dirtRoad:
  226. ret*=0.75;
  227. break;
  228. case grazvelRoad:
  229. ret*=0.667;
  230. break;
  231. case cobblestoneRoad:
  232. ret*=0.5;
  233. break;
  234. default:
  235. //TODO killllll me
  236. break;
  237. }
  238. return ret;
  239. }
  240. unsigned int CGHeroInstance::getLowestCreatureSpeed()
  241. {
  242. unsigned int sl = 100;
  243. for(size_t h=0; h < army.slots.size(); ++h)
  244. {
  245. if(VLC->creh->creatures[army.slots[h].first].speed<sl)
  246. sl = VLC->creh->creatures[army.slots[h].first].speed;
  247. }
  248. return sl;
  249. }
  250. int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  251. {
  252. if (toh3m)
  253. {
  254. src.x+=1;
  255. return src;
  256. }
  257. else
  258. {
  259. src.x-=1;
  260. return src;
  261. }
  262. }
  263. int3 CGHeroInstance::getPosition(bool h3m) const //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  264. {
  265. if (h3m) {
  266. return pos;
  267. }
  268. else {
  269. return convertPosition(pos,false);
  270. }
  271. }
  272. int CGHeroInstance::getSightDistance() const //returns sight distance of this hero
  273. {
  274. return 6 + getSecSkillLevel(3); //default + scouting
  275. }
  276. int CGHeroInstance::manaLimit() const
  277. {
  278. double modifier = 1.0;
  279. switch(getSecSkillLevel(24)) //intelligence level
  280. {
  281. case 1: modifier+=0.25; break;
  282. case 2: modifier+=0.5; break;
  283. case 3: modifier+=1.0; break;
  284. }
  285. return 10*getPrimSkillLevel(3)*modifier;
  286. }
  287. //void CGHeroInstance::setPosition(int3 Pos, bool h3m) //as above, but sets position
  288. //{
  289. // if (h3m)
  290. // pos = Pos;
  291. // else
  292. // pos = convertPosition(Pos,true);
  293. //}
  294. bool CGHeroInstance::canWalkOnSea() const
  295. {
  296. //TODO: write it - it should check if hero is flying, or something similiar
  297. return false;
  298. }
  299. int CGHeroInstance::getCurrentLuck() const
  300. {
  301. //TODO: write it
  302. return 0;
  303. }
  304. int CGHeroInstance::getCurrentMorale() const
  305. {
  306. //TODO: write it
  307. return 0;
  308. }
  309. int CGHeroInstance::getPrimSkillLevel(int id) const
  310. {
  311. return primSkills[id];
  312. }
  313. int CGHeroInstance::getSecSkillLevel(const int & ID) const
  314. {
  315. for(size_t i=0; i < secSkills.size(); ++i)
  316. if(secSkills[i].first==ID)
  317. return secSkills[i].second;
  318. return 0;
  319. }
  320. int lowestSpeed(const CGHeroInstance * chi)
  321. {
  322. if(!chi->army.slots.size())
  323. {
  324. tlog1 << "Error! Hero " << chi->id << " ("<<chi->name<<") has no army!\n";
  325. return 20;
  326. }
  327. std::map<si32,std::pair<ui32,si32> >::const_iterator i = chi->army.slots.begin();
  328. int ret = VLC->creh->creatures[(*i++).second.first].speed;
  329. for (;i!=chi->army.slots.end();i++)
  330. {
  331. ret = std::min(ret,VLC->creh->creatures[(*i).second.first].speed);
  332. }
  333. return ret;
  334. }
  335. int CGHeroInstance::maxMovePoints(bool onLand) const
  336. {
  337. int ret = 1270+70*lowestSpeed(this);
  338. if (ret>2000)
  339. ret=2000;
  340. if(onLand)
  341. {
  342. //logistics:
  343. switch(getSecSkillLevel(2))
  344. {
  345. case 1:
  346. ret *= 1.1f;
  347. break;
  348. case 2:
  349. ret *= 1.2f;
  350. break;
  351. case 3:
  352. ret *= 1.3f;
  353. break;
  354. }
  355. }
  356. else
  357. {
  358. //navigation:
  359. switch(getSecSkillLevel(2))
  360. {
  361. case 1:
  362. ret *= 1.5f;
  363. break;
  364. case 2:
  365. ret *= 2.0f;
  366. break;
  367. case 3:
  368. ret *= 2.5f;
  369. break;
  370. }
  371. }
  372. return ret;
  373. }
  374. ui32 CGHeroInstance::getArtAtPos(ui16 pos) const
  375. {
  376. if(pos<19)
  377. if(vstd::contains(artifWorn,pos))
  378. return artifWorn.find(pos)->second;
  379. else
  380. return -1;
  381. else
  382. if(pos-19 < artifacts.size())
  383. return artifacts[pos-19];
  384. else
  385. return -1;
  386. }
  387. void CGHeroInstance::setArtAtPos(ui16 pos, int art)
  388. {
  389. if(art<0)
  390. {
  391. if(pos<19)
  392. artifWorn.erase(pos);
  393. else
  394. artifacts -= artifacts[pos-19];
  395. }
  396. else
  397. {
  398. if(pos<19)
  399. artifWorn[pos] = art;
  400. else
  401. if(pos-19 < artifacts.size())
  402. artifacts[pos-19] = art;
  403. else
  404. artifacts.push_back(art);
  405. }
  406. }
  407. const CArtifact * CGHeroInstance::getArt(int pos) const
  408. {
  409. int id = getArtAtPos(pos);
  410. if(id>=0)
  411. return &VLC->arth->artifacts[id];
  412. else
  413. return NULL;
  414. }
  415. int CGHeroInstance::getSpellSecLevel(int spell) const
  416. {
  417. int bestslvl = 0;
  418. if(VLC->spellh->spells[spell].air)
  419. if(getSecSkillLevel(15) >= bestslvl)
  420. {
  421. bestslvl = getSecSkillLevel(15);
  422. }
  423. if(VLC->spellh->spells[spell].fire)
  424. if(getSecSkillLevel(14) >= bestslvl)
  425. {
  426. bestslvl = getSecSkillLevel(14);
  427. }
  428. if(VLC->spellh->spells[spell].water)
  429. if(getSecSkillLevel(16) >= bestslvl)
  430. {
  431. bestslvl = getSecSkillLevel(16);
  432. }
  433. if(VLC->spellh->spells[spell].earth)
  434. if(getSecSkillLevel(17) >= bestslvl)
  435. {
  436. bestslvl = getSecSkillLevel(17);
  437. }
  438. return bestslvl;
  439. }
  440. int CGTownInstance::getSightDistance() const //returns sight distance
  441. {
  442. return 10;
  443. }
  444. int CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle
  445. {
  446. if((builtBuildings.find(9))!=builtBuildings.end())
  447. return 3;
  448. if((builtBuildings.find(8))!=builtBuildings.end())
  449. return 2;
  450. if((builtBuildings.find(7))!=builtBuildings.end())
  451. return 1;
  452. return 0;
  453. }
  454. int CGTownInstance::hallLevel() const // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  455. {
  456. if ((builtBuildings.find(13))!=builtBuildings.end())
  457. return 3;
  458. if ((builtBuildings.find(12))!=builtBuildings.end())
  459. return 2;
  460. if ((builtBuildings.find(11))!=builtBuildings.end())
  461. return 1;
  462. if ((builtBuildings.find(10))!=builtBuildings.end())
  463. return 0;
  464. return -1;
  465. }
  466. int CGTownInstance::mageGuildLevel() const
  467. {
  468. if ((builtBuildings.find(4))!=builtBuildings.end())
  469. return 5;
  470. if ((builtBuildings.find(3))!=builtBuildings.end())
  471. return 4;
  472. if ((builtBuildings.find(2))!=builtBuildings.end())
  473. return 3;
  474. if ((builtBuildings.find(1))!=builtBuildings.end())
  475. return 2;
  476. if ((builtBuildings.find(0))!=builtBuildings.end())
  477. return 1;
  478. return 0;
  479. }
  480. bool CGTownInstance::creatureDwelling(const int & level, bool upgraded) const
  481. {
  482. return builtBuildings.find(30+level+upgraded*7)!=builtBuildings.end();
  483. }
  484. int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  485. {
  486. return town->hordeLvl[HID];
  487. }
  488. int CGTownInstance::creatureGrowth(const int & level) const
  489. {
  490. int ret = VLC->creh->creatures[town->basicCreatures[level]].growth;
  491. switch(fortLevel())
  492. {
  493. case 3:
  494. ret*=2;break;
  495. case 2:
  496. ret*=(1.5); break;
  497. }
  498. if(builtBuildings.find(26)!=builtBuildings.end()) //grail
  499. ret+=VLC->creh->creatures[town->basicCreatures[level]].growth;
  500. if(getHordeLevel(0)==level)
  501. if((builtBuildings.find(18)!=builtBuildings.end()) || (builtBuildings.find(19)!=builtBuildings.end()))
  502. ret+=VLC->creh->creatures[town->basicCreatures[level]].hordeGrowth;
  503. if(getHordeLevel(1)==level)
  504. if((builtBuildings.find(24)!=builtBuildings.end()) || (builtBuildings.find(25)!=builtBuildings.end()))
  505. ret+=VLC->creh->creatures[town->basicCreatures[level]].hordeGrowth;
  506. return ret;
  507. }
  508. int CGTownInstance::dailyIncome() const
  509. {
  510. int ret = 0;
  511. if ((builtBuildings.find(26))!=builtBuildings.end())
  512. ret+=5000;
  513. if ((builtBuildings.find(13))!=builtBuildings.end())
  514. ret+=4000;
  515. else if ((builtBuildings.find(12))!=builtBuildings.end())
  516. ret+=2000;
  517. else if ((builtBuildings.find(11))!=builtBuildings.end())
  518. ret+=1000;
  519. else if ((builtBuildings.find(10))!=builtBuildings.end())
  520. ret+=500;
  521. return ret;
  522. }
  523. bool CGTownInstance::hasFort() const
  524. {
  525. return (builtBuildings.find(7))!=builtBuildings.end();
  526. }
  527. bool CGTownInstance::hasCapitol() const
  528. {
  529. return (builtBuildings.find(13))!=builtBuildings.end();
  530. }
  531. CGTownInstance::CGTownInstance()
  532. {
  533. builded=-1;
  534. destroyed=-1;
  535. garrisonHero=NULL;
  536. town=NULL;
  537. visitingHero = NULL;
  538. }
  539. CGObjectInstance::CGObjectInstance(): animPhaseShift(rand()%0xff)
  540. {
  541. pos = int3(-1,-1,-1);
  542. //std::cout << "Tworze obiekt "<<this<<std::endl;
  543. //state = new CLuaObjectScript();
  544. ID = subID = id = -1;
  545. defInfo = NULL;
  546. state = NULL;
  547. info = NULL;
  548. tempOwner = 254;
  549. blockVisit = false;
  550. }
  551. CGObjectInstance::~CGObjectInstance()
  552. {
  553. //std::cout << "Usuwam obiekt "<<this<<std::endl;
  554. //if (state)
  555. // delete state;
  556. //state=NULL;
  557. }
  558. CGHeroInstance::CGHeroInstance()
  559. {
  560. ID = 34;
  561. tacticFormationEnabled = inTownGarrison = false;
  562. mana = movement = portrait = level = -1;
  563. isStanding = true;
  564. moveDir = 4;
  565. exp = 0xffffffff;
  566. visitedTown = NULL;
  567. type = NULL;
  568. secSkills.push_back(std::make_pair(-1, -1));
  569. }
  570. void CGHeroInstance::initHero(int SUBID)
  571. {
  572. subID = SUBID;
  573. initHero();
  574. }
  575. void CGHeroInstance::initHero()
  576. {
  577. if(!defInfo)
  578. {
  579. defInfo = new CGDefInfo();
  580. defInfo->id = 34;
  581. defInfo->subid = subID;
  582. defInfo->printPriority = 0;
  583. defInfo->visitDir = 0xff;
  584. }
  585. if(!type)
  586. type = VLC->heroh->heroes[subID];
  587. for(int i=0;i<6;i++)
  588. {
  589. defInfo->blockMap[i]=255;
  590. defInfo->visitMap[i]=0;
  591. }
  592. defInfo->handler=NULL;
  593. defInfo->blockMap[5] = 253;
  594. defInfo->visitMap[5] = 2;
  595. artifWorn[16] = 3;
  596. if(type->heroType % 2 == 1) //it's a magical hero
  597. {
  598. artifWorn[17] = 0; //give him spellbook
  599. }
  600. if(portrait < 0 || portrait == 255)
  601. portrait = subID;
  602. if((!primSkills.size()) || (getPrimSkillLevel(0)<0))
  603. {
  604. primSkills.resize(4);
  605. primSkills[0] = type->heroClass->initialAttack;
  606. primSkills[1] = type->heroClass->initialDefence;
  607. primSkills[2] = type->heroClass->initialPower;
  608. primSkills[3] = type->heroClass->initialKnowledge;
  609. }
  610. if(secSkills.size() == 1 && secSkills[0] == std::pair<ui8,ui8>(-1, -1)) //set secondary skills to default
  611. secSkills = type->secSkillsInit;
  612. if(mana < 0)
  613. mana = manaLimit();
  614. if (!name.length())
  615. name = type->name;
  616. if (exp == 0xffffffff)
  617. {
  618. exp=40+ (ran()) % 50;
  619. level = 1;
  620. }
  621. else
  622. {
  623. level = VLC->heroh->level(exp);
  624. }
  625. if (!army.slots.size()) //standard army//initial army
  626. {
  627. int pom, pom2=0;
  628. for(int x=0;x<3;x++)
  629. {
  630. pom = (VLC->creh->nameToID[type->refTypeStack[x]]);
  631. if(pom>=145 && pom<=149) //war machine
  632. {
  633. pom2++;
  634. switch (pom)
  635. {
  636. case 145: //catapult
  637. artifWorn[16] = 3;
  638. break;
  639. default:
  640. artifWorn[9+CArtHandler::convertMachineID(pom,true)] = CArtHandler::convertMachineID(pom,true);
  641. break;
  642. }
  643. continue;
  644. }
  645. army.slots[x-pom2].first = pom;
  646. if((pom = (type->highStack[x]-type->lowStack[x])) > 0)
  647. army.slots[x-pom2].second = (ran()%pom)+type->lowStack[x];
  648. else
  649. army.slots[x-pom2].second = +type->lowStack[x];
  650. army.formation = false;
  651. }
  652. }
  653. }
  654. CGHeroInstance::~CGHeroInstance()
  655. {
  656. }
  657. bool CGHeroInstance::needsLastStack() const
  658. {
  659. return true;
  660. }
  661. const std::string & CGHeroInstance::getBiography()
  662. {
  663. if (biography.length())
  664. return biography;
  665. else
  666. return VLC->generaltexth->hTxts[subID].biography;
  667. }
  668. CGTownInstance::~CGTownInstance()
  669. {}
  670. int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const
  671. {
  672. if(checkGuild && mageGuildLevel() < level)
  673. return 0;
  674. int ret = 6 - level; //how many spells are available at this level
  675. if(subID == 2 && vstd::contains(builtBuildings,22)) //magic library in Tower
  676. ret++;
  677. return ret;
  678. }
  679. bool CGTownInstance::needsLastStack() const
  680. {
  681. if(garrisonHero)
  682. return true;
  683. else return false;
  684. }
  685. CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
  686. {
  687. pos = right.pos;
  688. ID = right.ID;
  689. subID = right.subID;
  690. id = right.id;
  691. defInfo = right.defInfo;
  692. info = right.info;
  693. blockVisit = right.blockVisit;
  694. //state = new CLuaObjectScript(right.state->);
  695. //*state = *right.state;
  696. //state = right.state;
  697. tempOwner = right.tempOwner;
  698. }
  699. CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
  700. {
  701. pos = right.pos;
  702. ID = right.ID;
  703. subID = right.subID;
  704. id = right.id;
  705. defInfo = right.defInfo;
  706. info = right.info;
  707. blockVisit = right.blockVisit;
  708. //state = new CLuaObjectScript();
  709. //*state = *right.state;
  710. tempOwner = right.tempOwner;
  711. return *this;
  712. }