CObjectHandler.cpp 17 KB

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