CTownHandler.cpp 37 KB

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