Login
Register
Menu
Home
Forum
JassDoc
Types
Functions
Variables
Help
Chat
Media
Search
Search posts
WC3 JASS.com
"The Jass Vault" plus vJASS and Zinc
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
GetUnitCollisionSize
Warcraft III:
Maps
Models
Skins
Icons
Spells / Systems
Tools
Tutorials
Snippets
JASS vJASS Spells and Systems
Tutorials
Chat @Discord
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
Codes & Snippets
Started by
radamantus
Views
5948
Replies
2
Users
3
1
1
1
Pages:
1
Go Down
0 Members and 1 Guest are viewing this topic.
Rating
Average Score
- 5 / 5
«
Created: December 28, 2017, 10:11:26 PM by moyack
»
«
Last Edit: January 01, 2018, 11:49:26 PM by moyack
»
Vexorian
Recognized User
Posts:
5
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
100
Free Software Terrorist
GetUnitCollisionSize
on:
May 21, 2013, 05:16:02 AM
Category:
Units
Language:
vJASS
Related Topics or Resources
[Snippet] New Table
by
Bribe
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
//********************************************************
//* GetUnitCollisionSize (Standalone version)
//* --------------------
//* If you need it, use it.
//*
//* To implement it just create a custom text 'trigger'
//* called GetUnitCollisionSize, and paste this there.
//*
//* To copy from one map to another just copy the trigger
//* holding this code to the target map.
//*
//*********************************************************
//========================================================
library_once
GetUnitCollisionSize
globals
private
constant
integer
ITERATIONS = 10
//too much, slow, too short "innacurate", let it be bigger than 0...
//I *think* 10 is enough...
public
constant
real
MAX_COLLISION_SIZE = 300.0
//should be THE max collision size in the map,
//well, not really, just make sure it is greater than it
//few maps should have collision sizes bigger than 300.0...
endglobals
//========================================================
function
GetUnitCollisionSize
takes
unit
u
returns
real
local
integer
i=0
local
real
x=
GetUnitX
(u)
local
real
y=
GetUnitY
(u)
local
real
hi
local
real
lo
local
real
mid
set
hi=MAX_COLLISION_SIZE
set
lo=0.0
loop
set
mid=(lo+hi)/2.0
exitwhen
(i==ITERATIONS)
if
(
IsUnitInRangeXY
(u,x+mid,y,0))
then
set
lo=mid
else
set
hi=mid
endif
set
i=i+1
endloop
return
mid
endfunction
endlibrary
Table version
Code: jass
library_once
GetUnitCollisionSize
initializer
init
requires
Table
//********************************************************
//* GetUnitCollisionSize (Table version)
//* --------------------
//* If you need it, use it.
//*
//* To implement it just create a custom text 'trigger'
//* called GetUnitCollisionSize, and paste this there.
//*
//* To copy from one map to another just copy the trigger
//* holding this code to the target map.
//*
//*********************************************************
//=========================================================
globals
private
constant
integer
ITERATIONS = 10
//too much, slow, too short "innacurate", let it be bigger than 0...
//I *think* 10 is enough...
public
constant
real
MAX_COLLISION_SIZE = 300.0
//should be THE max collision size in the map,
//well, not really, just make sure it is greater than it
//few maps should have collision sizes bigger than 300.0...
private
Table memo
endglobals
//=============================================================================
function
GetUnitCollisionSize
takes
unit
u
returns
real
local
integer
i=0
local
real
x=
GetUnitX
(u)
local
real
y=
GetUnitY
(u)
local
integer
typ=
GetUnitTypeId
(u)
local
real
hi
local
real
lo
local
real
mid
if
(memo.exists(typ) )
then
return
I2R
(memo[typ])
endif
set
hi=MAX_COLLISION_SIZE
set
lo=0.0
loop
set
mid=(lo+hi)/2.0
exitwhen
(i==ITERATIONS)
if
(
IsUnitInRangeXY
(u,x+mid,y,0))
then
set
lo=mid
else
set
hi=mid
endif
set
i=i+1
endloop
set
memo[typ]=
R2I
(mid+0.500000001)
return
mid
endfunction
private
function
init
takes
nothing
returns
nothing
set
memo=Table.
create
()
endfunction
endlibrary
«
Last Edit: January 01, 2018, 11:51:35 PM by moyack
»
SonofJay
Your Awesome Site Director
Recognized User
Posts:
381
WC3 Models: 0
WC3 Tutorials: 0
WC3 Tools: 0
WC3 Maps: 0
WC3 Skins: 0
WC3 Icons: 0
WC3 Spells: 0
Reputation:
677
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.
moyack
Site Owner
Administrator
Posts:
970
WC3 Models: 20
WC3 Tutorials: 17
WC3 Tools: 19
WC3 Maps: 12
WC3 Skins: 0
WC3 Icons: 1
WC3 Spells: 16
Reputation:
1153
Site Admin - I love fix things
GetUnitCollisionSize v1 2 (1)
Reply #2 on:
May 21, 2013, 05:22:25 AM
Moved from media so it can handle better the information.
WC3 Modding Information Center
Print
Pages:
1
Go Up
« previous
next »
WC3 Modding Information Center
Forum
Warcraft (WC3) Modding
Warcraft III Resources
Warcraft III Spells and Systems
Codes & Snippets
GetUnitCollisionSize
PortaMx-SEF 1.54
|
PortaMx © 2008-2015
,
PortaMx corp.
Search
Username
Password
Always stay logged in
Forgot your password?