diff --git a/rts/Lua/LuaSyncedCtrl.cpp b/rts/Lua/LuaSyncedCtrl.cpp index def5f186e0..b450e87ac2 100644 --- a/rts/Lua/LuaSyncedCtrl.cpp +++ b/rts/Lua/LuaSyncedCtrl.cpp @@ -1999,6 +1999,8 @@ int LuaSyncedCtrl::SetUnitHealth(lua_State* L) case hashString("build"): { if ((unit->buildProgress = lua_tofloat(L, LUA_TABLE_VALUE_INDEX)) >= 1.0f) unit->FinishedBuilding(false); + else + unit->TurnIntoNanoframe(); } break; default: { } break; diff --git a/rts/Sim/Units/Unit.cpp b/rts/Sim/Units/Unit.cpp index 9f1ec62fbd..04d5331841 100644 --- a/rts/Sim/Units/Unit.cpp +++ b/rts/Sim/Units/Unit.cpp @@ -1940,6 +1940,22 @@ const CGroup* CUnit::GetGroup() const { return uiGroupHandlers[team].GetUnitGrou /******************************************************************************/ /******************************************************************************/ +void CUnit::TurnIntoNanoframe() +{ + if (beingBuilt) + return; + + beingBuilt = true; + SetStorage(0.0f); + + // make sure neighbor extractors update + const auto extractor = dynamic_cast (this); + if (extractor != nullptr) + extractor->ResetExtraction(); + + eventHandler.UnitReverseBuilt(this); +} + bool CUnit::AddBuildPower(CUnit* builder, float amount) { RECOIL_DETAILED_TRACY_ZONE; @@ -2050,17 +2066,8 @@ bool CUnit::AddBuildPower(CUnit* builder, float amount) } // turn reclaimee into nanoframe (even living units) - if ((modInfo.reclaimUnitMethod == 0) && !beingBuilt) { - beingBuilt = true; - SetStorage(0.0f); - - // make sure neighbor extractors update - CExtractorBuilding* extractor = dynamic_cast(this); - if (extractor != nullptr) - extractor->ResetExtraction(); - - eventHandler.UnitReverseBuilt(this); - } + if (modInfo.reclaimUnitMethod == 0) + TurnIntoNanoframe(); // reduce health & resources health = postHealth; diff --git a/rts/Sim/Units/Unit.h b/rts/Sim/Units/Unit.h index fe4af49685..39a7032f47 100644 --- a/rts/Sim/Units/Unit.h +++ b/rts/Sim/Units/Unit.h @@ -100,6 +100,9 @@ class CUnit : public CSolidObject int GetBlockingMapID() const { return id; } void ChangeLos(int losRad, int airRad); + + void TurnIntoNanoframe(); + // negative amount=reclaim, return= true -> build power was successfully applied bool AddBuildPower(CUnit* builder, float amount);