• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Speed adjustment dependent on terrain

Status
Not open for further replies.
Level 10
Joined
Oct 28, 2012
Messages
228
Hey! I am trying to make a trigger that would give units boost according to the terrain they're on.

For example: when you are on the dirt +5% movement speed when you are on the rock -5% movement speed. I would like the trigger to check all units every 1 second and depending on their position adjust the boost.

Is there some easy way how to do this with GUI? I tried this and it doesn't work:
trigger terrain.PNG
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
You do exactly what you described...

Event -> Every second.
Actions -> pick every unit in playable map area and check the terrain type under it. Remove all speed buff abilities and then add one based on which terrain type they are standing on.

Be aware that it is important such a trigger leaks nothing at all. Additionally it might cause performance issues if the map has a lot of units.
 
Level 38
Joined
Feb 27, 2007
Messages
4,951
By setting cast backswing and cast point to 0 and removing movement then one dummy can cast many spells instantly. However you don’t actually need a dummy here. You need a few different self-only auras or abilities based on boots of speed for the different terrain speeds. Then you’ll simply give those units the ability corresponding to the terrain type they’re on.

Oop: DSG is faster than me. I said what he said, basically.
 
Last edited:
Level 10
Joined
Oct 28, 2012
Messages
228
Umm ok, interesting (sorry I am new to dummy usage ^^), and if I would want to use the auras, how would I then apply the auras? I would use "unit - add ability" and add those auras to the units directly? And wouldn't it be laggy if the large masses of units were moving?

EDIT: And by that ofc switching between terrain?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Umm ok, interesting (sorry I am new to dummy usage ^^), and if I would want to use the auras, how would I then apply the auras? I would use "unit - add ability" and add those auras to the units directly? And wouldn't it be laggy if the large masses of units were moving?
I do not think self effecting auras are that demanding. Just make sure to set the radius to 1 or 0 or so.
EDIT: And by that ofc switching between terrain?
Remove all the abilities, and then add the correct one. If that is too computationally intensive, eg due to a log of terrain types, then use a hashtable to track which one is effecting a unit at any time and remove it with O(1) complexity and have another system to clear mappings from it when a unit is removed from game.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Yes the trigger above does not really make any sense. Hence why we instructed you to make a new one which does.

Event -> Every second.
Actions -> pick every unit in playable map area and check the terrain type under it. Remove all speed buff abilities and then add one based on which terrain type they are standing on.

Be aware that it is important such a trigger leaks nothing at all. Additionally it might cause performance issues if the map has a lot of units.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,180
Event -> Every second.
Actions -> pick every unit in playable map area and check the terrain type under it. Remove all speed buff abilities and then add one based on which terrain type they are standing on.

Nowhere should there be a wait action, since those might require network synchronization, use real time rather than game time and have an accuracy of at best 0.1 seconds.

One also wants a single group of all units you want this to effect on the map. This might require some filtering but maybe keeping a global updated with add/remove unit would be more efficient. Buildings obviously do not need this applied to them.

One iterates that group once, for every unit in the group you remove all the speed bonus abilities. It does not matter if they only have 1 of them, since there is no harm done removing an ability a unit does not have. Then you have a tree/multiple if then else blocks that test the terrain type under the unit. Based on that terrain type, add the appropriate ability to the unit.

Be aware that points (JASS location) and unit group (JASS group) leak unless explicitly destroyed after their useful life ends. Such leaks will degrade performance and can cause stability issues.

If performance of the trigger is an issue there are multiple optimizations one can do. The terrain type can be stored in a variable and then that value compared rather than being looked up from terrain each time. A hash table or indexing system can be used to track which buff effects which unit meaning that for possibly 16 different terrain speed bonuses only 1 removal action (function call) is needed. The unit group itself can be made smaller by removing all units which do not need to be effected by terrain speed bonuses such as stationary buildings, wards, dummy units and air units.
 
Last edited:
Status
Not open for further replies.
Top