Skip to content

Conversation

@Fx-Doo
Copy link

@Fx-Doo Fx-Doo commented Dec 10, 2025

Meant to fix #2674

Drop all autoacquired (non user) targets upon receiving a firestate < FIRESTATE_FIREATWILL state command

Co-authored-by: sprunk <spr.ng@o2.pl>
@Fx-Doo
Copy link
Author

Fx-Doo commented Dec 10, 2025

Yeah thanks for the correction, this was the wanted behaviour but it must've slipped through when committing, as i had previously tried dropping all.

Btw dropping all doesn't seem to cause any issue either, it's more a matter of staying "clean" i guess.

Creates Spring.DropCurrentUnitAutoTargets(number unitID) -> nil
untested
* @ return nil
*/

void LuaSyncedCtrl::DropCurrentUnitAutoTargets(lua_State* L)
Copy link
Collaborator

Choose a reason for hiding this comment

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

returns int

@sprunk
Copy link
Collaborator

sprunk commented Dec 12, 2025

Looks good, other than the two lines above.

@Fx-Doo
Copy link
Author

Fx-Doo commented Dec 15, 2025

Fixed the return type // the function definitions in LuaSyncedCtrl.h (wrong name and return type)
Fixed the typo

@badosu
Copy link
Collaborator

badosu commented Dec 24, 2025

Where is the part where this function is called? Unless you mean that games should call it manually? What does the "fix" look like?

@Fx-Doo
Copy link
Author

Fx-Doo commented Dec 24, 2025

Games would be responsible for calling it.
We found some cases where you might want a unit to not drop its current target (mostly the custom guidance fake weapons for retargetting units).
So this seemed a better alternative.
I'll have to make a ready to use simple gadget and test if it works as expected. I havent got the chance to yet.
For BAR we'd need that gadget to exclude some of our units, so i'll add a minimalist exclusion list aswell.

@Fx-Doo
Copy link
Author

Fx-Doo commented Jan 5, 2026

function gadget:GetInfo()
	return {
		name = "Hold fire means stop firing",
		desc = "",
		author = "DoodVanDaag",
		date = "dec 2025",
		license = "GNU GPL, v2 or later",
		layer = 0,
		enabled = true
	}
end


if gadgetHandler:IsSyncedCode() then

local exclusionList = {}

	function gadget:UnitCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions)
		if cmdID == CMD.FIRE_STATE and cmdParams[1] <= 1 then
			if not exclusionList[unitDefID] then
				Spring.DropCurrentUnitAutoTargets(unitID)
			-- else
				-- decide what to do (put a timer? remove targets one frame before reload progress is complete ? w/e)
				-- we might actually even want the hold fire command to be applied later on so that it keeps acquiring new targets aswell, in which case the moment it is applied would just drop targets aswell; so maybe the first solution is the one to go and games should delay hold fire instead? Any thoughts on that ?
			end
		end
	end
	
end

Would look like this.

https://www.youtube.com/watch?v=pUTdNWwhJzQ

@Fx-Doo
Copy link
Author

Fx-Doo commented Jan 5, 2026

I think i overreacted to the "retargetting" projectiles issue.
1st: it's already happenning anyway.
2nd: we can always use the fix just for cloakable units, since others usually drop their targets just fine, for some unknown reason.

@badosu badosu changed the title Fix #2674 feat(Synced): Add DropCurrentUnitAutoTargets for finer control Jan 5, 2026
Copy link
Collaborator

@badosu badosu left a comment

Choose a reason for hiding this comment

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

I defer to @sprunk, code looks good at a glance

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.

Units don't always drop their current auto target when given a Hold Fire or Return Fire command

3 participants