- Joined
- Jul 10, 2007
- Messages
- 6,306
So does this have a future?
library GetUnitCollision requires Table
//Created by Vexorian with some improvements by Bribe
globals
//-------------------------------------------------------------------
// You can optimize this to be the max collision in your map
// 172 is max natural collision - from tier 3 town halls.
private constant integer MAX_COLLISION = 172
// A Table for an optimization perk.
private Table t = 0
endglobals
//=======================================================================
private function Check takes integer id, unit u returns integer
local integer z = MAX_COLLISION
local integer a = 0
local integer i = z
local real x = GetUnitX(u)
local real y = GetUnitY(u)
loop
if IsUnitInRangeXY(u, x + i, y, 0) then
set a = i
else
set z = i
endif
exitwhen z - a <= 1
set i = (z + a) / 2
endloop
set i = i - z + a
set t[id] = i
return i
endfunction
//=======================================================================
// Golden function - optimized for fast repeat returns on type id's.
//
function GetUnitCollision takes unit u returns integer
local integer id = GetUnitTypeId(u)
if not t.has(id) then
return Check(id, u)
endif
return t[id]
endfunction
//=======================================================================
private module I
private static method onInit takes nothing returns nothing
set t = Table.create()
endmethod
endmodule
private struct S extends array
implement I
endstruct
endlibrary
set uc.real[i] = R2I(m*10)/10.
return R2I(m*10)/10.
set m = R2I(m*10)/10.
set uc.real[i] = m
return m
function TestGroup takes real x, real y, real r returns nothing
local unit u
local real ux
local real uy
call GroupEnumUnitsInRange(bj_lastCreatedGroup,x,y,r+MAX_COLLISION_SIZE,null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u==null
set ux = GetUnitX(u)-x
set uy = GetUnitY(u)-y
// check if the unit collides with the picking radius
if SquareRoot(ux*ux+uy*uy)-GetUnitCollision(u) <= r then
// Do Actions...
endif
call GroupRemoveUnit(bj_lastCreatedGroup,u)
endloop
set u = null
endfunction
Could you add a constant for the max unit collision so we can pick groups in range + max collision and then decide if the unit's collision matches the actual range?
@Nes, human town halls have 197 collision by default. That is the largest default object editor collision size.
but the pathing map is 160.