CTownHandler.cpp 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /*
  2. * CTownHandler.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 "CTownHandler.h"
  12. #include "VCMI_Lib.h"
  13. #include "CGeneralTextHandler.h"
  14. #include "JsonNode.h"
  15. #include "StringConstants.h"
  16. #include "CCreatureHandler.h"
  17. #include "CHeroHandler.h"
  18. #include "CArtHandler.h"
  19. #include "GameSettings.h"
  20. #include "TerrainHandler.h"
  21. #include "spells/CSpellHandler.h"
  22. #include "filesystem/Filesystem.h"
  23. #include "bonuses/Bonus.h"
  24. #include "bonuses/Propagators.h"
  25. #include "ResourceSet.h"
  26. #include "mapObjectConstructors/AObjectTypeHandler.h"
  27. #include "mapObjectConstructors/CObjectClassesHandler.h"
  28. #include "modding/IdentifierStorage.h"
  29. #include "modding/ModScope.h"
  30. VCMI_LIB_NAMESPACE_BEGIN
  31. const int NAMES_PER_TOWN=16; // number of town names per faction in H3 files. Json can define any number
  32. const std::map<std::string, CBuilding::EBuildMode> CBuilding::MODES =
  33. {
  34. { "normal", CBuilding::BUILD_NORMAL },
  35. { "auto", CBuilding::BUILD_AUTO },
  36. { "special", CBuilding::BUILD_SPECIAL },
  37. { "grail", CBuilding::BUILD_GRAIL }
  38. };
  39. const std::map<std::string, CBuilding::ETowerHeight> CBuilding::TOWER_TYPES =
  40. {
  41. { "low", CBuilding::HEIGHT_LOW },
  42. { "average", CBuilding::HEIGHT_AVERAGE },
  43. { "high", CBuilding::HEIGHT_HIGH },
  44. { "skyship", CBuilding::HEIGHT_SKYSHIP }
  45. };
  46. std::string CBuilding::getJsonKey() const
  47. {
  48. return modScope + ':' + identifier;;
  49. }
  50. std::string CBuilding::getNameTranslated() const
  51. {
  52. return VLC->generaltexth->translate(getNameTextID());
  53. }
  54. std::string CBuilding::getDescriptionTranslated() const
  55. {
  56. return VLC->generaltexth->translate(getDescriptionTextID());
  57. }
  58. std::string CBuilding::getBaseTextID() const
  59. {
  60. return TextIdentifier("building", modScope, town->faction->identifier, identifier).get();
  61. }
  62. std::string CBuilding::getNameTextID() const
  63. {
  64. return TextIdentifier(getBaseTextID(), "name").get();
  65. }
  66. std::string CBuilding::getDescriptionTextID() const
  67. {
  68. return TextIdentifier(getBaseTextID(), "description").get();
  69. }
  70. BuildingID CBuilding::getBase() const
  71. {
  72. const CBuilding * build = this;
  73. while (build->upgrade >= 0)
  74. {
  75. build = build->town->buildings.at(build->upgrade);
  76. }
  77. return build->bid;
  78. }
  79. si32 CBuilding::getDistance(const BuildingID & buildID) const
  80. {
  81. const CBuilding * build = town->buildings.at(buildID);
  82. int distance = 0;
  83. while (build->upgrade >= 0 && build != this)
  84. {
  85. build = build->town->buildings.at(build->upgrade);
  86. distance++;
  87. }
  88. if (build == this)
  89. return distance;
  90. return -1;
  91. }
  92. void CBuilding::addNewBonus(const std::shared_ptr<Bonus> & b, BonusList & bonusList) const
  93. {
  94. bonusList.push_back(b);
  95. }
  96. CFaction::~CFaction()
  97. {
  98. delete town;
  99. }
  100. int32_t CFaction::getIndex() const
  101. {
  102. return index;
  103. }
  104. int32_t CFaction::getIconIndex() const
  105. {
  106. return index; //???
  107. }
  108. std::string CFaction::getJsonKey() const
  109. {
  110. return modScope + ':' + identifier;;
  111. }
  112. void CFaction::registerIcons(const IconRegistar & cb) const
  113. {
  114. if(town)
  115. {
  116. auto & info = town->clientInfo;
  117. cb(info.icons[0][0], 0, "ITPT", info.iconLarge[0][0]);
  118. cb(info.icons[0][1], 0, "ITPT", info.iconLarge[0][1]);
  119. cb(info.icons[1][0], 0, "ITPT", info.iconLarge[1][0]);
  120. cb(info.icons[1][1], 0, "ITPT", info.iconLarge[1][1]);
  121. cb(info.icons[0][0] + 2, 0, "ITPA", info.iconSmall[0][0]);
  122. cb(info.icons[0][1] + 2, 0, "ITPA", info.iconSmall[0][1]);
  123. cb(info.icons[1][0] + 2, 0, "ITPA", info.iconSmall[1][0]);
  124. cb(info.icons[1][1] + 2, 0, "ITPA", info.iconSmall[1][1]);
  125. cb(index, 1, "CPRSMALL", info.towerIconSmall);
  126. cb(index, 1, "TWCRPORT", info.towerIconLarge);
  127. }
  128. }
  129. std::string CFaction::getNameTranslated() const
  130. {
  131. return VLC->generaltexth->translate(getNameTextID());
  132. }
  133. std::string CFaction::getNameTextID() const
  134. {
  135. return TextIdentifier("faction", modScope, identifier, "name").get();
  136. }
  137. FactionID CFaction::getId() const
  138. {
  139. return FactionID(index);
  140. }
  141. FactionID CFaction::getFaction() const
  142. {
  143. return FactionID(index);
  144. }
  145. bool CFaction::hasTown() const
  146. {
  147. return town != nullptr;
  148. }
  149. EAlignment CFaction::getAlignment() const
  150. {
  151. return alignment;
  152. }
  153. EBoatId CFaction::getBoatType() const
  154. {
  155. return boatType.toEnum();
  156. }
  157. TerrainId CFaction::getNativeTerrain() const
  158. {
  159. return nativeTerrain;
  160. }
  161. void CFaction::updateFrom(const JsonNode & data)
  162. {
  163. }
  164. void CFaction::serializeJson(JsonSerializeFormat & handler)
  165. {
  166. }
  167. CTown::CTown()
  168. : faction(nullptr), mageLevel(0), primaryRes(0), moatAbility(SpellID::NONE), defaultTavernChance(0)
  169. {
  170. }
  171. CTown::~CTown()
  172. {
  173. for(auto & build : buildings)
  174. build.second.dellNull();
  175. for(auto & str : clientInfo.structures)
  176. str.dellNull();
  177. }
  178. std::string CTown::getRandomNameTranslated(size_t index) const
  179. {
  180. return VLC->generaltexth->translate(getRandomNameTextID(index));
  181. }
  182. std::string CTown::getRandomNameTextID(size_t index) const
  183. {
  184. return TextIdentifier("faction", faction->modScope, faction->identifier, "randomName", index).get();
  185. }
  186. size_t CTown::getRandomNamesCount() const
  187. {
  188. return namesCount;
  189. }
  190. std::string CTown::getBuildingScope() const
  191. {
  192. if(faction == nullptr)
  193. //no faction == random faction
  194. return "building";
  195. else
  196. return "building." + faction->getJsonKey();
  197. }
  198. std::set<si32> CTown::getAllBuildings() const
  199. {
  200. std::set<si32> res;
  201. for(const auto & b : buildings)
  202. {
  203. res.insert(b.first.num);
  204. }
  205. return res;
  206. }
  207. const CBuilding * CTown::getSpecialBuilding(BuildingSubID::EBuildingSubID subID) const
  208. {
  209. for(const auto & kvp : buildings)
  210. {
  211. if(kvp.second->subId == subID)
  212. return buildings.at(kvp.first);
  213. }
  214. return nullptr;
  215. }
  216. BuildingID::EBuildingID CTown::getBuildingType(BuildingSubID::EBuildingSubID subID) const
  217. {
  218. const auto * building = getSpecialBuilding(subID);
  219. return building == nullptr ? BuildingID::NONE : building->bid.num;
  220. }
  221. std::string CTown::getGreeting(BuildingSubID::EBuildingSubID subID) const
  222. {
  223. return CTownHandler::getMappedValue<const std::string, BuildingSubID::EBuildingSubID>(subID, std::string(), specialMessages, false);
  224. }
  225. void CTown::setGreeting(BuildingSubID::EBuildingSubID subID, const std::string & message) const
  226. {
  227. specialMessages.insert(std::pair<BuildingSubID::EBuildingSubID, const std::string>(subID, message));
  228. }
  229. CTownHandler::CTownHandler():
  230. randomTown(new CTown()),
  231. randomFaction(new CFaction())
  232. {
  233. randomFaction->town = randomTown;
  234. randomTown->faction = randomFaction;
  235. randomFaction->identifier = "random";
  236. randomFaction->modScope = "core";
  237. }
  238. CTownHandler::~CTownHandler()
  239. {
  240. delete randomTown;
  241. }
  242. JsonNode readBuilding(CLegacyConfigParser & parser)
  243. {
  244. JsonNode ret;
  245. JsonNode & cost = ret["cost"];
  246. //note: this code will try to parse mithril as well but wil always return 0 for it
  247. for(const std::string & resID : GameConstants::RESOURCE_NAMES)
  248. cost[resID].Float() = parser.readNumber();
  249. cost.Struct().erase("mithril"); // erase mithril to avoid confusing validator
  250. parser.endLine();
  251. return ret;
  252. }
  253. TPropagatorPtr & CTownHandler::emptyPropagator()
  254. {
  255. static TPropagatorPtr emptyProp(nullptr);
  256. return emptyProp;
  257. }
  258. std::vector<JsonNode> CTownHandler::loadLegacyData()
  259. {
  260. size_t dataSize = VLC->settings()->getInteger(EGameSettings::TEXTS_FACTION);
  261. std::vector<JsonNode> dest(dataSize);
  262. objects.resize(dataSize);
  263. auto getBuild = [&](size_t town, size_t building) -> JsonNode &
  264. {
  265. return dest[town]["town"]["buildings"][EBuildingType::names[building]];
  266. };
  267. CLegacyConfigParser parser("DATA/BUILDING.TXT");
  268. parser.endLine(); // header
  269. parser.endLine();
  270. //Unique buildings
  271. for (size_t town=0; town<dataSize; town++)
  272. {
  273. parser.endLine(); //header
  274. parser.endLine();
  275. int buildID = 17;
  276. do
  277. {
  278. getBuild(town, buildID) = readBuilding(parser);
  279. buildID++;
  280. }
  281. while (!parser.isNextEntryEmpty());
  282. }
  283. // Common buildings
  284. parser.endLine(); // header
  285. parser.endLine();
  286. parser.endLine();
  287. int buildID = 0;
  288. do
  289. {
  290. JsonNode building = readBuilding(parser);
  291. for (size_t town=0; town<dataSize; town++)
  292. getBuild(town, buildID) = building;
  293. buildID++;
  294. }
  295. while (!parser.isNextEntryEmpty());
  296. parser.endLine(); //header
  297. parser.endLine();
  298. //Dwellings
  299. for (size_t town=0; town<dataSize; town++)
  300. {
  301. parser.endLine(); //header
  302. parser.endLine();
  303. for (size_t i=0; i<14; i++)
  304. {
  305. getBuild(town, 30+i) = readBuilding(parser);
  306. }
  307. }
  308. {
  309. CLegacyConfigParser parser("DATA/BLDGNEUT.TXT");
  310. for(int building=0; building<15; building++)
  311. {
  312. std::string name = parser.readString();
  313. std::string descr = parser.readString();
  314. parser.endLine();
  315. for(int j=0; j<dataSize; j++)
  316. {
  317. getBuild(j, building)["name"].String() = name;
  318. getBuild(j, building)["description"].String() = descr;
  319. }
  320. }
  321. parser.endLine(); // silo
  322. parser.endLine(); // blacksmith //unused entries
  323. parser.endLine(); // moat
  324. //shipyard with the ship
  325. std::string name = parser.readString();
  326. std::string descr = parser.readString();
  327. parser.endLine();
  328. for(int town=0; town<dataSize; town++)
  329. {
  330. getBuild(town, 20)["name"].String() = name;
  331. getBuild(town, 20)["description"].String() = descr;
  332. }
  333. //blacksmith
  334. for(int town=0; town<dataSize; town++)
  335. {
  336. getBuild(town, 16)["name"].String() = parser.readString();
  337. getBuild(town, 16)["description"].String() = parser.readString();
  338. parser.endLine();
  339. }
  340. }
  341. {
  342. CLegacyConfigParser parser("DATA/BLDGSPEC.TXT");
  343. for(int town=0; town<dataSize; town++)
  344. {
  345. for(int build=0; build<9; build++)
  346. {
  347. getBuild(town, 17 + build)["name"].String() = parser.readString();
  348. getBuild(town, 17 + build)["description"].String() = parser.readString();
  349. parser.endLine();
  350. }
  351. getBuild(town, 26)["name"].String() = parser.readString(); // Grail
  352. getBuild(town, 26)["description"].String() = parser.readString();
  353. parser.endLine();
  354. getBuild(town, 15)["name"].String() = parser.readString(); // Resource silo
  355. getBuild(town, 15)["description"].String() = parser.readString();
  356. parser.endLine();
  357. }
  358. }
  359. {
  360. CLegacyConfigParser parser("DATA/DWELLING.TXT");
  361. for(int town=0; town<dataSize; town++)
  362. {
  363. for(int build=0; build<14; build++)
  364. {
  365. getBuild(town, 30 + build)["name"].String() = parser.readString();
  366. getBuild(town, 30 + build)["description"].String() = parser.readString();
  367. parser.endLine();
  368. }
  369. }
  370. }
  371. {
  372. CLegacyConfigParser typeParser("DATA/TOWNTYPE.TXT");
  373. CLegacyConfigParser nameParser("DATA/TOWNNAME.TXT");
  374. size_t townID=0;
  375. do
  376. {
  377. dest[townID]["name"].String() = typeParser.readString();
  378. for (int i=0; i<NAMES_PER_TOWN; i++)
  379. {
  380. JsonNode name;
  381. name.String() = nameParser.readString();
  382. dest[townID]["town"]["names"].Vector().push_back(name);
  383. nameParser.endLine();
  384. }
  385. townID++;
  386. }
  387. while (typeParser.endLine());
  388. }
  389. return dest;
  390. }
  391. void CTownHandler::loadBuildingRequirements(CBuilding * building, const JsonNode & source, std::vector<BuildingRequirementsHelper> & bidsToLoad) const
  392. {
  393. if (source.isNull())
  394. return;
  395. BuildingRequirementsHelper hlp;
  396. hlp.building = building;
  397. hlp.town = building->town;
  398. hlp.json = source;
  399. bidsToLoad.push_back(hlp);
  400. }
  401. template<typename R, typename K>
  402. R CTownHandler::getMappedValue(const K key, const R defval, const std::map<K, R> & map, bool required)
  403. {
  404. auto it = map.find(key);
  405. if(it != map.end())
  406. return it->second;
  407. if(required)
  408. logMod->warn("Warning: Property: '%s' is unknown. Correct the typo or update VCMI.", key);
  409. return defval;
  410. }
  411. template<typename R>
  412. R CTownHandler::getMappedValue(const JsonNode & node, const R defval, const std::map<std::string, R> & map, bool required)
  413. {
  414. if(!node.isNull() && node.getType() == JsonNode::JsonType::DATA_STRING)
  415. return getMappedValue<R, std::string>(node.String(), defval, map, required);
  416. return defval;
  417. }
  418. void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
  419. {
  420. std::shared_ptr<Bonus> b;
  421. static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
  422. if(building->bid == BuildingID::TAVERN)
  423. {
  424. b = createBonus(building, BonusType::MORALE, +1);
  425. }
  426. switch(building->subId)
  427. {
  428. case BuildingSubID::BROTHERHOOD_OF_SWORD:
  429. b = createBonus(building, BonusType::MORALE, +2);
  430. building->overrideBids.insert(BuildingID::TAVERN);
  431. break;
  432. case BuildingSubID::FOUNTAIN_OF_FORTUNE:
  433. b = createBonus(building, BonusType::LUCK, +2);
  434. break;
  435. case BuildingSubID::SPELL_POWER_GARRISON_BONUS:
  436. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER);
  437. break;
  438. case BuildingSubID::ATTACK_GARRISON_BONUS:
  439. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::ATTACK);
  440. break;
  441. case BuildingSubID::DEFENSE_GARRISON_BONUS:
  442. b = createBonus(building, BonusType::PRIMARY_SKILL, +2, PrimarySkill::DEFENSE);
  443. break;
  444. case BuildingSubID::LIGHTHOUSE:
  445. b = createBonus(building, BonusType::MOVEMENT, +500, playerPropagator, 0);
  446. break;
  447. }
  448. if(b)
  449. building->addNewBonus(b, building->buildingBonuses);
  450. }
  451. std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, int subtype) const
  452. {
  453. return createBonus(build, type, val, emptyPropagator(), subtype);
  454. }
  455. std::shared_ptr<Bonus> CTownHandler::createBonus(CBuilding * build, BonusType type, int val, TPropagatorPtr & prop, int subtype) const
  456. {
  457. std::ostringstream descr;
  458. descr << build->getNameTranslated();
  459. return createBonusImpl(build->bid, type, val, prop, descr.str(), subtype);
  460. }
  461. std::shared_ptr<Bonus> CTownHandler::createBonusImpl(const BuildingID & building,
  462. BonusType type,
  463. int val,
  464. TPropagatorPtr & prop,
  465. const std::string & description,
  466. int subtype) const
  467. {
  468. auto b = std::make_shared<Bonus>(BonusDuration::PERMANENT, type, BonusSource::TOWN_STRUCTURE, val, building, description, subtype);
  469. if(prop)
  470. b->addPropagator(prop);
  471. return b;
  472. }
  473. void CTownHandler::loadSpecialBuildingBonuses(const JsonNode & source, BonusList & bonusList, CBuilding * building)
  474. {
  475. for(const auto & b : source.Vector())
  476. {
  477. auto bonus = JsonUtils::parseBuildingBonus(b, building->bid, building->getNameTranslated());
  478. if(bonus == nullptr)
  479. continue;
  480. bonus->sid = Bonus::getSid32(building->town->faction->getIndex(), building->bid);
  481. //JsonUtils::parseBuildingBonus produces UNKNOWN type propagator instead of empty.
  482. if(bonus->propagator != nullptr
  483. && bonus->propagator->getPropagatorType() == CBonusSystemNode::ENodeTypes::UNKNOWN)
  484. bonus->addPropagator(emptyPropagator());
  485. building->addNewBonus(bonus, bonusList);
  486. }
  487. }
  488. void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, const JsonNode & source)
  489. {
  490. assert(stringID.find(':') == std::string::npos);
  491. assert(!source.meta.empty());
  492. auto * ret = new CBuilding();
  493. ret->bid = getMappedValue<BuildingID, std::string>(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false);
  494. ret->subId = BuildingSubID::NONE;
  495. if(ret->bid == BuildingID::NONE && !source["id"].isNull())
  496. {
  497. // FIXME: A lot of false-positives with no clear way to handle them in mods
  498. //logMod->warn("Building %s: id field is deprecated", stringID);
  499. ret->bid = source["id"].isNull() ? BuildingID(BuildingID::NONE) : BuildingID(source["id"].Float());
  500. }
  501. if (ret->bid == BuildingID::NONE)
  502. logMod->error("Building '%s' isn't recognized and won't work properly. Correct the typo or update VCMI.", stringID);
  503. ret->mode = ret->bid == BuildingID::GRAIL
  504. ? CBuilding::BUILD_GRAIL
  505. : getMappedValue<CBuilding::EBuildMode>(source["mode"], CBuilding::BUILD_NORMAL, CBuilding::MODES);
  506. ret->height = getMappedValue<CBuilding::ETowerHeight>(source["height"], CBuilding::HEIGHT_NO_TOWER, CBuilding::TOWER_TYPES);
  507. ret->identifier = stringID;
  508. ret->modScope = source.meta;
  509. ret->town = town;
  510. VLC->generaltexth->registerString(source.meta, ret->getNameTextID(), source["name"].String());
  511. VLC->generaltexth->registerString(source.meta, ret->getDescriptionTextID(), source["description"].String());
  512. ret->resources = TResources(source["cost"]);
  513. ret->produce = TResources(source["produce"]);
  514. if(ret->bid == BuildingID::TAVERN)
  515. addBonusesForVanilaBuilding(ret);
  516. else if(ret->bid.IsSpecialOrGrail())
  517. {
  518. loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
  519. if(ret->buildingBonuses.empty())
  520. {
  521. ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS);
  522. addBonusesForVanilaBuilding(ret);
  523. }
  524. loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret);
  525. if(!ret->onVisitBonuses.empty())
  526. {
  527. if(ret->subId == BuildingSubID::NONE)
  528. ret->subId = BuildingSubID::CUSTOM_VISITING_BONUS;
  529. for(auto & bonus : ret->onVisitBonuses)
  530. bonus->sid = Bonus::getSid32(ret->town->faction->getIndex(), ret->bid);
  531. }
  532. if(source["type"].String() == "configurable" && ret->subId == BuildingSubID::NONE)
  533. {
  534. ret->subId = BuildingSubID::CUSTOM_VISITING_REWARD;
  535. ret->rewardableObjectInfo.init(source, ret->getBaseTextID());
  536. }
  537. }
  538. //MODS COMPATIBILITY FOR 0.96
  539. if(!ret->produce.nonZero())
  540. {
  541. switch (ret->bid) {
  542. break; case BuildingID::VILLAGE_HALL: ret->produce[EGameResID::GOLD] = 500;
  543. break; case BuildingID::TOWN_HALL : ret->produce[EGameResID::GOLD] = 1000;
  544. break; case BuildingID::CITY_HALL : ret->produce[EGameResID::GOLD] = 2000;
  545. break; case BuildingID::CAPITOL : ret->produce[EGameResID::GOLD] = 4000;
  546. break; case BuildingID::GRAIL : ret->produce[EGameResID::GOLD] = 5000;
  547. break; case BuildingID::RESOURCE_SILO :
  548. {
  549. switch (ret->town->primaryRes.toEnum())
  550. {
  551. case EGameResID::GOLD:
  552. ret->produce[ret->town->primaryRes] = 500;
  553. break;
  554. case EGameResID::WOOD_AND_ORE:
  555. ret->produce[EGameResID::WOOD] = 1;
  556. ret->produce[EGameResID::ORE] = 1;
  557. break;
  558. default:
  559. ret->produce[ret->town->primaryRes] = 1;
  560. break;
  561. }
  562. }
  563. }
  564. }
  565. loadBuildingRequirements(ret, source["requires"], requirementsToLoad);
  566. if(ret->bid.IsSpecialOrGrail())
  567. loadBuildingRequirements(ret, source["overrides"], overriddenBidsToLoad);
  568. if (!source["upgrades"].isNull())
  569. {
  570. // building id and upgrades can't be the same
  571. if(stringID == source["upgrades"].String())
  572. {
  573. throw std::runtime_error(boost::str(boost::format("Building with ID '%s' of town '%s' can't be an upgrade of the same building.") %
  574. stringID % ret->town->faction->getNameTranslated()));
  575. }
  576. VLC->identifiers()->requestIdentifier(ret->town->getBuildingScope(), source["upgrades"], [=](si32 identifier)
  577. {
  578. ret->upgrade = BuildingID(identifier);
  579. });
  580. }
  581. else
  582. ret->upgrade = BuildingID::NONE;
  583. ret->town->buildings[ret->bid] = ret;
  584. registerObject(source.meta, ret->town->getBuildingScope(), ret->identifier, ret->bid);
  585. }
  586. void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
  587. {
  588. if(source.isStruct())
  589. {
  590. for(const auto & node : source.Struct())
  591. {
  592. if (!node.second.isNull())
  593. loadBuilding(town, node.first, node.second);
  594. }
  595. }
  596. }
  597. void CTownHandler::loadStructure(CTown &town, const std::string & stringID, const JsonNode & source) const
  598. {
  599. auto * ret = new CStructure();
  600. ret->building = nullptr;
  601. ret->buildable = nullptr;
  602. VLC->identifiers()->tryRequestIdentifier( source.meta, "building." + town.faction->getJsonKey(), stringID, [=, &town](si32 identifier) mutable
  603. {
  604. ret->building = town.buildings[BuildingID(identifier)];
  605. });
  606. if (source["builds"].isNull())
  607. {
  608. VLC->identifiers()->tryRequestIdentifier( source.meta, "building." + town.faction->getJsonKey(), stringID, [=, &town](si32 identifier) mutable
  609. {
  610. ret->building = town.buildings[BuildingID(identifier)];
  611. });
  612. }
  613. else
  614. {
  615. VLC->identifiers()->requestIdentifier("building." + town.faction->getJsonKey(), source["builds"], [=, &town](si32 identifier) mutable
  616. {
  617. ret->buildable = town.buildings[BuildingID(identifier)];
  618. });
  619. }
  620. ret->identifier = stringID;
  621. ret->pos.x = static_cast<si32>(source["x"].Float());
  622. ret->pos.y = static_cast<si32>(source["y"].Float());
  623. ret->pos.z = static_cast<si32>(source["z"].Float());
  624. ret->hiddenUpgrade = source["hidden"].Bool();
  625. ret->defName = source["animation"].String();
  626. ret->borderName = source["border"].String();
  627. ret->areaName = source["area"].String();
  628. town.clientInfo.structures.emplace_back(ret);
  629. }
  630. void CTownHandler::loadStructures(CTown &town, const JsonNode & source) const
  631. {
  632. for(const auto & node : source.Struct())
  633. {
  634. if (!node.second.isNull())
  635. loadStructure(town, node.first, node.second);
  636. }
  637. }
  638. void CTownHandler::loadTownHall(CTown &town, const JsonNode & source) const
  639. {
  640. auto & dstSlots = town.clientInfo.hallSlots;
  641. const auto & srcSlots = source.Vector();
  642. dstSlots.resize(srcSlots.size());
  643. for(size_t i=0; i<dstSlots.size(); i++)
  644. {
  645. auto & dstRow = dstSlots[i];
  646. const auto & srcRow = srcSlots[i].Vector();
  647. dstRow.resize(srcRow.size());
  648. for(size_t j=0; j < dstRow.size(); j++)
  649. {
  650. auto & dstBox = dstRow[j];
  651. const auto & srcBox = srcRow[j].Vector();
  652. dstBox.resize(srcBox.size());
  653. for(size_t k=0; k<dstBox.size(); k++)
  654. {
  655. auto & dst = dstBox[k];
  656. const auto & src = srcBox[k];
  657. VLC->identifiers()->requestIdentifier("building." + town.faction->getJsonKey(), src, [&](si32 identifier)
  658. {
  659. dst = BuildingID(identifier);
  660. });
  661. }
  662. }
  663. }
  664. }
  665. Point JsonToPoint(const JsonNode & node)
  666. {
  667. if(!node.isStruct())
  668. return Point::makeInvalid();
  669. Point ret;
  670. ret.x = static_cast<si32>(node["x"].Float());
  671. ret.y = static_cast<si32>(node["y"].Float());
  672. return ret;
  673. }
  674. void CTownHandler::loadSiegeScreen(CTown &town, const JsonNode & source) const
  675. {
  676. town.clientInfo.siegePrefix = source["imagePrefix"].String();
  677. town.clientInfo.towerIconSmall = source["towerIconSmall"].String();
  678. town.clientInfo.towerIconLarge = source["towerIconLarge"].String();
  679. VLC->identifiers()->requestIdentifier("creature", source["shooter"], [&town](si32 creature)
  680. {
  681. auto crId = CreatureID(creature);
  682. if((*VLC->creh)[crId]->animation.missleFrameAngles.empty())
  683. logMod->error("Mod '%s' error: Creature '%s' on the Archer's tower is not a shooter. Mod should be fixed. Siege will not work properly!"
  684. , town.faction->getNameTranslated()
  685. , (*VLC->creh)[crId]->getNameSingularTranslated());
  686. town.clientInfo.siegeShooter = crId;
  687. });
  688. auto & pos = town.clientInfo.siegePositions;
  689. pos.resize(21);
  690. pos[8] = JsonToPoint(source["towers"]["top"]["tower"]);
  691. pos[17] = JsonToPoint(source["towers"]["top"]["battlement"]);
  692. pos[20] = JsonToPoint(source["towers"]["top"]["creature"]);
  693. pos[2] = JsonToPoint(source["towers"]["keep"]["tower"]);
  694. pos[15] = JsonToPoint(source["towers"]["keep"]["battlement"]);
  695. pos[18] = JsonToPoint(source["towers"]["keep"]["creature"]);
  696. pos[3] = JsonToPoint(source["towers"]["bottom"]["tower"]);
  697. pos[16] = JsonToPoint(source["towers"]["bottom"]["battlement"]);
  698. pos[19] = JsonToPoint(source["towers"]["bottom"]["creature"]);
  699. pos[9] = JsonToPoint(source["gate"]["gate"]);
  700. pos[10] = JsonToPoint(source["gate"]["arch"]);
  701. pos[7] = JsonToPoint(source["walls"]["upper"]);
  702. pos[6] = JsonToPoint(source["walls"]["upperMid"]);
  703. pos[5] = JsonToPoint(source["walls"]["bottomMid"]);
  704. pos[4] = JsonToPoint(source["walls"]["bottom"]);
  705. pos[13] = JsonToPoint(source["moat"]["moat"]);
  706. pos[14] = JsonToPoint(source["moat"]["bank"]);
  707. pos[11] = JsonToPoint(source["static"]["bottom"]);
  708. pos[12] = JsonToPoint(source["static"]["top"]);
  709. pos[1] = JsonToPoint(source["static"]["background"]);
  710. }
  711. static void readIcon(JsonNode source, std::string & small, std::string & large)
  712. {
  713. if (source.getType() == JsonNode::JsonType::DATA_STRUCT) // don't crash on old format
  714. {
  715. small = source["small"].String();
  716. large = source["large"].String();
  717. }
  718. }
  719. void CTownHandler::loadClientData(CTown &town, const JsonNode & source) const
  720. {
  721. CTown::ClientInfo & info = town.clientInfo;
  722. readIcon(source["icons"]["village"]["normal"], info.iconSmall[0][0], info.iconLarge[0][0]);
  723. readIcon(source["icons"]["village"]["built"], info.iconSmall[0][1], info.iconLarge[0][1]);
  724. readIcon(source["icons"]["fort"]["normal"], info.iconSmall[1][0], info.iconLarge[1][0]);
  725. readIcon(source["icons"]["fort"]["built"], info.iconSmall[1][1], info.iconLarge[1][1]);
  726. info.hallBackground = source["hallBackground"].String();
  727. info.musicTheme = source["musicTheme"].String();
  728. info.townBackground = source["townBackground"].String();
  729. info.guildWindow = source["guildWindow"].String();
  730. info.buildingsIcons = source["buildingsIcons"].String();
  731. //left for back compatibility - will be removed later
  732. if(!source["guildBackground"].String().empty())
  733. info.guildBackground = source["guildBackground"].String();
  734. else
  735. info.guildBackground = "TPMAGE.bmp";
  736. if(!source["tavernVideo"].String().empty())
  737. info.tavernVideo = source["tavernVideo"].String();
  738. else
  739. info.tavernVideo = "TAVERN.BIK";
  740. //end of legacy assignment
  741. loadTownHall(town, source["hallSlots"]);
  742. loadStructures(town, source["structures"]);
  743. loadSiegeScreen(town, source["siege"]);
  744. }
  745. void CTownHandler::loadTown(CTown * town, const JsonNode & source)
  746. {
  747. const auto * resIter = boost::find(GameConstants::RESOURCE_NAMES, source["primaryResource"].String());
  748. if(resIter == std::end(GameConstants::RESOURCE_NAMES))
  749. town->primaryRes = GameResID(EGameResID::WOOD_AND_ORE); //Wood + Ore
  750. else
  751. town->primaryRes = GameResID(resIter - std::begin(GameConstants::RESOURCE_NAMES));
  752. warMachinesToLoad[town] = source["warMachine"];
  753. town->mageLevel = static_cast<ui32>(source["mageGuild"].Float());
  754. town->namesCount = 0;
  755. for(const auto & name : source["names"].Vector())
  756. {
  757. VLC->generaltexth->registerString(town->faction->modScope, town->getRandomNameTextID(town->namesCount), name.String());
  758. town->namesCount += 1;
  759. }
  760. if (!source["moatAbility"].isNull()) // VCMI 1.2 compatibility code
  761. {
  762. VLC->identifiers()->requestIdentifier( "spell", source["moatAbility"], [=](si32 ability)
  763. {
  764. town->moatAbility = SpellID(ability);
  765. });
  766. }
  767. else
  768. {
  769. VLC->identifiers()->requestIdentifier( source.meta, "spell", "castleMoat", [=](si32 ability)
  770. {
  771. town->moatAbility = SpellID(ability);
  772. });
  773. }
  774. // Horde building creature level
  775. for(const JsonNode &node : source["horde"].Vector())
  776. town->hordeLvl[static_cast<int>(town->hordeLvl.size())] = static_cast<int>(node.Float());
  777. // town needs to have exactly 2 horde entries. Validation will take care of 2+ entries
  778. // but anything below 2 must be handled here
  779. for (size_t i=source["horde"].Vector().size(); i<2; i++)
  780. town->hordeLvl[static_cast<int>(i)] = -1;
  781. const JsonVector & creatures = source["creatures"].Vector();
  782. town->creatures.resize(creatures.size());
  783. for (size_t i=0; i< creatures.size(); i++)
  784. {
  785. const JsonVector & level = creatures[i].Vector();
  786. town->creatures[i].resize(level.size());
  787. for (size_t j=0; j<level.size(); j++)
  788. {
  789. VLC->identifiers()->requestIdentifier("creature", level[j], [=](si32 creature)
  790. {
  791. town->creatures[i][j] = CreatureID(creature);
  792. });
  793. }
  794. }
  795. town->defaultTavernChance = static_cast<ui32>(source["defaultTavern"].Float());
  796. /// set chance of specific hero class to appear in this town
  797. for(const auto & node : source["tavern"].Struct())
  798. {
  799. int chance = static_cast<int>(node.second.Float());
  800. VLC->identifiers()->requestIdentifier(node.second.meta, "heroClass",node.first, [=](si32 classID)
  801. {
  802. VLC->heroh->classes[HeroClassID(classID)]->selectionProbability[town->faction->getId()] = chance;
  803. });
  804. }
  805. for(const auto & node : source["guildSpells"].Struct())
  806. {
  807. int chance = static_cast<int>(node.second.Float());
  808. VLC->identifiers()->requestIdentifier(node.second.meta, "spell", node.first, [=](si32 spellID)
  809. {
  810. VLC->spellh->objects.at(spellID)->probabilities[town->faction->getId()] = chance;
  811. });
  812. }
  813. for(const JsonNode & d : source["adventureMap"]["dwellings"].Vector())
  814. {
  815. town->dwellings.push_back(d["graphics"].String());
  816. town->dwellingNames.push_back(d["name"].String());
  817. }
  818. loadBuildings(town, source["buildings"]);
  819. loadClientData(*town, source);
  820. }
  821. void CTownHandler::loadPuzzle(CFaction &faction, const JsonNode &source) const
  822. {
  823. faction.puzzleMap.reserve(GameConstants::PUZZLE_MAP_PIECES);
  824. std::string prefix = source["prefix"].String();
  825. for(const JsonNode &piece : source["pieces"].Vector())
  826. {
  827. size_t index = faction.puzzleMap.size();
  828. SPuzzleInfo spi;
  829. spi.x = static_cast<si16>(piece["x"].Float());
  830. spi.y = static_cast<si16>(piece["y"].Float());
  831. spi.whenUncovered = static_cast<ui16>(piece["index"].Float());
  832. spi.number = static_cast<ui16>(index);
  833. // filename calculation
  834. std::ostringstream suffix;
  835. suffix << std::setfill('0') << std::setw(2) << index;
  836. spi.filename = prefix + suffix.str();
  837. faction.puzzleMap.push_back(spi);
  838. }
  839. assert(faction.puzzleMap.size() == GameConstants::PUZZLE_MAP_PIECES);
  840. }
  841. CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode & source, const std::string & identifier, size_t index)
  842. {
  843. assert(identifier.find(':') == std::string::npos);
  844. auto * faction = new CFaction();
  845. faction->index = static_cast<FactionID>(index);
  846. faction->modScope = scope;
  847. faction->identifier = identifier;
  848. VLC->generaltexth->registerString(scope, faction->getNameTextID(), source["name"].String());
  849. faction->creatureBg120 = source["creatureBackground"]["120px"].String();
  850. faction->creatureBg130 = source["creatureBackground"]["130px"].String();
  851. faction->boatType = EBoatId::NONE;
  852. if (!source["boat"].isNull())
  853. {
  854. VLC->identifiers()->requestIdentifier("core:boat", source["boat"], [=](int32_t boatTypeID)
  855. {
  856. faction->boatType = BoatId(boatTypeID);
  857. });
  858. }
  859. int alignment = vstd::find_pos(GameConstants::ALIGNMENT_NAMES, source["alignment"].String());
  860. if (alignment == -1)
  861. faction->alignment = EAlignment::NEUTRAL;
  862. else
  863. faction->alignment = static_cast<EAlignment>(alignment);
  864. auto preferUndergound = source["preferUndergroundPlacement"];
  865. faction->preferUndergroundPlacement = preferUndergound.isNull() ? false : preferUndergound.Bool();
  866. // NOTE: semi-workaround - normally, towns are supposed to have native terrains.
  867. // Towns without one are exceptions. So, vcmi requires nativeTerrain to be defined
  868. // But allows it to be defined with explicit value of "none" if town should not have native terrain
  869. // This is better than allowing such terrain-less towns silently, leading to issues with RMG
  870. faction->nativeTerrain = ETerrainId::NONE;
  871. if ( !source["nativeTerrain"].isNull() && source["nativeTerrain"].String() != "none")
  872. {
  873. VLC->identifiers()->requestIdentifier("terrain", source["nativeTerrain"], [=](int32_t index){
  874. faction->nativeTerrain = TerrainId(index);
  875. auto const & terrain = VLC->terrainTypeHandler->getById(faction->nativeTerrain);
  876. if (!terrain->isSurface() && !terrain->isUnderground())
  877. logMod->warn("Faction %s has terrain %s as native, but terrain is not suitable for either surface or subterranean layers!", faction->getJsonKey(), terrain->getJsonKey());
  878. });
  879. }
  880. if (!source["town"].isNull())
  881. {
  882. faction->town = new CTown();
  883. faction->town->faction = faction;
  884. loadTown(faction->town, source["town"]);
  885. }
  886. else
  887. faction->town = nullptr;
  888. if (!source["puzzleMap"].isNull())
  889. loadPuzzle(*faction, source["puzzleMap"]);
  890. return faction;
  891. }
  892. void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  893. {
  894. auto * object = loadFromJson(scope, data, name, objects.size());
  895. objects.emplace_back(object);
  896. if (object->town)
  897. {
  898. auto & info = object->town->clientInfo;
  899. info.icons[0][0] = 8 + object->index * 4 + 0;
  900. info.icons[0][1] = 8 + object->index * 4 + 1;
  901. info.icons[1][0] = 8 + object->index * 4 + 2;
  902. info.icons[1][1] = 8 + object->index * 4 + 3;
  903. VLC->identifiers()->requestIdentifier(scope, "object", "town", [=](si32 index)
  904. {
  905. // register town once objects are loaded
  906. JsonNode config = data["town"]["mapObject"];
  907. config["faction"].String() = name;
  908. config["faction"].meta = scope;
  909. if (config.meta.empty())// MODS COMPATIBILITY FOR 0.96
  910. config.meta = scope;
  911. VLC->objtypeh->loadSubObject(object->identifier, config, index, object->index);
  912. // MODS COMPATIBILITY FOR 0.96
  913. const auto & advMap = data["town"]["adventureMap"];
  914. if (!advMap.isNull())
  915. {
  916. logMod->warn("Outdated town mod. Will try to generate valid templates out of fort");
  917. JsonNode config;
  918. config["animation"] = advMap["castle"];
  919. VLC->objtypeh->getHandlerFor(index, object->index)->addTemplate(config);
  920. }
  921. });
  922. }
  923. registerObject(scope, "faction", name, object->index);
  924. }
  925. void CTownHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  926. {
  927. auto * object = loadFromJson(scope, data, name, index);
  928. if (objects.size() > index)
  929. assert(objects[index] == nullptr); // ensure that this id was not loaded before
  930. else
  931. objects.resize(index + 1);
  932. objects[index] = object;
  933. if (object->town)
  934. {
  935. auto & info = object->town->clientInfo;
  936. info.icons[0][0] = (GameConstants::F_NUMBER + object->index) * 2 + 0;
  937. info.icons[0][1] = (GameConstants::F_NUMBER + object->index) * 2 + 1;
  938. info.icons[1][0] = object->index * 2 + 0;
  939. info.icons[1][1] = object->index * 2 + 1;
  940. VLC->identifiers()->requestIdentifier(scope, "object", "town", [=](si32 index)
  941. {
  942. // register town once objects are loaded
  943. JsonNode config = data["town"]["mapObject"];
  944. config["faction"].String() = name;
  945. config["faction"].meta = scope;
  946. VLC->objtypeh->loadSubObject(object->identifier, config, index, object->index);
  947. });
  948. }
  949. registerObject(scope, "faction", name, object->index);
  950. }
  951. void CTownHandler::loadRandomFaction()
  952. {
  953. static const ResourceID randomFactionPath("config/factions/random.json");
  954. JsonNode randomFactionJson(randomFactionPath);
  955. randomFactionJson.setMeta(ModScope::scopeBuiltin(), true);
  956. loadBuildings(randomTown, randomFactionJson["random"]["town"]["buildings"]);
  957. }
  958. void CTownHandler::loadCustom()
  959. {
  960. loadRandomFaction();
  961. }
  962. void CTownHandler::afterLoadFinalization()
  963. {
  964. initializeRequirements();
  965. initializeOverridden();
  966. initializeWarMachines();
  967. }
  968. void CTownHandler::initializeRequirements()
  969. {
  970. // must be done separately after all ID's are known
  971. for (auto & requirement : requirementsToLoad)
  972. {
  973. requirement.building->requirements = CBuilding::TRequired(requirement.json, [&](const JsonNode & node) -> BuildingID
  974. {
  975. if (node.Vector().size() > 1)
  976. {
  977. logMod->warn("Unexpected length of town buildings requirements: %d", node.Vector().size());
  978. logMod->warn("Entry contains: ");
  979. logMod->warn(node.toJson());
  980. }
  981. return BuildingID(VLC->identifiers()->getIdentifier(requirement.town->getBuildingScope(), node.Vector()[0]).value());
  982. });
  983. }
  984. requirementsToLoad.clear();
  985. }
  986. void CTownHandler::initializeOverridden()
  987. {
  988. for(auto & bidHelper : overriddenBidsToLoad)
  989. {
  990. auto jsonNode = bidHelper.json;
  991. auto scope = bidHelper.town->getBuildingScope();
  992. for(const auto & b : jsonNode.Vector())
  993. {
  994. auto bid = BuildingID(VLC->identifiers()->getIdentifier(scope, b).value());
  995. bidHelper.building->overrideBids.insert(bid);
  996. }
  997. }
  998. overriddenBidsToLoad.clear();
  999. }
  1000. void CTownHandler::initializeWarMachines()
  1001. {
  1002. // must be done separately after all objects are loaded
  1003. for(auto & p : warMachinesToLoad)
  1004. {
  1005. CTown * t = p.first;
  1006. JsonNode creatureKey = p.second;
  1007. auto ret = VLC->identifiers()->getIdentifier("creature", creatureKey, false);
  1008. if(ret)
  1009. {
  1010. const CCreature * creature = CreatureID(*ret).toCreature();
  1011. t->warMachine = creature->warMachine;
  1012. }
  1013. }
  1014. warMachinesToLoad.clear();
  1015. }
  1016. std::vector<bool> CTownHandler::getDefaultAllowed() const
  1017. {
  1018. std::vector<bool> allowedFactions;
  1019. allowedFactions.reserve(objects.size());
  1020. for(auto town : objects)
  1021. {
  1022. allowedFactions.push_back(town->town != nullptr);
  1023. }
  1024. return allowedFactions;
  1025. }
  1026. std::set<FactionID> CTownHandler::getAllowedFactions(bool withTown) const
  1027. {
  1028. std::set<FactionID> allowedFactions;
  1029. std::vector<bool> allowed;
  1030. if (withTown)
  1031. allowed = getDefaultAllowed();
  1032. else
  1033. allowed.resize( objects.size(), true);
  1034. for (size_t i=0; i<allowed.size(); i++)
  1035. if (allowed[i])
  1036. allowedFactions.insert(static_cast<FactionID>(i));
  1037. return allowedFactions;
  1038. }
  1039. const std::vector<std::string> & CTownHandler::getTypeNames() const
  1040. {
  1041. static const std::vector<std::string> typeNames = { "faction", "town" };
  1042. return typeNames;
  1043. }
  1044. VCMI_LIB_NAMESPACE_END