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

Town building build mode fixes

* CGameHandler::buildStructure was using wrong requirements for buildings in auto mode.
* Build mode loading was wrong in case of omitted value
* Show town hall slot for not built building only if it have normal build mode
This commit is contained in:
AlexVinS
2017-10-28 02:25:44 +03:00
parent 8027650f4a
commit c39cd5f951
5 changed files with 58 additions and 13 deletions

View File

@@ -66,6 +66,24 @@ si32 CBuilding::getDistance(BuildingID buildID) const
return -1;
}
void CBuilding::deserializeFix()
{
//default value for mode was broken, have to fix it here for old saves (v777 and older)
switch(mode)
{
case BUILD_NORMAL:
case BUILD_AUTO:
case BUILD_SPECIAL:
case BUILD_GRAIL:
break;
default:
mode = BUILD_NORMAL;
break;
}
}
CFaction::CFaction()
{
town = nullptr;
@@ -329,9 +347,20 @@ void CTownHandler::loadBuilding(CTown * town, const std::string & stringID, cons
{
auto ret = new CBuilding();
static const std::string modes [] = {"normal", "auto", "special", "grail"};
static const std::vector<std::string> MODES =
{
"normal", "auto", "special", "grail"
};
ret->mode = static_cast<CBuilding::EBuildMode>(boost::find(modes, source["mode"].String()) - modes);
ret->mode = CBuilding::BUILD_NORMAL;
{
if(source["mode"].getType() == JsonNode::DATA_STRING)
{
auto rawMode = vstd::find_pos(MODES, source["mode"].String());
if(rawMode > 0)
ret->mode = static_cast<CBuilding::EBuildMode>(rawMode);
}
}
ret->identifier = stringID;
ret->town = town;