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 unit::noGroup and Get/SetUnitNoGroup #1853

Merged
merged 3 commits into from
Jan 11, 2025
Merged
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
18 changes: 18 additions & 0 deletions cont/base/springcontent/LuaGadgets/Gadgets/unit_dead.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function gadget:GetInfo()
return {
name = "Dead Unit",
desc = "Remove behaviours from dead units",
license = "GNU GPL, v2 or later",
layer = -1999999,
enabled = true,
}
end

if gadgetHandler:IsSyncedCode() then
return
end

function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam)
Spring.SetUnitNoSelect(unitID, true)
Spring.SetUnitNoGroup(unitID, true)
end
2 changes: 1 addition & 1 deletion rts/Game/UI/Groups/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void CGroup::PostLoad()
bool CGroup::AddUnit(CUnit* unit)
{
RECOIL_DETAILED_TRACY_ZONE;
if (unit->team != ghIndex)
if (unit->team != ghIndex || unit->noGroup)
return false;

units.insert(unit->id);
Expand Down
24 changes: 24 additions & 0 deletions rts/Lua/LuaUnsyncedCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ bool LuaUnsyncedCtrl::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(SetUnitEngineDrawMask);
REGISTER_LUA_CFUNC(SetUnitAlwaysUpdateMatrix);
REGISTER_LUA_CFUNC(SetUnitNoMinimap);
REGISTER_LUA_CFUNC(SetUnitNoGroup);
REGISTER_LUA_CFUNC(SetUnitNoSelect);
REGISTER_LUA_CFUNC(SetUnitLeaveTracks);
REGISTER_LUA_CFUNC(SetUnitSelectionVolumeData);
Expand Down Expand Up @@ -2182,6 +2183,29 @@ int LuaUnsyncedCtrl::SetUnitNoMinimap(lua_State* L)
}


/***
*
* @function Spring.SetUnitNoGroup
* @number unitID
* @bool unitNoGroup whether unit can be added to selection groups
* @treturn nil
*/
int LuaUnsyncedCtrl::SetUnitNoGroup(lua_State* L)
{
CUnit* unit = ParseCtrlUnit(L, __func__, 1);

if (unit == nullptr)
return 0;

unit->noGroup = luaL_checkboolean(L, 2);

if (unit->noGroup) {
unit->SetGroup(nullptr);
}
return 0;
}


/***
*
* @function Spring.SetUnitNoSelect
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaUnsyncedCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class LuaUnsyncedCtrl {
static int SetUnitEngineDrawMask(lua_State* L);
static int SetUnitAlwaysUpdateMatrix(lua_State* L);
static int SetUnitNoMinimap(lua_State* L);
static int SetUnitNoGroup(lua_State* L);
static int SetUnitNoSelect(lua_State* L);
static int SetUnitLeaveTracks(lua_State* L);
static int SetUnitSelectionVolumeData(lua_State* L);
Expand Down
18 changes: 18 additions & 0 deletions rts/Lua/LuaUnsyncedRead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ bool LuaUnsyncedRead::PushEntries(lua_State* L)
REGISTER_LUA_CFUNC(GetUnitNoDraw);
REGISTER_LUA_CFUNC(GetUnitEngineDrawMask);
REGISTER_LUA_CFUNC(GetUnitNoMinimap);
REGISTER_LUA_CFUNC(GetUnitNoGroup);
REGISTER_LUA_CFUNC(GetUnitNoSelect);
REGISTER_LUA_CFUNC(GetUnitAlwaysUpdateMatrix);
REGISTER_LUA_CFUNC(GetUnitDrawFlag);
Expand Down Expand Up @@ -1304,6 +1305,23 @@ int LuaUnsyncedRead::GetUnitNoMinimap(lua_State* L)
return 1;
}

/***
*
* @function Spring.GetUnitNoGroup
* @number unitID
* @treturn nil|bool nil when unitID cannot be parsed
*/
int LuaUnsyncedRead::GetUnitNoGroup(lua_State* L)
{
CUnit* unit = ParseUnit(L, __func__, 1);

if (unit == nullptr)
return 0;

lua_pushboolean(L, unit->noGroup);
return 1;
}

/***
*
* @function Spring.GetUnitNoSelect
Expand Down
1 change: 1 addition & 0 deletions rts/Lua/LuaUnsyncedRead.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LuaUnsyncedRead {
static int GetUnitNoDraw(lua_State* L);
static int GetUnitEngineDrawMask(lua_State* L);
static int GetUnitNoMinimap(lua_State* L);
static int GetUnitNoGroup(lua_State* L);
static int GetUnitNoSelect(lua_State* L);
static int GetUnitAlwaysUpdateMatrix(lua_State* L);
static int GetUnitDrawFlag(lua_State* L);
Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Units/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,7 @@ CR_REG_METADATA(CUnit, (
CR_MEMBER(iconRadius),

CR_MEMBER(stunned),
CR_MEMBER_UN(noGroup),

// CR_MEMBER(expMultiplier),
// CR_MEMBER(expPowerScale),
Expand Down
2 changes: 2 additions & 0 deletions rts/Sim/Units/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ class CUnit : public CSolidObject
bool leaveTracks = false;

bool isSelected = false;
// if true, unit can not be added to groups by a player (UNSYNCED)
bool noGroup = false;

float iconRadius = 0.0f;

Expand Down