1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +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,15 +495,11 @@ void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
std::shared_ptr<Bonus> b;
static TPropagatorPtr playerPropagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::ENodeTypes::PLAYER);
if(building->subId == BuildingSubID::NONE)
{
if(building->bid == BuildingID::TAVERN)
{
b = createBonus(building, Bonus::MORALE, +1);
}
}
else
{
switch(building->subId)
{
case BuildingSubID::BROTHERHOOD_OF_SWORD:
@ -526,7 +522,7 @@ void CTownHandler::addBonusesForVanilaBuilding(CBuilding * building) const
b = createBonus(building, Bonus::MOVEMENT, +500, playerPropagator, 0);
break;
}
}
if(b)
building->addNewBonus(b, building->buildingBonuses);
}
@ -584,21 +580,19 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
auto * ret = new CBuilding();
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());
}
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
? CBuilding::BUILD_GRAIL
: getMappedValue<CBuilding::EBuildMode>(source["mode"], CBuilding::BUILD_NORMAL, CBuilding::MODES);
ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS);
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;
@ -618,7 +612,10 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
loadSpecialBuildingBonuses(source["bonuses"], ret->buildingBonuses, ret);
if(ret->buildingBonuses.empty())
{
ret->subId = getMappedValue<BuildingSubID::EBuildingSubID>(source["type"], BuildingSubID::NONE, MappedKeys::SPECIAL_BUILDINGS);
addBonusesForVanilaBuilding(ret);
}
loadSpecialBuildingBonuses(source["onVisitBonuses"], ret->onVisitBonuses, ret);
@ -686,11 +683,12 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
}
void CTownHandler::loadBuildings(CTown * town, const JsonNode & source)
{
if(source.isStruct())
{
for(const auto & node : source.Struct())
{
if (!node.second.isNull())
{
loadBuilding(town, node.first, node.second);
}
}

View File

@ -604,16 +604,43 @@ namespace MappedKeys
{ "special2", BuildingID::SPECIAL_2 },
{ "special3", BuildingID::SPECIAL_3 },
{ "special4", BuildingID::SPECIAL_4 },
{ "grail", BuildingID::GRAIL }
};
static const std::map<BuildingID, std::string> BUILDING_TYPES_TO_NAMES =
{
{ BuildingID::SPECIAL_1, "special1", },
{ BuildingID::SPECIAL_2, "special2" },
{ BuildingID::SPECIAL_3, "special3" },
{ BuildingID::SPECIAL_4, "special4" },
{ BuildingID::GRAIL, "grail"}
{ "grail", BuildingID::GRAIL },
{ "mageGuild1", BuildingID::MAGES_GUILD_1 },
{ "mageGuild2", BuildingID::MAGES_GUILD_2 },
{ "mageGuild3", BuildingID::MAGES_GUILD_3 },
{ "mageGuild4", BuildingID::MAGES_GUILD_4 },
{ "mageGuild5", BuildingID::MAGES_GUILD_5 },
{ "tavern", BuildingID::TAVERN },
{ "shipyard", BuildingID::SHIPYARD },
{ "fort", BuildingID::FORT },
{ "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 =