vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

GetUnitCollisionSize

radamantus · 4114

0 Members and 1 Guest are viewing this topic.

Rating
Average Score
« Created: December 28, 2017, 10:11:26 PM by moyack »
« Last Edit: January 01, 2018, 11:49:26 PM by moyack »

GetUnitCollisionSize
on: May 21, 2013, 05:16:02 AM
Category: Units
Language: vJASS

Related Topics or Resources



Gets a unit's collision size maybe?

Information:

  • ITERATIONS : This determines how many iterations it should use (it uses a binary search, 10 is fine, actually, 5 is fine as well, I don't think you need this to be ultra precise, but if you want, go ahead and have 30 iterations.
  • Flavors: It comes in three flavors, I figured some people may not like the idea of doing the iterations so much freaking times when collision size is constant per unit type, so using gamecache to memorize the values is possible, so one of the alternative versions uses CSSafeCache, while the other one uses Table. Please take note that I am not that sure gamecache is faster than the little 10 iterations this function does.

Standalone
Code: jass
  1. //********************************************************
  2. //* GetUnitCollisionSize (Standalone version)
  3. //* --------------------
  4. //*   If you need it, use it.
  5. //*
  6. //* To implement it just create a custom text 'trigger'
  7. //* called GetUnitCollisionSize, and paste this there.
  8. //*
  9. //* To copy from one map to another just copy the trigger
  10. //* holding this code to the target map.
  11. //*
  12. //*********************************************************
  13.  
  14. //========================================================
  15. library_once GetUnitCollisionSize
  16.  
  17.     globals
  18.         private constant integer ITERATIONS         = 10    //too much, slow, too short "innacurate", let it be bigger than 0...
  19.                                                             //I *think* 10 is enough...
  20.         public  constant real    MAX_COLLISION_SIZE = 300.0 //should be THE max collision size in the map,
  21.                                                             //well, not really, just make sure it is greater than it
  22.                                                             //few maps should have collision sizes bigger than 300.0...
  23.     endglobals
  24.  
  25. //========================================================
  26. function GetUnitCollisionSize takes unit u returns real
  27.  local integer i=0
  28.  local real x=GetUnitX(u)
  29.  local real y=GetUnitY(u)
  30.  local real hi
  31.  local real lo
  32.  local real mid
  33.  
  34.  
  35.     set hi=MAX_COLLISION_SIZE
  36.     set lo=0.0
  37.     loop
  38.         set mid=(lo+hi)/2.0
  39.         exitwhen (i==ITERATIONS)
  40.         if (IsUnitInRangeXY(u,x+mid,y,0)) then
  41.             set lo=mid
  42.         else
  43.             set hi=mid
  44.         endif
  45.         set i=i+1
  46.     endloop
  47.  return mid
  48. endfunction
  49.  
  50. endlibrary
  51.  

Table version
Code: jass
  1. library_once GetUnitCollisionSize initializer init requires Table
  2. //********************************************************
  3. //* GetUnitCollisionSize (Table version)
  4. //* --------------------
  5. //*   If you need it, use it.
  6. //*
  7. //* To implement it just create a custom text 'trigger'
  8. //* called GetUnitCollisionSize, and paste this there.
  9. //*
  10. //* To copy from one map to another just copy the trigger
  11. //* holding this code to the target map.
  12. //*
  13. //*********************************************************
  14.  
  15. //=========================================================
  16.     globals
  17.         private constant integer ITERATIONS         = 10    //too much, slow, too short "innacurate", let it be bigger than 0...
  18.                                                             //I *think* 10 is enough...
  19.         public  constant real    MAX_COLLISION_SIZE = 300.0 //should be THE max collision size in the map,
  20.                                                             //well, not really, just make sure it is greater than it
  21.                                                             //few maps should have collision sizes bigger than 300.0...
  22.  
  23.         private Table memo
  24.     endglobals
  25.  
  26.  
  27.  
  28. //=============================================================================
  29. function GetUnitCollisionSize takes unit u returns real
  30.  local integer i=0
  31.  local real x=GetUnitX(u)
  32.  local real y=GetUnitY(u)
  33.  local integer typ=GetUnitTypeId(u)
  34.  local real hi
  35.  local real lo
  36.  local real mid
  37.  
  38.     if (memo.exists(typ) ) then
  39.         return I2R(memo[typ])
  40.     endif
  41.  
  42.     set hi=MAX_COLLISION_SIZE
  43.     set lo=0.0
  44.     loop
  45.         set mid=(lo+hi)/2.0
  46.         exitwhen (i==ITERATIONS)
  47.         if (IsUnitInRangeXY(u,x+mid,y,0)) then
  48.             set lo=mid
  49.         else
  50.             set hi=mid
  51.         endif
  52.         set i=i+1
  53.     endloop
  54.     set memo[typ]=R2I(mid+0.500000001)
  55.  return mid
  56. endfunction
  57.  
  58.     private function init takes nothing returns nothing
  59.      set memo=Table.create()
  60.     endfunction
  61.  
  62. endlibrary
  63.  
« Last Edit: January 01, 2018, 11:51:35 PM by moyack »



GetUnitCollisionSize v1 2 (1)
Reply #1 on: May 21, 2013, 05:17:40 AM

As always your spells/systems are well made and useful I'm gonna mass approve this all with my lovely 4/5 rating.

Chronicles of Darkness
by: SonofJay

A BlizzMod Hosted Project

They can hate, let them hate, make them hate.


GetUnitCollisionSize v1 2 (1)
Reply #2 on: May 21, 2013, 05:22:25 AM

Moved from media so it can handle better the information.


 

Power of Corruption - A Warcraft III altered melee map   Chaos Realm - The world of Game modders and wc3 addicts     WC3JASS.com - The JASS Vault   Jetcraft - A Starcraft II mod