Name | Type | is_array | initial_value |
library AttachObject /*
AttachObject v2.05
by
Spellbound
________DESCRIPTION_____________________________________________________________________________
AttachObject (formetly AttachUnit) will bind a unit or special effect to a unit, with respect
to angle, distance and, optionally, facing angle of the host. Carrier units are called Hosts
and attached units/effects are called Guests.
AttachObject comes with a turret functionality that allows unit Guests to rotate and attack
normally, after which they will return to a specific facing position. They can also be made
to slowly rotate over time, which maybe be useful for sci-fi type attachements.
________REQUIREMENTS____________________________________________________________________________
*/ requires /*
*/ ListT, /* https://www.hiveworkshop.com/threads/containers-list-t.249011/
*/ optional /*
*/ RiseAndFall /* https://www.hiveworkshop.com/threads/riseandfall.306703/
________INSTALLATION____________________________________________________________________________
Simply copy-paste this trigger into your map and install a unit indexer that uses custom values.
If you get an error telling you that UnitAlive or BlzGetUnitMovementType have been re-declared,
comment out the corresponding line:
*/
native UnitAlive takes unit whichUnit returns boolean
native BlzGetUnitMovementType takes unit whichUnit returns integer
/*
________API_____________________________________________________________________________________
/* IMPORTANT */ For units to function as Guests, they must have a positive, non-zero movement
speed. Otherwise they will not move along with their Host.
STRUCTS
¯¯¯¯¯¯¯
GuestEx
GuestEx is you main referrence struct. When you attach a unit or a special effect, the
funciton will return a GuestEx instance.
GuestEx members are readonly:
.host
.guest
.fx
EffectTimed
EffectTimed is used internally to destroy special effects after a certain time, similar
to an expiration timer on units.
EffectTimed.start(whichEffect, whichDuration)
Destroys whichEffect after whichDuration.
FUNCTIONS
¯¯¯¯¯¯¯¯¯
call AttachUnitToHost takes unit g, unit host, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle returns GuestEx
^ This function will attach a unit to a host. Returns the guest instance.
[_PARAMETERS_]
unit guest - the unit to attach (aka the Guest)
unit host - the Host
real angle - the angle relative to the Host's facing angle at which the Guest is offset to. In degrees.
real distance - the distance between the Host and the Guest
real zOffset - the height difference from the Host
real offsetFix - if your Guest is off-center, try setting this to -16 or 16.
boolean staticAngle - if true, the Guest's angle offset will ignore the Host's facing direction
call AttachEffectToHost takes effect fx, unit h, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle returns GuestEx
Similarly you may attach a special effect to a host instead of a unit. The only difference is the unit parameter is instead a special effect parameter.
call SetUnitFacingProperties takes unit guest, real startAngle, real rate, real cooldown, boolean dynamicFacing, boolean turretMode
^ This sets an attached unit's facing properties. If this is not called, the unit will always face the same direction.
[_PARAMETERS_]
unit guest - the attached unit (aka Guest)
real startAngle - the angle at which the Guest begins at. If dynamicFacing (see below) is false, the guest will always face this specific angle.
real rate - the speed at which the Guest rotates over time. Set to zero to ignore.
real cooldown - this is neccessary if the Guest can attack. It will resume it facing parameters after that cooldown has expired.
boolean dynamicFacing - if this is true, the facing angle of the Guest will depend on the facing of the Host.
boolean turretMode - Set this to true if you want your Guest to be able to attack. Otherwise, the facing parameters will keep interferring.
call SetEffectFacingProperties takes effect fx, real startAngle, real rate, boolean dynamicFacing
With a special effect, the facing parameters have fewer options. Use this function instead of SetUnitFacingProperties.
call DettachUnit takes unit g, boolean resetHeight, real duration
^ Call this function when you want to Dettach a Guest from a Host. real duration is for how long after Dettachement do you want the Guest to die.
Set real time to zero if you don't want the Guest to die. This function is called automatically when a Guest dies.
call DettachEffect takes effect fx, real duration
^ same as above, but specific to attached effects. real duration call EffectTimed.start(guest.fx, duration) internally if duration is greater than zero.
call DettachAllGuests takes unit h, boolean resetHeight, real duration
^ Call this function on a Host to Dettach all its Guests. This function will NOT get called automatically on Host death and must be done manually.
Similarly to DettachGuest, real duration will determine how long after Dettachment will the Guest die. Set to zero to not destroy your Dettached Guests.
call GetRandomGuest takes unit h, boolepx guestFilter returns unit
^ This will return a random Guest attached to a Host. Set guestFilter to null if you do not wish to filter your guests.
/* IMPORTANT */ In your filter you MUST use the variable 'FilterGuest' and NOT GetFilterUnit().
call GetNumberOfGuests takes unit h returns integer
^ This will return the number of Guests currently connected to a Host.
call GroupUnitGuests takes unit h returns group
^ this will take all UNIT Guests attached to a Host and put them in a unit group via:
set YourGroup = GrouGuests(host).
call GetGuestList takes unit h returns integer
^ this will copy the Guest list of a host and return either an IntegerList instance or
LinkedList instance. When you are done with that copy, YOU MUST DESTROY IT with
list.destroy().
The list returned will be an IntegerList type. See the trigger HowToIterateThroughLists
if you are unfamiliar with linked lists.
GetGuestList() is not wait-safe as the list is not being updated if Guests are
added or removed.
call IsUnitHost takes unit h returns boolean
^ Returns true if a unit is a Host.
call IsUnitGuest takes unit g returns boolean
^ Returns true if a unit is a Guest.
call IsEffectGuest takes effect fx returns boolean
^ Returns true if an effect is a Guest.
call IsGuestUnit takes GuestEx ex returns boolean
^ Returns true if a Guest is a unit.
call IsGuestEffect takes GuestEx ex returns boolean
^ Returns true if a Guest is a special effect.
call GetHost takes GuestEx ex returns unit
^ Returns the Host unit of a Guest.
call GetGuestUnitId takes unit g returns GuestEx
^ Returns the readonly instance id of a unit Guest.
call GetGuestEffectId takes effect fx returns GuestEx
^ Returns the readonly instance id of an effect Guest.
call ShowGuests takes unit h returns nothing
^ Cycles through all the Guests of a Host and unhides them.
This function is called automatically when a Host is unhidden.
call HideGuests takes unit h returns nothing
^ Cycles through all Guests a Host has and hides them.
This function is called automatically when a Host is hidden.
call ShowGuest takes GuestEx ex returns nothing
^ not to be mistaken with ShowGuests, this will reveal ONE Guest. ShowGuest does
not break locaut ('Aloc').
*/
globals
// interval between Guest updates. Do not change this or things will look choppy.
private constant real TIMEOUT = .03125
// order attack for turret mode
private constant integer ORDER_ATTACK = 851983
// If true then Guests will reset to their default fly height when they are dettached.
private constant boolean RESET_HEIGHT = true
// the speed at which they rise/fall if RESET_HEIGHT is true.
private constant real FALL_SPEED = 300.
unit FilterGuest = null
private trigger FilterTrig = CreateTrigger()
private hashtable TurretStorage = InitHashtable()
private hashtable HostIdStorage = InitHashtable()
private hashtable GuestIdStorage = InitHashtable()
private timer Clock = CreateTimer()
private group GuestGroup = CreateGroup()
endglobals
//! runtextmacro optional DEFINE_LIST("", "AOList", "integer")
private struct GlobalListT
static AOList Guests = 0
static AOList Hosts = 0
endstruct
function ListTGetRandom takes AOList list returns AOListItem
local integer size = list.size()
local integer i
local AOListItem node = 0
debug if size == 0 then
debug call BJDebugMsg("the list is empty")
debug return 0
debug endif
// thanks to Wareditor for that bit of code
if size > 0 then
set i = GetRandomInt(1, size)
if i > size / 2 then
set i = size - i
set node = list.last
loop
exitwhen i == 0
set node = node.prev
set i = i - 1
endloop
else
set i = i - 1
set node = list.first
loop
exitwhen i == 0
set node = node.next
set i = i - 1
endloop
endif
endif
return node
endfunction
// specfic for reading Guest data
struct GuestEx
readonly unit host
readonly unit guest
readonly effect fx
method destroy takes nothing returns nothing
set this.host = null
set this.guest = null
set this.fx = null
call this.deallocate()
endmethod
static method create takes unit h, unit g, effect fx returns thistype
local thistype this = allocate()
set this.host = h
set this.guest = g
set this.fx = fx
return this
endmethod
endstruct
private struct Guest
real cooldown
real cooldownReset
trigger turretTrigger
boolean dynamicFacing
boolean updateFacing
boolean isHidden
real distance
real angle
real zOffset
real offsetFix
real angleRate
real facing
real idleAngle
boolean staticAngle
unit parent
unit u
effect fx
GuestEx ex
method destroy takes nothing returns nothing
if this.fx != null then
call FlushChildHashtable(GuestIdStorage, GetHandleId(this.fx))
set this.fx = null
else
call FlushChildHashtable(GuestIdStorage, GetHandleId(this.u))
set this.u = null
endif
set this.parent = null
set this.staticAngle = false
set this.dynamicFacing = false
set this.updateFacing = false
set this.isHidden = false
set this.angleRate = 0.
set this.idleAngle = 0.
call this.ex.destroy()
set this.ex = 0
call this.deallocate()
endmethod
static method create takes unit g, effect fx, unit h returns thistype
local thistype this = allocate()
call GlobalListT.Guests.push(this)
set this.parent = h
set this.u = g
set this.fx = fx
set this.ex = GuestEx.create(h, g, fx)
if g == null then
call SaveInteger(GuestIdStorage, GetHandleId(fx), 0, this)
else
call SaveInteger(GuestIdStorage, GetHandleId(g), 0, this)
endif
return this
endmethod
endstruct
private struct Host
real x
real y
real z
real t
real f
unit u
boolean hiddenState
AOList guestList
method destroy takes nothing returns nothing
call FlushChildHashtable(HostIdStorage, GetHandleId(this.u))
call this.guestList.destroy()
set this.u = null
set this.hiddenState = false
call GlobalListT.Hosts.removeElem(this)
if GlobalListT.Hosts.empty() then
call PauseTimer(Clock)
endif
call this.deallocate()
endmethod
method addGuest takes Guest guest returns nothing
call this.guestList.push(guest)
endmethod
static method create takes unit h returns thistype
local thistype this = allocate()
set this.guestList = AOList.create()
call GlobalListT.Hosts.push(this)
set this.u = h
set this.hiddenState = IsUnitHidden(h)
call SaveInteger(HostIdStorage, GetHandleId(h), 0, this)
return this
endmethod
endstruct
struct EffectTimed
private effect fx
private real dur
private static timer clock = CreateTimer()
static AOList fxList
private static method update takes nothing returns nothing
local thistype this
local AOListItem node = thistype.fxList.first
local AOListItem nodeNext
loop
exitwhen node == 0
set nodeNext = node.next
set this = node.data
set this.dur = this.dur - TIMEOUT
if this.dur <= 0. then
call DestroyEffect(this.fx)
set this.fx = null
call this.deallocate()
endif
set node = nodeNext
endloop
if thistype.fxList.size() < 1 then
call PauseTimer(thistype.clock)
endif
endmethod
static method start takes effect vfx, real duration returns nothing
local thistype this = allocate()
set this.fx = vfx
set this.dur = duration
call thistype.fxList.push(this)
if thistype.fxList.size() == 1 then
call TimerStart(thistype.clock, TIMEOUT, true, function thistype.update)
endif
endmethod
endstruct
//REFERENCE AND OTHER USEFUL FUNCTIONS
// library use only
private function GetPrivateHostUnitId takes unit h returns Host
return LoadInteger(HostIdStorage, GetHandleId(h), 0)
endfunction
private function GetPrivateGuestUnitId takes unit g returns Guest
return LoadInteger(GuestIdStorage, GetHandleId(g), 0)
endfunction
private function GetPrivateGuestEffectId takes effect e returns Guest
return LoadInteger(GuestIdStorage, GetHandleId(e), 0)
endfunction
// public use
function GetHost takes Guest guest returns unit
return guest.parent
endfunction
function IsUnitHost takes unit h returns boolean
return LoadInteger(HostIdStorage, GetHandleId(h), 0) != 0
endfunction
function IsUnitGuest takes unit g returns boolean
return LoadInteger(GuestIdStorage, GetHandleId(g), 0) != 0
endfunction
function IsEffectGuest takes effect e returns boolean
return LoadInteger(GuestIdStorage, GetHandleId(e), 0) != 0
endfunction
function IsGuestUnit takes GuestEx ex returns boolean
return ex.guest != null
endfunction
function IsGuestEffect takes GuestEx ex returns boolean
return ex.fx != null
endfunction
function GetGuestUnitId takes unit g returns GuestEx
local Guest guest = LoadInteger(GuestIdStorage, GetHandleId(g), 0)
return guest.ex
endfunction
function GetGuestEffectId takes effect e returns GuestEx
local Guest guest = LoadInteger(GuestIdStorage, GetHandleId(e), 0)
return guest.ex
endfunction
function GetNumberOfGuests takes unit h returns integer
local Host host = GetPrivateHostUnitId(h)
return host.guestList.size()
endfunction
function GroupUnitGuests takes unit h returns group
local Host host = GetPrivateHostUnitId(h)
local Guest guest
local AOListItem node = host.guestList.first
if GuestGroup == null then
set GuestGroup = CreateGroup()
else
call GroupClear(GuestGroup)
endif
if IsUnitHost(h) then
loop
exitwhen node == 0
set guest = node.data
call GroupAddUnit(GuestGroup, guest.u)
set node = node.next
endloop
endif
return GuestGroup
endfunction
function GetGuestList takes unit h returns IntegerList
local Host host = GetPrivateHostUnitId(h)
local Guest guest
local IntegerList list = IntegerList.create()
local IntegerListItem node = host.guestList.first
loop
exitwhen node == 0
set guest = node.data
call list.push(guest.ex)
set node = node.next
endloop
return list
endfunction
function GetRandomGuest takes unit h, boolexpr guestFilter returns unit
local Host host = GetPrivateHostUnitId(h)
local Guest guest
local AOListItem node = ListTGetRandom(host.guestList)
local unit u
local triggercondition tcnd
local boolean firstPass = false
local integer n = host.guestList.size()
if guestFilter == null then
set guest = node.data
return guest.u
else
set firstPass = (node == host.guestList.first)
set FilterGuest = null
loop
exitwhen node == 0 and firstPass
if node == 0 and not firstPass then
set node = host.guestList.first
set firstPass = true
endif
set guest = node.data
set u = guest.u
set tcnd = TriggerAddCondition(FilterTrig, guestFilter)
if TriggerEvaluate(FilterTrig) then
set FilterGuest = u
endif
call TriggerRemoveCondition(FilterTrig, tcnd)
set node = node.next
endloop
set u = null
set tcnd = null
return FilterGuest
endif
return null
endfunction
function ShowGuest takes GuestEx ex returns nothing
local Guest guest
if ex.guest != null then
set guest = GetGuestUnitId(ex.guest)
if IsUnitHidden(guest.u) then
call ShowUnit(guest.u, true)
if GetUnitAbilityLevel(guest.u, 'Aloc') > 0 then
call UnitRemoveAbility(guest.u, 'Aloc')
call UnitAddAbility(guest.u, 'Aloc')
endif
endif
else
set guest = GetGuestEffectId(ex.fx)
endif
set guest.isHidden = false
endfunction
private function ShowGuestEx takes Guest guest returns nothing
set guest.isHidden = false
if guest.u != null then
if IsUnitHidden(guest.u) then
call ShowUnit(guest.u, true)
if GetUnitAbilityLevel(guest.u, 'Aloc') > 0 then
call UnitRemoveAbility(guest.u, 'Aloc')
call UnitAddAbility(guest.u, 'Aloc')
endif
endif
endif
endfunction
function ShowGuestsEx takes unit h, boolean flag returns nothing
local Host host = GetPrivateHostUnitId(h)
local Guest guest
local AOListItem node = host.guestList.first
loop
exitwhen node == 0
set guest = node.data
if flag then
call ShowGuestEx(guest)
else
call ShowUnit(guest.u, false)
call BlzSetSpecialEffectZ(guest.fx, -1000.)
set guest.isHidden = true
endif
set node = node.next
endloop
endfunction
function ShowGuests takes unit h returns nothing
call ShowGuestsEx(h, true)
endfunction
function HideGuests takes unit h returns nothing
call ShowGuestsEx(h, false)
endfunction
//Core function to dettach guests from hosts
private function DettachObject takes Guest guest, boolean resetHeight, real time returns nothing
local Host host
static if LIBRARY_RiseAndFall then
local real hc // height current
local real hd // height default
local integer moveType
local real duration
endif
if guest.turretTrigger != null then
call FlushChildHashtable(TurretStorage, GetHandleId(guest.turretTrigger))
call DestroyTrigger(guest.turretTrigger)
set guest.turretTrigger = null
endif
if guest.parent != null then
set host = GetPrivateHostUnitId(guest.parent)
call host.guestList.removeElem(guest)
if guest.u != null then
if UnitAlive(guest.u) and time > 0. then
call UnitApplyTimedLife(guest.u , 'BTLF', time)
endif
static if RESET_HEIGHT then
if resetHeight then
static if LIBRARY_RiseAndFall then
set hc = GetUnitFlyHeight(guest.u)
set hd = GetUnitDefaultFlyHeight(guest.u)
set moveType = BlzGetUnitMovementType(guest.u)
set duration = (hc - hd) / FALL_SPEED
if duration < 0. then
set duration = -duration
endif
call RiseAndFall.create(guest.u, hc, hd, duration, (moveType == 8 or moveType == 2))
else
call SetUnitFlyHeight(guest.u, GetUnitDefaultFlyHeight(guest.u), FALL_SPEED)
endif
endif
endif
endif
if guest.fx != null and time > 0. then
call EffectTimed.start(guest.fx, time)
endif
call SetUnitPropWindow(guest.u, GetUnitDefaultPropWindow(guest.u) * bj_DEGTORAD)
call UnitRemoveAbility(guest.u, 'Aeth')
call SetUnitPathing(guest.u, true)
if host.guestList.empty() then
call host.destroy()
endif
endif
call guest.destroy()
endfunction
private function DettachAllObjects takes Host host, boolean resetHeight, real time returns nothing
local Guest guest
local AOListItem node = host.guestList.first
local AOListItem nodeNext
loop
exitwhen node == 0
set nodeNext = node.next
set guest = node.data
call DettachObject(guest, resetHeight, time)
set node = nodeNext
endloop
endfunction
function DettachEffect takes effect fx, boolean resetHeight, real time returns nothing
call DettachObject(GetPrivateGuestEffectId(fx), resetHeight, time)
endfunction
function DettachUnit takes unit g, boolean resetHeight, real time returns nothing
call DettachObject(GetPrivateGuestUnitId(g), resetHeight, time)
endfunction
function DettachAllGuests takes unit h, boolean resetHeight, real time returns nothing
call DettachAllObjects(GetPrivateHostUnitId(h), resetHeight, time)
endfunction
private function TurretActions takes nothing returns nothing
local Guest guest = LoadInteger(TurretStorage, GetHandleId(GetTriggeringTrigger()), 0)
set guest.cooldown = guest.cooldownReset
if GetUnitCurrentOrder(guest.u) != ORDER_ATTACK then
call IssuePointOrderById(guest.u, ORDER_ATTACK, GetUnitX(guest.u), GetUnitY(guest.u))
endif
endfunction
private function UpdateGuests takes nothing returns nothing
local real x
local real y
local real z
local real t
local real f
local real a
local real xNew
local real yNew
local AOListItem node = GlobalListT.Hosts.first
local AOListItem nodeNext
local AOListItem nNode
local AOListItem nNodeNext
local Host host
local Guest guest
// This loop cycles through all the Hosts and a secondary loop inside cycles through their
// attached Guests, updating their x, y and z coordiates.
loop
exitwhen node == 0
set nodeNext = node.next
set host = node.data
set x = GetUnitX(host.u)
set y = GetUnitY(host.u)
set z = GetUnitFlyHeight(host.u) // fly height
set t = BlzGetLocalUnitZ(host.u) // terrain height
set f = GetUnitFacing(host.u)
if not IsUnitHidden(host.u) then
// unhide guests if host was previously hidden
if host.hiddenState then
set host.hiddenState = false
call ShowGuestsEx(host.u, true)
endif
if x != host.x or y != host.y or z != host.z or t != host.t or f != host.f then
set nNode = host.guestList.first
loop
exitwhen nNode == 0
set nNodeNext = nNode.next
set guest = nNode.data
// required for manually hidden special effects
if not guest.isHidden then
if guest.staticAngle then
set a = 0.
else
set a = f * bj_DEGTORAD
endif
set xNew = guest.offsetFix + x + Cos(guest.angle + a) * guest.distance
set yNew = guest.offsetFix + y + Sin(guest.angle + a) * guest.distance
if guest.u != null then
call SetUnitX(guest.u, xNew)
call SetUnitY(guest.u, yNew)
if z != host.z then
call SetUnitFlyHeight(guest.u, z + guest.zOffset, 0.)
endif
endif
if guest.fx != null then
call BlzSetSpecialEffectPosition(guest.fx, xNew, yNew, t + z + guest.zOffset)
endif
endif
set nNode = nNodeNext
endloop
set host.x = x
set host.y = y
set host.z = z
set host.t = t
set host.f = f * bj_RADTODEG
endif
else
// hide guests if host was not previously hidden
if not host.hiddenState then
set host.hiddenState = true
call ShowGuestsEx(host.u, false)
endif
endif
set node = nodeNext
endloop
set node = GlobalListT.Guests.first
// Updates the facing angle of Guests that rotate when idle and when not to turn (eg when in combat).
loop
exitwhen node == 0
set nodeNext = node.next
set guest = node.data
if guest.u != null and not UnitAlive(guest.u) then
call DettachObject(guest, true, 0.)
else
if guest.updateFacing and not guest.isHidden then
if guest.dynamicFacing then
set f = GetUnitFacing(guest.parent)
else
set f = 0.
endif
set guest.facing = guest.facing + guest.angleRate
if guest.u == null then
call BlzSetSpecialEffectYaw(guest.fx, guest.facing + f * bj_DEGTORAD)
else
if GetUnitCurrentOrder(guest.u) != 0 then
if guest.cooldown > 0. then
set guest.cooldown = guest.cooldown - TIMEOUT
else
set guest.cooldown = guest.cooldownReset
call IssueImmediateOrderById(guest.u, 851973) //order stunned
call SetUnitFacing(guest.u, guest.idleAngle + f)
endif
if guest.angleRate != 0. then
// Store the facing of the unit if it needs to rotate later
set guest.facing = GetUnitFacing(guest.u)
endif
else
call SetUnitFacing(guest.u, guest.facing + f)
endif
endif
endif
endif
set node = nodeNext
endloop
endfunction
private function SetFacingProperties takes Guest guest, real startAngle, real rate, real cooldown, boolean dynamicFacing, boolean turretMode returns nothing
if guest != 0 then
set guest.cooldownReset = cooldown
set guest.cooldown = cooldown
set guest.updateFacing = true
set guest.angleRate = rate * TIMEOUT
set guest.dynamicFacing = dynamicFacing
if guest.u == null then
set guest.facing = startAngle * bj_DEGTORAD
set guest.idleAngle = guest.facing
set guest.angleRate = guest.angleRate * bj_DEGTORAD
call BlzSetSpecialEffectYaw(guest.fx, guest.facing)
else
set guest.facing = startAngle
set guest.idleAngle = startAngle
call SetUnitFacing(guest.u, guest.facing)
endif
if turretMode and guest.u != null then
set guest.turretTrigger = CreateTrigger()
call TriggerRegisterUnitEvent(guest.turretTrigger, guest.u, EVENT_UNIT_ACQUIRED_TARGET)
call TriggerRegisterUnitEvent(guest.turretTrigger, guest.u, EVENT_UNIT_TARGET_IN_RANGE)
call SaveInteger(TurretStorage, GetHandleId(guest.turretTrigger), 0, guest)
call TriggerAddCondition(guest.turretTrigger, Condition(function TurretActions))
endif
endif
endfunction
function SetEffectFacingProperties takes effect fx, real startAngle, real rate, boolean dynamicFacing returns nothing
call SetFacingProperties(GetPrivateGuestEffectId(fx), startAngle, rate, 0., dynamicFacing, false)
endfunction
function SetUnitFacingProperties takes unit g, real startAngle, real rate, real cooldown, boolean dynamicFacing, boolean turretMode returns nothing
call SetFacingProperties(GetPrivateGuestUnitId(g), startAngle, rate, cooldown, dynamicFacing, turretMode)
endfunction
private function AttachObject takes unit g, effect fx, unit h, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle returns GuestEx
local Host host = GetPrivateHostUnitId(h)
local Guest guest
local AOListItem node = GlobalListT.Hosts.first
local real x = GetUnitX(h)
local real y = GetUnitY(h)
local real z = GetUnitFlyHeight(h)
local real t = BlzGetLocalUnitZ(h)
local real f = GetUnitFacing(h)
local real a
local real xNew
local real yNew
if g == null then
set guest = GetPrivateGuestUnitId(g)
else
set guest = GetPrivateGuestEffectId(fx)
endif
// if there is no host or not effect and guest unit, end the function
if h == null or (g == null and fx == null) then
return 0
endif
// if guest instance is not null then it's already attached to a unit
if guest != 0 then
if guest.parent == h then
return 0
else
call DettachObject(guest, false, 0.)
endif
endif
// check if the Host has an instance
if host == 0 then
set host = Host.create(h)
set host.x = x
set host.y = y
set host.z = z
set host.t = t
set host.f = f
endif
set guest = Guest.create(g, fx, h)
call host.addGuest(guest)
set guest.angle = angle * bj_DEGTORAD
set guest.staticAngle = staticAngle
set guest.distance = distance
set guest.zOffset = zOffset
set guest.offsetFix = offsetFix
// if angle is static then ignore the Host's facing angle.
if staticAngle then
set a = guest.angle
else
set a = guest.angle + f * bj_DEGTORAD
endif
set xNew = offsetFix + x + Cos(a) * distance
set yNew = offsetFix + y + Sin(a) * distance
if g == null then
set guest.facing = f * bj_DEGTORAD
call BlzSetSpecialEffectPosition(fx, xNew, yNew, t + z + zOffset)
call BlzSetSpecialEffectYaw(fx, guest.facing)
else
set guest.facing = f
call SetUnitX(g, xNew)
call SetUnitY(g, yNew)
call SetUnitFlyHeight(g, z + zOffset, 0.)
call SetUnitFacing(g, guest.facing)
call SetUnitPropWindow(g, 0.)
call UnitAddAbility(g, 'Aeth')
call SetUnitPathing(g, false)
endif
if GlobalListT.Hosts.size() == 1 then
call TimerStart(Clock, TIMEOUT, true, function UpdateGuests)
endif
return guest.ex
endfunction
function AttachEffectToHost takes effect fx, unit h, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle returns Guest
return AttachObject(null, fx, h, angle, distance, zOffset, offsetFix, staticAngle)
endfunction
function AttachUnitToHost takes unit g, unit h, real angle, real distance, real zOffset, real offsetFix, boolean staticAngle returns Guest
return AttachObject(g, null, h, angle, distance, zOffset, offsetFix, staticAngle)
endfunction
// Initialisation - the module, the module's method and the struct must all be private. The method must be static.
private module init
private static method onInit takes nothing returns nothing
set GlobalListT.Guests = AOList.create()
set GlobalListT.Hosts = AOList.create()
set EffectTimed.fxList = AOList.create()
endmethod
endmodule
private struct Init
implement init
endstruct
endlibrary
/*****************************************************************************
*
* List<T> v2.1.2.3
* by Bannar
*
* Doubly-linked list.
*
******************************************************************************
*
* Requirements:
*
* Table by Bribe
* hiveworkshop.com/threads/snippet-new-table.188084/
*
* Alloc - choose whatever you like
* e.g.: by Sevion hiveworkshop.com/threads/snippet-alloc.192348/
*
******************************************************************************
*
* Implementation:
*
* macro DEFINE_LIST takes ACCESS, NAME, TYPE
*
* macro DEFINE_STRUCT_LIST takes ACCESS, NAME, TYPE
*
* ACCESS - encapsulation, choose restriction access
* NAME - name of list type
* TYPE - type of values stored
*
* Implementation notes:
*
* - DEFINE_STRUCT_LIST macro purpose is to provide natural typecasting syntax for struct types.
* - <NAME>Item structs inline directly into hashtable operations thus generate basically no code.
* - Lists defined with DEFINE_STRUCT_LIST are inlined nicely into single create method and single integer array.
*
******************************************************************************
*
* struct API:
*
* struct <NAME>Item:
*
* | <TYPE> data
* | <NAME>Item next
* | <NAME>Item prev
*
*
* General:
*
* | static method create takes nothing returns thistype
* | Default ctor.
* |
* | static method operator [] takes thistype other returns thistype
* | Copy ctor.
* |
* | method destroy takes nothing returns nothing
* | Default dctor.
* |
* | method empty takes nothing returns boolean
* | Checks whether the list is empty.
* |
* | method size takes nothing returns integer
* | Returns size of a list.
*
*
* Access:
*
* | readonly <NAME>Item first
* | readonly <NAME>Item last
* |
* | method front takes nothing returns $TYPE$
* | Retrieves first element.
* |
* | method back takes nothing returns $TYPE$
* | Retrieves last element.
*
*
* Modifiers:
*
* | method clear takes nothing returns nothing
* | Flushes list and recycles its nodes.
* |
* | method push takes $TYPE$ value returns thistype
* | Adds elements to the end.
* |
* | method unshift takes $TYPE$ value returns thistype
* | Adds elements to the front.
* |
* | method pop takes nothing returns thistype
* | Removes the last element.
* |
* | method shift takes nothing returns thistype
* | Removes the first element.
* |
* | method find takes $TYPE$ value returns $NAME$Item
* | Returns the first node which data equals value.
* |
* | method erase takes $NAME$Item node returns boolean
* | Removes node from the list, returns true on success.
* |
* | method removeElem takes $TYPE$ value returns thistype
* | Removes first element that equals value from the list.
*
*
*****************************************************************************/
library ListT requires Table, Alloc
//! runtextmacro DEFINE_LIST("", "IntegerList", "integer")
// Run here any global list types you want to be defined.
//! textmacro_once DEFINE_LIST takes ACCESS, NAME, TYPE
$ACCESS$ struct $NAME$Item extends array
// No default ctor and dctor due to limited array size
method operator data takes nothing returns $TYPE$
return Table(this).$TYPE$[-1] // hashtable[ node, -1 ] = data
endmethod
method operator data= takes $TYPE$ value returns nothing
set Table(this).$TYPE$[-1] = value
endmethod
method operator next takes nothing returns thistype
return Table(this)[-2] // hashtable[ node, -2 ] = next
endmethod
method operator next= takes thistype value returns nothing
set Table(this)[-2] = value
endmethod
method operator prev takes nothing returns thistype
return Table(this)[-3] // hashtable[ node, -3 ] = prev
endmethod
method operator prev= takes thistype value returns nothing
set Table(this)[-3] = value
endmethod
endstruct
$ACCESS$ struct $NAME$ extends array
readonly $NAME$Item first
readonly $NAME$Item last
private integer count
implement Alloc
private static method setNodeOwner takes $NAME$Item node, $NAME$ owner returns nothing
set Table(node)[-4] = owner
endmethod
private static method getNodeOwner takes $NAME$Item node returns thistype
return Table(node)[-4]
endmethod
private method createNode takes $TYPE$ value returns $NAME$Item
local $NAME$Item node = Table.create()
set node.data = value
call setNodeOwner(node, this) // ownership
return node
endmethod
private method deleteNode takes $NAME$Item node returns nothing
call Table(node).destroy() // also removes ownership
endmethod
static method create takes nothing returns thistype
local thistype this = allocate()
set count = 0
return this
endmethod
method clear takes nothing returns nothing
local $NAME$Item node = first
local $NAME$Item temp
loop // recycle all Table indexes
exitwhen 0 == node
set temp = node.next
call deleteNode(node)
set node = temp
endloop
set first = 0
set last = 0
set count = 0
endmethod
method destroy takes nothing returns nothing
call clear()
call deallocate()
endmethod
method front takes nothing returns $TYPE$
return first.data
endmethod
method back takes nothing returns $TYPE$
return last.data
endmethod
method empty takes nothing returns boolean
return count == 0
endmethod
method size takes nothing returns integer
return count
endmethod
method push takes $TYPE$ value returns thistype
local $NAME$Item node = createNode(value)
if not empty() then
set last.next = node
set node.prev = last
else
set first = node
set node.prev = 0
endif
set last = node
set node.next = 0
set count = count + 1
return this
endmethod
method unshift takes $TYPE$ value returns thistype
local $NAME$Item node = createNode(value)
if not empty() then
set first.prev = node
set node.next = first
else
set last = node
set node.next = 0
endif
set first = node
set node.prev = 0
set count = count + 1
return this
endmethod
method pop takes nothing returns thistype
local $NAME$Item node
if not empty() then
set node = last
set last = last.prev
if last == 0 then
set first = 0
else
set last.next = 0
endif
call deleteNode(node)
set count = count - 1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"$NAME$::pop failed for instance "+I2S(this)+". List is empty.")
endif
return this
endmethod
method shift takes nothing returns thistype
local $NAME$Item node
if not empty() then
set node = first
set first = first.next
if first == 0 then
set last = 0
else
set first.prev = 0
endif
call deleteNode(node)
set count = count - 1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"$NAME$::shift failed for instance "+I2S(this)+". List is empty.")
endif
return this
endmethod
static method operator [] takes thistype other returns thistype
local thistype instance = create()
local $NAME$Item node = other.first
loop
exitwhen node == 0
call instance.push(node.data)
set node = node.next
endloop
return instance
endmethod
method find takes $TYPE$ value returns $NAME$Item
local $NAME$Item node = first
loop
exitwhen node == 0 or node.data == value
set node = node.next
endloop
return node
endmethod
method erase takes $NAME$Item node returns boolean
if getNodeOwner(node) == this then // match ownership
if node == first then
call shift()
elseif node == last then
call pop()
else
set node.prev.next = node.next
set node.next.prev = node.prev
call deleteNode(node)
set count = count - 1
endif
return true
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"$NAME$::erase failed for instance "+I2S(this)+". Attempted to remove invalid node "+I2S(node)+".")
endif
return false
endmethod
method remove takes $NAME$Item node returns boolean
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"Method $NAME$::remove is obsolete, use $NAME$::erase instead.")
return erase(node)
endmethod
method removeElem takes $TYPE$ value returns thistype
local $NAME$Item node = find(value)
if node != 0 then
call erase(node)
endif
return this
endmethod
endstruct
//! endtextmacro
//! textmacro_once DEFINE_STRUCT_LIST takes ACCESS, NAME, TYPE
$ACCESS$ struct $NAME$Item extends array
// Cannot inherit methods via delegate due to limited array size
method operator data takes nothing returns $TYPE$
return IntegerListItem(this).data
endmethod
method operator data= takes $TYPE$ value returns nothing
set IntegerListItem(this).data = value
endmethod
method operator next takes nothing returns thistype
return IntegerListItem(this).next
endmethod
method operator next= takes thistype value returns nothing
set IntegerListItem(this).next = value
endmethod
method operator prev takes nothing returns thistype
return IntegerListItem(this).prev
endmethod
method operator prev= takes thistype value returns nothing
set IntegerListItem(this).prev = value
endmethod
endstruct
$ACCESS$ struct $NAME$ extends array
private delegate IntegerList parent
static method create takes nothing returns thistype
local thistype this = IntegerList.create()
set parent = this
return this
endmethod
method front takes nothing returns $TYPE$
return parent.front()
endmethod
method back takes nothing returns $TYPE$
return parent.back()
endmethod
endstruct
//! endtextmacro
endlibrary
library Alloc /* v1.3.1.1
*************************************************************************************
*
* */ uses /*
*
* */ optional ErrorMessage /* github.com/nestharus/JASS/tree/master/jass/Systems/ErrorMessage
* */ optional MemoryAnalysis /*
*
*************************************************************************************
*
* Minimizes code generation and global variables while maintaining
* excellent performance.
*
* local thistype this = recycler[0]
*
* if (recycler[this] == 0) then
* set recycler[0] = this + 1
* else
* set recycler[0] = recycler[this]
* endif
*
************************************************************************************
*
* module Alloc
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
* The Following Require Error Message To Be In The Map
* --------------------------------------------------------
*
* debug readonly boolean allocated
*
* The Following Require Memory Analysis To Be In The Map
* --------------------------------------------------------
*
* debug readonly integer monitorCount
* - the amount of global memory being monitored by this
* debug readonly integer monitorString
* - gets a string representation of all global memory being monitored by this
* debug readonly integer address
* - global memory address for debugging
* - used with monitor and stopMonitor
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
* debug method monitor takes string label, integer address returns nothing
* - monitor a global memory address with a label
* - used to identify memory leaks
* - should be memory that ought to be destroyed by the time this is destroyed
* debug method stopMonitor takes integer address returns nothing
* - stops monitoring global memory
* debug method stopMonitorValue takes handle monitoredHandle returns nothing
* - stops monitoring handle values
*
* The Following Are Used To Monitor Handle Values
*
* debug method monitor_widget takes string label, widget handleToTrack returns nothing
* debug method monitor_destructable takes string label, destructable handleToTrack returns nothing
* debug method monitor_item takes string label, item handleToTrack returns nothing
* debug method monitor_unit takes string label, unit handleToTrack returns nothing
* debug method monitor_timer takes string label, timer handleToTrack returns nothing
* debug method monitor_trigger takes string label, trigger handleToTrack returns nothing
* debug method monitor_triggercondition takes string label, triggercondition handleToTrack returns nothing
* debug method monitor_triggeraction takes string label, triggeraction handleToTrack returns nothing
* debug method monitor_force takes string label, force handleToTrack returns nothing
* debug method monitor_group takes string label, group handleToTrack returns nothing
* debug method monitor_location takes string label, location handleToTrack returns nothing
* debug method monitor_rect takes string label, rect handleToTrack returns nothing
* debug method monitor_boolexpr takes string label, boolexpr handleToTrack returns nothing
* debug method monitor_effect takes string label, effect handleToTrack returns nothing
* debug method monitor_unitpool takes string label, unitpool handleToTrack returns nothing
* debug method monitor_itempool takes string label, itempool handleToTrack returns nothing
* debug method monitor_quest takes string label, quest handleToTrack returns nothing
* debug method monitor_defeatcondition takes string label, defeatcondition handleToTrack returns nothing
* debug method monitor_timerdialog takes string label, timerdialog handleToTrack returns nothing
* debug method monitor_leaderboard takes string label, leaderboard handleToTrack returns nothing
* debug method monitor_multiboard takes string label, multiboard handleToTrack returns nothing
* debug method monitor_multiboarditem takes string label, multiboarditem handleToTrack returns nothing
* debug method monitor_dialog takes string label, dialog handleToTrack returns nothing
* debug method monitor_button takes string label, button handleToTrack returns nothing
* debug method monitor_texttag takes string label, texttag handleToTrack returns nothing
* debug method monitor_lightning takes string label, lightning handleToTrack returns nothing
* debug method monitor_image takes string label, image handleToTrack returns nothing
* debug method monitor_ubersplat takes string label, ubersplat handleToTrack returns nothing
* debug method monitor_region takes string label, region handleToTrack returns nothing
* debug method monitor_fogmodifier takes string label, fogmodifier handleToTrack returns nothing
* debug method monitor_hashtable takes string label, hashtable handleToTrack returns nothing
*
*
* Thanks to Ruke for the algorithm
************************************************************************************/
module Alloc
/*
* stack
*/
private static integer array recycler
static if LIBRARY_MemoryAnalysis then
debug private MemoryMonitor globalAddress
debug method operator address takes nothing returns integer
debug call ThrowError(recycler[this] != -1, "Alloc", "address", "thistype", this, "Attempted To Access Null Instance.")
debug return globalAddress
debug endmethod
endif
/*
* allocation
*/
static method allocate takes nothing returns thistype
local thistype this = recycler[0]
static if LIBRARY_ErrorMessage then
debug call ThrowError(this == 8192, "Alloc", "allocate", "thistype", 0, "Overflow.")
endif
if (recycler[this] == 0) then
set recycler[0] = this + 1
else
set recycler[0] = recycler[this]
endif
static if LIBRARY_ErrorMessage then
debug set recycler[this] = -1
endif
static if LIBRARY_MemoryAnalysis then
debug set globalAddress = MemoryMonitor.allocate("thistype")
endif
return this
endmethod
method deallocate takes nothing returns nothing
static if LIBRARY_ErrorMessage then
debug call ThrowError(recycler[this] != -1, "Alloc", "deallocate", "thistype", this, "Attempted To Deallocate Null Instance.")
endif
static if LIBRARY_MemoryAnalysis then
debug call globalAddress.deallocate()
debug set globalAddress = 0
endif
set recycler[this] = recycler[0]
set recycler[0] = this
endmethod
static if LIBRARY_MemoryAnalysis then
debug method monitor takes string label, integer address returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor(label, address)
debug endmethod
debug method stopMonitor takes integer address returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "stopMonitor", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.stopMonitor(address)
debug endmethod
debug method stopMonitorValue takes handle monitoredHandle returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "stopMonitorValue", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.stopMonitorValue(monitoredHandle)
debug endmethod
debug method operator monitorCount takes nothing returns integer
debug call ThrowError(recycler[this] != -1, "Alloc", "monitorCount", "thistype", this, "Attempted To Access Null Instance.")
debug return globalAddress.monitorCount
debug endmethod
debug method operator monitorString takes nothing returns string
debug call ThrowError(recycler[this] != -1, "Alloc", "monitorString", "thistype", this, "Attempted To Access Null Instance.")
debug return globalAddress.monitorString
debug endmethod
debug method monitor_widget takes string label, widget handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_widget", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_widget(label, handleToTrack)
debug endmethod
debug method monitor_destructable takes string label, destructable handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_destructable", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_destructable(label, handleToTrack)
debug endmethod
debug method monitor_item takes string label, item handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_item", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_item(label, handleToTrack)
debug endmethod
debug method monitor_unit takes string label, unit handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_unit", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_unit(label, handleToTrack)
debug endmethod
debug method monitor_timer takes string label, timer handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_timer", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_timer(label, handleToTrack)
debug endmethod
debug method monitor_trigger takes string label, trigger handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_trigger", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_trigger(label, handleToTrack)
debug endmethod
debug method monitor_triggercondition takes string label, triggercondition handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_triggercondition", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_triggercondition(label, handleToTrack)
debug endmethod
debug method monitor_triggeraction takes string label, triggeraction handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_triggeraction", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_triggeraction(label, handleToTrack)
debug endmethod
debug method monitor_force takes string label, force handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_force", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_force(label, handleToTrack)
debug endmethod
debug method monitor_group takes string label, group handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_group", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_group(label, handleToTrack)
debug endmethod
debug method monitor_location takes string label, location handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_location", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_location(label, handleToTrack)
debug endmethod
debug method monitor_rect takes string label, rect handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_rect", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_rect(label, handleToTrack)
debug endmethod
debug method monitor_boolexpr takes string label, boolexpr handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_boolexpr", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_boolexpr(label, handleToTrack)
debug endmethod
debug method monitor_effect takes string label, effect handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_effect", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_effect(label, handleToTrack)
debug endmethod
debug method monitor_unitpool takes string label, unitpool handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_unitpool", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_unitpool(label, handleToTrack)
debug endmethod
debug method monitor_itempool takes string label, itempool handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_itempool", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_itempool(label, handleToTrack)
debug endmethod
debug method monitor_quest takes string label, quest handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_quest", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_quest(label, handleToTrack)
debug endmethod
debug method monitor_defeatcondition takes string label, defeatcondition handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_defeatcondition", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_defeatcondition(label, handleToTrack)
debug endmethod
debug method monitor_timerdialog takes string label, timerdialog handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_timerdialog", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_timerdialog(label, handleToTrack)
debug endmethod
debug method monitor_leaderboard takes string label, leaderboard handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_leaderboard", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_leaderboard(label, handleToTrack)
debug endmethod
debug method monitor_multiboard takes string label, multiboard handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_multiboard", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_multiboard(label, handleToTrack)
debug endmethod
debug method monitor_multiboarditem takes string label, multiboarditem handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_multiboarditem", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_multiboarditem(label, handleToTrack)
debug endmethod
debug method monitor_dialog takes string label, dialog handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_dialog", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_dialog(label, handleToTrack)
debug endmethod
debug method monitor_button takes string label, button handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_button", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_button(label, handleToTrack)
debug endmethod
debug method monitor_texttag takes string label, texttag handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_texttag", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_texttag(label, handleToTrack)
debug endmethod
debug method monitor_lightning takes string label, lightning handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_lightning", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_lightning(label, handleToTrack)
debug endmethod
debug method monitor_image takes string label, image handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_image", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_image(label, handleToTrack)
debug endmethod
debug method monitor_ubersplat takes string label, ubersplat handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_ubersplat", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_ubersplat(label, handleToTrack)
debug endmethod
debug method monitor_region takes string label, region handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_region", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_region(label, handleToTrack)
debug endmethod
debug method monitor_fogmodifier takes string label, fogmodifier handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_fogmodifier", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_fogmodifier(label, handleToTrack)
debug endmethod
debug method monitor_hashtable takes string label, hashtable handleToTrack returns nothing
debug call ThrowError(recycler[this] != -1, "Alloc", "monitor_hashtable", "thistype", this, "Attempted To Access Null Instance.")
debug call globalAddress.monitor_hashtable(label, handleToTrack)
debug endmethod
static if DEBUG_MODE then
//! runtextmacro optional MEMORY_ANALYSIS_STATIC_FIELD_NEW("recycler")
static method calculateMemoryUsage takes nothing returns integer
return calculateAllocatedMemory__recycler()
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
return allocatedMemoryString__recycler()
endmethod
endif
endif
/*
* analysis
*/
static if LIBRARY_ErrorMessage then
debug method operator allocated takes nothing returns boolean
debug return recycler[this] == -1
debug endmethod
endif
/*
* initialization
*/
private static method onInit takes nothing returns nothing
set recycler[0] = 1
endmethod
endmodule
endlibrary
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 4.1.0.1.
One map, one hashtable. Welcome to NewTable 4.1.0.1
This newest iteration of Table introduces the new HashTable struct.
You can now instantiate HashTables which enables the use of large
parent and large child keys, just like a standard hashtable. Previously,
the user would have to instantiate a Table to do this on their own which -
while doable - is something the user should not have to do if I can add it
to this resource myself (especially if they are inexperienced).
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key) //return this.integer[key]
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb) //set this.integer[key] = tb
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key) //return this.integer.has(key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key) //call this.integer.remove(key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
//NEW: Added in Table 4.0. A fairly simple struct but allows you to do more
//than that which was previously possible.
struct HashTable extends array
//Enables myHash[parentKey][childKey] syntax.
//Basically, it creates a Table in the place of the parent key if
//it didn't already get created earlier.
method operator [] takes integer index returns Table
local Table t = Table(this)[index]
if t == 0 then
set t = Table.create()
set Table(this)[index] = t //whoops! Forgot that line. I'm out of practice!
endif
return t
endmethod
//You need to call this on each parent key that you used if you
//intend to destroy the HashTable or simply no longer need that key.
method remove takes integer index returns nothing
local Table t = Table(this)[index]
if t != 0 then
call t.destroy()
call Table(this).remove(index)
endif
endmethod
//Added in version 4.1
method has takes integer index returns boolean
return Table(this).has(index)
endmethod
//HashTables are just fancy Table indices.
method destroy takes nothing returns nothing
call Table(this).destroy()
endmethod
//Like I said above...
static method create takes nothing returns thistype
return Table.create()
endmethod
endstruct
endlibrary
library RiseAndFall requires ListT optional UnitDex
/*
RiseAndFall v1.05
by Spellbound
Special thanks to Wareditor for the math and re-organising my code and got rid of a lot of
needless lines and methods.
This simple library can be used to simulate an airborne effect by causing units to bob up and
down. It can also be used to make a unit fall from a certain height or rise in the air. The
purpose of this library is to be used with AttachObject, but one could always find some other
use for it.
_________________________________________________________________________
REQUIREMENTS
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Required:
ListT: https://www.hiveworkshop.com/threads/containers-list-t.249011/
Optional
UnitDex: https://www.hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/
UnitDex will replace hashtables for retrieving airbone instances. Highly recommended so
as to avoid the hashtable limit.
PS if you want units with non-hover or non-flying movement type to be able to levitate, you
need to give them and then immediately remove Crow Form from the. Alternatively, just get an
Autofly library and make your life easier. One is available in the test map. Requires UnitDex.
_________________________________________________________________________
API
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
operator:
RiseAndFall[yourUnit] will return the RiseAndFall instance of a unit.
static methods:
RiseAndFall.create(unit u, real currentZ, real endZ, real duration, boolean flag)
^ This will cause a unit to changed its height from currentZ to endZ over duration.
If the flag is true, the unit will decelerate as they reach destination height. This
can be useful for units that fly or hover.
This function returns the struct instance if you wish to store it.
RiseAndFall.createAirborne(unit u, real currentZ, real endZ, real duration)
^ This will make your unit appear to levitate between currentZ and endZ over duration.
Set a narrow distance for a more realistic effect.
This function returns the struct instance if you wish to store it.
RiseAndFall.isUnitAirborne(unit u)
^ This returns true if a unit is airborne/falling/rising.
non-static methods:
RiseAndFall.end(real endZ, real speed)
^ Ends the Rise/Fall/Airborne of a unit. real endZ determines the height at which you
want the unit to end at and speed determines how fast in gets there. use Warcraft 3
missile speed for referrence.
Set to the current height of the unit to terminate immediately.
*/
globals
private constant real INTERVAL = .03125
endglobals
private module Init
private static method onInit takes nothing returns nothing
static if not LIBRARY_UnitDex then
set instance_storage = InitHashtable()
endif
set list = IntegerList.create()
endmethod
endmodule
struct RiseAndFall
private unit u
private real heightStart
private real heightEnd
private real speed
private real progress
private boolean useSmoothstep
private boolean isAirborne
private static IntegerList list
private static timer clock = CreateTimer()
static if LIBRARY_UnitDex then
private static integer array instance
else
private static hashtable instance_storage
endif
static method operator [] takes unit u returns thistype
static if LIBRARY_UnitDex then
return instance[GetUnitId(u)]
else
return LoadInteger(instance_storage, GetHandleId(u), 0)
endif
endmethod
static method isUnitAirborne takes unit u returns boolean
static if LIBRARY_UnitDex then
return instance[GetUnitId(u)] != 0
else
return LoadInteger(instance_storage, GetHandleId(u), 0) != 0
endif
endmethod
method destroy takes nothing returns nothing
static if LIBRARY_UnitDex then
set instance[GetUnitId(u)] = 0
else
call FlushChildHashtable(instance_storage, GetHandleId(.u))
endif
set .u = null
call list.removeElem(this)
if list.size() == 0 then
call PauseTimer(clock)
endif
call .deallocate()
endmethod
private static method update takes nothing returns nothing
local thistype this
local IntegerListItem node = list.first
local IntegerListItem nodeNext
local real s
local real hs
loop
exitwhen node == 0
set nodeNext = node.next
set this = node.data
set .progress = .progress + .speed
if .progress >= 1.then
call SetUnitFlyHeight(.u, .heightEnd, 0.)
if .isAirborne then
set hs = .heightStart
set .heightStart = .heightEnd
set .heightEnd = hs
set .progress = 0.
else
call .destroy()
endif
else
set s = .progress
if .useSmoothstep then
call SetUnitFlyHeight(.u, .heightStart + ( .heightEnd - .heightStart ) * (s * s * s * (s * (s * 6 - 15) + 10)), 0.) //smoothstep
else
call SetUnitFlyHeight(.u, .heightStart + ( .heightEnd - .heightStart ) * (s * s), 0.)
endif
endif
set node = nodeNext
endloop
endmethod
method end takes real endZ, real spd returns nothing
local real height = GetUnitFlyHeight(.u)
if endZ != height then
set .heightStart = height
set .heightEnd = endZ
set .progress = 0.
set .isAirborne = false
set .useSmoothstep = false
if spd == 0. then // divide by zero prevention
set spd = 600.
endif
set .speed = INTERVAL / ((.heightStart - .heightEnd) / spd)
else
call .destroy()
endif
endmethod
private static method createEx takes unit u, real currentZ, real endZ, real duration, boolean smooth, boolean airborn returns thistype
local thistype this = RiseAndFall[u]
if this != 0 then
call this.end(GetUnitFlyHeight(u), 1.)
endif
set this = allocate()
set this.u = u
set this.heightStart = currentZ
set this.heightEnd = endZ
set this.progress = 0.
set this.speed = INTERVAL/duration
set this.useSmoothstep = smooth
set this.isAirborne = airborn
static if LIBRARY_UnitDex then
set instance[GetUnitId(u)] = this
else
call SaveInteger(instance_storage, GetHandleId(u), 0, this)
endif
call list.push(this)
if list.size() == 1 then
call TimerStart(clock, INTERVAL, true, function thistype.update)
endif
return this
endmethod
static method create takes unit u, real currentZ, real endZ, real duration, boolean smooth returns thistype
return createEx(u, currentZ, endZ, duration, smooth, false)
endmethod
static method createAirborne takes unit u, real currentZ, real endZ, real duration returns thistype
return createEx(u, currentZ, endZ, duration, true, true)
endmethod
implement Init
endstruct
endlibrary
scope Init initializer init
globals
constant real DIST = 128. * 4
constant real REVERSE_ANGLE = 180.
constant player PLAY = Player(0)
constant string ORB = "Abilities\\Weapons\\BloodElfMissile\\BloodElfMissile.mdl"
constant string SPEAR = "abilities\\weapons\\WyvernSpear\\WyvernSpearMissile.mdl"
constant string ARROW = "Abilities\\Spells\\Other\\BlackArrow\\BlackArrowMissile.mdl"
unit TestUnit
endglobals
private function Actions takes nothing returns nothing
local real x
local real y
local real a
local unit u
local unit array guest
local effect array fx
//Gryphon Rider
set a = 90. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'hgry', x, y, a * bj_RADTODEG + REVERSE_ANGLE)
/*
This is an example of guests that face the same way as the host. They are allowed to
attack and cast spells but will after 4 seconds of inaction return to face the same
angle as their host.
*/
set guest[0] = CreateUnit(PLAY, 'hsor', 0., 0., 0.)
set guest[1] = CreateUnit(PLAY, 'hsor', 0., 0., 0.)
set guest[2] = CreateUnit(PLAY, 'hsor', 0., 0., 0.)
call AttachUnitToHost(guest[0], u, 90., 96., 30., 0., false)
call AttachUnitToHost(guest[1], u, -90., 96., 30., 0., false)
call AttachUnitToHost(guest[2], u, 180., 96., 30., 0., false)
call SetUnitFacingProperties(guest[0], 0., 0., 4., true, true)
call SetUnitFacingProperties(guest[1], 0., 0., 4., true, true)
call SetUnitFacingProperties(guest[2], 0., 0., 4., true, true)
set TestUnit = u //Used in Filter Test
//Knight
/*
This is an example of a static-angle, static-facing host. Its turret properties enable
it to attack and cast spells, but afterwards it will return to face a 225° angle at 315°
of the knight's location. This guest ignores the Knight's facing direction.
*/
set a = 45. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'hkni', x, y, a * bj_RADTODEG + REVERSE_ANGLE)
set guest[0] = CreateUnit(PLAY, 'uban', 0., 0., 0.)
call AttachUnitToHost(guest[0], u, 315., 128., 120., 0., true)
call SetUnitFacingProperties(guest[0], 225., 0., 4., false, true)
//Witch Doctor
/*
These guests do not have any facing parameters set up and thus will not be subject to
any facing restrictions and will always face the their starting direction. Guests with
no facing parameters cannot attack.
*/
set a = 0. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'odoc', x, y, a * bj_RADTODEG + REVERSE_ANGLE)
set guest[0] = CreateUnit(PLAY, 'osp1', 0., 0., 180.)
set guest[1] = CreateUnit(PLAY, 'osp1', 0., 0., 180.)
call AttachUnitToHost(guest[0], u, 90., 32., 60., 0., false)
call AttachUnitToHost(guest[1], u, -90., 32., 60., 0., false)
//Mountain Giant
/*
This is the same as with the gryphon rider.
*/
set a = 135. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'emtg', x, y, a * bj_RADTODEG + REVERSE_ANGLE)
set guest[0] = CreateUnit(PLAY, 'earc', 0., 0., 0.)
set guest[1] = CreateUnit(PLAY, 'earc', 0., 0., 0.)
call AttachUnitToHost(guest[0], u, 80., 60., 180., -16., false)
call AttachUnitToHost(guest[1], u, -80., 60., 180., -16., false)
call SetUnitFacingProperties(guest[0], 0., 0., 4., true, true)
call SetUnitFacingProperties(guest[1], 0., 0., 4., true, true)
//Steam Tank
/*
This is an example of the rotating turret guest. This guest has been set to rotate with
the host's facing angle, but merely for demonstration purposes. It's recommend for the
dynamicFacing parameter to be set to false.
This guest can attack and cast spells, but after 4 seconds of inaction will resume its
rotation from its current facing angle.
*/
set a = 180. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'hmtt', x, y, a * bj_RADTODEG + REVERSE_ANGLE)
set guest[0] = CreateUnit(PLAY, 'hgyr', 0., 0., 0.)
call AttachUnitToHost(guest[0], u, 0., 0., 140., -16., false)
call SetUnitFacingProperties(guest[0], 360., 60., 4., true, true)
//Spell Breaker - Attached Effect Simple
set a = 270. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'hspt', x, y, 270.)
/*
This is a demonstration of attached effects.
*/
set guest[0] = CreateUnit(PLAY, 'efdr', 0., 0., 270.)
set fx[1] = AddSpecialEffect(ORB, 0., 0.)
set fx[2] = AddSpecialEffect(ORB, 0., 0.)
set fx[3] = AddSpecialEffect(ORB, 0., 0.)
set fx[4] = AddSpecialEffect(ORB, 0., 0.)
set fx[5] = AddSpecialEffect(ORB, 0., 0.)
call AttachUnitToHost(guest[0], u, 0., 0., 300., -16., false)
call AttachEffectToHost(fx[1], u, 90., 65., 75., -16., false)
call AttachEffectToHost(fx[2], u, 90., 50., 145., -16., false)
call AttachEffectToHost(fx[3], u, -90., 65., 75., -16., false)
call AttachEffectToHost(fx[4], u, -90., 50., 145., -16., false)
call AttachEffectToHost(fx[5], u, 0., 0., 180., -16., false)
call SetUnitFacingProperties(guest[0], 0., 0., 4., true, true)
//Faerie Dragon - Attached Effect with Facing
set a = 225. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'efdr', x, y, 225.)
/*
This is a demonstration of attached effects.
*/
set fx[1] = AddSpecialEffect(ARROW, 0., 0.)
set fx[2] = AddSpecialEffect(ARROW, 0., 0.)
set fx[3] = AddSpecialEffect(ARROW, 0., 0.)
set fx[4] = AddSpecialEffect(ARROW, 0., 0.)
set fx[5] = AddSpecialEffect(ARROW, 0., 0.)
call AttachEffectToHost(fx[1], u, 90., 65., 75., -16., false)
call AttachEffectToHost(fx[2], u, 90., 50., 145., -16., false)
call AttachEffectToHost(fx[3], u, -90., 65., 75., -16., false)
call AttachEffectToHost(fx[4], u, -90., 50., 145., -16., false)
call AttachEffectToHost(fx[5], u, 0., 0., 180., -16., false)
call SetEffectFacingProperties(fx[1], 0., 0., true)
call SetEffectFacingProperties(fx[2], 0., 0., true)
call SetEffectFacingProperties(fx[3], 0., 0., true)
call SetEffectFacingProperties(fx[4], 0., 0., true)
call SetEffectFacingProperties(fx[5], 0., 0., true)
//Spell Breaker - Attached Effect static angles with dynamic facing
set a = 315. * bj_DEGTORAD
set x = Cos(a) * DIST
set y = Sin(a) * DIST
set u = CreateUnit(PLAY, 'hspt', x, y, 315.)
/*
This is a demonstration of attached effects that spin.
*/
set fx[1] = AddSpecialEffect(SPEAR, 0., 0.)
set fx[2] = AddSpecialEffect(SPEAR, 0., 0.)
set fx[3] = AddSpecialEffect(SPEAR, 0., 0.)
set fx[4] = AddSpecialEffect(SPEAR, 0., 0.)
set fx[5] = AddSpecialEffect(SPEAR, 0., 0.)
call AttachEffectToHost(fx[1], u, 30., 65., 75., -16., true)
call AttachEffectToHost(fx[2], u, 110., 50., 145., -16., true)
call AttachEffectToHost(fx[3], u, 190., 65., 75., -16., true)
call AttachEffectToHost(fx[4], u, 250., 50., 145., -16., true)
call AttachEffectToHost(fx[5], u, 340., 45., 180., -16., true)
call SetEffectFacingProperties(fx[1], 0., 150., true)
call SetEffectFacingProperties(fx[2], 0., 170., true)
call SetEffectFacingProperties(fx[3], 0., 120., true)
call SetEffectFacingProperties(fx[4], 0., 180., true)
call SetEffectFacingProperties(fx[5], 0., 140., true)
//____END OF DEMONSTATION___________________________________________________________________
call SetTimeOfDay(8)
call FogEnableOff()
call FogMaskEnableOff()
set u = null
set guest[0] = null
set guest[1] = null
set guest[2] = null
set fx[1] = null
set fx[2] = null
set fx[3] = null
set fx[4] = null
set fx[5] = null
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent(t, 0., false)
call TriggerAddAction(t, function Actions)
set t = null
endfunction
endscope
library AutoFly requires UnitDex
private function Actions takes nothing returns nothing
local unit u = GetIndexedUnit()
// By Magtheridon96
// This trigger will run whenever a unit is indexed.
// This means that it runs whenever a new unit enters the map.
// First, I'm adding the crow form ability to the indexed unit.
// The reason we're using it inside an if block is because the "UnitAddAbility" function returns a boolean.
// This boolean represents the successfulness of the ability adding. We need this here, because if a unit
// already had a crow form ability, it couldn't be added. The reason we're also using UnitRemoveAbility
// in the same line is because JASS has a short-circuiting feature. If one of the expressions in an 'and'
// expression returns false, then it stops.
// We do not want to call UnitRemoveAbility for a unit that failed to have the ability added.
// Without this form of protection, units that already had the crow form ability would have it
// removed completely.
if UnitAddAbility(u, 'Amrf') and UnitRemoveAbility(u, 'Amrf') then
endif
set u = null
endfunction
private module Init
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Filter(function Actions), EVENT_UNIT_INDEX)
endmethod
endmodule
private struct init
implement Init
endstruct
endlibrary
library UnitDex uses optional WorldBounds, optional GroupUtils
/***************************************************************
*
* v1.2.1, by TriggerHappy
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex assigns every unit an unique integer. It attempts to make that number within the
* maximum array limit so you can associate it with one.
* _________________________________________________________________________
* 1. Installation
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the script to your map, save it, then restart the editor and comment out the line below.
*/
// external ObjectMerger w3a Adef uDex anam "Detect Leave" ansf "(UnitDex)" aart "" acat "" arac 0
/* ________________________________________________________________________
* 2. Configuration
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
private module UnitDexConfig
// The raw code of the leave detection ability.
static constant integer DETECT_LEAVE_ABILITY = 'uDex'
// Allow debug messages (debug mode must also be on)
static constant boolean ALLOW_DEBUGGING = true
// Uncomment the lines below to define a filter for units being indexed
/*static method onFilter takes unit u returns boolean
return true
endmethod*/
endmodule
/* _________________________________________________________________________
* 3. Function API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Every function inlines except for UnitDexRemove
*
* function GetUnitId takes unit whichUnit returns integer
* function GetUnitById takes integer index returns unit
*
* function UnitDexEnable takes boolean flag returns nothing
* function UnitDexRemove takes unit u, boolean runEvents returns boolean
*
* function IsUnitIndexed takes unit u returns boolean
* function IsIndexingEnabled takes nothing returns boolean
*
* function GetIndexedUnit takes nothing returns unit
* function GetIndexedUnitId takes nothing returns integer
*
* function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns indexevent
* function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
*
* function OnUnitIndex takes code func returns triggercondition
* function OnUnitDeidex takes code func returns triggercondition
* _________________________________________________________________________
* 4. Struct API
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* UnitDex.Enabled = false // toggle the indexer
* UnitDex.Initialized // returns true if the preload timer has finished
* UnitDex.Count // returns the amount of units indexed
* UnitDex.Unit[0] // access the UnitDex array directly
* UnitDex.Group // a unit group containing every indexed unit (for enumeration)
* UnitDex.LastIndex // returns the last indexed unit's id
* _________________________________________________________________________
* 5. Public Variables
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* These are to be used with the "eventtype" argument of the event API:
*
* constant integer EVENT_UNIT_INDEX = 0
* constant integer EVENT_UNIT_DEINDEX = 1
* _________________________________________________________________________
* 6. Examples
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Associate a unit with a variable
*
* set UnitFlag[GetUnitId(yourUnit)] = true
*
* 2. Allocate a struct instance using a units assigned ID
*
* local somestruct data = GetUnitId(yourUnit)
*
* 3. Detect when a unit leaves the map
*
* function Exit takes nothing returns nothing
* call BJDebugMsg("The unit " + GetUnitName(GetIndexedUnit()) + " has left the map.")
* endfunction
*
* call OnUnitDeindex(function Exit)
* // or
* call RegisterUnitIndexEvent(Filter(function Exit), EVENT_UNIT_DEINDEX)
*
*
* _________________________________________________________________________
* 7. How it works
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* 1. Enumerate all preplaced units
* 2. TriggerRegisterEnterRegion native to detect when a unit enters the map
* 3. Assign each unit that enters the map a unique integer
* 4. Give every unit an ability based off of defend. There is no native to accurately
* detect when a unit leaves the map but when a unit dies or is removed from the game
* they are issued the "undefend" order
* 5. Catch the "undefend" order and remove unit from the queue
* _________________________________________________________________________
* 8. Notes
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* - This system is compatable with GUI because it utilizes UnitUserData (custom values for units).
* - The object merger line should be commented out after saving and restarting.
* - All public functions are inlined except UnitDexRemove.
*
* -http://www.hiveworkshop.com/forums/submissions-414/unitdex-lightweight-unit-indexer-248209/
*
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
globals
// Event types
constant integer EVENT_UNIT_INDEX = 0
constant integer EVENT_UNIT_DEINDEX = 1
// System variables
private trigger array IndexTrig
private integer Index = 0
private real E=-1
private boolexpr FilterEnter
endglobals
function GetUnitId takes unit whichUnit returns integer
return GetUnitUserData(whichUnit)
endfunction
function GetUnitById takes integer index returns unit
return UnitDex.Unit[index]
endfunction
function GetIndexedUnit takes nothing returns unit
return UnitDex.Unit[UnitDex.LastIndex]
endfunction
function GetIndexedUnitId takes nothing returns integer
return UnitDex.LastIndex
endfunction
function IsUnitIndexed takes unit u returns boolean
return (GetUnitById(GetUnitId(u)) != null)
endfunction
function UnitDexEnable takes boolean flag returns nothing
set UnitDex.Enabled = flag
endfunction
function IsIndexingEnabled takes nothing returns boolean
return UnitDex.Enabled
endfunction
function RegisterUnitIndexEvent takes boolexpr func, integer eventtype returns triggercondition
return TriggerAddCondition(IndexTrig[eventtype], func)
endfunction
function RemoveUnitIndexEvent takes triggercondition c, integer eventtype returns nothing
call TriggerRemoveCondition(IndexTrig[eventtype], c)
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t, integer eventtype returns nothing
call TriggerRegisterVariableEvent(t, SCOPE_PRIVATE + "E", EQUAL, eventtype)
endfunction
function OnUnitIndex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_INDEX], Filter(func))
endfunction
function OnUnitDeindex takes code func returns triggercondition
return TriggerAddCondition(IndexTrig[EVENT_UNIT_DEINDEX], Filter(func))
endfunction
function UnitDexRemove takes unit u, boolean runEvents returns boolean
return UnitDex.Remove.evaluate(u, runEvents)
endfunction
/****************************************************************/
private keyword UnitDexCore
struct UnitDex extends array
static boolean Enabled = true
readonly static integer LastIndex
readonly static boolean Initialized=false
readonly static group Group=CreateGroup()
readonly static unit array Unit
readonly static integer Count = 0
readonly static integer array List
implement UnitDexConfig
private static integer Counter = 0
implement UnitDexCore
endstruct
/****************************************************************/
private module UnitDexCore
static method Remove takes unit u, boolean runEvents returns boolean
local integer i
if (IsUnitIndexed(u)) then
set i = GetUnitId(u)
set UnitDex.List[i] = Index
set Index = i
call GroupRemoveUnit(UnitDex.Group, u)
call SetUnitUserData(u, 0)
if (runEvents) then
set UnitDex.LastIndex = i
set E = EVENT_UNIT_DEINDEX
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
set E = -1
endif
set UnitDex.Unit[i] = null
set UnitDex.Count = UnitDex.Count - 1
return true
endif
return false
endmethod
private static method onGameStart takes nothing returns nothing
local integer i = 0
static if (not LIBRARY_GroupUtils) then // Check if GroupUtils exists so we can use it's enumeration group.
local group ENUM_GROUP = CreateGroup() // If not, create the group.
endif
// Index preplaced units
loop
call GroupEnumUnitsOfPlayer(ENUM_GROUP, Player(i), FilterEnter)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
static if (not LIBRARY_GroupUtils) then
call DestroyGroup(ENUM_GROUP)
set ENUM_GROUP = null
endif
// run init triggers
set i = 1
loop
exitwhen i > Counter
set LastIndex = i
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
set E = EVENT_UNIT_INDEX
set E = -1
set i = i + 1
endloop
set LastIndex = Counter
set Initialized = true
set FilterEnter = null
call DestroyTimer(GetExpiredTimer())
endmethod
private static method onEnter takes nothing returns boolean
local unit u = GetFilterUnit()
local integer i = GetUnitId(u)
local integer t = Index
if (i == 0 and thistype.Enabled) then
// If a filter was defined pass the unit through it.
static if (thistype.onFilter.exists) then
if (not thistype.onFilter(u)) then
set u = null
return false // check failed
endif
endif
// Handle debugging
static if (thistype.DEBUG_MODE and thistype.ALLOW_DEBUGGING) then
if (t == 0 and Counter+1 >= JASS_MAX_ARRAY_SIZE) then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, "UnitDex: Maximum number of units reached!")
set u = null
return false
endif
endif
// Add to group of indexed units
call GroupAddUnit(thistype.Group, u)
// Give unit the leave detection ability
call UnitAddAbility(u, thistype.DETECT_LEAVE_ABILITY)
call UnitMakeAbilityPermanent(u, true, thistype.DETECT_LEAVE_ABILITY)
// Allocate index
if (Index != 0) then
set Index = List[t]
else
set Counter = Counter + 1
set t = Counter
endif
set List[t] = -1
set LastIndex = t
set thistype.Unit[t] = u
set Count = Count + 1
// Store the index
call SetUnitUserData(u, t)
if (thistype.Initialized) then
// Execute custom events registered with RegisterUnitIndexEvent
call TriggerEvaluate(IndexTrig[EVENT_UNIT_INDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_INDEX
// Reset so the event can occur again
set E = -1
endif
endif
set u = null
return false
endmethod
private static method onLeave takes nothing returns boolean
local unit u
local integer i
// Check if order is undefend.
if (thistype.Enabled and GetIssuedOrderId() == 852056) then
set u = GetTriggerUnit()
// If unit was killed (not removed) then don't continue
if (GetUnitAbilityLevel(u, thistype.DETECT_LEAVE_ABILITY) != 0) then
set u = null
return false
endif
set i = GetUnitId(u)
// If unit has been indexed then deindex it
if (i > 0 and i <= Counter and u == GetUnitById(i)) then
// Recycle the index
set List[i] = Index
set Index = i
set LastIndex = i
// Remove to group of indexed units
call GroupRemoveUnit(thistype.Group, u)
// Execute custom events without any associated triggers
call TriggerEvaluate(IndexTrig[EVENT_UNIT_DEINDEX])
// Handle TriggerRegisterUnitIndexEvent
set E = EVENT_UNIT_DEINDEX
// Remove entry
call SetUnitUserData(u, 0)
set thistype.Unit[i] = null
// Decrement unit count
set Count = Count - 1
// Reset so the event can occur again
set E = -1
endif
set u = null
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
local player p
local unit u
static if (not LIBRARY_WorldBounds) then // Check if WorldBounts exists, if not then define the necessary vars
local region reg = CreateRegion() // If WorldBounds wasn't found, create the region manually
local rect world = GetWorldBounds()
endif
set FilterEnter = Filter(function thistype.onEnter)
// Begin to index units when they enter the map
static if (LIBRARY_WorldBounds) then
call TriggerRegisterEnterRegion(CreateTrigger(), WorldBounds.worldRegion, FilterEnter)
else
call RegionAddRect(reg, world)
call TriggerRegisterEnterRegion(CreateTrigger(), reg, FilterEnter)
call RemoveRect(world)
set world = null
endif
call TriggerAddCondition(t, Filter(function thistype.onLeave))
set IndexTrig[EVENT_UNIT_INDEX] = CreateTrigger()
set IndexTrig[EVENT_UNIT_DEINDEX] = CreateTrigger()
loop
set p = Player(i)
// Detect "undefend"
call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_UNIT_ISSUED_ORDER, null)
// Hide the detect ability from players
call SetPlayerAbilityAvailable(p, thistype.DETECT_LEAVE_ABILITY, false)
set i = i + 1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call TimerStart(CreateTimer(), 0, false, function thistype.onGameStart)
endmethod
endmodule
endlibrary
scope ListDemo
// This demo will explain how to use the GetGuestList() function
function UsingListsExample takes unit yourHost returns nothing
// a static if will write the code only if the library in question is present.
// If you have ListT, you will need the following locals
static if LIBRARY_ListT then
local IntegerList list = GetGuestList(yourHost)
local IntegerListItem node = list.first
local IntegerListItem nodeNext
// If you do NOT have ListT, you will have to use AttachObject's internal linked list as locals
else
local LinkedList list = GetGuestList(yourHost)
local ListItem node = list.first
local ListItem nodeNext
endif
// GuestEx is the struct that contains all guest information. It is readonly.
local GuestEx guest
loop
exitwhen node == 0
set nodeNext = node.next
set guest = node.data
// guest.host is your host
// guest.guest is your guest
// guest.fx if your special effect
set node = nodeNext
endloop
// This is how you destroy your list. This is EXTREMELY IMPORTANT.
call list.destroy()
endfunction
endscope
/*
The following is an example of how to filter when using GetRandomGuest
*/
function FilterSorceresses takes nothing returns boolean
return GetUnitTypeId(FilterGuest) == 'hsor'
endfunction
function Trig_Filter_Test_Actions takes nothing returns nothing
local unit u = GetRandomGuest(TestUnit, Filter(function FilterSorceresses))
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\OrbOfDeath\\OrbOfDeathMissile.mdl", u, "chest"))
set u = null
endfunction
//===========================================================================
function InitTrig_Filter_Test takes nothing returns nothing
set gg_trg_Filter_Test = CreateTrigger( )
call TriggerRegisterTimerEvent( gg_trg_Filter_Test, 1.5, true )
call TriggerAddAction( gg_trg_Filter_Test, function Trig_Filter_Test_Actions )
endfunction