CGDwelling.cpp 17 KB

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