From e0542ff0e1a33539e24e9334003e1bf4283dd384 Mon Sep 17 00:00:00 2001 From: cybermind <iddqd_mail@mail.ru> Date: Sun, 12 May 2013 14:24:45 +0600 Subject: [PATCH] [-] Fixed action freeze when speeds are lower than 100 --- src/action/action_built.cpp | 6 +++--- src/action/action_research.cpp | 2 +- src/action/action_resource.cpp | 8 ++++---- src/action/action_train.cpp | 2 +- src/action/action_upgradeto.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/action/action_built.cpp b/src/action/action_built.cpp index eaf101774..465daaa9d 100644 --- a/src/action/action_built.cpp +++ b/src/action/action_built.cpp @@ -346,7 +346,7 @@ void COrder_Built::Progress(CUnit &unit, int amount) Boost(unit, amount, HP_INDEX); Boost(unit, amount, SHIELD_INDEX); - this->ProgressCounter += amount * unit.Player->SpeedBuild / SPEEDUP_FACTOR; + this->ProgressCounter += std::max(1, amount * unit.Player->SpeedBuild / SPEEDUP_FACTOR); UpdateConstructionFrame(unit); } @@ -354,7 +354,7 @@ void COrder_Built::ProgressHp(CUnit &unit, int amount) { Boost(unit, amount, HP_INDEX); - this->ProgressCounter += amount * unit.Player->SpeedBuild / SPEEDUP_FACTOR; + this->ProgressCounter += std::max(1, amount * unit.Player->SpeedBuild / SPEEDUP_FACTOR); UpdateConstructionFrame(unit); } @@ -365,7 +365,7 @@ void COrder_Built::Boost(CUnit &building, int amount, int varIndex) const const int costs = building.Stats->Costs[TimeCost] * 600; const int progress = this->ProgressCounter; - const int newProgress = progress + amount * building.Player->SpeedBuild / SPEEDUP_FACTOR; + const int newProgress = progress + std::max(1, amount * building.Player->SpeedBuild / SPEEDUP_FACTOR); const int maxValue = building.Variable[varIndex].Max; int ¤tValue = building.Variable[varIndex].Value; diff --git a/src/action/action_research.cpp b/src/action/action_research.cpp index 48561c49a..4c79cbfc3 100644 --- a/src/action/action_research.cpp +++ b/src/action/action_research.cpp @@ -131,7 +131,7 @@ } #endif CPlayer &player = *unit.Player; - player.UpgradeTimers.Upgrades[upgrade.ID] += player.SpeedResearch / SPEEDUP_FACTOR; + player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, player.SpeedResearch / SPEEDUP_FACTOR); if (player.UpgradeTimers.Upgrades[upgrade.ID] >= upgrade.Costs[TimeCost]) { player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), type.Name.c_str()); if (&player == ThisPlayer) { diff --git a/src/action/action_resource.cpp b/src/action/action_resource.cpp index 2faa19a5c..1fac45338 100644 --- a/src/action/action_resource.cpp +++ b/src/action/action_resource.cpp @@ -470,7 +470,7 @@ int COrder_Resource::StartGathering(CUnit &unit) #endif UnitHeadingFromDeltaXY(unit, this->goalPos - unit.tilePos); if (resinfo.WaitAtResource) { - this->TimeToHarvest = resinfo.WaitAtResource / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId] * SPEEDUP_FACTOR; + this->TimeToHarvest = std::max<int>(1, resinfo.WaitAtResource * SPEEDUP_FACTOR / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId]); } else { this->TimeToHarvest = 1; } @@ -538,7 +538,7 @@ int COrder_Resource::StartGathering(CUnit &unit) goal->Resource.Active++; if (resinfo.WaitAtResource) { - this->TimeToHarvest = resinfo.WaitAtResource / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId] * SPEEDUP_FACTOR; + this->TimeToHarvest = std::max<int>(1, resinfo.WaitAtResource * SPEEDUP_FACTOR / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId]); } else { this->TimeToHarvest = 1; } @@ -671,7 +671,7 @@ int COrder_Resource::GatherResource(CUnit &unit) while (!this->DoneHarvesting && this->TimeToHarvest < 0) { //FIXME: rb - how should it look for WaitAtResource == 0 if (resinfo.WaitAtResource) { - this->TimeToHarvest += resinfo.WaitAtResource * SPEEDUP_FACTOR / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId]; + this->TimeToHarvest += std::max<int>(1, resinfo.WaitAtResource * SPEEDUP_FACTOR / unit.Player->SpeedResourcesHarvest[resinfo.ResourceId]); } else { this->TimeToHarvest += 1; } @@ -954,7 +954,7 @@ int COrder_Resource::MoveToDepot(CUnit &unit) unit.CurrentResource = 0; if (unit.Wait) { - unit.Wait /= unit.Player->SpeedResourcesReturn[resinfo.ResourceId] / SPEEDUP_FACTOR; + unit.Wait /= std::max(1, unit.Player->SpeedResourcesReturn[resinfo.ResourceId] / SPEEDUP_FACTOR); if (unit.Wait) { unit.Wait--; } diff --git a/src/action/action_train.cpp b/src/action/action_train.cpp index 2b388b26c..c60169f33 100644 --- a/src/action/action_train.cpp +++ b/src/action/action_train.cpp @@ -183,7 +183,7 @@ static void AnimateActionTrain(CUnit &unit) CPlayer &player = *unit.Player; const CUnitType &nType = *this->Type; const int cost = nType.Stats[player.Index].Costs[TimeCost]; - this->Ticks += player.SpeedTrain / SPEEDUP_FACTOR; + this->Ticks += std::max(1, player.SpeedTrain / SPEEDUP_FACTOR); if (this->Ticks < cost) { unit.Wait = CYCLES_PER_SECOND / 6; diff --git a/src/action/action_upgradeto.cpp b/src/action/action_upgradeto.cpp index 4a12e9511..39cf2b207 100644 --- a/src/action/action_upgradeto.cpp +++ b/src/action/action_upgradeto.cpp @@ -260,7 +260,7 @@ static void AnimateActionUpgradeTo(CUnit &unit) const CUnitType &newtype = *this->Type; const CUnitStats &newstats = newtype.Stats[player.Index]; - this->Ticks += player.SpeedUpgrade / SPEEDUP_FACTOR; + this->Ticks += std::max(1, player.SpeedUpgrade / SPEEDUP_FACTOR); if (this->Ticks < newstats.Costs[TimeCost]) { unit.Wait = CYCLES_PER_SECOND / 6; return ;