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

Add UnitConstructionDecayed call-in #1631

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions cont/LuaUI/callins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ CallInsList = {
"UnitFinished",
"UnitFromFactory",
"UnitReverseBuilt",
"UnitConstructionDecayed",
"UnitDestroyed",
"RenderUnitDestroyed",
"UnitTaken",
Expand Down
9 changes: 9 additions & 0 deletions cont/LuaUI/widgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ local flexCallIns = {
'UnitFinished',
'UnitFromFactory',
'UnitReverseBuilt',
'UnitConstructionDecayed',
'UnitDestroyed',
'RenderUnitDestroyed',
'UnitTaken',
Expand Down Expand Up @@ -1853,6 +1854,14 @@ function widgetHandler:UnitReverseBuilt(unitID, unitDefID, unitTeam)
end


function widgetHandler:UnitConstructionDecayed(unitID, unitDefID, unitTeam, part)
for _,w in ipairs(self.UnitConstructionDecayedList) do
w:UnitConstructionDecayed(unitID, unitDefID, unitTeam, part)
end
return
end


function widgetHandler:UnitDestroyed(unitID, unitDefID, unitTeam)
for _,w in ipairs(self.UnitDestroyedList) do
w:UnitDestroyed(unitID, unitDefID, unitTeam)
Expand Down
1 change: 1 addition & 0 deletions cont/base/springcontent/LuaGadgets/callins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CALLIN_LIST = {
"UnitFinished",
"UnitFromFactory",
"UnitReverseBuilt",
"UnitConstructionDecayed",
"UnitDestroyed",
"RenderUnitDestroyed",
"UnitExperience",
Expand Down
7 changes: 7 additions & 0 deletions cont/base/springcontent/LuaGadgets/gadgets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,13 @@ function gadgetHandler:UnitReverseBuilt(unitID, unitDefID, unitTeam)
end


function gadgetHandler:UnitConstructionDecayed(unitID, unitDefID, unitTeam, part)
for _,g in r_ipairs(self.UnitConstructionDecayedList) do
g:UnitConstructionDecayed(unitID, unitDefID, unitTeam, part)
end
end


function gadgetHandler:UnitDestroyed(
unitID, unitDefID, unitTeam,
attackerID, attackerDefID, attackerTeam
Expand Down
29 changes: 29 additions & 0 deletions rts/Lua/LuaHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,35 @@ void CLuaHandle::UnitReverseBuilt(const CUnit* unit)
}


/*** Called when a unit being built starts decaying.
*
* @function UnitConstructionDecayed
* @number unitID
* @number unitDefID
* @number unitTeam
* @number part
*/
void CLuaHandle::UnitConstructionDecayed(const CUnit* unit, float part)
{
RECOIL_DETAILED_TRACY_ZONE;
LUA_CALL_IN_CHECK(L);
luaL_checkstack(L, 7, __func__);
const LuaUtils::ScopedDebugTraceBack traceBack(L);

static const LuaHashString cmdStr(__func__);
if (!cmdStr.GetGlobalFunc(L))
return;

lua_pushnumber(L, unit->id);
lua_pushnumber(L, unit->unitDef->id);
lua_pushnumber(L, unit->team);
lua_pushnumber(L, part);

// call the routine
RunCallInTraceback(L, cmdStr, 4, 0, traceBack.GetErrFuncIdx(), false);
}


/*** Called when a unit is destroyed.
*
* @function UnitDestroyed
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CLuaHandle : public CEventClient
void UnitFinished(const CUnit* unit) override;
void UnitFromFactory(const CUnit* unit, const CUnit* factory, bool userOrders) override;
void UnitReverseBuilt(const CUnit* unit) override;
void UnitConstructionDecayed(const CUnit* unit, float part) override;
void UnitDestroyed(const CUnit* unit, const CUnit* attacker) override;
void UnitTaken(const CUnit* unit, int oldTeam, int newTeam) override;
void UnitGiven(const CUnit* unit, int oldTeam, int newTeam) override;
Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,8 @@ void CUnit::SlowUpdate()

AddMetal(cost.metal * buildDecay, false);

eventHandler.UnitConstructionDecayed(this, buildDecay);

if (health <= 0.0f || buildProgress <= 0.0f)
KillUnit(nullptr, false, true);
}
Expand Down
1 change: 1 addition & 0 deletions rts/System/EventClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class CEventClient
virtual void UnitCreated(const CUnit* unit, const CUnit* builder) {}
virtual void UnitFinished(const CUnit* unit) {}
virtual void UnitReverseBuilt(const CUnit* unit) {}
virtual void UnitConstructionDecayed(const CUnit* unit, float part) {}
virtual void UnitFromFactory(const CUnit* unit, const CUnit* factory, bool userOrders) {}
virtual void UnitDestroyed(const CUnit* unit, const CUnit* attacker) {}
virtual void UnitTaken(const CUnit* unit, int oldTeam, int newTeam) {}
Expand Down
6 changes: 6 additions & 0 deletions rts/System/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CEventHandler
void UnitCreated(const CUnit* unit, const CUnit* builder);
void UnitFinished(const CUnit* unit);
void UnitReverseBuilt(const CUnit* unit);
void UnitConstructionDecayed(const CUnit* unit, float part);
void UnitFromFactory(const CUnit* unit, const CUnit* factory, bool userOrders);
void UnitDestroyed(const CUnit* unit, const CUnit* attacker);
void UnitTaken(const CUnit* unit, int oldTeam, int newTeam);
Expand Down Expand Up @@ -463,6 +464,11 @@ UNIT_CALLIN_LOS_PARAM(LeftRadar)
UNIT_CALLIN_LOS_PARAM(LeftLos)


inline void CEventHandler::UnitConstructionDecayed(const CUnit* unit,
float part)
{
ITERATE_UNIT_ALLYTEAM_EVENTCLIENTLIST(UnitConstructionDecayed, unit, part)
}

inline void CEventHandler::UnitFromFactory(const CUnit* unit,
const CUnit* factory,
Expand Down
15 changes: 8 additions & 7 deletions rts/System/Events.def
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
SETUP_EVENT(PlayerAdded, MANAGED_BIT | UNSYNCED_BIT)
SETUP_EVENT(PlayerRemoved, MANAGED_BIT | UNSYNCED_BIT)

SETUP_EVENT(UnitCreated, MANAGED_BIT)
SETUP_EVENT(UnitFinished, MANAGED_BIT)
SETUP_EVENT(UnitFromFactory, MANAGED_BIT)
SETUP_EVENT(UnitReverseBuilt, MANAGED_BIT)
SETUP_EVENT(UnitDestroyed, MANAGED_BIT)
SETUP_EVENT(UnitTaken, MANAGED_BIT)
SETUP_EVENT(UnitGiven, MANAGED_BIT)
SETUP_EVENT(UnitCreated, MANAGED_BIT)
SETUP_EVENT(UnitFinished, MANAGED_BIT)
SETUP_EVENT(UnitFromFactory, MANAGED_BIT)
SETUP_EVENT(UnitReverseBuilt, MANAGED_BIT)
SETUP_EVENT(UnitConstructionDecayed, MANAGED_BIT)
SETUP_EVENT(UnitDestroyed, MANAGED_BIT)
SETUP_EVENT(UnitTaken, MANAGED_BIT)
SETUP_EVENT(UnitGiven, MANAGED_BIT)

SETUP_EVENT(UnitIdle, MANAGED_BIT)
SETUP_EVENT(UnitCommand, MANAGED_BIT)
Expand Down