• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Guards deployment

Status
Not open for further replies.
Level 3
Joined
Jul 26, 2013
Messages
41
I have a sort of zombie survival map in wich I can build towers. I want to make it so that when zombies come in X range of them, a nr. of guards would appear around the tower. The region around the tower is made via variables thus I can not use ''A unit enters region'' because there is no predetermined region. Is there a way I can do it?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can have enter region events for ingame-created regions, too. But it sounds like you are GUI-only, so you won't be able to get rid of the events and regions anymore. Besides "unit enters region", there is "unit comes within range", which is basically the same problem. A periodic range check/group pick is possible but you will have to keep track of the units that were already within range, which gets leaky/limited in GUI, too, unless you make own structures like avoiding group picks and instead register all units on the map, check everyone and store them into dynamically allocated areas of unit arrays for example.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
The region around the tower is made via variables thus I can not use ''A unit enters region'' because there is no predetermined region. Is there a way I can do it?
Well lucky for you that regions are dynamic collections of cells. Simply add a rect around the new tower to the region. Tower destruction is slightly harder as a negative rect would not suffice if there is one or more other towers inside it you need to re-add those. Detecting which towers to spawn guards for is also tricky but iteration through them all probably would suffice for small (less than 100) such towers.

Another approach is the staggered polling approach. Every tick (time a periodic timed event fires) you check if there are appropriate units in range of a few towers and spawn guards if so. Staggering means that if a large number of them exist the processor load remains constant in exchange for guard deployment latency. You could compensate to some degree by making the detection area larger so that guards will be deployed with more time to spare as the polling period increases to cope better.
 
Status
Not open for further replies.
Top