How to make units cooperate to prevent overkill? Zero-K

How to make units cooperate to prevent overkill? Zero-K

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

Moderators: Moderators, Moderators

Post Reply
Posts: 2
Joined: 13 Jan 2015, 09:40

How to make units cooperate to prevent overkill? Zero-K

Post by Autowar »

I want to write a widget that will make units cooperate to prevent overkill, but I need some advice on how to go about finding the range without being a massive resource hog!

Example of execution:
Three Trident AA gunships are set to be controlled by the widget by setting them to "hold fire", adding them to table "Tridents".
Two Raven bombers enter player LOS and are automatically entered into table "Enemy Bombers" and given a value of [2] based on the Raven's current health.
Every second math.distance (or somesuch function) is used to calculate if any unit in the table "Tridents" is some X distance or less away from any units in the table "Enemy Bombers".
When The value returned by math.distance for a given unit in the table of "Tridents" to a unit in the table of "enemy bombers" is less than or equal to some X range value, that unitID in the table of "Tridents" is given an attack order on the unitID in the table of "Enemy Bombers" and the value for that Raven's unitID in that table is reduced by 1.
When the same Raven enters into range of another Trident, that trident also recieves an attack order and that Raven's unitID key value is then reduced by 1 again.
When that same Raven is detected to be in range of the third Trident, no attack order is issued because that Raven's unitID value in the table "Enemy Bombers" is less than [1] or equal to [0], meaning that the Trident will not waste it's missiles on a doomed bomber.
When the second Raven enters into range of the third Trident, an attack order is issued like normal and tat Raven's unitID value in the "Enemy Bombers" table is reduced by 1 like normal.

I'll add lua pseudocode later.

This is to be done for every unit type, allowing two different unit types to overkill (2 Trident and 3 Flail may target the same bomber unless i can figure out a neat way to get around that mess) but at least preventing the same unittype from excessively wasting shots on the same unit (a nest of three HLT Stingers splitting up their fire between 2 Zues, killing neither), and i also intend on having a list of unittypes to ignore for each table of unittypes targeting enemy units.

Is there any sane way to check if any units in table X are in range Y of units in table Z without simply redoing the work the engine has already done to check if a unit is in range to be auto attacked?

Thank you in advance!
0 x

User avatar
Posts: 3628
Joined: 25 Oct 2008, 00:23

Re: How to make units cooperate to prevent overkill? Zero-K

Post by Silentwings »

I don't know ZK units, so I don't know exactly what you're trying to do, but is your source of information about units.

There is no point in trying to optimize your code before you've written it. Write your code, find out how heavy it is by comparison to the rest of ZKs lua (there is a widget profiler for this). If it's looking bad, then think about perf.
0 x

User avatar
Posts: 6475
Joined: 02 May 2005, 03:56

Re: How to make units cooperate to prevent overkill? Zero-K

Post by SinbadEV »

What if it was one table for all currently known enemies and their "health balance" (and then yeah, a second table of "Controlled Units" assigned to)

Let's say Enemy units E1 and E2 have 1000 HP and Controlled Ally units A1, A2 and A3 has an attack that reliably does at least 500HP damage per hit.

E1 and E2 come into range of A1, A2 and A3... We go through controlled units and when we see A1 can attack E1 we assign A1 to attack E1 and then E1's "health balance" is reduced to 500HP... next we hit A2 and see that E1 is in range and give the attack order and reduce E1's health balance to 0HP... when we get to A3 it sees that E1 is doomed and is assigned to attack E2 instead (leaving E2 with 500HP unaccounted for and still an eligible target.)

So what you said except with two permanent tables instead of dynamically created ones.
0 x

User avatar
Journeywar Developer & Mapper
Posts: 10306
Joined: 24 Jan 2006, 21:12

Re: How to make units cooperate to prevent overkill? Zero-K

Post by PicassoCT »

May i suggest, watching only units who get damaged, and who are about to be killed.

With that small irregular subset, you can then find out who is still firing, and determinate the best possible of all outcomes.

PS: Silentwings - optimized allready, you made me do this

:-o X()_)
0 x

Posts: 2445
Joined: 12 Oct 2007, 09:24

Re: How to make units cooperate to prevent overkill? Zero-K

Post by Google_Frog »

Latency is too high for this to be an effective widget and you would only have attack commands, holdfire and settarget to deal with.

You can both get the target of a unit and check whether it really should fire with script.BlockShot(num, targetID). Simply adding up expected damage here would prevent many units from firing at the same thing although they would not intelligently retarget unit the first target is dead. This may be sufficient.
0 x

Post Reply

Return to “Lua Scripts”