Skip to content

Commit

Permalink
Fix command target ID comparison checks for unit vs feature (#3958)
Browse files Browse the repository at this point in the history
Commands that target a unit or feature return a single ID number that doesn't differentiate, the caller must apply the logic ID < max units -> unit, ID >= max units -> feature. This fixes those callers using the wrong logic.
  • Loading branch information
WatchTheFort authored Nov 27, 2024
1 parent 5e62628 commit c433f41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions luarules/gadgets/unit_attached_con_turret.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ local function auto_repair_routine(unitID,unitDefID)
end
if (commandQueue[1] ~= nil and commandQueue[1]["id"] == CMD_REPAIR) then
-- out of range repair command
if (commandQueue[1]["params"][1] > Game.maxUnits) then
tx,ty,tz = SpGetFeaturePosition(commandQueue[1]["params"][1]-Game.maxUnits)
object_radius = SpGetFeatureRadius(commandQueue[1]["params"][1]-Game.maxUnits)
if (commandQueue[1]["params"][1] >= Game.maxUnits) then
tx,ty,tz = SpGetFeaturePosition(commandQueue[1]["params"][1] - Game.maxUnits)
object_radius = SpGetFeatureRadius(commandQueue[1]["params"][1] - Game.maxUnits)
else
tx,ty,tz = SpGetUnitPosition(commandQueue[1]["params"][1])
object_radius = SpGetUnitRadius(commandQueue[1]["params"][1])
Expand All @@ -109,9 +109,9 @@ local function auto_repair_routine(unitID,unitDefID)
end
if (commandQueue[1] ~= nil and commandQueue[1]["id"] == CMD_RECLAIM) then
-- out of range reclaim command
if (commandQueue[1]["params"][1] > Game.maxUnits) then
tx,ty,tz = SpGetFeaturePosition(commandQueue[1]["params"][1]-Game.maxUnits)
object_radius = SpGetFeatureRadius(commandQueue[1]["params"][1]-Game.maxUnits)
if (commandQueue[1]["params"][1] >= Game.maxUnits) then
tx,ty,tz = SpGetFeaturePosition(commandQueue[1]["params"][1] - Game.maxUnits)
object_radius = SpGetFeatureRadius(commandQueue[1]["params"][1] - Game.maxUnits)
else
tx,ty,tz = SpGetUnitPosition(commandQueue[1]["params"][1])
object_radius = SpGetUnitRadius(commandQueue[1]["params"][1])
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/cmd_commandinsert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ end
--]]

local function GetUnitOrFeaturePosition(id)
if id <= Game.maxUnits then
if id < Game.maxUnits then
return Spring.GetUnitPosition(id)
else
return Spring.GetFeaturePosition(id-Game.maxUnits)
return Spring.GetFeaturePosition(id - Game.maxUnits)
end
end

Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_customformations2.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ local function GetUnitFinalPosition(uID)
local pID = params[1]
local px, py, pz

if pID > maxUnits then
if pID >= maxUnits then
px, py, pz = spGetFeaturePosition(pID - maxUnits)
else
px, py, pz = spGetUnitPosition(pID)
Expand Down

0 comments on commit c433f41

Please sign in to comment.