Page 1 of 1
exclude units from being attacked in area-attack commands
Posted: 07 Apr 2013, 03:54
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?
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
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 09:19
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.
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 11:01
by jK
why not just set "neutral"?
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 11:29
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.
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 12:38
by KingRaptor
Not to mention any weapon with avoidNeutral=true won't be able to target it even with explicit order.
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 12:57
by jK
that's what the lua code here does, too.
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 13:09
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.
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 13:49
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
Re: exclude units from being attacked in area-attack command
Posted: 07 Apr 2013, 14:30
by FLOZi
Couldn't the engine somehow give an indication of the origin of the attack order? What is cmdTag for in AllowCommand?
Re: exclude units from being attacked in area-attack command
Posted: 09 Apr 2013, 00:41
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)
Re: exclude units from being attacked in area-attack command
Posted: 09 Apr 2013, 01:46
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.
Re: exclude units from being attacked in area-attack command
Posted: 09 Apr 2013, 02:51
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.
Re: exclude units from being attacked in area-attack command
Posted: 09 Apr 2013, 13:32
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
Re: exclude units from being attacked in area-attack command
Posted: 10 Apr 2013, 01:10
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.)
Re: exclude units from being attacked in area-attack command
Posted: 11 Apr 2013, 20:54
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:
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:

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.
Re: exclude units from being attacked in area-attack command
Posted: 11 Apr 2013, 22:44
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.