Skip to content

Commit

Permalink
[fix] Fix handling of upgrade (especially in windowstorage for dirty …
Browse files Browse the repository at this point in the history
…version)
  • Loading branch information
Jarod42 committed Aug 19, 2024
1 parent fcb0d3b commit e751144
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/lib/game/logic/action/actionupgradebuilding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ void cActionUpgradeBuilding::execute (cModel& model) const
cSubBase& subbase = *building->subBase;
int availableMetal = subbase.getResourcesStored().metal;
cDynamicUnitData& upgradedData = *building->getOwner()->getLastUnitData (building->data.getId());
upgradedData.markLastVersionUsed();
cUpgradeCalculator& uc = cUpgradeCalculator::instance();
const int upgradeCost = uc.getMaterialCostForUpgrading (upgradedData.getBuildCost());

// first update the selected building
if (availableMetal >= upgradeCost && building->data.getVersion() < upgradedData.getVersion())
if (availableMetal >= upgradeCost && building->data.canBeUpgradedTo (upgradedData))
{
upgradedBuildings.push_back (building);
totalCosts += upgradeCost;
Expand All @@ -68,7 +67,7 @@ void cActionUpgradeBuilding::execute (cModel& model) const
if (b == building) continue;

// check unit version
if (b->data.getVersion() >= upgradedData.getVersion()) continue; // already up to date
if (!b->data.canBeUpgradedTo (upgradedData)) continue; // already up to date

// check upgrade costs
if (upgradeCost > availableMetal) break;
Expand All @@ -82,6 +81,7 @@ void cActionUpgradeBuilding::execute (cModel& model) const
// execute the upgrades
for (auto b : upgradedBuildings)
{
upgradedData.markLastVersionUsed();
// update scan & sentry
if (b->getOwner() && b->data.getScan() < upgradedData.getScan())
{
Expand Down
4 changes: 2 additions & 2 deletions src/lib/game/logic/action/actionupgradevehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ void cActionUpgradeVehicle::execute (cModel& model) const
{
// check unit version
cDynamicUnitData& upgradedData = *vehicle->getOwner()->getLastUnitData (vehicle->data.getId());
upgradedData.markLastVersionUsed();
if (vehicle->data.getVersion() >= upgradedData.getVersion()) continue; // already up to date
if (!vehicle->data.canBeUpgradedTo (upgradedData)) continue; // already up to date

// check upgrade costs
cUpgradeCalculator& uc = cUpgradeCalculator::instance();
const int upgradeCost = uc.getMaterialCostForUpgrading (upgradedData.getBuildCost());
if (upgradeCost > containingBuilding->subBase->getResourcesStored().metal) continue;

// ok, execute upgrade
upgradedData.markLastVersionUsed();
vehicle->upgradeToCurrentVersion();
containingBuilding->subBase->addMetal (-upgradeCost);
result[vehicle->data.getId()].costs += upgradeCost;
Expand Down
6 changes: 3 additions & 3 deletions src/ui/graphical/menu/windows/windowstorage/windowstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void cWindowStorage::updateUnitButtons (const cVehicle& storedUnit, size_t posit
repairButtons[positionIndex]->unlock();
else
repairButtons[positionIndex]->lock();
if (storedUnit.data.getVersion() != upgraded.getVersion() && metalBar->getValue() >= 1)
if (storedUnit.data.canBeUpgradedTo (upgraded) && metalBar->getValue() >= 1)
upgradeButtons[positionIndex]->unlock();
else
upgradeButtons[positionIndex]->lock();
Expand All @@ -202,7 +202,7 @@ void cWindowStorage::updateUnitName (const cVehicle& storedUnit, size_t position
auto name = getDisplayName (storedUnit);

const auto& upgraded = *storedUnit.getOwner()->getLastUnitData (storedUnit.data.getId());
if (storedUnit.data.getVersion() != upgraded.getVersion())
if (storedUnit.data.canBeUpgradedTo (upgraded))
{
name += "\n(" + lngPack.i18n ("Comp~Dated") + ")";
}
Expand Down Expand Up @@ -294,7 +294,7 @@ void cWindowStorage::updateGlobalButtons()

if (!vehicle->getOwner()) continue;
const auto& upgraded = *vehicle->getOwner()->getLastUnitData (vehicle->data.getId());
if (vehicle->data.getVersion() != upgraded.getVersion()) upgradeAllButton->unlock();
if (vehicle->data.canBeUpgradedTo (upgraded)) upgradeAllButton->unlock();
}
}
}
Expand Down

0 comments on commit e751144

Please sign in to comment.