CTownHandler.cpp 37 KB

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