CGTownInstance.cpp 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. /*
  2. * CGTownInstance.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CGTownInstance.h"
  12. #include "CObjectClassesHandler.h"
  13. #include "../NetPacks.h"
  14. #include "../CGeneralTextHandler.h"
  15. using namespace boost::assign;
  16. std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
  17. std::vector<int> CGTownInstance::universitySkills;
  18. void CGDwelling::initObj()
  19. {
  20. switch(ID)
  21. {
  22. case Obj::CREATURE_GENERATOR1:
  23. case Obj::CREATURE_GENERATOR4:
  24. {
  25. VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, cb->gameState()->getRandomGenerator());
  26. if (getOwner() != PlayerColor::NEUTRAL)
  27. cb->gameState()->players[getOwner()].dwellings.push_back (this);
  28. }
  29. //putStack(SlotID(0), new CStackInstance(CreatureID::GOLD_GOLEM, 9));
  30. //putStack(SlotID(1), new CStackInstance(CreatureID::DIAMOND_GOLEM, 6));
  31. //putStack(SlotID(0), new CStackInstance(CreatureID::EARTH_ELEMENTAL, 12));
  32. break;
  33. case Obj::REFUGEE_CAMP:
  34. //is handled within newturn func
  35. break;
  36. case Obj::WAR_MACHINE_FACTORY:
  37. creatures.resize(3);
  38. creatures[0].second.push_back(CreatureID::BALLISTA);
  39. creatures[1].second.push_back(CreatureID::FIRST_AID_TENT);
  40. creatures[2].second.push_back(CreatureID::AMMO_CART);
  41. break;
  42. default:
  43. assert(0);
  44. break;
  45. }
  46. }
  47. void CGDwelling::setPropertyDer(ui8 what, ui32 val)
  48. {
  49. switch (what)
  50. {
  51. case ObjProperty::OWNER: //change owner
  52. if (ID == Obj::CREATURE_GENERATOR1) //single generators
  53. {
  54. if (tempOwner != PlayerColor::NEUTRAL)
  55. {
  56. std::vector<ConstTransitivePtr<CGDwelling> >* dwellings = &cb->gameState()->players[tempOwner].dwellings;
  57. dwellings->erase (std::find(dwellings->begin(), dwellings->end(), this));
  58. }
  59. if (PlayerColor(val) != PlayerColor::NEUTRAL) //can new owner be neutral?
  60. cb->gameState()->players[PlayerColor(val)].dwellings.push_back (this);
  61. }
  62. break;
  63. case ObjProperty::AVAILABLE_CREATURE:
  64. creatures.resize(1);
  65. creatures[0].second.resize(1);
  66. creatures[0].second[0] = CreatureID(val);
  67. break;
  68. }
  69. }
  70. void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
  71. {
  72. if(ID == Obj::REFUGEE_CAMP && !creatures[0].first) //Refugee Camp, no available cres
  73. {
  74. InfoWindow iw;
  75. iw.player = h->tempOwner;
  76. iw.text.addTxt(MetaString::ADVOB_TXT, 44); //{%s} \n\n The camp is deserted. Perhaps you should try next week.
  77. iw.text.addReplacement(MetaString::OBJ_NAMES, ID);
  78. cb->sendAndApply(&iw);
  79. return;
  80. }
  81. PlayerRelations::PlayerRelations relations = cb->gameState()->getPlayerRelations( h->tempOwner, tempOwner );
  82. if ( relations == PlayerRelations::ALLIES )
  83. return;//do not allow recruiting or capturing
  84. if( !relations && stacksCount() > 0) //object is guarded, owned by enemy
  85. {
  86. BlockingDialog bd(true,false);
  87. bd.player = h->tempOwner;
  88. bd.text.addTxt(MetaString::GENERAL_TXT, 421); //Much to your dismay, the %s is guarded by %s %s. Do you wish to fight the guards?
  89. bd.text.addReplacement(ID == Obj::CREATURE_GENERATOR1 ? MetaString::CREGENS : MetaString::CREGENS4, subID);
  90. bd.text.addReplacement(MetaString::ARRAY_TXT, 176 + Slots().begin()->second->getQuantityID()*3);
  91. bd.text.addReplacement(*Slots().begin()->second);
  92. cb->showBlockingDialog(&bd);
  93. return;
  94. }
  95. if(!relations && ID != Obj::WAR_MACHINE_FACTORY)
  96. {
  97. cb->setOwner(this, h->tempOwner);
  98. }
  99. BlockingDialog bd (true,false);
  100. bd.player = h->tempOwner;
  101. if(ID == Obj::CREATURE_GENERATOR1 || ID == Obj::CREATURE_GENERATOR4)
  102. {
  103. bd.text.addTxt(MetaString::ADVOB_TXT, ID == Obj::CREATURE_GENERATOR1 ? 35 : 36); //{%s} Would you like to recruit %s? / {%s} Would you like to recruit %s, %s, %s, or %s?
  104. bd.text.addReplacement(ID == Obj::CREATURE_GENERATOR1 ? MetaString::CREGENS : MetaString::CREGENS4, subID);
  105. for(auto & elem : creatures)
  106. bd.text.addReplacement(MetaString::CRE_PL_NAMES, elem.second[0]);
  107. }
  108. else if(ID == Obj::REFUGEE_CAMP)
  109. {
  110. bd.text.addTxt(MetaString::ADVOB_TXT, 35); //{%s} Would you like to recruit %s?
  111. bd.text.addReplacement(MetaString::OBJ_NAMES, ID);
  112. for(auto & elem : creatures)
  113. bd.text.addReplacement(MetaString::CRE_PL_NAMES, elem.second[0]);
  114. }
  115. else if(ID == Obj::WAR_MACHINE_FACTORY)
  116. bd.text.addTxt(MetaString::ADVOB_TXT, 157); //{War Machine Factory} Would you like to purchase War Machines?
  117. else
  118. throw std::runtime_error("Illegal dwelling!");
  119. cb->showBlockingDialog(&bd);
  120. }
  121. void CGDwelling::newTurn() const
  122. {
  123. if(cb->getDate(Date::DAY_OF_WEEK) != 1) //not first day of week
  124. return;
  125. //town growths and War Machines Factories are handled separately
  126. if(ID == Obj::TOWN || ID == Obj::WAR_MACHINE_FACTORY)
  127. return;
  128. if(ID == Obj::REFUGEE_CAMP) //if it's a refugee camp, we need to pick an available creature
  129. {
  130. cb->setObjProperty(id, ObjProperty::AVAILABLE_CREATURE, VLC->creh->pickRandomMonster(cb->gameState()->getRandomGenerator()));
  131. }
  132. bool change = false;
  133. SetAvailableCreatures sac;
  134. sac.creatures = creatures;
  135. sac.tid = id;
  136. for (size_t i = 0; i < creatures.size(); i++)
  137. {
  138. if(creatures[i].second.size())
  139. {
  140. CCreature *cre = VLC->creh->creatures[creatures[i].second[0]];
  141. TQuantity amount = cre->growth * (1 + cre->valOfBonuses(Bonus::CREATURE_GROWTH_PERCENT)/100) + cre->valOfBonuses(Bonus::CREATURE_GROWTH);
  142. if (VLC->modh->settings.DWELLINGS_ACCUMULATE_CREATURES && ID != Obj::REFUGEE_CAMP) //camp should not try to accumulate different kinds of creatures
  143. sac.creatures[i].first += amount;
  144. else
  145. sac.creatures[i].first = amount;
  146. change = true;
  147. }
  148. }
  149. if(change)
  150. cb->sendAndApply(&sac);
  151. }
  152. void CGDwelling::heroAcceptsCreatures( const CGHeroInstance *h) const
  153. {
  154. CreatureID crid = creatures[0].second[0];
  155. CCreature *crs = VLC->creh->creatures[crid];
  156. TQuantity count = creatures[0].first;
  157. if(crs->level == 1 && ID != Obj::REFUGEE_CAMP) //first level - creatures are for free
  158. {
  159. if(count) //there are available creatures
  160. {
  161. SlotID slot = h->getSlotFor(crid);
  162. if(!slot.validSlot()) //no available slot
  163. {
  164. InfoWindow iw;
  165. iw.player = h->tempOwner;
  166. iw.text.addTxt(MetaString::GENERAL_TXT, 425);//The %s would join your hero, but there aren't enough provisions to support them.
  167. iw.text.addReplacement(MetaString::CRE_PL_NAMES, crid);
  168. cb->showInfoDialog(&iw);
  169. }
  170. else //give creatures
  171. {
  172. SetAvailableCreatures sac;
  173. sac.tid = id;
  174. sac.creatures = creatures;
  175. sac.creatures[0].first = 0;
  176. InfoWindow iw;
  177. iw.player = h->tempOwner;
  178. iw.text.addTxt(MetaString::GENERAL_TXT, 423); //%d %s join your army.
  179. iw.text.addReplacement(count);
  180. iw.text.addReplacement(MetaString::CRE_PL_NAMES, crid);
  181. cb->showInfoDialog(&iw);
  182. cb->sendAndApply(&sac);
  183. cb->addToSlot(StackLocation(h, slot), crs, count);
  184. }
  185. }
  186. else //there no creatures
  187. {
  188. InfoWindow iw;
  189. iw.text.addTxt(MetaString::GENERAL_TXT, 422); //There are no %s here to recruit.
  190. iw.text.addReplacement(MetaString::CRE_PL_NAMES, crid);
  191. iw.player = h->tempOwner;
  192. cb->sendAndApply(&iw);
  193. }
  194. }
  195. else
  196. {
  197. if(ID == Obj::WAR_MACHINE_FACTORY) //pick available War Machines
  198. {
  199. //there is 1 war machine available to recruit if hero doesn't have one
  200. SetAvailableCreatures sac;
  201. sac.tid = id;
  202. sac.creatures = creatures;
  203. sac.creatures[0].first = !h->getArt(ArtifactPosition::MACH1); //ballista
  204. sac.creatures[1].first = !h->getArt(ArtifactPosition::MACH3); //first aid tent
  205. sac.creatures[2].first = !h->getArt(ArtifactPosition::MACH2); //ammo cart
  206. cb->sendAndApply(&sac);
  207. }
  208. OpenWindow ow;
  209. ow.id1 = id.getNum();
  210. ow.id2 = h->id.getNum();
  211. ow.window = (ID == Obj::CREATURE_GENERATOR1 || ID == Obj::REFUGEE_CAMP)
  212. ? OpenWindow::RECRUITMENT_FIRST
  213. : OpenWindow::RECRUITMENT_ALL;
  214. cb->sendAndApply(&ow);
  215. }
  216. }
  217. void CGDwelling::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
  218. {
  219. if (result.winner == 0)
  220. {
  221. onHeroVisit(hero);
  222. }
  223. }
  224. void CGDwelling::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) const
  225. {
  226. auto relations = cb->getPlayerRelations(getOwner(), hero->getOwner());
  227. if(stacksCount() > 0 && relations == PlayerRelations::ENEMIES) //guards present
  228. {
  229. if(answer)
  230. cb->startBattleI(hero, this);
  231. }
  232. else if(answer)
  233. {
  234. heroAcceptsCreatures(hero);
  235. }
  236. }
  237. int CGTownInstance::getSightRadious() const //returns sight distance
  238. {
  239. if (subID == ETownType::TOWER)
  240. {
  241. if (hasBuilt(BuildingID::GRAIL)) //skyship
  242. return -1; //entire map
  243. if (hasBuilt(BuildingID::LOOKOUT_TOWER)) //lookout tower
  244. return 20;
  245. }
  246. return 5;
  247. }
  248. void CGTownInstance::setPropertyDer(ui8 what, ui32 val)
  249. {
  250. ///this is freakin' overcomplicated solution
  251. switch (what)
  252. {
  253. case ObjProperty::STRUCTURE_ADD_VISITING_HERO:
  254. bonusingBuildings[val]->setProperty (ObjProperty::VISITORS, visitingHero->id.getNum());
  255. break;
  256. case ObjProperty::STRUCTURE_CLEAR_VISITORS:
  257. bonusingBuildings[val]->setProperty (ObjProperty::STRUCTURE_CLEAR_VISITORS, 0);
  258. break;
  259. case ObjProperty::STRUCTURE_ADD_GARRISONED_HERO: //add garrisoned hero to visitors
  260. bonusingBuildings[val]->setProperty (ObjProperty::VISITORS, garrisonHero->id.getNum());
  261. break;
  262. case ObjProperty::BONUS_VALUE_FIRST:
  263. bonusValue.first = val;
  264. break;
  265. case ObjProperty::BONUS_VALUE_SECOND:
  266. bonusValue.second = val;
  267. break;
  268. }
  269. }
  270. CGTownInstance::EFortLevel CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle
  271. {
  272. if (hasBuilt(BuildingID::CASTLE))
  273. return CASTLE;
  274. if (hasBuilt(BuildingID::CITADEL))
  275. return CITADEL;
  276. if (hasBuilt(BuildingID::FORT))
  277. return FORT;
  278. return NONE;
  279. }
  280. int CGTownInstance::hallLevel() const // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
  281. {
  282. if (hasBuilt(BuildingID::CAPITOL))
  283. return 3;
  284. if (hasBuilt(BuildingID::CITY_HALL))
  285. return 2;
  286. if (hasBuilt(BuildingID::TOWN_HALL))
  287. return 1;
  288. if (hasBuilt(BuildingID::VILLAGE_HALL))
  289. return 0;
  290. return -1;
  291. }
  292. int CGTownInstance::mageGuildLevel() const
  293. {
  294. if (hasBuilt(BuildingID::MAGES_GUILD_5))
  295. return 5;
  296. if (hasBuilt(BuildingID::MAGES_GUILD_4))
  297. return 4;
  298. if (hasBuilt(BuildingID::MAGES_GUILD_3))
  299. return 3;
  300. if (hasBuilt(BuildingID::MAGES_GUILD_2))
  301. return 2;
  302. if (hasBuilt(BuildingID::MAGES_GUILD_1))
  303. return 1;
  304. return 0;
  305. }
  306. int CGTownInstance::getHordeLevel(const int & HID) const//HID - 0 or 1; returns creature level or -1 if that horde structure is not present
  307. {
  308. return town->hordeLvl.at(HID);
  309. }
  310. int CGTownInstance::creatureGrowth(const int & level) const
  311. {
  312. return getGrowthInfo(level).totalGrowth();
  313. }
  314. GrowthInfo CGTownInstance::getGrowthInfo(int level) const
  315. {
  316. GrowthInfo ret;
  317. if (level<0 || level >=GameConstants::CREATURES_PER_TOWN)
  318. return ret;
  319. if (creatures[level].second.empty())
  320. return ret; //no dwelling
  321. const CCreature *creature = VLC->creh->creatures[creatures[level].second.back()];
  322. const int base = creature->growth;
  323. int castleBonus = 0;
  324. ret.entries.push_back(GrowthInfo::Entry(VLC->generaltexth->allTexts[590], base));// \n\nBasic growth %d"
  325. if (hasBuilt(BuildingID::CASTLE))
  326. ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CASTLE, castleBonus = base));
  327. else if (hasBuilt(BuildingID::CITADEL))
  328. ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::CITADEL, castleBonus = base / 2));
  329. if(town->hordeLvl.at(0) == level)//horde 1
  330. if(hasBuilt(BuildingID::HORDE_1))
  331. ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_1, creature->hordeGrowth));
  332. if(town->hordeLvl.at(1) == level)//horde 2
  333. if(hasBuilt(BuildingID::HORDE_2))
  334. ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::HORDE_2, creature->hordeGrowth));
  335. int dwellingBonus = 0;
  336. if(const PlayerState *p = cb->getPlayer(tempOwner, false))
  337. {
  338. for(const CGDwelling *dwelling : p->dwellings)
  339. if(vstd::contains(creatures[level].second, dwelling->creatures[0].second[0]))
  340. dwellingBonus++;
  341. }
  342. if(dwellingBonus)
  343. ret.entries.push_back(GrowthInfo::Entry(VLC->generaltexth->allTexts[591], dwellingBonus));// \nExternal dwellings %+d
  344. //other *-of-legion-like bonuses (%d to growth cumulative with grail)
  345. TBonusListPtr bonuses = getBonuses(Selector::type(Bonus::CREATURE_GROWTH).And(Selector::subtype(level)));
  346. for(const Bonus *b : *bonuses)
  347. ret.entries.push_back(GrowthInfo::Entry(b->Description() + " %+d", b->val));
  348. //statue-of-legion-like bonus: % to base+castle
  349. TBonusListPtr bonuses2 = getBonuses(Selector::type(Bonus::CREATURE_GROWTH_PERCENT));
  350. for(const Bonus *b : *bonuses2)
  351. ret.entries.push_back(GrowthInfo::Entry(b->Description() + " %+d", b->val * (base + castleBonus) / 100));
  352. if(hasBuilt(BuildingID::GRAIL)) //grail - +50% to ALL (so far added) growth
  353. ret.entries.push_back(GrowthInfo::Entry(subID, BuildingID::GRAIL, ret.totalGrowth() / 2));
  354. return ret;
  355. }
  356. TResources CGTownInstance::dailyIncome() const
  357. {
  358. TResources ret;
  359. for (auto & p : town->buildings)
  360. {
  361. BuildingID buildingUpgrade;
  362. for (auto & p2 : town->buildings)
  363. {
  364. if (p2.second->upgrade == p.first)
  365. {
  366. buildingUpgrade = p2.first;
  367. }
  368. }
  369. if (!hasBuilt(buildingUpgrade)&&(hasBuilt(p.first)))
  370. {
  371. ret += p.second->produce;
  372. }
  373. }
  374. return ret;
  375. }
  376. bool CGTownInstance::hasFort() const
  377. {
  378. return hasBuilt(BuildingID::FORT);
  379. }
  380. bool CGTownInstance::hasCapitol() const
  381. {
  382. return hasBuilt(BuildingID::CAPITOL);
  383. }
  384. CGTownInstance::CGTownInstance()
  385. :IShipyard(this), IMarket(this), town(nullptr), builded(0), destroyed(0), identifier(0), alignment(0xff)
  386. {
  387. }
  388. CGTownInstance::~CGTownInstance()
  389. {
  390. for (auto & elem : bonusingBuildings)
  391. delete elem;
  392. }
  393. int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const
  394. {
  395. if(checkGuild && mageGuildLevel() < level)
  396. return 0;
  397. int ret = 6 - level; //how many spells are available at this level
  398. if (hasBuilt(BuildingID::LIBRARY, ETownType::TOWER))
  399. ret++;
  400. return ret;
  401. }
  402. bool CGTownInstance::needsLastStack() const
  403. {
  404. if(garrisonHero)
  405. return true;
  406. else return false;
  407. }
  408. void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
  409. {
  410. if( !cb->gameState()->getPlayerRelations( getOwner(), h->getOwner() ))//if this is enemy
  411. {
  412. if(armedGarrison() || visitingHero)
  413. {
  414. const CGHeroInstance *defendingHero = nullptr;
  415. const CArmedInstance *defendingArmy = this;
  416. if(visitingHero)
  417. defendingHero = visitingHero;
  418. else if(garrisonHero)
  419. defendingHero = garrisonHero;
  420. if(defendingHero)
  421. defendingArmy = defendingHero;
  422. bool outsideTown = (defendingHero == visitingHero && garrisonHero);
  423. //TODO
  424. //"borrowing" army from garrison to visiting hero
  425. cb->startBattlePrimary(h, defendingArmy, getSightCenter(), h, defendingHero, false, (outsideTown ? nullptr : this));
  426. }
  427. else
  428. {
  429. cb->setOwner(this, h->tempOwner);
  430. removeCapitols(h->getOwner());
  431. cb->heroVisitCastle(this, h);
  432. }
  433. }
  434. else if(h->visitablePos() == visitablePos())
  435. {
  436. if (h->commander && !h->commander->alive) //rise commander. TODO: interactive script
  437. {
  438. SetCommanderProperty scp;
  439. scp.heroid = h->id;
  440. scp.which = SetCommanderProperty::ALIVE;
  441. scp.amount = 1;
  442. cb->sendAndApply (&scp);
  443. }
  444. cb->heroVisitCastle(this, h);
  445. }
  446. else
  447. {
  448. logGlobal->errorStream() << h->name << " visits allied town of " << name << " from different pos?";
  449. }
  450. }
  451. void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
  452. {
  453. cb->stopHeroVisitCastle(this, h);
  454. }
  455. std::string CGTownInstance::getObjectName() const
  456. {
  457. return name + ", " + town->faction->name;
  458. }
  459. void CGTownInstance::initObj()
  460. ///initialize town structures
  461. {
  462. blockVisit = true;
  463. if (subID == ETownType::DUNGEON)
  464. creatures.resize(GameConstants::CREATURES_PER_TOWN+1);//extra dwelling for Dungeon
  465. else
  466. creatures.resize(GameConstants::CREATURES_PER_TOWN);
  467. for (int level = 0; level < GameConstants::CREATURES_PER_TOWN; level++)
  468. {
  469. BuildingID buildID = BuildingID(BuildingID::DWELL_FIRST).advance(level);
  470. int upgradeNum = 0;
  471. for (; town->buildings.count(buildID); upgradeNum++, buildID.advance(GameConstants::CREATURES_PER_TOWN))
  472. {
  473. if (hasBuilt(buildID) && town->creatures.at(level).size() > upgradeNum)
  474. creatures[level].second.push_back(town->creatures[level][upgradeNum]);
  475. }
  476. }
  477. switch (subID)
  478. { //add new visitable objects
  479. case 0:
  480. bonusingBuildings.push_back (new COPWBonus(BuildingID::STABLES, this));
  481. break;
  482. case 5:
  483. bonusingBuildings.push_back (new COPWBonus(BuildingID::MANA_VORTEX, this));
  484. //fallthrough
  485. case 2: case 3: case 6:
  486. bonusingBuildings.push_back (new CTownBonus(BuildingID::SPECIAL_4, this));
  487. break;
  488. case 7:
  489. bonusingBuildings.push_back (new CTownBonus(BuildingID::SPECIAL_1, this));
  490. break;
  491. }
  492. //add special bonuses from buildings
  493. recreateBuildingsBonuses();
  494. updateAppearance();
  495. }
  496. void CGTownInstance::newTurn() const
  497. {
  498. if (cb->getDate(Date::DAY_OF_WEEK) == 1) //reset on new week
  499. {
  500. auto & rand = cb->gameState()->getRandomGenerator();
  501. //give resources for Rampart, Mystic Pond
  502. if (hasBuilt(BuildingID::MYSTIC_POND, ETownType::RAMPART)
  503. && cb->getDate(Date::DAY) != 1 && (tempOwner < PlayerColor::PLAYER_LIMIT))
  504. {
  505. int resID = rand.nextInt(2, 5); //bonus to random rare resource
  506. resID = (resID==2)?1:resID;
  507. int resVal = rand.nextInt(1, 4);//with size 1..4
  508. cb->giveResource(tempOwner, static_cast<Res::ERes>(resID), resVal);
  509. cb->setObjProperty (id, ObjProperty::BONUS_VALUE_FIRST, resID);
  510. cb->setObjProperty (id, ObjProperty::BONUS_VALUE_SECOND, resVal);
  511. }
  512. if ( subID == ETownType::DUNGEON )
  513. for (auto & elem : bonusingBuildings)
  514. {
  515. if ((elem)->ID == BuildingID::MANA_VORTEX)
  516. cb->setObjProperty (id, ObjProperty::STRUCTURE_CLEAR_VISITORS, (elem)->id); //reset visitors for Mana Vortex
  517. }
  518. if (tempOwner == PlayerColor::NEUTRAL) //garrison growth for neutral towns
  519. {
  520. std::vector<SlotID> nativeCrits; //slots
  521. for (auto & elem : Slots())
  522. {
  523. if (elem.second->type->faction == subID) //native
  524. {
  525. nativeCrits.push_back(elem.first); //collect matching slots
  526. }
  527. }
  528. if (nativeCrits.size())
  529. {
  530. SlotID pos = *RandomGeneratorUtil::nextItem(nativeCrits, rand);
  531. StackLocation sl(this, pos);
  532. const CCreature *c = getCreature(pos);
  533. if (rand.nextInt(99) < 90 || c->upgrades.empty()) //increase number if no upgrade available
  534. {
  535. cb->changeStackCount(sl, c->growth);
  536. }
  537. else //upgrade
  538. {
  539. cb->changeStackType(sl, VLC->creh->creatures[*c->upgrades.begin()]);
  540. }
  541. }
  542. if ((stacksCount() < GameConstants::ARMY_SIZE && rand.nextInt(99) < 25) || Slots().empty()) //add new stack
  543. {
  544. int i = rand.nextInt(std::min(GameConstants::CREATURES_PER_TOWN, cb->getDate(Date::MONTH) << 1) - 1);
  545. if (!town->creatures[i].empty())
  546. {
  547. CreatureID c = town->creatures[i][0];
  548. SlotID n;
  549. TQuantity count = creatureGrowth(i);
  550. if (!count) // no dwelling
  551. count = VLC->creh->creatures[c]->growth;
  552. {//no lower tiers or above current month
  553. if ((n = getSlotFor(c)).validSlot())
  554. {
  555. StackLocation sl(this, n);
  556. if (slotEmpty(n))
  557. cb->insertNewStack(sl, VLC->creh->creatures[c], count);
  558. else //add to existing
  559. cb->changeStackCount(sl, count);
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. /*
  568. int3 CGTownInstance::getSightCenter() const
  569. {
  570. return pos - int3(2,0,0);
  571. }
  572. */
  573. bool CGTownInstance::passableFor(PlayerColor color) const
  574. {
  575. if (!armedGarrison())//empty castle - anyone can visit
  576. return true;
  577. if ( tempOwner == PlayerColor::NEUTRAL )//neutral guarded - no one can visit
  578. return false;
  579. if (cb->getPlayerRelations(tempOwner, color) != PlayerRelations::ENEMIES)
  580. return true;
  581. return false;
  582. }
  583. void CGTownInstance::getOutOffsets( std::vector<int3> &offsets ) const
  584. {
  585. offsets += int3(-1,2,0), int3(-3,2,0);
  586. }
  587. void CGTownInstance::removeCapitols (PlayerColor owner) const
  588. {
  589. if (hasCapitol()) // search if there's an older capitol
  590. {
  591. PlayerState* state = cb->gameState()->getPlayer (owner); //get all towns owned by player
  592. for (auto i = state->towns.cbegin(); i < state->towns.cend(); ++i)
  593. {
  594. if (*i != this && (*i)->hasCapitol())
  595. {
  596. RazeStructures rs;
  597. rs.tid = id;
  598. rs.bid.insert(BuildingID::CAPITOL);
  599. rs.destroyed = destroyed;
  600. cb->sendAndApply(&rs);
  601. return;
  602. }
  603. }
  604. }
  605. }
  606. int CGTownInstance::getBoatType() const
  607. {
  608. switch (town->faction->alignment)
  609. {
  610. case EAlignment::EVIL : return 0;
  611. case EAlignment::GOOD : return 1;
  612. case EAlignment::NEUTRAL : return 2;
  613. }
  614. assert(0);
  615. return -1;
  616. }
  617. int CGTownInstance::getMarketEfficiency() const
  618. {
  619. if (!hasBuilt(BuildingID::MARKETPLACE))
  620. return 0;
  621. const PlayerState *p = cb->getPlayer(tempOwner);
  622. assert(p);
  623. int marketCount = 0;
  624. for(const CGTownInstance *t : p->towns)
  625. if(t->hasBuilt(BuildingID::MARKETPLACE))
  626. marketCount++;
  627. return marketCount;
  628. }
  629. bool CGTownInstance::allowsTrade(EMarketMode::EMarketMode mode) const
  630. {
  631. switch(mode)
  632. {
  633. case EMarketMode::RESOURCE_RESOURCE:
  634. case EMarketMode::RESOURCE_PLAYER:
  635. return hasBuilt(BuildingID::MARKETPLACE);
  636. case EMarketMode::ARTIFACT_RESOURCE:
  637. case EMarketMode::RESOURCE_ARTIFACT:
  638. return hasBuilt(BuildingID::ARTIFACT_MERCHANT, ETownType::TOWER)
  639. || hasBuilt(BuildingID::ARTIFACT_MERCHANT, ETownType::DUNGEON)
  640. || hasBuilt(BuildingID::ARTIFACT_MERCHANT, ETownType::CONFLUX);
  641. case EMarketMode::CREATURE_RESOURCE:
  642. return hasBuilt(BuildingID::FREELANCERS_GUILD, ETownType::STRONGHOLD);
  643. case EMarketMode::CREATURE_UNDEAD:
  644. return hasBuilt(BuildingID::SKELETON_TRANSFORMER, ETownType::NECROPOLIS);
  645. case EMarketMode::RESOURCE_SKILL:
  646. return hasBuilt(BuildingID::MAGIC_UNIVERSITY, ETownType::CONFLUX);
  647. default:
  648. assert(0);
  649. return false;
  650. }
  651. }
  652. std::vector<int> CGTownInstance::availableItemsIds(EMarketMode::EMarketMode mode) const
  653. {
  654. if(mode == EMarketMode::RESOURCE_ARTIFACT)
  655. {
  656. std::vector<int> ret;
  657. for(const CArtifact *a : merchantArtifacts)
  658. if(a)
  659. ret.push_back(a->id);
  660. else
  661. ret.push_back(-1);
  662. return ret;
  663. }
  664. else if ( mode == EMarketMode::RESOURCE_SKILL )
  665. {
  666. return universitySkills;
  667. }
  668. else
  669. return IMarket::availableItemsIds(mode);
  670. }
  671. void CGTownInstance::setType(si32 ID, si32 subID)
  672. {
  673. assert(ID == Obj::TOWN); // just in case
  674. CGObjectInstance::setType(ID, subID);
  675. town = VLC->townh->factions[subID]->town;
  676. randomizeArmy(subID);
  677. updateAppearance();
  678. }
  679. void CGTownInstance::updateAppearance()
  680. {
  681. //FIXME: not the best way to do this
  682. auto app = VLC->objtypeh->getHandlerFor(ID, subID)->getOverride(cb->gameState()->getTile(visitablePos())->terType, this);
  683. if (app)
  684. appearance = app.get();
  685. }
  686. std::string CGTownInstance::nodeName() const
  687. {
  688. return "Town (" + (town ? town->faction->name : "unknown") + ") of " + name;
  689. }
  690. void CGTownInstance::deserializationFix()
  691. {
  692. attachTo(&townAndVis);
  693. //Hero is already handled by CGameState::attachArmedObjects
  694. // if(visitingHero)
  695. // visitingHero->attachTo(&townAndVis);
  696. // if(garrisonHero)
  697. // garrisonHero->attachTo(this);
  698. }
  699. void CGTownInstance::updateMoraleBonusFromArmy()
  700. {
  701. Bonus *b = getBonusList().getFirst(Selector::sourceType(Bonus::ARMY).And(Selector::type(Bonus::MORALE)));
  702. if(!b)
  703. {
  704. b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
  705. addNewBonus(b);
  706. }
  707. if (garrisonHero)
  708. b->val = 0;
  709. else
  710. CArmedInstance::updateMoraleBonusFromArmy();
  711. }
  712. void CGTownInstance::recreateBuildingsBonuses()
  713. {
  714. static TPropagatorPtr playerProp(new CPropagatorNodeType(PLAYER));
  715. BonusList bl;
  716. getExportedBonusList().getBonuses(bl, Selector::sourceType(Bonus::TOWN_STRUCTURE));
  717. for(Bonus *b : bl)
  718. removeBonus(b);
  719. //tricky! -> checks tavern only if no bratherhood of sword or not a castle
  720. if(subID != ETownType::CASTLE || !addBonusIfBuilt(BuildingID::BROTHERHOOD, Bonus::MORALE, +2))
  721. addBonusIfBuilt(BuildingID::TAVERN, Bonus::MORALE, +1);
  722. if(subID == ETownType::CASTLE) //castle
  723. {
  724. addBonusIfBuilt(BuildingID::LIGHTHOUSE, Bonus::SEA_MOVEMENT, +500, playerProp);
  725. addBonusIfBuilt(BuildingID::GRAIL, Bonus::MORALE, +2, playerProp); //colossus
  726. }
  727. else if(subID == ETownType::RAMPART) //rampart
  728. {
  729. addBonusIfBuilt(BuildingID::FOUNTAIN_OF_FORTUNE, Bonus::LUCK, +2); //fountain of fortune
  730. addBonusIfBuilt(BuildingID::GRAIL, Bonus::LUCK, +2, playerProp); //guardian spirit
  731. }
  732. else if(subID == ETownType::TOWER) //tower
  733. {
  734. addBonusIfBuilt(BuildingID::GRAIL, Bonus::PRIMARY_SKILL, +15, PrimarySkill::KNOWLEDGE); //grail
  735. }
  736. else if(subID == ETownType::INFERNO) //Inferno
  737. {
  738. addBonusIfBuilt(BuildingID::STORMCLOUDS, Bonus::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER); //Brimstone Clouds
  739. }
  740. else if(subID == ETownType::NECROPOLIS) //necropolis
  741. {
  742. addBonusIfBuilt(BuildingID::COVER_OF_DARKNESS, Bonus::DARKNESS, +20);
  743. addBonusIfBuilt(BuildingID::NECROMANCY_AMPLIFIER, Bonus::SECONDARY_SKILL_PREMY, +10, playerProp, SecondarySkill::NECROMANCY); //necromancy amplifier
  744. addBonusIfBuilt(BuildingID::GRAIL, Bonus::SECONDARY_SKILL_PREMY, +20, playerProp, SecondarySkill::NECROMANCY); //Soul prison
  745. }
  746. else if(subID == ETownType::DUNGEON) //Dungeon
  747. {
  748. addBonusIfBuilt(BuildingID::GRAIL, Bonus::PRIMARY_SKILL, +12, PrimarySkill::SPELL_POWER); //grail
  749. }
  750. else if(subID == ETownType::STRONGHOLD) //Stronghold
  751. {
  752. addBonusIfBuilt(BuildingID::GRAIL, Bonus::PRIMARY_SKILL, +20, PrimarySkill::ATTACK); //grail
  753. }
  754. else if(subID == ETownType::FORTRESS) //Fortress
  755. {
  756. addBonusIfBuilt(BuildingID::GLYPHS_OF_FEAR, Bonus::PRIMARY_SKILL, +2, PrimarySkill::DEFENSE); //Glyphs of Fear
  757. addBonusIfBuilt(BuildingID::BLOOD_OBELISK, Bonus::PRIMARY_SKILL, +2, PrimarySkill::ATTACK); //Blood Obelisk
  758. addBonusIfBuilt(BuildingID::GRAIL, Bonus::PRIMARY_SKILL, +10, PrimarySkill::ATTACK); //grail
  759. addBonusIfBuilt(BuildingID::GRAIL, Bonus::PRIMARY_SKILL, +10, PrimarySkill::DEFENSE); //grail
  760. }
  761. else if(subID == ETownType::CONFLUX)
  762. {
  763. }
  764. }
  765. bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, int subtype /*= -1*/)
  766. {
  767. static auto emptyPropagator = TPropagatorPtr();
  768. return addBonusIfBuilt(building, type, val, emptyPropagator, subtype);
  769. }
  770. bool CGTownInstance::addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr & prop, int subtype /*= -1*/)
  771. {
  772. if(hasBuilt(building))
  773. {
  774. std::ostringstream descr;
  775. descr << town->buildings.at(building)->Name() << " ";
  776. if(val > 0)
  777. descr << "+";
  778. else if(val < 0)
  779. descr << "-";
  780. descr << val;
  781. Bonus *b = new Bonus(Bonus::PERMANENT, type, Bonus::TOWN_STRUCTURE, val, building, descr.str(), subtype);
  782. if(prop)
  783. b->addPropagator(prop);
  784. addNewBonus(b);
  785. return true;
  786. }
  787. return false;
  788. }
  789. void CGTownInstance::setVisitingHero(CGHeroInstance *h)
  790. {
  791. assert(!!visitingHero == !h);
  792. if(h)
  793. {
  794. PlayerState *p = cb->gameState()->getPlayer(h->tempOwner);
  795. assert(p);
  796. h->detachFrom(p);
  797. h->attachTo(&townAndVis);
  798. visitingHero = h;
  799. h->visitedTown = this;
  800. h->inTownGarrison = false;
  801. }
  802. else
  803. {
  804. PlayerState *p = cb->gameState()->getPlayer(visitingHero->tempOwner);
  805. visitingHero->visitedTown = nullptr;
  806. visitingHero->detachFrom(&townAndVis);
  807. visitingHero->attachTo(p);
  808. visitingHero = nullptr;
  809. }
  810. }
  811. void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
  812. {
  813. assert(!!garrisonHero == !h);
  814. if(h)
  815. {
  816. PlayerState *p = cb->gameState()->getPlayer(h->tempOwner);
  817. assert(p);
  818. h->detachFrom(p);
  819. h->attachTo(this);
  820. garrisonHero = h;
  821. h->visitedTown = this;
  822. h->inTownGarrison = true;
  823. }
  824. else
  825. {
  826. PlayerState *p = cb->gameState()->getPlayer(garrisonHero->tempOwner);
  827. garrisonHero->visitedTown = nullptr;
  828. garrisonHero->inTownGarrison = false;
  829. garrisonHero->detachFrom(this);
  830. garrisonHero->attachTo(p);
  831. garrisonHero = nullptr;
  832. }
  833. updateMoraleBonusFromArmy(); //avoid giving morale bonus for same army twice
  834. }
  835. bool CGTownInstance::armedGarrison() const
  836. {
  837. return stacksCount() || garrisonHero;
  838. }
  839. int CGTownInstance::getTownLevel() const
  840. {
  841. // count all buildings that are not upgrades
  842. return boost::range::count_if(builtBuildings, [&](const BuildingID & build)
  843. {
  844. return town->buildings.at(build) && town->buildings.at(build)->upgrade == -1;
  845. });
  846. }
  847. CBonusSystemNode * CGTownInstance::whatShouldBeAttached()
  848. {
  849. return &townAndVis;
  850. }
  851. const CArmedInstance * CGTownInstance::getUpperArmy() const
  852. {
  853. if(garrisonHero)
  854. return garrisonHero;
  855. return this;
  856. }
  857. bool CGTownInstance::hasBuilt(BuildingID buildingID, int townID) const
  858. {
  859. if (townID == town->faction->index || townID == ETownType::ANY)
  860. return hasBuilt(buildingID);
  861. return false;
  862. }
  863. bool CGTownInstance::hasBuilt(BuildingID buildingID) const
  864. {
  865. return vstd::contains(builtBuildings, buildingID);
  866. }
  867. void CGTownInstance::addHeroToStructureVisitors( const CGHeroInstance *h, si32 structureInstanceID ) const
  868. {
  869. if(visitingHero == h)
  870. cb->setObjProperty(id, ObjProperty::STRUCTURE_ADD_VISITING_HERO, structureInstanceID); //add to visitors
  871. else if(garrisonHero == h)
  872. cb->setObjProperty(id, ObjProperty::STRUCTURE_ADD_GARRISONED_HERO, structureInstanceID); //then it must be garrisoned hero
  873. else
  874. {
  875. //should never ever happen
  876. logGlobal->errorStream() << "Cannot add hero " << h->name << " to visitors of structure #" << structureInstanceID;
  877. assert(0);
  878. }
  879. }
  880. void CGTownInstance::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
  881. {
  882. if(result.winner == 0)
  883. {
  884. removeCapitols(hero->getOwner());
  885. cb->setOwner (this, hero->tempOwner); //give control after checkout is done
  886. FoWChange fw;
  887. fw.player = hero->tempOwner;
  888. fw.mode = 1;
  889. cb->getTilesInRange(fw.tiles, getSightCenter(), getSightRadious(), tempOwner, 1);
  890. cb->sendAndApply (&fw);
  891. }
  892. }
  893. COPWBonus::COPWBonus (BuildingID index, CGTownInstance *TOWN)
  894. {
  895. ID = index;
  896. town = TOWN;
  897. id = town->bonusingBuildings.size();
  898. }
  899. void COPWBonus::setProperty(ui8 what, ui32 val)
  900. {
  901. switch (what)
  902. {
  903. case ObjProperty::VISITORS:
  904. visitors.insert(val);
  905. break;
  906. case ObjProperty::STRUCTURE_CLEAR_VISITORS:
  907. visitors.clear();
  908. break;
  909. }
  910. }
  911. void COPWBonus::onHeroVisit (const CGHeroInstance * h) const
  912. {
  913. ObjectInstanceID heroID = h->id;
  914. if (town->hasBuilt(ID))
  915. {
  916. InfoWindow iw;
  917. iw.player = h->tempOwner;
  918. switch (town->subID)
  919. {
  920. case ETownType::CASTLE: //Stables
  921. if (!h->hasBonusFrom(Bonus::OBJECT, Obj::STABLES)) //does not stack with advMap Stables
  922. {
  923. GiveBonus gb;
  924. gb.bonus = Bonus(Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, Bonus::OBJECT, 600, 94, VLC->generaltexth->arraytxt[100]);
  925. gb.id = heroID.getNum();
  926. cb->giveHeroBonus(&gb);
  927. iw.text << VLC->generaltexth->allTexts[580];
  928. cb->showInfoDialog(&iw);
  929. }
  930. break;
  931. case ETownType::DUNGEON: //Mana Vortex
  932. if (visitors.empty() && h->mana <= h->manaLimit() * 2)
  933. {
  934. cb->setManaPoints (heroID, 2 * h->manaLimit());
  935. //TODO: investigate line below
  936. //cb->setObjProperty (town->id, ObjProperty::VISITED, true);
  937. iw.text << VLC->generaltexth->allTexts[579];
  938. cb->showInfoDialog(&iw);
  939. town->addHeroToStructureVisitors(h, id);
  940. }
  941. break;
  942. }
  943. }
  944. }
  945. CTownBonus::CTownBonus (BuildingID index, CGTownInstance *TOWN)
  946. {
  947. ID = index;
  948. town = TOWN;
  949. id = town->bonusingBuildings.size();
  950. }
  951. void CTownBonus::setProperty (ui8 what, ui32 val)
  952. {
  953. if(what == ObjProperty::VISITORS)
  954. visitors.insert(ObjectInstanceID(val));
  955. }
  956. void CTownBonus::onHeroVisit (const CGHeroInstance * h) const
  957. {
  958. ObjectInstanceID heroID = h->id;
  959. if (town->hasBuilt(ID) && visitors.find(heroID) == visitors.end())
  960. {
  961. InfoWindow iw;
  962. PrimarySkill::PrimarySkill what = PrimarySkill::ATTACK;
  963. int val=0, mid=0;
  964. switch (ID)
  965. {
  966. case BuildingID::SPECIAL_4:
  967. switch(town->subID)
  968. {
  969. case ETownType::TOWER: //wall
  970. what = PrimarySkill::KNOWLEDGE;
  971. val = 1;
  972. mid = 581;
  973. iw.components.push_back (Component(Component::PRIM_SKILL, 3, 1, 0));
  974. break;
  975. case ETownType::INFERNO: //order of fire
  976. what = PrimarySkill::SPELL_POWER;
  977. val = 1;
  978. mid = 582;
  979. iw.components.push_back (Component(Component::PRIM_SKILL, 2, 1, 0));
  980. break;
  981. case ETownType::STRONGHOLD://hall of Valhalla
  982. what = PrimarySkill::ATTACK;
  983. val = 1;
  984. mid = 584;
  985. iw.components.push_back (Component(Component::PRIM_SKILL, 0, 1, 0));
  986. break;
  987. case ETownType::DUNGEON://academy of battle scholars
  988. what = PrimarySkill::EXPERIENCE;
  989. val = h->calculateXp(1000);
  990. mid = 583;
  991. iw.components.push_back (Component(Component::EXPERIENCE, 0, val, 0));
  992. break;
  993. }
  994. break;
  995. case BuildingID::SPECIAL_1:
  996. switch(town->subID)
  997. {
  998. case ETownType::FORTRESS: //cage of warlords
  999. what = PrimarySkill::DEFENSE;
  1000. val = 1;
  1001. mid = 585;
  1002. iw.components.push_back (Component(Component::PRIM_SKILL, 1, 1, 0));
  1003. break;
  1004. }
  1005. break;
  1006. }
  1007. assert(mid);
  1008. iw.player = cb->getOwner(heroID);
  1009. iw.text << VLC->generaltexth->allTexts[mid];
  1010. cb->showInfoDialog(&iw);
  1011. cb->changePrimSkill (cb->getHero(heroID), what, val);
  1012. town->addHeroToStructureVisitors(h, id);
  1013. }
  1014. }
  1015. GrowthInfo::Entry::Entry(const std::string &format, int _count)
  1016. : count(_count)
  1017. {
  1018. description = boost::str(boost::format(format) % count);
  1019. }
  1020. GrowthInfo::Entry::Entry(int subID, BuildingID building, int _count)
  1021. : count(_count)
  1022. {
  1023. description = boost::str(boost::format("%s %+d") % VLC->townh->factions[subID]->town->buildings.at(building)->Name() % count);
  1024. }
  1025. CTownAndVisitingHero::CTownAndVisitingHero()
  1026. {
  1027. setNodeType(TOWN_AND_VISITOR);
  1028. }
  1029. int GrowthInfo::totalGrowth() const
  1030. {
  1031. int ret = 0;
  1032. for(const Entry &entry : entries)
  1033. ret += entry.count;
  1034. return ret;
  1035. }