function SetBuildingFacing takes unit u, real a returns nothing
call UnitRemoveType(u, UNIT_TYPE_STRUCTURE)
call SetUnitMoveSpeed(u, 100)
call SetUnitTurnSpeed(u,1.)
call SetUnitFacing(u, a)
call SetUnitMoveSpeed(u, 0)
call UnitAddType(u, UNIT_TYPE_STRUCTURE)
endfunction
UNIT_TYPE_SUMMONED
from ladder summons will make them take no damage and be untargetable for single-target dispell spells.function SetBuildingFacing takes unit u, real a returns nothing
call SetUnitPosition(u, GetUnitX(u), GetUnitY(u))
call SetUnitFacing(u, a)
endfunction
function GetMagnitude2D takes real x, real y returns reaal
return SquareRoot(x*x+y*y)
endfunction
function GetMagnitude3D takes real x, real y, real z returns real
return SquareRoot(x*x+y*y+z*z)
endfunction
function GetAngle2D takes real x, real y returns real
return Atan2(y, x)
endfunction
function GetAngle3D takes real distance2D, real z returns real
return Atan2(z, distance2D)
endfunction
function GetProjectedX takes real distance2D, real angle2D returns real
return distance2D*Cos(angle2D)
endfunction
function GetProjectedY takes real distance2D, real angle2D returns real
return distance2D*Sin(angle2D)
endfunction
function GetProjectedZ takes real distance3D, real angle3D returns real
return distance3D*Sin(angle3D)
endfunction
function GetProjectedZ2 takes real distance2D, real angle3D returns real
return Tan(angle3D)*distance2D
endfunction
function GetDistance2D takes real distance3D, real angle3D returns real
return distance3D*Cos(angle3D)
endfunction
function GetDistance3D takes real distance2D, real angle3D returns real
return distance2D/Cos(angle3D)
endfunction
GetMagnitude3D is dangerous as GetLocationZ is asynchronous
local real dist2D = dist3D*Cos(angle3D)
set x = x0 + dist2D*Cos(angle2D)
set y = y0 + dist2D*Sin(angle2D)
set z = z0 + dist3D*Sin(angle3D)
library CompressInt
//performs lossy compression on integers
//compressed number = number^(2/3)
//decomperssed number = roundDown(number^1.5+.5)
function CompressInt takes integer n returns integer
return R2I(Pow(n,2/3.))
endfunction
function DecompressInt takes integer n returns integer
return R2I(Pow(n,1.5)+.5)
endfunction
endlibrary
function Compress takes integer n returns integer
return R2I(n,2/3.)
endfunction
function Decompress takes integer n returns integer
return R2I(Pow(n,1.5))
endfunction
function CompressInt takes integer i returns integer
return R2I(Pow(i, 2/3.) + 0.5)
endfunction
function DecompressInt takes integer i returns integer
return R2I(Pow(i, 1.5) + 0.5)
endfunction
function CompressInt takes integer i returns integer
return R2I(Pow(i, 2/5) + 0.5)
endfunction
function DecompressInt takes integer i returns integer
return R2I(Pow(i, 5/2) + 0.5)
endfunction
def compress(i):
return int(i ** (2/3.)) #Python 3.X does not need the dot after the 3
def decompress(i):
return int(i ** 1.5 + 0.5)
def test(i):
j = compress(i)
print j, "\n", i, "\n", decompress(j) #Python 2.X
#print(j, "\n", i, "\n", decompress(j)) #Python 3.X
library GroupMacro
/*
Example use:
local unit caster = GetTriggerUnit()
local unit u
local real x = GetSpellTargetX()
local real y = GetSpellTargetY()
local real range = 100
//! runtextmacro GroupMacro("u", "x", "y", "range")
call UnitDamageTarget(caster, u, false, false, null, null, null)
//! runtextmacro GroupMacroEnd()
The "172" in the below textmacro should be configured to the max collision
size in your map. 172 is the max natural collision size which is used by
a town-hall type building.
*/
//! textmacro GroupMacro takes UNIT_VAR, X, Y, RANGE
call GroupEnumUnitsInRange(bj_lastCreatedGroup, $X$, $Y$, $RANGE$ + 172, null)
loop
set $UNIT_VAR$ = FirstOfGroup(bj_lastCreatedGroup)
exitwhen $UNIT_VAR$ == null
call GroupRemoveUnit(bj_lastCreatedGroup, $UNIT_VAR$)
if IsUnitInRangeXY($UNIT_VAR$, $X$, $Y$, $RANGE$) then
//! endtextmacro
//! textmacro GroupMacroEnd
endif
endloop
//! endtextmacro
endlibrary
library RectEvent uses Table
globals
private Table t
endglobals
function RegisterEnterRectEvent takes rect whichRect, code func returns nothing
local integer id=GetHandleId(whichRect)
local trigger trig=t.trigger[id]
local region reg
if trig==null then
set trig=CreateTrigger()
set reg=CreateRegion()
call RegionAddRect(reg,whichRect)
call TriggerRegisterEnterRegion(trig,reg,null)
set reg=null
endif
call TriggerAddCondition(trig,Condition(func))
set trig=null
endfunction
private module RectEventModule
static method onInit takes nothing returns nothing
set t=Table.create()
endmethod
endmodule
private struct RectEventStruct extends array
implement RectEventModule
endstruct
endlibrary
requires Table
function RegisterEnterRectEvent takes rect r, code func returns nothing
local trigger t = CreateTrigger()
local region g = CreateRegion()
call RegionAddRect(g, r)
call TriggerRegisterEnterRegion(t, g, null)
call TriggerAddCondition(t, Filter(func))
set g = null
set t = null
endfunction
library DestroyFX requires TimerUtils
globals
private integer n = 0
private integer array r
private effect array x
endglobals
private function Expire takes nothing returns nothing
local integer i = GetTimerData(GetExpiredTimer())
call ReleaseTimer(GetExpiredTimer())
call DestroyEffect(x[i])
set r[i] = r[0]
set r[0] = i
endfunction
function DestroyFX takes effect e, real duration returns nothing
local integer i = r[0]
if i == 0 then
set i = n + 1
set n = i
else
set r[0] = r[i]
endif
set x[i] = e
call TimerStart(NewTimerEx(i), duration, false, function Expire)
endfunction
endlibrary
library UnitPropWindow requires optional UnitIndexer, optional AIDS //Needs 1
struct UnitPropWindow extends array
private integer n
method lock takes nothing returns nothing
if this.n == 0 then
static if LIBRARY_AIDS then
call AIDS_AddLock(this)
call SetUnitPropWindow(GetIndexUnit(this), 0)
else
call UnitIndex(this).lock()
call SetUnitPropWindow(GetUnitById(this), 0)
endif
endif
set this.n = this.n + 1
endmethod
method unlock takes nothing returns nothing
set this.n = this.n - 1
if this.n == 0 then
static if LIBRARY_AIDS then
call AIDS_RemoveLock(this)
call SetUnitPropWindow(GetIndexUnit(this), GetUnitDefaultPropWindow(GetIndexUnit(this)))
else
call UnitIndex(this).unlock()
call SetUnitPropWindow(GetUnitById(this), GetUnitDefaultPropWindow(GetUnitById(this)))
endif
endif
endmethod
endstruct
function LockUnitPropWindow takes unit u returns nothing
call UnitPropWindow(GetUnitUserData(u)).lock()
endfunction
function UnlockUnitPropWindow takes unit u returns nothing
call UnitPropWindow(GetUnitUserData(u)).unlock()
endfunction
endlibrary
There is TimedHandles by TriggerHappy and TimedEffects by Moyack, however I wanted a super-super light version that didn't have any more code than necessary (vJass struct safety is not required here, for example) so I made this.
Well Moyack has updated his TimedEffects library on wc3c I will use his.
I mean the one that uses TimerUtils dude![]()
What not use UnitApplyTimedLife?
library AngleTools
//Turns any real into a radian between 0 and bj_PI*2
function R2A takes real a returns real
loop
exitwhen a>=0
set a=a+bj_PI*2
endloop
loop
exitwhen a<=bj_PI*2
set a=a-bj_PI*2
endloop
return a
endfunction
//Determines if "a" gets closer to "b" if it increases.
//Tells you which direction to turn to if you want to spin an angle
function IsAngleGreater takes real a, real b returns boolean
return Sin(b-a)>=0
endfunction
//Returns if the angle "b" is inside a cone pointing towards angle "a" of overture "o"
//if Cone(GetUnitFacing(unit),Atan2(GetUnitY(target)-GetUnitY(unit),GetUnitX(target)-GetUnitX(unit)),bj_PI/12) then
function Cone takes real a, real b, real o returns boolean
return Cos(b-a)>=Cos(o)
endfunction
endlibrary
function IsPointOnLine takes real slope, real yIntercept, real x, real y returns boolean
return y == slope * x + yIntercept
endfunction
Bribe said:What not use UnitApplyTimedLife?
Dirac said:Doesn't remove the dummy from the game, and units "decaying" cause leaks and doesn't clear the index.
Isn't the epsilon value 0.000000001?
but 0.000000001 is supposed to be used when in need of extremely accurate reals
local real N = 5.0 // Use normal numbers
local real x = 1.0 / N
local integer k = 0
call BJDebugMsg("Original Fraction: 1/"+I2S(R2I(N)))
loop
exitwhen (k == 10)
set x = x * (N + 1.0) - 1.0
set k = k + 1
endloop
call BJDebugMsg(R2S(x))
call BJDebugMsg("9-decimal number: "+R2S(0.0123000000))
call BJDebugMsg("4-decimal number: "+R2S(0.0123))
library TestPeriods initializer init
globals
private constant real PERIOD1 = 0.000200090
private constant real PERIOD2 = 0.000200009
private constant real PERIOD3 = 0.000200000
private constant real PERIOD4 = 0.0002
endglobals
globals
private integer I1 = 0
private integer I2 = 0
private integer I3 = 0
private integer I4 = 0
private timer Tim1 = CreateTimer()
private timer Tim2 = CreateTimer()
private timer Tim3 = CreateTimer()
private timer Tim4 = CreateTimer()
endglobals
private function F1 takes nothing returns nothing
set I1 = I1+1
endfunction
private function F2 takes nothing returns nothing
set I2 = I2+1
endfunction
private function F3 takes nothing returns nothing
set I3 = I3+1
endfunction
private function F4 takes nothing returns nothing
set I4 = I4+1
endfunction
private function init takes nothing returns nothing
call TimerStart(Tim1,PERIOD1,true,function F1)
call TimerStart(Tim2,PERIOD2,true,function F2)
call TimerStart(Tim3,PERIOD3,true,function F3)
call TimerStart(Tim4,PERIOD4,true,function F4)
call TriggerSleepAction(11.0) // or more time if it's needed
call BJDebugMsg(I2S(I1))
call BJDebugMsg(I2S(I2))
call BJDebugMsg(I2S(I3))
call BJDebugMsg(I2S(I4))
endfunction
endlibrary