Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Utils
function AngleBetweenRealsRad takes real x1, real y1, real x2, real y2 returns real
return Atan2(y2 - y1, x2 - x1)
endfunction
function AngleBetweenRealsDeg takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
function DistanceBetweenReals takes real x1, real y1, real x2, real y2 returns real
local real dx = x2 - x1
local real dy = y2 - y1
return SquareRoot(dx * dx + dy * dy)
endfunction
function PolarProjectionXDeg takes real sourceX, real dist, real angle returns real
local real x = sourceX + dist * Cos(angle * bj_DEGTORAD)
return x
endfunction
function PolarProjectionXRad takes real sourceX, real dist, real angle returns real
local real x = sourceX + dist * Cos(angle)
return x
endfunction
function PolarProjectionYDeg takes real sourceY, real dist, real angle returns real
local real y = sourceY + dist * Sin(angle * bj_DEGTORAD)
return y
endfunction
function PolarProjectionYRad takes real sourceY, real dist, real angle returns real
local real y = sourceY + dist * Sin(angle)
return y
endfunction
// exemple: set groupToCopy = CopyGroupToGroup(groupToCopy, groupToPasteInto)
function CopyGroupToGroup takes group groupToCopy, group groupToPasteInto returns group
local group g = CreateGroup()
local unit u
loop
set u = FirstOfGroup(groupToCopy)
exitwhen u == null
call GroupRemoveUnit(groupToCopy, u)
call GroupAddUnit(groupToPasteInto, u)
call GroupAddUnit(g, u)
endloop
call DestroyGroup(groupToCopy)
set u = null
return g
endfunction
function GroupCountUnits takes group g returns integer
set bj_groupCountUnits = 0
call ForGroup(g, function CountUnitsInGroupEnum)
return bj_groupCountUnits
endfunction
endlibrary
//TESH.scrollpos=90
//TESH.alwaysfold=0
library BigStomp requires TimerUtils
globals
constant integer maxInstance = 8191 // Don't chnage this
BigStomp_BigStompStruct array bigStompStructs[8191] // Don't chnage this
integer currentInstance = 0 // Don't chnage this
constant string buffId = "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl" // You can change this
constant integer spellId = 'A000' // You can change this
endglobals
function PickUnitsConditions takes nothing returns boolean
return IsPlayerEnemy(bigStompStructs[currentInstance].casterOwner, GetOwningPlayer(GetFilterUnit())) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING) and IsUnitAliveBJ(GetFilterUnit()) // The conditions to pick a units
endfunction
public struct BigStompStruct
integer currentFrame
player casterOwner
group targets
real locx
real locy
real duration
integer maxFrames
real radius
real distance
real velocity
real a
public static method LoopActions takes nothing returns nothing
local BigStompStruct s = GetTimerData(GetExpiredTimer())
local integer targetsCount = GroupCountUnits(s.targets)
local unit u = null
local group mirrorGroup = CreateGroup()
local real distance = 0
local real angle = 0
local real ux = 0
local real uy = 0
local effect e = null
if(s.currentFrame >= s.maxFrames) then
call s.destroy()
call ReleaseTimer(GetExpiredTimer())
endif
set s.targets = CopyGroupToGroup(s.targets, mirrorGroup)
if(s.currentFrame != 0) then
loop
set u = FirstOfGroup(mirrorGroup)
exitwhen (u == null)
set ux = GetUnitX(u)
set uy = GetUnitY(u)
set angle = AngleBetweenRealsRad(s.locx, s.locy, ux, uy)
call SetUnitX(u, PolarProjectionXRad(ux, s.a * Pow(s.currentFrame, 2) + s.velocity, angle))
call SetUnitY(u, PolarProjectionYRad(uy, s.a * Pow(s.currentFrame, 2) + s.velocity, angle))
call GroupRemoveUnit(mirrorGroup, u)
endloop
else
loop
set u = FirstOfGroup(mirrorGroup)
exitwhen (u == null)
set e = AddSpecialEffectTarget(buffId, u, "origin")
set ux = GetUnitX(u)
set uy = GetUnitY(u)
set angle = AngleBetweenRealsRad(s.locx, s.locy, ux, uy)
call SetUnitX(u, PolarProjectionXRad(ux, s.a * Pow(s.currentFrame, 2) + s.velocity, angle))
call SetUnitY(u, PolarProjectionYRad(uy, s.a * Pow(s.currentFrame, 2) + s.velocity, angle))
call GroupRemoveUnit(mirrorGroup, u)
call DestroyEffect(e)
endloop
endif
call DestroyGroup(mirrorGroup)
set mirrorGroup = null
set e = null
set u = null
set s.currentFrame = s.currentFrame + 1
endmethod
static method create takes unit caster, integer level returns BigStompStruct
local timer t
if(currentInstance > maxInstance) then
set currentInstance = 0
endif
set bigStompStructs[currentInstance] = BigStompStruct.allocate()
set t = NewTimer()
set bigStompStructs[currentInstance].duration = 0.5 + (I2R(level) / 20)// You can change this
set bigStompStructs[currentInstance].maxFrames = R2I(bigStompStructs[currentInstance].duration / 0.03) // 0.03 represents the time for the timer to call again the loop
set bigStompStructs[currentInstance].radius = 200 + 31 + (50 * level)// You can change this BUT I RECOMMEND YOU TO NOT REMOVE THE +31 JUST DO AS IF IT WASN'T THERE!
set bigStompStructs[currentInstance].distance = 400 + (50 * level)// You can change this
set bigStompStructs[currentInstance].velocity = bigStompStructs[currentInstance].distance / bigStompStructs[currentInstance].duration * 0.03
set bigStompStructs[currentInstance].a = -bigStompStructs[currentInstance].velocity / Pow(bigStompStructs[currentInstance].maxFrames, 2)
set bigStompStructs[currentInstance].targets = CreateGroup()
set bigStompStructs[currentInstance].currentFrame = 0
set bigStompStructs[currentInstance].locx = GetUnitX(caster)
set bigStompStructs[currentInstance].locy = GetUnitY(caster)
set bigStompStructs[currentInstance].casterOwner = GetOwningPlayer(caster)
call GroupEnumUnitsInRange(bigStompStructs[currentInstance].targets, bigStompStructs[currentInstance].locx, bigStompStructs[currentInstance].locy, bigStompStructs[currentInstance].radius, Condition(function PickUnitsConditions))
call SetTimerData(t, bigStompStructs[currentInstance])
set currentInstance = currentInstance + 1
call TimerStart(t, 0.03, true, function BigStompStruct.LoopActions )
return bigStompStructs[currentInstance - 1]
endmethod
method onDestroy takes nothing returns nothing
call DestroyGroup(.targets)
set .targets = null
set .casterOwner = null
endmethod
endstruct
function SpellConditions takes nothing returns boolean
return GetSpellAbilityId() == spellId
endfunction
function SpellActions takes nothing returns nothing
call BigStompStruct.create(GetTriggerUnit(), GetUnitAbilityLevel(GetTriggerUnit(), spellId))
endfunction
//===========================================================================
function InitTrig_Big_Stomp takes nothing returns nothing
set gg_trg_Big_Stomp = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Big_Stomp, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Big_Stomp, Condition(function SpellConditions) )
call TriggerAddAction( gg_trg_Big_Stomp, function SpellActions)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope FILTERS initializer Init
globals
boolexpr FILTER_True
endglobals
private function ReturnTrue takes nothing returns boolean
return true
endfunction
private function Init takes nothing returns nothing
set FILTER_True = Condition(function ReturnTrue)
endfunction
endscope
// whichGroup: the group the units will be added to
// xc, yc: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in radians
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in radians
// filter: the condition function to apply to the units in the sector.
function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing
local group g = CreateGroup()
local unit u
local real x
local real y
local real x1
local real y1
local real x2
local real y2
call GroupEnumUnitsInRange(g, xc, yc, radius, filter)
set angle = angle * 0.5
set x1 = Cos(facing - angle)
set y1 = Sin(facing - angle)
set x2 = Cos(facing + angle)
set y2 = Sin(facing + angle)
loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)
set x = GetUnitX(u) - xc
set y = GetUnitY(u) - yc
if y * x1 >= x * y1 and y * x2 <= x * y2 then
call GroupAddUnit(whichGroup, u)
endif
endloop
call DestroyGroup(g)
set g = null
endfunction
// point: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in degrees
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSectorDeg takes location point, real facing, real radius, real angle, boolexpr filter returns group
local group g = CreateGroup()
if filter == null then
set filter = FILTER_True
endif
call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
return g
endfunction
// point: the starting point, sort of like the center of the circle
// facing: the direction the "middle" of the sector goes to, in radians
// radius: the "length" of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSectorRad takes location point, real facing, real radius, real angle, boolexpr filter returns group
local group g = CreateGroup()
if filter == null then
set filter = FILTER_True
endif
call GroupEnumUnitsInSector(g, GetLocationX(point), GetLocationY(point), facing * bj_DEGTORAD, radius, angle * bj_DEGTORAD, filter)
return g
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+)
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
endglobals
//==========================================================================================
function NewTimer takes nothing returns timer
if (tN==0) then
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
set tT[0]=CreateTimer()
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],0)
return tT[tN]
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary