feat(guard): implement area guard functionality#7399
feat(guard): implement area guard functionality#7399WybrenKoelmans wants to merge 2 commits intobeyond-all-reason:masterfrom
Conversation
|
I know that there are many many more things we can do with this, and also fix bugs around it and such, but lets just keep things small for once and merge it iteratively. IMO this is already a huge improvement and brings many new strategic moves to the table. |
| if cmdID == CMD_GUARD then | ||
| return true | ||
| end |
There was a problem hiding this comment.
why "handle" native guard if you're going to always let it through anyway?
luarules/gadgets/unit_guard_area.lua
Outdated
| function gadget:DefaultCommand(type, id) | ||
| if type ~= "unit" then return end | ||
| if not spIsUnitAllied(id) then return end | ||
| for unitDefID in pairs(spGetSelectedUnitsCounts()) do | ||
| if canGuardDefs[unitDefID] then | ||
| return CMD_AREA_GUARD | ||
| end |
There was a problem hiding this comment.
If this is supposed to implement "return area guard whenever the native ui would return native guard" then
| function gadget:DefaultCommand(type, id) | |
| if type ~= "unit" then return end | |
| if not spIsUnitAllied(id) then return end | |
| for unitDefID in pairs(spGetSelectedUnitsCounts()) do | |
| if canGuardDefs[unitDefID] then | |
| return CMD_AREA_GUARD | |
| end | |
| function gadget:DefaultCommand(type, id, defaultCmd) | |
| if defaultCmd == CMD_GUARD | |
| return CMD_AREA_GUARD |
luarules/gadgets/unit_guard_area.lua
Outdated
| -- Direct click on a unit via AREA_GUARD button: forward as engine CMD.GUARD | ||
| local targetID = cmdParams[1] | ||
| if spValidUnitID(targetID) and isAllied(unitID, targetID) then | ||
| spGiveOrderToUnit(unitID, CMD_GUARD, { targetID }, cmdOptions.coded or 0) |
There was a problem hiding this comment.
| spGiveOrderToUnit(unitID, CMD_GUARD, { targetID }, cmdOptions.coded or 0) | |
| spGiveOrderToUnit(unitID, CMD_GUARD, targetID, cmdOptions.coded or 0) |
luarules/gadgets/unit_guard_area.lua
Outdated
| local allyTeamID = spGetUnitAllyTeam(unitID) | ||
|
|
||
| local unitsInArea = spGetUnitsInCylinder(x, z, radius) | ||
| if not unitsInArea then return {} end |
luarules/gadgets/unit_guard_area.lua
Outdated
|
|
||
| for _, targetID in ipairs(targets) do | ||
| if not alreadyGuarded[targetID] then | ||
| spGiveOrderToUnit(unitID, CMD_GUARD, { targetID }, { "shift" }) |
There was a problem hiding this comment.
- avoid tables (CMD.OPT_SHIFT, plain targetID)
- avoid multiple GiveOrder calls (-> GiveOrderArrayToUnit)
- shouldn't the first command be given without shift? right now it looks like it always appends
- consider copying alt/ctrl/etc from the area guard command (i don't remember off the top of my head whether they do anything for guard, but people will inevitably copypaste this snippet to other commands that might)
|
Auto-approved per Game Design Doc, @beyond-all-reason/game-design-team see. |
…ed on feedback and testing
| if unitDef.modCategories and unitDef.modCategories['object'] | ||
| or (unitDef.customParams and unitDef.customParams.objectify) then |
There was a problem hiding this comment.
modcategories and customparams cannot be nil
| end | ||
|
|
||
| if truncated then | ||
| spEcho(string.format("Area guard: attempted %d guard targets, truncated to %d.", attempted, MAX_GUARD_ORDERS)) |
There was a problem hiding this comment.
this will display publicly for everybody in the game
| end | ||
| end | ||
|
|
||
| -- Use UnitFinished to ensure the engine has added its default commands first |
There was a problem hiding this comment.
is that a real worry? engine should probably add its stuff before UnitCreated runs
| end | ||
| end | ||
|
|
||
| -- Handle transfer of units between teams (capture/share) |
There was a problem hiding this comment.
these can happen before UnitFinished, also engine probably isn't supposed to drop command capabilities upon transfer
| end | ||
| end | ||
|
|
||
| function gadget:UnitTaken(unitID, unitDefID, oldTeam, newTeam) |
There was a problem hiding this comment.
why do it on both taken and given?
| end | ||
|
|
||
| local function giveGuardOrders(unitID, targets, append) | ||
| if not targets or #targets == 0 then return end |
There was a problem hiding this comment.
does this behave consistently regarding dropping the existing command queue when given without shift on an area with 0 targets?
Work done
Added Guard Area (unit targets) command, works kinda like repair area.
Test steps
AI / LLM usage statement:
Vibes for initial prototype then just manually fixed and optimized.
Screen.Recording.2026-04-11.155422.mp4