CGTownInstance.cpp 33 KB

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