1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +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

@ -1339,14 +1339,22 @@ CHallInterface::CHallInterface(const CGTownInstance *Town):
{
for(size_t col=0; col<boxList[row].size(); col++) //for each box
{
const CBuilding *building = nullptr;
for(auto & elem : boxList[row][col])//we are looking for the first not build structure
const CBuilding * building = nullptr;
for(auto & buildingID : boxList[row][col])//we are looking for the first not built structure
{
auto buildingID = elem;
building = town->town->buildings.at(buildingID);
if(!vstd::contains(town->builtBuildings,buildingID))
break;
const CBuilding * current = town->town->buildings.at(buildingID);
if(vstd::contains(town->builtBuildings, buildingID))
{
building = current;
}
else
{
if(current->mode == CBuilding::BUILD_NORMAL)
{
building = current;
break;
}
}
}
int posX = pos.w/2 - boxList[row].size()*154/2 - (boxList[row].size()-1)*20 + 194*col,
posY = 35 + 104*row;

View File

@ -129,7 +129,7 @@
[
[ [ "villageHall", "townHall", "cityHall", "capitol" ], [ "fort", "citadel", "castle" ], [ "tavern" ], [ "blacksmith" ] ],
[ [ "marketplace", "resourceSilo" ], [ "mageGuild1", "mageGuild2", "mageGuild3", "mageGuild4", "mageGuild5" ], [ "special2" ], [ "special3" ] ],
[ [ "special1" ], [ "special4" ], [ "horde1" ] ],
[ [ "special1" ], [ "special4" ], [ "horde1", "horde1Upgr" ] ],
[ [ "dwellingLvl1", "dwellingUpLvl1" ], [ "dwellingLvl2", "dwellingUpLvl2" ], [ "dwellingLvl3", "dwellingUpLvl3" ], [ "dwellingLvl4", "dwellingUpLvl4" ] ],
[ [ "dwellingLvl5", "dwellingUpLvl5" ], [ "dwellingLvl6", "dwellingUpLvl6" ], [ "dwellingLvl7", "dwellingUpLvl7" ] ]
],
@ -171,7 +171,7 @@
"special1": { "id" : 17, "requires" : [ "marketplace" ] },
"horde1": { "id" : 18, "upgrades" : "dwellingLvl1" },
"horde1Upgr": { "id" : 19, "upgrades" : "dwellingUpLvl1", "requires" : [ "allOf", [ "horde1" ], [ "dwellingUpLvl1" ] ], "mode" : "auto" },
"horde1Upgr": { "id" : 19, "upgrades" : "dwellingUpLvl1", "requires" : [ "horde1" ], "mode" : "auto" },
"special2": { "id" : 21, "requires" : [ "mageGuild1" ] },
"special3": { "id" : 22 },
"special4": { "id" : 23 },

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;

View File

@ -78,9 +78,15 @@ public:
h & requirements;
h & upgrade;
h & mode;
if(!h.saving)
deserializeFix();
}
friend class CTownHandler;
private:
void deserializeFix();
};
/// This is structure used only by client

View File

@ -2993,9 +2993,11 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID,
buildingsThatWillBe.insert(b->bid);
remainingAutoBuildings -= b;
for (auto autoBuilding : remainingAutoBuildings)
for(auto autoBuilding : remainingAutoBuildings)
{
if (autoBuilding->requirements.test(areRequirementsFullfilled))
auto actualRequirements = t->genBuildingRequirements(autoBuilding->bid);
if(actualRequirements.test(areRequirementsFullfilled))
buildingsToAdd.push(autoBuilding);
}
}