Categories
AI Shard Spring

Shard Attacks

I was asked a question about Shards attack system on the spring engine lobby server. Having described Shards attack system, I decided to repost the log here for posterity

[20:19:31] <[Mr]Peanus_Butter> yo its #fhh£hu@4545, just a few questions about shard if you've a moment
[20:19:41]  oh rly?
[20:20:10] <[Mr]Peanus_Butter> i'm wondering how shard determines threats or enemy positions... how does it choose how to attack basically
[20:20:27] <[Mr]Peanus_Butter> i know it waits until a certain number of units are massed
[20:20:33] <[Mr]Peanus_Butter> but how does it decide where to go?
[20:20:37]  the files in question are attackhandler.lua and attackerbehaviour.lua
[20:20:46] <[Mr]Peanus_Butter> just a sec, i make open
[20:20:55]  when the unit is built
[20:21:07]  behaviourfactory looks at the behaviours table and loads the ones specified
[20:21:13]  if no entry is found
[20:21:25]  it looks to see if the unit is in the attackerslist table
[20:21:32]  and adds the attackerbehaviour
[20:21:45]  the attackerbehaviour then acts kind of like a conscripted soldier at home
[20:21:58]  it fires off an event registering its presence to the attackhandler
[20:22:09]  attackhandler then saves it in a table and does a check
[20:22:23]  if the queue of waiting attackers in the list is above a threshold
[20:22:28]  it removes them from the queue
[20:22:36]  and starts looking for a target
[20:22:48]  it iterates through every enemy on the map
[20:22:55] <[Mr]Peanus_Butter> ok i'm going to need a DL link, apparently i havent got it on this computer
[20:22:59]  adding its position to a counter on a grid
[20:23:08] <[Mr]Peanus_Butter> (still listening, thx for this)
[20:23:23]  when all the units are categorised, it picks the grid sector with the lowest nonzero value
[20:23:45]  this is how AAI, and NTai chose their targets
[20:23:53]  only AAI and NTai chose the highest
[20:23:56]  not the lowest
[20:24:02]  NTai had a lot of other twists also
[20:24:04] <[Mr]Peanus_Butter> so the choice of area to send attackers to is -not- actually using a threatmap, but a similar behavior, looking for a weak point
[20:24:24]  those 2 AIs did the targeting loop every few frames and added it to a heatmap that decayed
[20:24:34]  its more instantaneous and reactive
[20:24:37]  no lingering threats
[20:24:45]  rather simple if I do say so
[20:24:53]  when an enemy target is found
[20:25:01] <[Mr]Peanus_Butter> hmmmm
[20:25:04]  the attackhandler orders the attackerbehaviour to attack
[20:25:13]  a fight command is sent to the position
[20:25:20]  and the attacker is now left ot its own devices
[20:25:27]  and si out of the loop
[20:25:43]  when the attackerbehaviour recieves a unitIdle event for the attacker
[20:25:52]  the assumption is that there is nothing for it to do
[20:26:01]  so it assigns the attacker as in waiting
[20:26:08]  and repeats the whole process from the beginning
[20:26:23] <[Mr]Peanus_Butter> well it sounds pretty efficient
[20:26:23]  a nice and simple 'new' unit goes in
[20:26:26]  attacker comes out
[20:26:53] <[Mr]Peanus_Butter> attacking a weakpoint seems like a better strategy than attacking the strongest point
[20:26:58]  I have further optimisations to make to the algorithm to make it pluggable
[20:27:13]  you have IK to thank for that insight
[20:27:15]  but
[20:27:23]  I intend to make it a choice in future
[20:27:27]  like supcom
[20:27:33]  cull weakest vs attack strongest
[20:28:22]  do you mind if I repost this as a blog post?
[20:28:41] <[Mr]Peanus_Butter> yeah for sure; its helpful knowing how it works
[20:29:15] <[Mr]Peanus_Butter> i'm playing with a survival game idea with car and bob and wombat and a few others; trying to learn what i can about the various AI behaviours in spring
[20:29:26]  note
[20:29:31]  that the entire attacking system can be either
[20:29:33]  sidestepped
[20:29:35]  or replaced
[20:29:53]  all it would take is either your own behaviours, thats then assigned to attacker units
[20:29:54]  or
[20:30:05] <[Mr]Peanus_Butter> the other day I was testing shard against some other AI I've forgotten which and noticed the difference in attacking weak vs strong; i attributed it to a difference in threatmapping, but now i am wiser
[20:30:07]  put your own attackerhandler and attackbehaviour in your games subfolder
[20:30:21]  Shards Lua VM is set to ignore the main files if one is present in a game subdir
[20:30:29]  so itll be as if ym implementation never existed
[20:30:55]  or you can have different units use differing attack systems

Leave a Reply

Your email address will not be published. Required fields are marked *