exclude units from being attacked in area-attack commands

exclude units from being attacked in area-attack commands

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

exclude units from being attacked in area-attack commands

Post by knorke »

Imagine ducks.
gaia units that waddle around on the map.

The problem is, if you issue an area-attack command the ducks will be targeted along with enemy units.
This is potentially very annoying.
Features have autoReclaimable=false so that area-commands will ignore them. Sadly for units there is no autoAttackable=false.


For each targeted unit AllowCommand() is called with CMD.ATTACK so can easily filter the ducks like this:

Code: Select all

function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced)
	Spring.Echo (CMD[cmdID] or "nil")
	if cmdID and cmdID == CMD.ATTACK then 		
		if cmdParams and #cmdParams == 1 then			
			Spring.Echo ("target is unit" .. cmdParams[1] .. " #cmdParams=" .. #cmdParams)
			if critterUnits[cmdParams[1]] then Spring.Echo ("target is a critter and ignored!") return false end
		end
	end		
return true
end
Right?
Image

Now there is the problem that ducks might block your attack commands. Say you want to fire a nuke, accidently click on a duck - and the nuke does not fire. Outrageous!
Sometimes you might want to attack _single_ ducks, if they block your units.

So how to detect if is a attack-unit or area-attack command?
Or does it need sillyness like "count attack-commands of each unit per frame"

tl;dr
certain units should only be targetable indviually but be ignored by area-attack
User avatar
CarRepairer
Cursed Zero-K Developer
Posts: 3359
Joined: 07 Nov 2007, 21:48

Re: exclude units from being attacked in area-attack command

Post by CarRepairer »

Gaia units have caused all sorts of headaches for me. For example, they completely ruin the GetUnitNearestEnemy function. Even if I set gaia units to neutral and force the user to /ally the gaia team.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: exclude units from being attacked in area-attack command

Post by jK »

why not just set "neutral"?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: exclude units from being attacked in area-attack command

Post by knorke »

"neutral" as in:
Spring.SetUnitNeutral (unitID, true)
Spring.SetUnitNoSelect (unitID, true)
?
is not enought. it only makes the unit be ignored by fight/patrol command, area-attack still targets it.
User avatar
KingRaptor
Zero-K Developer
Posts: 838
Joined: 14 Mar 2007, 03:44

Re: exclude units from being attacked in area-attack command

Post by KingRaptor »

Not to mention any weapon with avoidNeutral=true won't be able to target it even with explicit order.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: exclude units from being attacked in area-attack command

Post by jK »

that's what the lua code here does, too.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: exclude units from being attacked in area-attack command

Post by knorke »

yes, thats the problem.

I hoped there would maybe be a CMD.AREA_ATTACK event with table of targeted unitIDs and one could sort out the ducks.
But did not find such thing.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: exclude units from being attacked in area-attack command

Post by Kloot »

knorke wrote:So how to detect if is a attack-unit or area-attack command?
Not possible because "area attack" as in a+drag just exists as a GUI feature (only aircraft have an _actual_ CMD_AREA_ATTACK ability) and Spring always converts that to individual attack commands.
knorke wrote: tl;dr
certain units should only be targetable indviually but be ignored by area-attack
c'est ne pas possible except by making a custom command
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: exclude units from being attacked in area-attack command

Post by FLOZi »

Couldn't the engine somehow give an indication of the origin of the attack order? What is cmdTag for in AllowCommand?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: exclude units from being attacked in area-attack command

Post by knorke »

oho so in unsynced CommandNotify is a place where CMD.AREA_ATTACK does arrive. So there one can do

Code: Select all

function widget:CommandNotify(cmdId, cmdParams, cmdOpts)
  if cmdId == CMD_AREA_ATTACK
and whatever filtering is wanted like in this example of [LCC]Pako: http://pastebin.com/7TV7XQ47
Somehow feels a bit too obtrusive but worth a try.

Possible problem is maybe that targets might be attacked in different order? With engine areattack it always seemed pretty random to me but maybe other players notice differences. (like possibly not taking into account distance or targetweight, though didnt check yet, my iphone battery is almost empty)
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: exclude units from being attacked in area-attack command

Post by Kloot »

FLOZi wrote:What is cmdTag for in AllowCommand?
Tag is an internal counter used to uniquely identify a command within its queue.
knorke wrote:oho so in unsynced CommandNotify is a place where CMD.AREA_ATTACK does arrive
Not CMD.AREA_ATTACK (a+drag always creates a queue of CMD_ATTACK's), but CMD_ATTACK with #params == 4.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: exclude units from being attacked in area-attack command

Post by Floris »

Today i saw loads of bladewings wasted because they were area attacking and thus chasing enemy air units.... Major fail.

I know this isnt really the same type of issue but I want to comment it anyway.
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: exclude units from being attacked in area-attack command

Post by NeonStorm »

It is a major issue.
On all mods, not just with gaja within targets, but also bad targets within good ones.
-> Maybe ZK's planet wars structure code has solved this already.

What we need for all area-commands:
* Object at mouse-down (feature, gaja, neutral, bad target? -> Then allow these in your area-attack command)

* Else only target the good targets in your area command, or whatever is your next priority if there are no good targets.

And maybe enhance the area-attacks of widgets with a helper-widget that don't cause problems in any mod or combination of widgets.
-> So that we can use a unified API
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: exclude units from being attacked in area-attack command

Post by Silentwings »

@Neon: "We need..." won't make anything happen by itself - implement some basic version of this and see if anyone starts using it.

I'm pretty sure there is a widget somewhere (or if not, it's a dead easy modification of cf2) where if you hover your mouse on a single unit type a you start to draw the area attack, attack orders are only given aimed at units of the same type as the one you hovered. (Similar to the widget, forgot its name, while allows you to reclaim all buildings of a particular type.)
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: exclude units from being attacked in area-attack command

Post by knorke »

Kloot wrote:
knorke wrote:oho so in unsynced CommandNotify is a place where CMD.AREA_ATTACK does arrive
Not CMD.AREA_ATTACK (a+drag always creates a queue of CMD_ATTACK's), but CMD_ATTACK with #params == 4.
hm ok, so in posted widget:

Code: Select all

if cmdId == CMD_AREA_ATTACK
will never be true anyway? Seemed like this when tested.


with regard to how default A-click + drag chooses targets, I thought it was more clever. Seems it just cares about distance. So you get things like this:
Image
BA jethro can not even shot ground units, yet with areaatack the windmills are queued as targets before the bombers.
So yes, if somebody improves that with a wupget it would probally bring much joy.
User avatar
NeonStorm
Posts: 173
Joined: 23 May 2012, 18:36

Re: exclude units from being attacked in area-attack command

Post by NeonStorm »

also important is that mixed units are separated into target categories.

maybe it would be a lot better if not units but weapons queue targets.
and the unit just a "wait for weapons to kill all targets" order.

For bombers - it reminds me to the central build AI widget which splits cons (bombers) among closest buildings (targets) or equally if buildings are cheap walls (wind gens).
It sorts cons which can't build these things out (weapons which can't target)

Looks like some of it could easily be adopted.
Post Reply

Return to “Lua Scripts”