Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1698, reverting units to nanoframe via Lua #1864

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rts/Lua/LuaSyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 18 additions & 11 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CExtractorBuilding*> (this);
if (extractor != nullptr)
extractor->ResetExtraction();

eventHandler.UnitReverseBuilt(this);
}

bool CUnit::AddBuildPower(CUnit* builder, float amount)
{
RECOIL_DETAILED_TRACY_ZONE;
Expand Down Expand Up @@ -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<CExtractorBuilding*>(this);
if (extractor != nullptr)
extractor->ResetExtraction();

eventHandler.UnitReverseBuilt(this);
}
if (modInfo.reclaimUnitMethod == 0)
TurnIntoNanoframe();

// reduce health & resources
health = postHealth;
Expand Down
3 changes: 3 additions & 0 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down