CGDwelling.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /*
  2. * CGDwelling.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 "CGDwelling.h"
  12. #include "../callback/IGameInfoCallback.h"
  13. #include "../callback/IGameEventCallback.h"
  14. #include "../callback/IGameRandomizer.h"
  15. #include "../serializer/JsonSerializeFormat.h"
  16. #include "../entities/faction/CTownHandler.h"
  17. #include "../mapping/CMap.h"
  18. #include "../mapObjectConstructors/AObjectTypeHandler.h"
  19. #include "../mapObjectConstructors/CObjectClassesHandler.h"
  20. #include "../mapObjectConstructors/DwellingInstanceConstructor.h"
  21. #include "../mapObjects/CGHeroInstance.h"
  22. #include "../mapObjects/CGTownInstance.h"
  23. #include "../networkPacks/StackLocation.h"
  24. #include "../networkPacks/PacksForClient.h"
  25. #include "../networkPacks/PacksForClientBattle.h"
  26. #include "../gameState/CGameState.h"
  27. #include "../CPlayerState.h"
  28. #include "../IGameSettings.h"
  29. #include "../CConfigHandler.h"
  30. #include "../texts/CGeneralTextHandler.h"
  31. #include <vstd/RNG.h>
  32. VCMI_LIB_NAMESPACE_BEGIN
  33. void CGDwellingRandomizationInfo::serializeJson(JsonSerializeFormat & handler)
  34. {
  35. handler.serializeString("sameAsTown", instanceId);
  36. handler.serializeIdArray("allowedFactions", allowedFactions);
  37. handler.serializeInt("minLevel", minLevel, static_cast<uint8_t>(1));
  38. handler.serializeInt("maxLevel", maxLevel, static_cast<uint8_t>(7));
  39. if(!handler.saving)
  40. {
  41. //todo: safely allow any level > 7
  42. vstd::abetween<uint8_t>(minLevel, 1, 7);
  43. vstd::abetween<uint8_t>(maxLevel, minLevel, 7);
  44. }
  45. }
  46. CGDwelling::CGDwelling(IGameInfoCallback *cb):
  47. CArmedInstance(cb)
  48. {}
  49. CGDwelling::~CGDwelling() = default;
  50. FactionID CGDwelling::randomizeFaction(IGameRandomizer & gameRandomizer)
  51. {
  52. if (ID == Obj::RANDOM_DWELLING_FACTION)
  53. return FactionID(subID.getNum());
  54. assert(ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_LVL);
  55. assert(randomizationInfo.has_value());
  56. if (!randomizationInfo)
  57. return FactionID::CASTLE;
  58. CGTownInstance * linkedTown = nullptr;
  59. if (!randomizationInfo->instanceId.empty())
  60. {
  61. auto iter = cb->gameState().getMap().instanceNames.find(randomizationInfo->instanceId);
  62. if(iter == cb->gameState().getMap().instanceNames.end())
  63. logGlobal->error("Map object not found: %s", randomizationInfo->instanceId);
  64. linkedTown = dynamic_cast<CGTownInstance *>(iter->second.get());
  65. }
  66. if (randomizationInfo->identifier != 0)
  67. {
  68. for(auto & townID : cb->gameState().getMap().getAllTowns())
  69. {
  70. auto town = cb->gameState().getTown(townID);
  71. if(town && town->identifier == randomizationInfo->identifier)
  72. {
  73. linkedTown = town;
  74. break;
  75. }
  76. }
  77. }
  78. if (linkedTown)
  79. {
  80. if(linkedTown->ID==Obj::RANDOM_TOWN)
  81. linkedTown->pickRandomObject(gameRandomizer); //we have to randomize the castle first
  82. assert(linkedTown->ID == Obj::TOWN);
  83. if(linkedTown->ID==Obj::TOWN)
  84. return linkedTown->getFactionID();
  85. }
  86. if(!randomizationInfo->allowedFactions.empty())
  87. return *RandomGeneratorUtil::nextItem(randomizationInfo->allowedFactions, gameRandomizer.getDefault());
  88. std::vector<FactionID> potentialPicks;
  89. for (FactionID faction(0); faction < FactionID(LIBRARY->townh->size()); ++faction)
  90. if (LIBRARY->factions()->getById(faction)->hasTown())
  91. potentialPicks.push_back(faction);
  92. assert(!potentialPicks.empty());
  93. return *RandomGeneratorUtil::nextItem(potentialPicks, gameRandomizer.getDefault());
  94. }
  95. int CGDwelling::randomizeLevel(vstd::RNG & rand)
  96. {
  97. if (ID == Obj::RANDOM_DWELLING_LVL)
  98. return subID.getNum();
  99. assert(ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_FACTION);
  100. assert(randomizationInfo.has_value());
  101. if (!randomizationInfo)
  102. return rand.nextInt(1, 7) - 1;
  103. if(randomizationInfo->minLevel == randomizationInfo->maxLevel)
  104. return randomizationInfo->minLevel - 1;
  105. return rand.nextInt(randomizationInfo->minLevel, randomizationInfo->maxLevel) - 1;
  106. }
  107. void CGDwelling::pickRandomObject(IGameRandomizer & gameRandomizer)
  108. {
  109. if (ID == Obj::RANDOM_DWELLING || ID == Obj::RANDOM_DWELLING_LVL || ID == Obj::RANDOM_DWELLING_FACTION)
  110. {
  111. FactionID faction = randomizeFaction(gameRandomizer);
  112. int level = randomizeLevel(gameRandomizer.getDefault());
  113. assert(faction != FactionID::NONE && faction != FactionID::NEUTRAL);
  114. assert(level >= 0 && level <= 6);
  115. randomizationInfo.reset();
  116. CreatureID cid = (*LIBRARY->townh)[faction]->town->creatures[level][0];
  117. //NOTE: this will pick last dwelling with this creature (Mantis #900)
  118. //check for block map equality is better but more complex solution
  119. auto testID = [&](const Obj & primaryID) -> MapObjectSubID
  120. {
  121. auto dwellingIDs = LIBRARY->objtypeh->knownSubObjects(primaryID);
  122. for (MapObjectSubID entry : dwellingIDs)
  123. {
  124. const auto * handler = dynamic_cast<const DwellingInstanceConstructor *>(LIBRARY->objtypeh->getHandlerFor(primaryID, entry).get());
  125. if (!handler->isBannedForRandomDwelling() && handler->producesCreature(cid.toCreature()))
  126. return MapObjectSubID(entry);
  127. }
  128. return MapObjectSubID();
  129. };
  130. ID = Obj::CREATURE_GENERATOR1;
  131. subID = testID(Obj::CREATURE_GENERATOR1);
  132. if (subID == MapObjectSubID())
  133. {
  134. ID = Obj::CREATURE_GENERATOR4;
  135. subID = testID(Obj::CREATURE_GENERATOR4);
  136. }
  137. if (subID == MapObjectSubID())
  138. {
  139. logGlobal->error("Error: failed to find dwelling for %s of level %d", (*LIBRARY->townh)[faction]->getNameTranslated(), int(level));
  140. ID = Obj::CREATURE_GENERATOR1;
  141. subID = *RandomGeneratorUtil::nextItem(LIBRARY->objtypeh->knownSubObjects(Obj::CREATURE_GENERATOR1), gameRandomizer.getDefault());
  142. }
  143. setType(ID, subID);
  144. }
  145. }
  146. void CGDwelling::initObj(IGameRandomizer & gameRandomizer)
  147. {
  148. switch(ID.toEnum())
  149. {
  150. case Obj::CREATURE_GENERATOR1:
  151. case Obj::CREATURE_GENERATOR4:
  152. case Obj::WAR_MACHINE_FACTORY:
  153. {
  154. getObjectHandler()->configureObject(this, gameRandomizer);
  155. assert(!creatures.empty());
  156. assert(!creatures[0].second.empty());
  157. break;
  158. }
  159. case Obj::REFUGEE_CAMP:
  160. //is handled within newturn func
  161. break;
  162. default:
  163. assert(0);
  164. break;
  165. }
  166. }
  167. void CGDwelling::setPropertyDer(ObjProperty what, ObjPropertyID identifier)
  168. {
  169. switch (what)
  170. {
  171. case ObjProperty::AVAILABLE_CREATURE:
  172. creatures.resize(1);
  173. creatures[0].second.resize(1);
  174. creatures[0].second[0] = identifier.as<CreatureID>();
  175. break;
  176. }
  177. }
  178. void CGDwelling::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
  179. {
  180. if(ID == Obj::REFUGEE_CAMP)
  181. {
  182. ChangeObjectVisitors cow;
  183. cow.mode = ChangeObjectVisitors::VISITOR_CLEAR;
  184. cow.object = id;
  185. gameEvents.sendAndApply(cow);
  186. cow.mode = ChangeObjectVisitors::VISITOR_ADD_PLAYER;
  187. cow.hero = h->id;
  188. gameEvents.sendAndApply(cow);
  189. if (!creatures[0].first) //Refugee Camp, no available cres
  190. {
  191. InfoWindow iw;
  192. iw.type = EInfoWindowMode::AUTO;
  193. iw.player = h->tempOwner;
  194. iw.text.appendLocalString(EMetaText::ADVOB_TXT, 44); //{%s} \n\n The camp is deserted. Perhaps you should try next week.
  195. iw.text.replaceName(ID, subID);
  196. gameEvents.sendAndApply(iw);
  197. return;
  198. }
  199. }
  200. PlayerRelations relations = cb->getPlayerRelations( h->tempOwner, tempOwner );
  201. if ( relations == PlayerRelations::ALLIES )
  202. return;//do not allow recruiting or capturing
  203. if(relations == PlayerRelations::ENEMIES && stacksCount() > 0) //object is guarded, owned by enemy
  204. {
  205. BlockingDialog bd(true,false);
  206. bd.player = h->tempOwner;
  207. bd.text.appendLocalString(EMetaText::GENERAL_TXT, 421); //Much to your dismay, the %s is guarded by %s %s. Do you wish to fight the guards?
  208. bd.text.replaceTextID(getObjectHandler()->getNameTextID());
  209. if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
  210. bd.text.replaceRawString(CCreature::getQuantityRangeStringForId(Slots().begin()->second->getQuantityID()));
  211. else
  212. bd.text.replaceLocalString(EMetaText::ARRAY_TXT, 173 + (int)Slots().begin()->second->getQuantityID()*3);
  213. bd.text.replaceName(*Slots().begin()->second);
  214. gameEvents.showBlockingDialog(this, &bd);
  215. return;
  216. }
  217. // TODO this shouldn't be hardcoded
  218. if(relations == PlayerRelations::ENEMIES && ID != Obj::WAR_MACHINE_FACTORY && ID != Obj::REFUGEE_CAMP)
  219. {
  220. gameEvents.setOwner(this, h->tempOwner);
  221. }
  222. BlockingDialog bd (true,false);
  223. bd.player = h->tempOwner;
  224. if(ID == Obj::CREATURE_GENERATOR1 || ID == Obj::CREATURE_GENERATOR4)
  225. {
  226. const size_t count = std::min<size_t>(creatures.size(), 4);
  227. constexpr std::array dwellingVisitTextID = {
  228. "core.advevent.35", // 0 creatures, should not happen
  229. "core.advevent.35",
  230. "vcmi.adventureMap.dwelling2",
  231. "vcmi.adventureMap.dwelling3",
  232. "core.advevent.36"
  233. };
  234. bd.text.appendTextID(dwellingVisitTextID[count]);
  235. bd.text.replaceTextID(getObjectHandler()->getNameTextID());
  236. for(const auto & elem : creatures)
  237. bd.text.replaceNamePlural(elem.second[0]);
  238. }
  239. else if(ID == Obj::REFUGEE_CAMP)
  240. {
  241. bd.text.appendLocalString(EMetaText::ADVOB_TXT, 35); //{%s} Would you like to recruit %s?
  242. bd.text.replaceName(ID, subID);
  243. for(const auto & elem : creatures)
  244. bd.text.replaceNamePlural(elem.second[0]);
  245. }
  246. else if(ID == Obj::WAR_MACHINE_FACTORY)
  247. bd.text.appendLocalString(EMetaText::ADVOB_TXT, 157); //{War Machine Factory} Would you like to purchase War Machines?
  248. else
  249. throw std::runtime_error("Illegal dwelling!");
  250. if(ID == Obj::REFUGEE_CAMP || (ID == Obj::CREATURE_GENERATOR1 && LIBRARY->creatures()->getById(creatures[0].second[0])->getLevel() != 1))
  251. {
  252. bd.flags |= BlockingDialog::SAFE_TO_AUTOACCEPT;
  253. }
  254. gameEvents.showBlockingDialog(this, &bd);
  255. }
  256. void CGDwelling::newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const
  257. {
  258. if(cb->getDate(Date::DAY_OF_WEEK) != 1) //not first day of week
  259. return;
  260. //town growths and War Machines Factories are handled separately
  261. if(ID == Obj::TOWN || ID == Obj::WAR_MACHINE_FACTORY)
  262. return;
  263. if(ID == Obj::REFUGEE_CAMP) //if it's a refugee camp, we need to pick an available creature
  264. {
  265. ChangeObjectVisitors cow;
  266. cow.mode = ChangeObjectVisitors::VISITOR_CLEAR;
  267. cow.object = id;
  268. gameEvents.sendAndApply(cow);
  269. gameEvents.setObjPropertyID(id, ObjProperty::AVAILABLE_CREATURE, gameRandomizer.rollCreature());
  270. }
  271. bool change = false;
  272. SetAvailableCreatures sac;
  273. sac.creatures = creatures;
  274. sac.tid = id;
  275. for (size_t i = 0; i < creatures.size(); i++)
  276. {
  277. if(!creatures[i].second.empty())
  278. {
  279. bool creaturesAccumulate = false;
  280. if (tempOwner.isValidPlayer())
  281. creaturesAccumulate = cb->getSettings().getBoolean(EGameSettings::DWELLINGS_ACCUMULATE_WHEN_OWNED);
  282. else
  283. creaturesAccumulate = cb->getSettings().getBoolean(EGameSettings::DWELLINGS_ACCUMULATE_WHEN_NEUTRAL);
  284. const CCreature * cre =creatures[i].second[0].toCreature();
  285. TQuantity amount = cre->getGrowth() * (1 + cre->valOfBonuses(BonusType::CREATURE_GROWTH_PERCENT)/100) + cre->valOfBonuses(BonusType::CREATURE_GROWTH, BonusCustomSubtype::creatureLevel(cre->getLevel()));
  286. if (creaturesAccumulate && ID != Obj::REFUGEE_CAMP) //camp should not try to accumulate different kinds of creatures
  287. sac.creatures[i].first += amount;
  288. else
  289. sac.creatures[i].first = amount;
  290. change = true;
  291. }
  292. }
  293. if(change)
  294. gameEvents.sendAndApply(sac);
  295. updateGuards(gameEvents);
  296. }
  297. bool CGDwelling::wasVisited (PlayerColor player) const
  298. {
  299. return cb->getPlayerState(player)->visitedObjects.count(id) != 0;
  300. }
  301. std::vector<Component> CGDwelling::getPopupComponents(PlayerColor player) const
  302. {
  303. bool visitedByOwner = getOwner() == player;
  304. bool isDwelling = ID == Obj::CREATURE_GENERATOR1 || ID == Obj::CREATURE_GENERATOR4;
  305. bool isRefugeeCamp = ID == Obj::REFUGEE_CAMP;
  306. bool canSeeUnitTypes = isDwelling || (isRefugeeCamp && wasVisited(player));
  307. bool canSeeUnitAmount = (isDwelling && visitedByOwner) || (isRefugeeCamp && wasVisited(player));
  308. std::vector<Component> result;
  309. if (creatures.empty())
  310. return result;
  311. if (canSeeUnitTypes)
  312. {
  313. for (auto const & creatureLevel : creatures)
  314. {
  315. for (auto const & creature : creatureLevel.second)
  316. {
  317. if (canSeeUnitAmount)
  318. result.emplace_back(ComponentType::CREATURE, creature, creatures.front().first);
  319. else
  320. result.emplace_back(ComponentType::CREATURE, creature);
  321. }
  322. }
  323. }
  324. return result;
  325. }
  326. void CGDwelling::updateGuards(IGameEventCallback & gameEvents) const
  327. {
  328. //TODO: store custom guard config and use it
  329. //TODO: store boolean flag for guards
  330. bool guarded = false;
  331. //default condition - creatures are of level 5 or higher
  332. for (auto creatureEntry : creatures)
  333. {
  334. if (LIBRARY->creatures()->getById(creatureEntry.second.at(0))->getLevel() >= 5 && ID != Obj::REFUGEE_CAMP)
  335. {
  336. guarded = true;
  337. break;
  338. }
  339. }
  340. if (guarded)
  341. {
  342. for (auto creatureEntry : creatures)
  343. {
  344. const CCreature * crea = creatureEntry.second.at(0).toCreature();
  345. SlotID slot = getSlotFor(crea->getId());
  346. if (hasStackAtSlot(slot)) //stack already exists, overwrite it
  347. {
  348. ChangeStackCount csc;
  349. csc.army = this->id;
  350. csc.slot = slot;
  351. csc.count = crea->getGrowth() * 3;
  352. csc.mode = ChangeValueMode::ABSOLUTE;
  353. gameEvents.sendAndApply(csc);
  354. }
  355. else //slot is empty, create whole new stack
  356. {
  357. InsertNewStack ns;
  358. ns.army = this->id;
  359. ns.slot = slot;
  360. ns.type = crea->getId();
  361. ns.count = crea->getGrowth() * 3;
  362. gameEvents.sendAndApply(ns);
  363. }
  364. }
  365. }
  366. }
  367. void CGDwelling::heroAcceptsCreatures(IGameEventCallback & gameEvents, const CGHeroInstance *h) const
  368. {
  369. CreatureID crid = creatures[0].second[0];
  370. auto *crs = crid.toCreature();
  371. TQuantity count = creatures[0].first;
  372. if(crs->getLevel() == 1 && ID != Obj::REFUGEE_CAMP) //first level - creatures are for free
  373. {
  374. if(count) //there are available creatures
  375. {
  376. if (cb->getSettings().getBoolean(EGameSettings::DWELLINGS_MERGE_ON_RECRUIT))
  377. {
  378. SlotID testSlot = h->getSlotFor(crid);
  379. if(!testSlot.validSlot()) //no available slot - try merging army of visiting hero
  380. {
  381. std::pair<SlotID, SlotID> toMerge;
  382. if (h->mergeableStacks(toMerge))
  383. {
  384. gameEvents.moveStack(StackLocation(h->id, toMerge.first), StackLocation(h->id, toMerge.second), -1); //merge toMerge.first into toMerge.second
  385. assert(!h->hasStackAtSlot(toMerge.first)); //we have now a new free slot
  386. }
  387. }
  388. }
  389. SlotID slot = h->getSlotFor(crid);
  390. if(!slot.validSlot()) //no available slot
  391. {
  392. InfoWindow iw;
  393. iw.type = EInfoWindowMode::AUTO;
  394. iw.player = h->tempOwner;
  395. iw.text.appendLocalString(EMetaText::GENERAL_TXT, 425);//The %s would join your hero, but there aren't enough provisions to support them.
  396. iw.text.replaceNamePlural(crid);
  397. gameEvents.showInfoDialog(&iw);
  398. }
  399. else //give creatures
  400. {
  401. SetAvailableCreatures sac;
  402. sac.tid = id;
  403. sac.creatures = creatures;
  404. sac.creatures[0].first = 0;
  405. InfoWindow iw;
  406. iw.type = EInfoWindowMode::AUTO;
  407. iw.player = h->tempOwner;
  408. iw.text.appendLocalString(EMetaText::GENERAL_TXT, 423); //%d %s join your army.
  409. iw.text.replaceNumber(count);
  410. iw.text.replaceNamePlural(crid);
  411. gameEvents.showInfoDialog(&iw);
  412. gameEvents.sendAndApply(sac);
  413. gameEvents.addToSlot(StackLocation(h->id, slot), crs, count);
  414. }
  415. }
  416. else //there no creatures
  417. {
  418. InfoWindow iw;
  419. iw.type = EInfoWindowMode::AUTO;
  420. iw.text.appendLocalString(EMetaText::GENERAL_TXT, 422); //There are no %s here to recruit.
  421. iw.text.replaceNamePlural(crid);
  422. iw.player = h->tempOwner;
  423. gameEvents.sendAndApply(iw);
  424. }
  425. }
  426. else
  427. {
  428. if(ID == Obj::WAR_MACHINE_FACTORY) //pick available War Machines
  429. {
  430. //there is 1 war machine available to recruit if hero doesn't have one
  431. SetAvailableCreatures sac;
  432. sac.tid = id;
  433. sac.creatures = creatures;
  434. for (auto & entry : sac.creatures)
  435. {
  436. CreatureID creature = entry.second.at(0);
  437. ArtifactID warMachine = creature.toCreature()->warMachine;
  438. if (h->hasArt(warMachine, true, false))
  439. entry.first = 0;
  440. else
  441. entry.first = 1;
  442. }
  443. gameEvents.sendAndApply(sac);
  444. }
  445. auto windowMode = (ID == Obj::CREATURE_GENERATOR1 || ID == Obj::REFUGEE_CAMP) ? EOpenWindowMode::RECRUITMENT_FIRST : EOpenWindowMode::RECRUITMENT_ALL;
  446. gameEvents.showObjectWindow(this, windowMode, h, true);
  447. }
  448. }
  449. void CGDwelling::battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const
  450. {
  451. if (result.winner == BattleSide::ATTACKER)
  452. {
  453. onHeroVisit(gameEvents, hero);
  454. }
  455. }
  456. void CGDwelling::blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const
  457. {
  458. auto relations = cb->getPlayerRelations(getOwner(), hero->getOwner());
  459. if(stacksCount() > 0 && relations == PlayerRelations::ENEMIES) //guards present
  460. {
  461. if(answer)
  462. gameEvents.startBattle(hero, this);
  463. }
  464. else if(answer)
  465. {
  466. heroAcceptsCreatures(gameEvents, hero);
  467. }
  468. }
  469. void CGDwelling::serializeJsonOptions(JsonSerializeFormat & handler)
  470. {
  471. switch (ID.toEnum())
  472. {
  473. case Obj::WAR_MACHINE_FACTORY:
  474. case Obj::REFUGEE_CAMP:
  475. //do nothing
  476. break;
  477. case Obj::RANDOM_DWELLING:
  478. case Obj::RANDOM_DWELLING_LVL:
  479. case Obj::RANDOM_DWELLING_FACTION:
  480. if (!handler.saving)
  481. randomizationInfo = CGDwellingRandomizationInfo();
  482. randomizationInfo->serializeJson(handler);
  483. [[fallthrough]];
  484. default:
  485. serializeJsonOwner(handler);
  486. break;
  487. }
  488. }
  489. const IOwnableObject * CGDwelling::asOwnable() const
  490. {
  491. switch (ID.toEnum())
  492. {
  493. case Obj::WAR_MACHINE_FACTORY:
  494. case Obj::REFUGEE_CAMP:
  495. return nullptr; // can't be owned
  496. default:
  497. return this;
  498. }
  499. }
  500. ResourceSet CGDwelling::dailyIncome() const
  501. {
  502. return {};
  503. }
  504. std::vector<CreatureID> CGDwelling::providedCreatures() const
  505. {
  506. if (ID == Obj::WAR_MACHINE_FACTORY || ID == Obj::REFUGEE_CAMP)
  507. return {};
  508. std::vector<CreatureID> result;
  509. for (const auto & level : creatures)
  510. result.insert(result.end(), level.second.begin(), level.second.end());
  511. return result;
  512. }
  513. VCMI_LIB_NAMESPACE_END