library LibraryDT initializer Init
//= Adjustables =============================================================
////////////////////////////////////
// ADJUSTABLES //
////////////////////////////////////
globals
constant integer DummyDT = 'h000' // The ID of the General Dummy
endglobals
////////////////////////////////////
// ADJUSTABLES END //
////////////////////////////////////
//***************************************************************************
//* GENERAL PURPOSE FUNCTIONS *
//***************************************************************************
//= Spell Init ==============================================================
// call SpellInitDT(pue, action, condition)
function SpellInitDT takes playerunitevent pue, code action, code condition returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), pue, null)
exitwhen i >= 15
set i = i + 1
endloop
call TriggerAddCondition(t, Condition(condition))
call TriggerAddAction(t, action)
set t = null
endfunction
//= Timer User Data (works for handles too) ================================
// call SetTimerUserData(whichTimer, whichStruct)
function SetTimerUserData takes handle whichTimer, integer whichStruct returns nothing
call SaveInteger(HASHTABLE_DT, 1, GetHandleId(whichTimer), whichStruct)
endfunction
// call GetTimerUserData(whichTimer)
function GetTimerUserData takes handle whichTimer returns integer
return LoadInteger(HASHTABLE_DT, 1, GetHandleId(whichTimer))
endfunction
// call FlushTimerUserData(whichTimer)
function FlushTimerUserData takes handle whichTimer returns nothing
call FlushChildHashtable(HASHTABLE_DT, GetHandleId(whichTimer))
endfunction
//= Preload =================================================================
globals
private constant real PRELOAD_X = GetRectCenterX(bj_mapInitialPlayableArea)
private constant real PRELOAD_Y = GetRectCenterY(bj_mapInitialPlayableArea)
endglobals
// call PreloadSpecialEffectDT(SFX)
function PreloadSpecialEffectDT takes string whichSFX returns nothing
call Preload(whichSFX)
call PreloadStart()
endfunction
// call PreloadUnitDT(whichUnit)
function PreloadUnitDT takes integer unitid returns nothing
set bj_lastCreatedUnit = CreateUnit(Player(15), unitid, PRELOAD_X, PRELOAD_Y, 0.)
call RemoveUnit(bj_lastCreatedUnit)
endfunction
//= General Initializer =====================================================
globals
hashtable HASHTABLE_DT
endglobals
private function Init takes nothing returns nothing
set HASHTABLE_DT = InitHashtable()
call PreloadUnitDT(DummyDT)
debug call BJDebugMsg("|cffffcc00LibraryDT Initiated|r")
endfunction
//***************************************************************************
//* MATH FUNCTIONS *
//***************************************************************************
//= Distance ================================================================
globals
private real dx
private real dy
endglobals
// call GetDistanceBetweenPointsDT(ax, ay, bx, by)
function GetDistanceBetweenPointsDT takes real ax, real ay, real bx, real by returns real
set dx = bx - ax
set dy = by - ay
return SquareRoot(dx * dx + dy * dy)
endfunction
// call GetDistanceBetweenUnitsDT(unita, unitb)
function GetDistanceBetweenUnitsDT takes unit a, unit b returns real
return GetDistanceBetweenPointsDT(GetUnitX(a), GetUnitY(a), GetUnitX(b), GetUnitY(b))
endfunction
//***************************************************************************
//* DUMMY FUNCTIONS *
//***************************************************************************
//= Cast Target =============================================================
// call CastTargetDT(aster, targer, abil, order, level)
function CastTargetDT takes unit caster, unit target, integer abilcode, string order, integer level returns nothing
call UnitAddAbility(caster, abilcode)
call SetUnitAbilityLevel(caster, abilcode, level)
call IssueTargetOrder(caster, order, target)
endfunction
// call DummyCastTargetDT(id, target, abil, order, level)
function DummyCastTargetDT takes player id, unit target, integer abilcode, string order, integer level returns nothing
set bj_lastCreatedUnit = CreateUnit(id, DummyDT, GetUnitX(target), GetUnitY(target), 0.)
call CastTargetDT(bj_lastCreatedUnit, target, abilcode, order, level)
call UnitApplyTimedLife(bj_lastCreatedUnit, 'BTLF', .5)
endfunction
//***************************************************************************
//* TEXTTAG FUNCTIONS *
//***************************************************************************
//= TextTag Unit ============================================================
// call TextTagUnitDT(u, tag, fade, size, height, vel, red, green, blue, trans)
function TextTagUnitDT takes unit u, string tag, real fade, real size, real heightoffset, real vel, integer red, integer green, integer blue, integer visibility returns nothing
set bj_lastCreatedTextTag = CreateTextTag()
call SetTextTagText(bj_lastCreatedTextTag, tag, size)
call SetTextTagPosUnit(bj_lastCreatedTextTag, u, heightoffset)
call SetTextTagColor(bj_lastCreatedTextTag, red, green, blue, visibility)
call SetTextTagPermanent(bj_lastCreatedTextTag, false)
call SetTextTagVelocity(bj_lastCreatedTextTag, 0., vel)
call SetTextTagLifespan(bj_lastCreatedTextTag, fade)
call SetTextTagFadepoint(bj_lastCreatedTextTag, fade)
call SetTextTagVisibility(bj_lastCreatedTextTag, true)
endfunction
//***************************************************************************
//* MISSILE FUNCTIONS *
//***************************************************************************
//= Move Missile ============================================================
globals
private real xm
private real ym
private real an
endglobals
// call MoveMissileDT(missile, tx, ty, speed)
function MoveMissileDT takes unit missile, real tx, real ty, real speed returns nothing
set xm = GetUnitX(missile)
set ym = GetUnitY(missile)
set an = Atan2(ty - ym, tx - xm)
call SetUnitPosition(missile, xm + speed * Cos(an), ym + speed * Sin(an))
call SetUnitFacing(missile, (bj_RADTODEG * an))
endfunction
// call MoveMissileTargetDT(missile, target, speed)
function MoveMissileTargetDT takes unit missile, unit target, real speed returns nothing
call MoveMissileDT(missile, GetUnitX(target), GetUnitY(target), speed)
endfunction
//= Create Missile ==========================================================
globals
private effect array MissileModel
endglobals
// call CreateMissileDT(owner, x, y, facing, offset, model, attachmentpt, height, size)
function CreateMissileDT takes player owner, real x, real y, real facing, real offset, string model, string attachmentpt, real height, real size returns unit
set bj_lastCreatedUnit = CreateUnit(owner, DummyDT, x + offset * Cos(facing), y + offset * Sin(facing), facing)
if size != 1. then
call SetUnitScale(bj_lastCreatedUnit, size, size, size)
endif
if height != 0. then
call UnitAddAbility(bj_lastCreatedUnit, 'Arav')
call SetUnitFlyHeight(bj_lastCreatedUnit, height, 0.)
call UnitRemoveAbility(bj_lastCreatedUnit, 'Arav')
endif
call SaveEffectHandle(HASHTABLE_DT, 1, GetHandleId(bj_lastCreatedUnit), AddSpecialEffectTarget(model, bj_lastCreatedUnit, attachmentpt))
return bj_lastCreatedUnit
endfunction
// call CreateFiredMissileDT(firingunit, offset, model, attachmentpt, height, size)
function CreateFiredMissileDT takes unit firingunit, real offset, string model, string attachmentpt, real height, real size returns unit
return CreateMissileDT(GetOwningPlayer(firingunit), GetUnitX(firingunit), GetUnitY(firingunit), GetUnitFacing(firingunit), offset, model, attachmentpt, height, size)
endfunction
// call DestroyMissileDT(whichMissile)
function DestroyMissileDT takes unit whichMissile returns nothing
call DestroyEffect(LoadEffectHandle(HASHTABLE_DT, 1, GetHandleId(whichMissile)))
call UnitApplyTimedLife(whichMissile, 'BTLF', .01)
endfunction
//===========================================================================
endlibrary