Skip to content

Chicken Spawner: keep the burrow target in PvP mode - #6056

Open
moss-orbit-9f339e wants to merge 2 commits into
ZeroK-RTS:masterfrom
moss-orbit-9f339e:split/5937-chicken-burrow-target-v2
Open

moss-orbit-9f339e wants to merge 2 commits into
ZeroK-RTS:masterfrom
moss-orbit-9f339e:split/5937-chicken-burrow-target-v2

Conversation

@moss-orbit-9f339e

@moss-orbit-9f339e moss-orbit-9f339e commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

In unit_spawner.lua, UpdateBurrowTarget(burrowID, targetArg) stores the chosen target in targetData (data.burrows[burrowID]). But it then checks spValidUnitID(data.targetID), and data is the table of all burrows and targets, which has no targetID. So the check gets nil and fails, and the next branch sets targetData.targetID = nil. The code also reads the team with spGetUnitTeam(data.targets[data.targetID]), but data.targets maps a unit ID to a team ID. A burrow also starts with targetID = unitID (its own ID), so a burrow with no candidate would keep itself as the target.

This reads targetData.targetID in both places, passes the unit ID to spGetUnitTeam, and treats a target equal to burrowID as not valid. In PvP mode the burrow now keeps the nearest enemy structure as its cached target. The spawn code (if pvp and data.burrows[burrowID].targetID) reads the cached structure's position and sends newly spawned chickens a FIGHT order toward it. They can engage other units along the way.

A second commit fixes the noTarget test in UnitFinished: noTarget.name is always nil, so Wolverine mines also became burrow targets. It now reads noTarget[name], as ChooseTarget already does.

Gameplay/sync: this changes where chickens from a burrow go in PvP mode. The gadget changes synced targeting state; no multiplayer sync comparison was run. Games that are not in PvP mode do not use the cached target. PvP mode is detected separately; a separate PR fixes the detection when the human team IDs have gaps or include team 0 (for example a 1v1 with chickens).

Testing: a live game on the test bench. At frame 120 the test script loads UpdateBurrowTarget from the file and runs it with test inputs: burrow ID 10 (its own target at the start) and structure candidates 20 and 30 at distances 100 and 200. The distance, validity and team queries are replaced by stubs. The test runs five cases and logs the target ID and the target team. It ran on master, this change and master again:

case master (target, team) this change (target, team)
nearest structure of 20 and 30 nil,nil 20,0
20 is dead, 30 remains nil,nil 30,3
no candidates (control) nil,nil nil,nil
no candidates, initially self-targeting (repeat control) nil,nil nil,nil
both candidates dead in the same frame (control) nil,nil nil,nil

The two master runs gave the same numbers. This is a call of the real function with stub inputs, not a played PvP chicken game.

AI disclosure: found by OpenAI Codex in a code audit; the live test was written by Codex; checked, edited and tested with Claude Code.

🤖 Generated with Claude Code

The burrow target check reads IDs from the wrong table. Validate
targetData.targetID and read its team directly. Reject the burrow itself
as a target.

Gameplay/sync: changes chicken burrow target selection.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@moss-orbit-9f339e

Copy link
Copy Markdown
Contributor Author

Closing with the other chicken PvP PRs; I can send them as one PR if you want them.

@sprunk sprunk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to get a gameplay check but this generally looks fine regardless.

UnitFinished tested noTarget.name, which is always nil, so every finished
immobile unit of a human team became a burrow target, Wolverine mines too.
Test the unit's name instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@moss-orbit-9f339e

Copy link
Copy Markdown
Contributor Author

Gameplay check on master 81b9b72: master / master + the first commit / master + both commits. The second commit changes noTarget.name to noTarget[name] in UnitFinished. Before, the test was always true, so Wolverine mines also became burrow targets.

What was played: live games on Nuclear Winter, 4800 frames. Two Null AI teams on different ally teams play the "human" sides (the spawner counts every team that is not a chicken AI and not allied with it). "Chicken: Custom" with graceperiod=0.5, chickenspawnrate=15, burrowspawnrate=15. Each side has its commander and five solar collectors. Burrows and waves spawn normally. A test gadget logs each burrow's targetID/targetTeam and the FIGHT order of each chicken from SpawnChicken. It also makes a Wolverine mine 377 elmos from one burrow at frame 1800 (the nearest solar is more than 2000 elmos away). It adds one solar next to two burrows at frame 2400, and it destroys one burrow's nearest structure at frame 3300.

run targetID chickens FIGHT at the burrow's nearest structure FIGHT at the mine median distance burrow -> FIGHT point
master, PvP (2 runs, identical) always nil 299 72 0 3401
first commit, PvP nearest immobile unit, the mine too 266 248 18 2009
both commits, PvP nearest structure 254 254 0 2313
master, sides allied (not PvP), 3400 frames always nil 167 24 0 3937
both commits, sides allied, 3400 frames nearest structure 167 24 0 3937
  • Master in PvP: each chicken goes to a random unit of the team that owns the burrow's nearest enemy (the ChooseTarget fallback), so the chickens spread over the nearest side's whole base. With the PR, each chicken goes to the burrow's nearest structure.
  • First commit only: three burrows took the mine as their target and sent 18 chickens to it until it died (frame 2008). With both commits these burrows kept the nearest solar.
  • With the PR, the solars added at frame 2400 became the targets of both burrows. After the kill at frame 3300 the burrow took the next nearest structure. When chickens killed a target, the burrows took the next one. On master targetID stayed nil.
  • Allied control: master and both commits gave the same chickens and the same FIGHT points, one by one.

The comment "HOW BURROW TARGETING WORKS" says chickens attack a random unit of the cached target's owner. The code (not changed here) sends them to the cached structure itself.

Not tested: a multiplayer game (sync), capture or transfer of a targeted structure, terraform units (also in noTarget; I did not check if they can finish), more than two sides, the PvP endgame.

AI-assisted: test written and run with Claude Code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants