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 allegiance filter to spatial queries #4065

Open
wants to merge 3 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
5 changes: 3 additions & 2 deletions luarules/gadgets/pve_boss_priority_targetting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ function gadget:GameFrame(frame)
if frame%30 == 21 then
for queenID, _ in pairs(aliveQueens) do
local queenx,queeny,queenz = Spring.GetUnitPosition(queenID)
local surroundingUnits = Spring.GetUnitsInSphere(queenx, queeny, queenz, 750)
local queenTeamID = Spring.GetUnitTeam(queenID)
local surroundingUnits = CallAsTeam(queenTeamID, Spring.GetUnitsInSphere, queenx, queeny, queenz, 750, -4)
for i = 1,#surroundingUnits do
if aliveTargets[surroundingUnits[i]] and Spring.GetUnitAllyTeam(surroundingUnits[i]) ~= Spring.GetUnitAllyTeam(queenID) then
if aliveTargets[surroundingUnits[i]] then
Spring.GiveOrderToUnit(queenID, CMD.STOP, 0, 0)
Spring.GiveOrderToUnit(queenID, CMD.ATTACK, {surroundingUnits[i]}, 0)
break
Expand Down
6 changes: 3 additions & 3 deletions luarules/gadgets/unit_evolution.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ if gadgetHandler:IsSyncedCode() then


if commandQueue[1] then
local teamID = Spring.GetUnitTeam(unitID)
for _,command in pairs(commandQueue) do
local coded = command.options.coded + (command.options.shift and 0 or CMD.OPT_SHIFT) -- orders without SHIFT can appear at positions other than the 1st due to CMD.INSERT; they'd cancel any previous commands if added raw
if command.id < 0 then -- repair case for construction
local units = Spring.GetUnitsInRectangle(command.params[1] - 16, command.params[3] - 16, command.params[1] + 16, command.params[3] + 16)
local allyTeam = Spring.GetUnitAllyTeam(unitID)
local units = CallAsTeam(teamID, Spring.GetUnitsInRectangle, command.params[1] - 16, command.params[3] - 16, command.params[1] + 16, command.params[3] + 16, -3)
local notFound = true
for j = 1, #units do
local areaUnitID = units[j]
if allyTeam == Spring.GetUnitAllyTeam(areaUnitID) and Spring.GetUnitDefID(areaUnitID) == -command.id then
if Spring.GetUnitDefID(areaUnitID) == -command.id then
Spring.GiveOrderToUnit(newUnitID, CMD.REPAIR, areaUnitID, coded)
notFound = false
break
Expand Down
12 changes: 5 additions & 7 deletions luarules/gadgets/unit_prevent_lab_hax.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end

local spGetGroundHeight = Spring.GetGroundHeight
local spGetUnitBuildFacing = Spring.GetUnitBuildFacing
local spGetUnitAllyTeam = Spring.GetUnitAllyTeam
local spGetUnitTeam = Spring.GetUnitTeam
local spGetUnitsInBox = Spring.GetUnitsInBox
local spSetUnitPosition = Spring.SetUnitPosition
local spGetUnitDefID = Spring.GetUnitDefID
Expand Down Expand Up @@ -58,12 +58,10 @@ end

function checkLabs()
for Lid,Lv in pairs(lab) do

local units = spGetUnitsInBox(Lv.minx + 8, Lv.miny, Lv.minz + 8, Lv.maxx - 8, Lv.maxy, Lv.maxz - 8)
local units = CallAsTeam(Lv.team, spGetUnitsInBox, Lv.minx + 8, Lv.miny, Lv.minz + 8, Lv.maxx - 8, Lv.maxy, Lv.maxz - 8, -4)
for i=1,#units do
local id = units[i]
local team = spGetUnitAllyTeam(id)
if (team ~= Lv.team) and not canFly[spGetUnitDefID(id)] then
if not canFly[spGetUnitDefID(id)] then

local ux, _, uz = spGetUnitPosition(id)

Expand Down Expand Up @@ -118,7 +116,7 @@ function gadget:UnitCreated(unitID, unitDefID)
local face = spGetUnitBuildFacing(unitID)
local xsize = unitXsize[unitDefID] * 4
local ysize = (unitYsize[unitDefID] or unitZsize[unitDefID]) * 4
local team = spGetUnitAllyTeam(unitID)
local team = spGetUnitTeam(unitID)

if face == 0 or face == 2 then
lab[unitID] = { team = team, face = 0, minx = ux-ysize, minz = uz-xsize, maxx = ux+ysize, maxz = uz+xsize}
Expand All @@ -139,7 +137,7 @@ end

function gadget:UnitGiven(unitID, unitDefID)
if lab[unitID] then
lab[unitID].team = spGetUnitAllyTeam(unitID)
lab[unitID].team = spGetUnitTeam(unitID)
end
end

Expand Down
4 changes: 2 additions & 2 deletions luarules/gadgets/unit_target_on_the_move.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ if gadgetHandler:IsSyncedCode() then
top = cmdParams[3]
end

targets = CallAsTeam(teamID, spGetUnitsInRectangle, left, top, right, bot)
targets = CallAsTeam(teamID, spGetUnitsInRectangle, left, top, right, bot, -4)
elseif #cmdParams == 4 then
--circle
targets = CallAsTeam(teamID, spGetUnitsInCylinder, cmdParams[1], cmdParams[3], cmdParams[4])
targets = CallAsTeam(teamID, spGetUnitsInCylinder, cmdParams[1], cmdParams[3], cmdParams[4], -4)
end
if targets then
local orders = {}
Expand Down
2 changes: 1 addition & 1 deletion luaui/Widgets/cmd_nanoturrets_assist_priority.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function widget:UnitCreated(unitID, unitDefID, unitTeam, builderID)
if (nanoDefs[unitDefID] ~= nil) then
-- Echo(turretCreatedMessage .. ": " .. unitID)
local pos = {GetUnitPosition(unitID)}
local unitsNear = GetUnitsInSphere(pos[1], pos[2], pos[3], nanoDefs[unitDefID])
local unitsNear = GetUnitsInSphere(pos[1], pos[2], pos[3], nanoDefs[unitDefID], -3)
-- Echo("found units nearby: " .. unitsNear)
for _, id in ipairs(unitsNear) do
if (nanoDefs[GetUnitDefID(id)] ~= nil) then
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/cmd_share_unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ local function findTeamInArea(mx, my)
return nil
end

local foundUnits = GetUnitsInCylinder(cUnitID[1], cUnitID[3], range)
local foundUnits = GetUnitsInCylinder(cUnitID[1], cUnitID[3], range, -3)

if #foundUnits < 1 then
return nil
Expand All @@ -251,7 +251,7 @@ local function findTeamInArea(mx, my)

for _, unitId in ipairs(foundUnits) do
local unitTeamId = GetUnitTeam(unitId)
if isAlly(unitTeamId) then
if unitTeamId ~= myTeamID then
unitTeamId = tostring(unitTeamId)
if unitTeamCounters[unitTeamId] == nil then
unitTeamCounters[unitTeamId] = 1
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/unit_set_target_by_type.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ function widget:CommandNotify(cmdID, cmdParams, cmdOpts)
local cmdRadius = cmdParams[4]

local filterUnitDefID = spGetUnitDefID(targetId)
local areaUnits = Spring.GetUnitsInCylinder(cmdX, cmdZ, cmdRadius)
local areaUnits = Spring.GetUnitsInCylinder(cmdX, cmdZ, cmdRadius, -4)

local newCmds = {}
for i = 1, #areaUnits do
local unitID = areaUnits[i]
if spGetUnitAllyTeam(unitID) ~= allyTeam and spGetUnitDefID(unitID) == filterUnitDefID then
if spGetUnitDefID(unitID) == filterUnitDefID then
local newCmdOpts = {}
if #newCmds ~= 0 or cmdOpts.shift then
newCmdOpts = { "shift" }
Expand Down
20 changes: 11 additions & 9 deletions luaui/Widgets/unit_specific_unit_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ function widget:CommandNotify(id, params, options)

local targetEnemy = reclaimEnemy and spGetUnitAllyTeam(id) ~= allyTeam
local unitDef = spGetUnitDefID(id)
local preareaUnits = spGetUnitsInCylinder(cx ,cz , cr)
if not targetEnemy then
preareaUnits = spGetUnitsInCylinder(cx ,cz , cr, team)
end
local preareaUnits
local countarea = 0
local areaUnits = {}
for i=1,#preareaUnits do
local unitID = preareaUnits[i]
if (targetEnemy and spGetUnitAllyTeam(unitID) ~= allyTeam) or (options.alt and not targetEnemy and spGetUnitDefID(unitID) == unitDef ) or (options.ctrl and not targetEnemy) then
countarea = countarea + 1
areaUnits[countarea] = unitID
if targetEnemy then
areaUnits = spGetUnitsInCylinder(cx, cz, cr, -4)
else
preareaUnits = spGetUnitsInCylinder(cx, cz, cr, team)
for i=1,#preareaUnits do
local unitID = preareaUnits[i]
if (options.alt and spGetUnitDefID(unitID) == unitDef) or options.ctrl then
countarea = countarea + 1
areaUnits[countarea] = unitID
end
end
end
for ct=1,#selUnits do
Expand Down
9 changes: 5 additions & 4 deletions luaui/Widgets/unit_specific_unit_reclaimer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,18 @@ function widget:CommandNotify(id, params, options)

local targetEnemy = reclaimEnemy and spGetUnitAllyTeam(id) ~= allyTeam
local unitDef = spGetUnitDefID(id)
local areaUnits = spGetUnitsInCylinder(cx ,cz , cr)

if not targetEnemy then
local areaUnits
if targetEnemy then
areaUnits = spGetUnitsInCylinder(cx, cz, cr, -4)
else
areaUnits = spGetUnitsInCylinder(cx ,cz , cr, team)
end

local selUnits = false
local count = 0
for i=1,#areaUnits do
local unitID = areaUnits[i]
if (targetEnemy and spGetUnitAllyTeam(unitID) ~= allyTeam) or (options.alt and not targetEnemy and spGetUnitDefID(unitID) == unitDef ) or (options.ctrl and not targetEnemy) then
if targetEnemy or (options.alt and spGetUnitDefID(unitID) == unitDef) or options.ctrl then
local cmdOpts = {}
if count ~= 0 or options.shift then
cmdOpts = {"shift"}
Expand Down