mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Fix granting of building upgrade as bonus
Such as granting Mages Guild Level 4 when town does not have Mages Guild Level 1
This commit is contained in:
@@ -526,29 +526,49 @@ void CGameStateCampaign::initTowns()
|
|||||||
{
|
{
|
||||||
auto chosenBonus = currentBonus();
|
auto chosenBonus = currentBonus();
|
||||||
|
|
||||||
if (chosenBonus && chosenBonus->type == CampaignBonusType::BUILDING)
|
if (!chosenBonus)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (chosenBonus->type != CampaignBonusType::BUILDING)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int g=0; g<gameState->map->towns.size(); ++g)
|
||||||
{
|
{
|
||||||
for (int g=0; g<gameState->map->towns.size(); ++g)
|
CGTownInstance * town = gameState->map->towns[g];
|
||||||
|
|
||||||
|
PlayerState * owner = gameState->getPlayerState(town->getOwner());
|
||||||
|
if (!owner)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PlayerInfo & pi = gameState->map->players[owner->color.getNum()];
|
||||||
|
|
||||||
|
if (!owner->human)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (town->pos != pi.posOfMainTown)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BuildingID newBuilding;
|
||||||
|
if(gameState->scenarioOps->campState->formatVCMI())
|
||||||
|
newBuilding = BuildingID(chosenBonus->info1);
|
||||||
|
else
|
||||||
|
newBuilding = CBuildingHandler::campToERMU(chosenBonus->info1, town->subID, town->builtBuildings);
|
||||||
|
|
||||||
|
// Build granted building & all prerequisites - e.g. Mages Guild Lvl 3 should also give Mages Guild Lvl 1 & 2
|
||||||
|
while(true)
|
||||||
{
|
{
|
||||||
PlayerState * owner = gameState->getPlayerState(gameState->map->towns[g]->getOwner());
|
if (newBuilding == BuildingID::NONE)
|
||||||
if (owner)
|
break;
|
||||||
{
|
|
||||||
PlayerInfo & pi = gameState->map->players[owner->color.getNum()];
|
|
||||||
|
|
||||||
if (owner->human && //human-owned
|
if (town->builtBuildings.count(newBuilding) != 0)
|
||||||
gameState->map->towns[g]->pos == pi.posOfMainTown)
|
break;
|
||||||
{
|
|
||||||
BuildingID buildingId;
|
|
||||||
if(gameState->scenarioOps->campState->formatVCMI())
|
|
||||||
buildingId = BuildingID(chosenBonus->info1);
|
|
||||||
else
|
|
||||||
buildingId = CBuildingHandler::campToERMU(chosenBonus->info1, gameState->map->towns[g]->subID, gameState->map->towns[g]->builtBuildings);
|
|
||||||
|
|
||||||
gameState->map->towns[g]->builtBuildings.insert(buildingId);
|
town->builtBuildings.insert(newBuilding);
|
||||||
break;
|
|
||||||
}
|
auto building = town->town->buildings.at(newBuilding);
|
||||||
}
|
newBuilding = building->upgrade;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user