1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

get rid of building id

This commit is contained in:
nordsoft
2023-04-29 15:46:51 +04:00
parent cc4277748d
commit 3df0ce229e
2 changed files with 74 additions and 49 deletions

View File

@@ -495,38 +495,34 @@ void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
std::shared_ptr<Bonus> b; std::shared_ptr<Bonus> b;
static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER); static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
if(building->subId == BuildingSubID::NONE) if(building->bid == BuildingID::TAVERN)
{ {
if(building->bid == BuildingID::TAVERN) b = createBonus(building, Bonus::MORALE, +1);
{
b = createBonus(building, Bonus::MORALE, +1);
}
} }
else
switch(building->subId)
{ {
switch(building->subId) case BuildingSubID::BROTHERHOOD_OF_SWORD:
{ b = createBonus(building, Bonus::MORALE, +2);
case BuildingSubID::BROTHERHOOD_OF_SWORD: building->overrideBids.insert(BuildingID::TAVERN);
b = createBonus(building, Bonus::MORALE, +2); break;
building->overrideBids.insert(BuildingID::TAVERN); case BuildingSubID::FOUNTAIN_OF_FORTUNE:
break; b = createBonus(building, Bonus::LUCK, +2);
case BuildingSubID::FOUNTAIN_OF_FORTUNE: break;
b = createBonus(building, Bonus::LUCK, +2); case BuildingSubID::SPELL_POWER_GARRISON_BONUS:
break; b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER);
case BuildingSubID::SPELL_POWER_GARRISON_BONUS: break;
b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::SPELL_POWER); case BuildingSubID::ATTACK_GARRISON_BONUS:
break; b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::ATTACK);
case BuildingSubID::ATTACK_GARRISON_BONUS: break;
b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::ATTACK); case BuildingSubID::DEFENSE_GARRISON_BONUS:
break; b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::DEFENSE);
case BuildingSubID::DEFENSE_GARRISON_BONUS: break;
b = createBonus(building, Bonus::PRIMARY_SKILL, +2, PrimarySkill::DEFENSE); case BuildingSubID::LIGHTHOUSE:
break; b = createBonus(building, Bonus::MOVEMENT, +500, playerPropagator, 0);
case BuildingSubID::LIGHTHOUSE: break;
b = createBonus(building, Bonus::MOVEMENT, +500, playerPropagator, 0);
break;
}
} }
if(b) if(b)
building->addNewBonus(b, building->buildingBonuses); building->addNewBonus(b, building->buildingBonuses);
} }
@@ -584,22 +580,20 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
auto * ret = new CBuilding(); auto * ret = new CBuilding();
ret->bid = getMappedValue<BuildingID, std::string>(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false); ret->bid = getMappedValue<BuildingID, std::string>(stringID, BuildingID::NONE, MappedKeys::BUILDING_NAMES_TO_TYPES, false);
if(ret->bid == BuildingID::NONE) if(ret->bid == BuildingID::NONE && !source["id"].isNull())
{
logMod->warn("Building %s: id field is deprecated", stringID);
ret->bid = source["id"].isNull() ? BuildingID(BuildingID::NONE) : BuildingID(source["id"].Float()); ret->bid = source["id"].isNull() ? BuildingID(BuildingID::NONE) : BuildingID(source["id"].Float());
}
if (ret->bid == BuildingID::NONE) if (ret->bid == BuildingID::NONE)
logMod->error("Error: Building '%s' has not internal ID and won't work properly. Correct the typo or update VCMI.", stringID); logMod->error("Building '%s' isn't recognized and won't work properly. Correct the typo or update VCMI.", stringID);
ret->mode = ret->bid == BuildingID::GRAIL ret->mode = ret->bid == BuildingID::GRAIL
? CBuilding::BUILD_GRAIL ? CBuilding::BUILD_GRAIL
: getMappedValue<CBuilding::EBuildMode>(source["mode"], CBuilding::BUILD_NORMAL, CBuilding::MODES); : getMappedValue<CBuilding::EBuildMode>(source["mode"], CBuilding::BUILD_NORMAL, CBuilding::MODES);
ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS); ret->height = getMappedValue<CBuilding::ETowerHeight>(source["height"], CBuilding::HEIGHT_NO_TOWER, CBuilding::TOWER_TYPES);
ret->height = CBuilding::HEIGHT_NO_TOWER;
if(ret->subId == BuildingSubID::LOOKOUT_TOWER
|| ret->bid == BuildingID::GRAIL)
ret->height = getMappedValue<CBuilding::ETowerHeight>(source["height"], CBuilding::HEIGHT_NO_TOWER, CBuilding::TOWER_TYPES);
ret->identifier = stringID; ret->identifier = stringID;
ret->modScope = source.meta; ret->modScope = source.meta;
@@ -618,7 +612,10 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret); loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
if(ret->buildingBonuses.empty()) if(ret->buildingBonuses.empty())
{
ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS);
addBonusesForVanilaBuilding(ret); addBonusesForVanilaBuilding(ret);
}
loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret); loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret);
@@ -687,11 +684,12 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
void CTownHandler::loadBuildings(CTown * town, const JsonNode & source) void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
{ {
for(const auto & node : source.Struct()) if(source.isStruct())
{ {
if (!node.second.isNull()) for(const auto & node : source.Struct())
{ {
loadBuilding(town, node.first, node.second); if (!node.second.isNull())
loadBuilding(town, node.first, node.second);
} }
} }
} }

View File

@@ -604,16 +604,43 @@ namespace MappedKeys
{ "special2", BuildingID::SPECIAL_2 }, { "special2", BuildingID::SPECIAL_2 },
{ "special3", BuildingID::SPECIAL_3 }, { "special3", BuildingID::SPECIAL_3 },
{ "special4", BuildingID::SPECIAL_4 }, { "special4", BuildingID::SPECIAL_4 },
{ "grail", BuildingID::GRAIL } { "grail", BuildingID::GRAIL },
}; { "mageGuild1", BuildingID::MAGES_GUILD_1 },
{ "mageGuild2", BuildingID::MAGES_GUILD_2 },
static const std::map<BuildingID, std::string> BUILDING_TYPES_TO_NAMES = { "mageGuild3", BuildingID::MAGES_GUILD_3 },
{ { "mageGuild4", BuildingID::MAGES_GUILD_4 },
{ BuildingID::SPECIAL_1, "special1", }, { "mageGuild5", BuildingID::MAGES_GUILD_5 },
{ BuildingID::SPECIAL_2, "special2" }, { "tavern", BuildingID::TAVERN },
{ BuildingID::SPECIAL_3, "special3" }, { "shipyard", BuildingID::SHIPYARD },
{ BuildingID::SPECIAL_4, "special4" }, { "fort", BuildingID::FORT },
{ BuildingID::GRAIL, "grail"} { "citadel", BuildingID::CITADEL },
{ "castle", BuildingID::CASTLE },
{ "villageHall", BuildingID::VILLAGE_HALL },
{ "townHall", BuildingID::TOWN_HALL },
{ "cityHall", BuildingID::CITY_HALL },
{ "capitol", BuildingID::CAPITOL },
{ "marketplace", BuildingID::MARKETPLACE },
{ "resourceSilo", BuildingID::RESOURCE_SILO },
{ "blacksmith", BuildingID::BLACKSMITH },
{ "horde1", BuildingID::HORDE_1 },
{ "horde1Upgr", BuildingID::HORDE_1_UPGR },
{ "horde2", BuildingID::HORDE_2 },
{ "horde2Upgr", BuildingID::HORDE_2_UPGR },
{ "ship", BuildingID::SHIP },
{ "dwellingLvl1", BuildingID::DWELL_LVL_1 },
{ "dwellingLvl2", BuildingID::DWELL_LVL_2 },
{ "dwellingLvl3", BuildingID::DWELL_LVL_3 },
{ "dwellingLvl4", BuildingID::DWELL_LVL_4 },
{ "dwellingLvl5", BuildingID::DWELL_LVL_5 },
{ "dwellingLvl6", BuildingID::DWELL_LVL_6 },
{ "dwellingLvl7", BuildingID::DWELL_LVL_7 },
{ "dwellingUpLvl1", BuildingID::DWELL_LVL_1_UP },
{ "dwellingUpLvl2", BuildingID::DWELL_LVL_2_UP },
{ "dwellingUpLvl3", BuildingID::DWELL_LVL_3_UP },
{ "dwellingUpLvl4", BuildingID::DWELL_LVL_4_UP },
{ "dwellingUpLvl5", BuildingID::DWELL_LVL_5_UP },
{ "dwellingUpLvl6", BuildingID::DWELL_LVL_6_UP },
{ "dwellingUpLvl7", BuildingID::DWELL_LVL_7_UP },
}; };
static const std::map<std::string, BuildingSubID::EBuildingSubID> SPECIAL_BUILDINGS = static const std::map<std::string, BuildingSubID::EBuildingSubID> SPECIAL_BUILDINGS =