How to make units cooperate to prevent overkill? Zero-K
Posted: 13 Jan 2015, 09:57
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!
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!