Name | Type | is_array | initial_value |
bool | boolean | No | |
HARVESTER | unit | No | |
i | integer | No | |
JUMP_EFFECT | string | No | |
JUMP_FINISH_TRIGGER | trigger | No | |
loc | location | No | |
p | location | No | |
RECT | rect | No | |
u | unit | No | |
u2 | unit | No | |
x | real | No | |
y | location | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
/**********************************************************
*
* Shadow Trail System v 1.1.1.7 by Maker
*
* Creates a trail of units behind the caster
*
* To use this system, copy this library,
* and then Table and CTL from Resources folder into your map.
*
* struct ShadowTrail
* static method add takes unit target, integer trailType, real duration returns thistype
* - target is the unit to attach the trail to
* - trailType, 0 = units are created repeatedly, 1 = uses the same units. Test which suits your spell better
* - duration is how long the trail lasts in seconds. 0 = lasts until the unit dies
*
* method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
* - use this only if the trail type is 1, TRAIL_TYPE_MOTION
* - must be used if trail type is 1
* - count is how many units are in the trail. More units -> longer trail
* - separation is the distance between units.
* - alphaFactor is the transparency multiplier between units. The further away the trail unit is from the main unit,
* the more transparent it will be. Use values between 0 and 1.
*
* method setInterval takes real timee returns nothing
* - only affects trail type 0, TRAIL_TYPE_STATIC
* - must be used with trail type 0
* - timee is how often new units are created
*
* method setFadeRate takes real rate, boolean flatMode returns nothing
* - rate is how quickly the units fade out after the trail is terminated
* - flatMode == true, units fade at a constant rate. Transparency = transparency - rate. Try values around 10. Higher value, faster fading.
* - flatMode == false, units fade out at multiplicative rate. Transparency = transparency*(1-rate). Use values around 0.9. Lower value, faster fading-
*
* method setAnimationSpeed takes real r returns nothing
* - how quickly the animations of the trail units are played. Default value is 1.
*
* method setAnimationIndex takes integer k returns nothing
* - what animation index the trail units play
*
* method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
* - sets the colouring of the trail units. Use values between 0 and 255.
* - if alpha is 0, the unit is completely transparent, 255 means it is fully visible
*
* method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
* - attaches a special effect to the trail units and the main unit
* - model = the path of a effect to attach
* - attachPoint is the attachment point
* - attachToShadows, if set to true will attach the effect to the trail units and the main unit, if
* set to false then the effect is only attached to the main unit
*
* method remove takes nothing returns nothing
* - destroys/removes/ends the trail
* - you can use this to remove the trail before the duration ends.
* - trails are automatically detroyed when the duration ends so there is no need to use this
*
* method setPlayerColor takes playercolor pColor returns nothing
* - Sets the player color of the dummy units
*
*
* Examples
*
* / --------- Moving Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_MOTION, 8) // Lasts 8 seconds
* call ST.setupMovingTrail(5, 20, 0.85) // This method affects only trail type 1, must use
* call ST.setAnimationIndex(2) // Recommended to set
* call ST.setFadeRate(10, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
*
* ---------------------------------------- /
*
*
* /--------- Static Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_STAITC, 8) // Lasts 8 seconds
* call ST.setInterval(0.06250) // This method affects only trail type 0, must use
* call ST.setAnimationIndex(6) // Recommended to set
* call ST.setFadeRate(7, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
* ----------------------------------------/
*
*
* Credits
* Bribe : Table
* Nestharus : CTL
*
***********************************************************/
library ShadowTrail requires Table, CTL
globals
// Does it use the team color of the owner of the main unit
private constant boolean COLOUR_OWNER = true
// Default player colour for shadows, used if COLOUR_OWNER is false
private constant playercolor PCOL = GetPlayerColor(Player(15))
// Dummies are created here and then isntantly placed at the hero's position
private constant real CREATE_X = 0
private constant real CREATE_Y = 0
constant integer TRAIL_TYPE_STATIC = 0
constant integer TRAIL_TYPE_MOTION = 1
// The image to use as shadows for the dummies. No need to change this as the image will be hidden
private constant string SHADOWPATH = "Textures\\white.blp"
private Table tab
private integer dc = 0 // Dummy count
private unit u
endglobals
// Credit to Deaod, edited by Maker
private function CreateUnitWithoutShadow takes player owner, integer uid, real facing, string shadowfile returns unit
local image i = CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // creates a dummy image
if GetHandleId(i) == -1 then // if the new shadow is invalid, abort, it can screw up the game
debug call BJDebugMsg("CreateUnitWithShadow: Invalid path for new shadow!") // it could also be caused by an imageType of 0, but thats a less common cause
return null // since the image is invalid, we dont need to destroy it
endif
call DestroyImage(i) // destroy the dummy.
set u = CreateUnit(owner, uid, CREATE_X, CREATE_Y, facing) // create the unit. this also creates a new image which functions as the shadow of the unit. The shadow will use the ID of the dummy image.
call DestroyImage(i) // destroy the shadow of the unit
call CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // this creates the new shadow for the unit, note that i dont need to overwrite "i" as the id this image will get is predictable
call SetImageRenderAlways(i, false) // Hides the shadow
call SetImageColor(i, 0, 0, 0, 0) // Makes the shadow invisible
// no need to null "i", as images dont use ref-counting
return u
endfunction
// Fades out units over time
private struct Alpha extends array
private static unit array u // The unit
private static unit array hero // The hero
private static integer array aMax // Maximum alpha value
private static integer array a // Current alpha value
private static integer array r // Red
private static integer array g // Green
private static integer array b // Blue
private static integer array rf // Flat alpha rate
private static real array rs // Multiplicative alpha rate
private static boolean array bl // Is fading flat
private static boolean array rem // Is the unit removed in the end
private static boolean array sync // Prevents overlapping fade in and fade out
private static effect array e // Effect
implement CTLExpire
if tab.boolean[GetHandleId(u[this])] == sync[this] then
if bl[this] then
set a[this] = a[this] + rf[this]
else
set a[this] = R2I(a[this] +rs[this]*50 + (aMax[this] - a[this]) * rs[this])
endif
if a[this] > 0 and a[this] < aMax[this] then
if IsUnitInvisible(hero[this], GetLocalPlayer()) then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], 0)
else
call SetUnitVertexColor(u[this], r[this], g[this], b[this], a[this])
endif
else
if rem[this] then
if e[this] != null then
call DestroyEffect(e[this])
set e[this] = null
endif
call RemoveUnit(u[this])
set dc = dc - 1
if dc == 0 then
call tab.flush()
endif
elseif a[this] <= 0 then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], 0)
call ShowUnit(u[this], false)
else
if IsUnitInvisible(hero[this], GetLocalPlayer()) then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], 0)
else
call SetUnitVertexColor(u[this], r[this], g[this], b[this], aMax[this])
endif
endif
set e[this] = null
set u[this] = null
set hero[this] = null
call destroy()
endif
else
set e[this] = null
set u[this] = null
set hero[this] = null
call destroy()
endif
implement CTLEnd
static method start takes unit un, unit caster, integer rate1, real rate2, integer maxAlpha, integer red, integer grn, integer blu, integer alpha, boolean flatFade, boolean remove, boolean synch, effect eff returns nothing
local thistype this = create()
set u[this] = un
set hero[this] = caster
set a[this] = alpha
set aMax[this] = maxAlpha
set r[this] = red
set g[this] = grn
set b[this] = blu
set rf[this] = rate1
set rs[this] = rate2
set bl[this] = flatFade
set rem[this] = remove
set sync[this] = synch
set e[this] = eff
endmethod
endstruct
struct ShadowTrail extends array
private static unit array main // The unit with the trail
private static real array dur // How long the trail lasts
private static real array xm // X of main during the previous loop
private static real array ym // Y of main during the previous loop
private static real array ts // Animation speed, time scale
private static real array fd // follow distance
private static real array fp // How quickly the shadow fades, multiplicative
private static real array time // Calculates the interval time
private static real array interval // How often a new shadow is created
private static real array af // Alpha factor between moving shadows
private static real array d // Distance between moving shadows
private static integer array tc // Number of moving shadows
private static integer array fr // How quickly the shadow fades, flat
private static integer array r // Red of shadows
private static integer array g // Green of shadows
private static integer array b // Blue of shadows
private static integer array a // Transparency of shadows
private static integer array uid // Unit type if of shadows
private static integer array anim // Animation index to play for the shadows
private static integer array id // Shadow Trail type
private static string array eff // Special effect on copies
private static string array att // Special effect attach point
private static boolean array bo1 // True = flat fading time, false = multiplicative fading time
private static boolean array bo2 // Is the specified effect created on dummies also
private static boolean array h // Are moving trail units hidden
private static boolean array perm // Is the trail permanent
private static Table array ta // For shadow copy units
private static Table array tb // For shadow copy effects
private static playercolor array pc // Player colour of the shadows
implement CTL
local real x
local real y
local real an
local real f
local unit u
local unit s
local effect e = null // Passing unitialized variable to Alpha.start causes problems, null is good.
local integer i
local integer j
implement CTLExpire
if not IsUnitType(main[this], UNIT_TYPE_DEAD) and (dur[this] >= 0 or perm[this]) and GetUnitTypeId(main[this]) != 0 then
if not perm[this] then
set dur[this] = dur[this] - 0.031250
endif
set x = GetUnitX(main[this])
set y = GetUnitY(main[this])
if x != xm[this] or y != ym[this] then
if id[this] == TRAIL_TYPE_STATIC then // Is moving, static trail
set time[this] = time[this] + 0.031250
if time[this] >= interval[this] then
set u = CreateUnitWithoutShadow(Player(15), uid[this], GetUnitFacing(main[this]), SHADOWPATH)
set dc = dc + 1
call SetUnitTurnSpeed(u, 1000)
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
call PauseUnit(u, true)
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitTimeScale(u, ts[this])
call SetUnitColor(u, pc[this])
call SetUnitVertexColor(u, r[this], g[this], b[this], 0)
call SetUnitAnimationByIndex(u, anim[this])
call SetUnitFlyHeight(u, GetUnitFlyHeight(main[this]), 0)
if bo2[this] then
set e = AddSpecialEffectTarget(eff[this], u, att[this])
endif
set tab.boolean[GetHandleId(u)] = false
call Alpha.start(u, main[this], -fr[this], -fp[this], 255, r[this], g[this], b[this], a[this], bo1[this], true, false, e)
set time[this] = 0
set u = null
set e = null
endif
else // Is moving, moving trail (type 1)
set i = tc[this]
loop
exitwhen i == 0
set s = ta[this].unit[i]
set u = ta[this].unit[i-1]
set f = GetUnitFacing(u)
set an = (f+180)*bj_DEGTORAD
if IsUnitHidden(s) then // If units are hidden, they should be set to visible
set tab.boolean[GetHandleId(s)] = true
call Alpha.start(s, main[this], fr[this], fp[this], R2I(a[this]*Pow(af[this], i-1)), r[this], g[this], b[this], 0, bo1[this], false, true, e)
call ShowUnit(s, true)
call UnitRemoveAbility(s, 'Aloc') // Showing unit makes units with Locust selectable
call UnitAddAbility(s, 'Aloc') // Must apply Locust again
call SetUnitAnimationByIndex(s, anim[this])
endif
call SetUnitX(s, GetUnitX(u) + d[this] * Cos(an))
call SetUnitY(s, GetUnitY(u) + d[this] * Sin(an))
call SetUnitFacing(s, f)
call SetUnitFlyHeight(s, GetUnitFlyHeight(u), 0)
set i = i - 1
endloop
if h[this] then
set h[this] = false
endif
set s = null
set u = null
endif
elseif not h[this] and id[this] == TRAIL_TYPE_MOTION then // Is not moving, trail is visible, trail type 1
set i = tc[this]
loop
exitwhen i == 0
set j = R2I(a[this]*Pow(af[this], i-1))
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], main[this], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], false, false, null)
set i = i - 1
endloop
set h[this] = true
endif
set xm[this] = x
set ym[this] = y
else
set i = tc[this]
loop
exitwhen i == 0
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set j = R2I(a[this]*Pow(af[this], i-1)) - 1
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], main[this], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], true, false, null)
set i = i - 1
endloop
if tb[this].effect[0] != null then
call DestroyEffect(tb[this].effect[0])
endif
set main[this] = null
call ta[this].flush()
call tb[this].flush()
call destroy()
endif
implement CTLEnd
method remove takes nothing returns nothing
set dur[this] = 0
set perm[this] = false
endmethod
method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
local integer i = 1
set eff[this] = model
set att[this] = attachPoint
set bo2[this] = attachToShadows
if attachToShadows then
loop
exitwhen ta[this].unit[i] == null
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[i] = AddSpecialEffectTarget(model, ta[this].unit[i], attachPoint)
set i = i + 1
endloop
endif
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[0] = AddSpecialEffectTarget(model, main[this], attachPoint)
endmethod
method setPlayerColor takes playercolor pColor returns nothing
local integer i = 1
set pc[this] = pColor
loop
exitwhen ta[this].unit[i] == null
call SetUnitColor(ta[this].unit[i], pc[this])
set i = i + 1
endloop
endmethod
method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
local integer i = 1
set r[this] = red
set g[this] = grn
set b[this] = blu
set a[this] = alpha
loop
exitwhen ta[this].unit[i] == null
if id[this] == TRAIL_TYPE_STATIC or not h[this] then
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, R2I(a[this]*Pow(af[this], i-1)))
else
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, 0)
endif
set i = i + 1
endloop
endmethod
method setAnimationIndex takes integer k returns nothing
local integer i = 1
set anim[this] = k
loop
exitwhen ta[this].unit[i] == null
call SetUnitAnimationByIndex(ta[this].unit[i], k)
set i = i + 1
endloop
endmethod
method setAnimationSpeed takes real r returns nothing
local integer i = 1
set ts[this] = r
loop
exitwhen ta[this].unit[i] == null
call SetUnitTimeScale(ta[this].unit[i], r)
set i = i + 1
endloop
endmethod
method setFadeRate takes real rate, boolean flatMode returns nothing
if flatMode then
set fr[this] = R2I(rate)
else
set fp[this] = 1-rate
endif
set bo1[this] = flatMode
endmethod
method setInterval takes real timee returns nothing
set time[this] = 0
set interval[this] = timee
endmethod
method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
local integer i
local unit u
local real x = GetUnitX(main[this])
local real y = GetUnitY(main[this])
local real f = GetUnitFacing(main[this])
if id[this] == TRAIL_TYPE_MOTION then
if count > 0 then
set d[this] = separation
set tc[this] = count
set h[this] = false
set af[this] = alphaFactor
set xm[this] = GetUnitX(main[this])
set ym[this] = GetUnitY(main[this])
set ta[this] = Table.create()
set i = 1
loop
set u = CreateUnitWithoutShadow(Player(15), uid[this], f, SHADOWPATH)
call ShowUnit(u, false)
call SetUnitVertexColor(u, r[this], g[this], b[this], 0)
set dc = dc + 1
call SetUnitColor(u, pc[this])
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
call PauseUnit(u, true)
set ta[this].unit[i] = u
exitwhen i == count
set i = i + 1
endloop
set h[this] = true
set ta[this].unit[0] = main[this]
set u = null
else
debug call BJDebugMsg("Tried to use setupMovingTrail method with invalid dummy unit count. (Less than 1)")
endif
debug else
debug call BJDebugMsg("Tried to use setupMovingTrail method with instance that has a wrong shadow trail type.")
endif
endmethod
static method add takes unit target, integer trailType, real duration returns thistype
local thistype this = 0
if trailType == TRAIL_TYPE_MOTION or trailType == TRAIL_TYPE_STATIC then
set this = create()
set main[this] = target
set uid[this] = GetUnitTypeId(target)
set id[this] = trailType
set dur[this] = duration
set tc[this] = 0
set perm[this] = duration == 0
call this.setColor(255, 255, 255, 255)
call this.setAnimationIndex(0)
call this.setAnimationSpeed(1)
call this.setFadeRate(0, true)
call this.setFadeRate(0, false)
call this.setInterval(0.2)
call this.setEffect(null, null, false)
static if COLOUR_OWNER then
set pc[this] = GetPlayerColor(GetOwningPlayer(target))
else
set pc[this] = PCOL
endif
debug else
debug call BJDebugMsg("Invalid shadow trail type.")
endif
return this
endmethod
private static method onInit takes nothing returns nothing
set tab = Table.create()
endmethod
endstruct
endlibrary
//TESH.scrollpos=33
//TESH.alwaysfold=0
library Jump requires CTL, IsTerrainWalkable optional GetUnitCollision, Table
/*
* Jumping v. 1.0.1.6 by Maker
* -Does not pause units
* -Allows jumping in place
* -Real life physics equation for the jump arc
* -Supports collision with destructables and units
*
* function IsPointJumpable takes real x, real y returns boolean
* -Tells if the point is walkable
*
* static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
* - un = unit that jumps
* - x1, y1 = coordinates to jump to
* - maxZ = height of the arc
* - time = duration of the jump
* - gravity = well, duh
*
* method setUnitCollisionHeight takes real h returns nothing
* - Overrides the global U_COL_Z variable for the jump instance
* If set to 0, the jumping unit won't collide with units
* while being in air
*
* method setDestructableCollisionDistance takes real d returns nothing
* - Overrides the global D_COL_D variable for the jump instance
* If set to 0, the jumping unit won't collide with destructables
* while being in air
*
* You can catch the ending of the jump and register it for a trigger like this:
* call TriggerRegisterVariableEvent(trigger, "EVENT_JUMP_FINISH", EQUAL, 1)
*
* Import this library and required CTL and IsTerrainWalkable libraries from resources folder.
* I recommend also importing GetUnitCollision and Table libraries from resources folder.
*
* Credits
* CTL, GetUniCollision : Nestharus
* IsTerrainWalkable : anitarf and Vexorian
* Table : Bribe
*/
globals
// Tolerance distance for pathability
private constant real TOL = 1
// Minimum flying heigh for colliding with units. If set to 0 then won't collide with units.
private constant real U_COL_Z = 96
// Collision distance with units. Uses this if GetUnitCollision library is not used
private constant real U_COL_D = 96
// Collision distance with destructables. If set to 0 then won't collide with destructables.
private constant real D_COL_D = 96
// Maximum collision radius of units in the map. 196 for tier 3 Town Halls etc.
private constant real MAX_RAD = 196
// Moves the unit to nearest pathable point when landing
private constant boolean PATHING_LAND = false
// Is the turn speed locked when jumping
private constant boolean LOCK_FACING = true
private rect rct = Rect(0,0,0,0)
private group enu = CreateGroup()
private location loc = Location(0,0)
real EVENT_JUMP_FINISH = 0
unit EVENT_JUMP_UNIT = null
private real flh = 0
private boolean b = false
endglobals
private function GetLocZ takes real x, real y returns real
call MoveLocation(loc, x, y)
return GetLocationZ(loc)
endfunction
private function DestructableFilter takes nothing returns boolean
if GetDestructableLife(GetFilterDestructable()) > 0 and GetDestructableOccluderHeight(GetFilterDestructable()) > flh then
set b = true
endif
return false
endfunction
function IsPointJumpable takes real x, real y returns boolean
if not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then
return IsTerrainWalkable(x, y)
endif
return false
endfunction
struct Jump extends array
private static unit array u // Jumping unit
private static real array z0 // Location Z at jump origin point
private static real array sx // The x component of speed
private static real array sy // The y component of speed
private static real array t // Elapsed jump time
private static real array dt // How much "time" is passed during each loop
private static real array g // Gravity
private static real array sinZ // Z angle
private static real array endX // Targeted x
private static real array endY // Targeted y
private static real array tEnd // Jump end time
private static real array dfh // Default flying height
private static real array col // Collision size of the unit
private static real array colUZ // Minimum height to collide with other units
private static real array colDD // Minimum distance to collide with destructables
private static real array pw // Propulsion window of the unit
private static real array ts // Turn speed of the unit
method setUnitCollisionHeight takes real h returns nothing
set colUZ[this] = h
endmethod
method setDestructableCollisionDistance takes real d returns nothing
set colDD[this] = d
endmethod
implement CTL
local real x
local real y
local real z
local real fh
local unit un
implement CTLExpire
set x = GetUnitX(u[this]) + sx[this]
set y = GetUnitY(u[this]) + sy[this]
set z = GetLocZ(x, y) - z0[this]
set t[this] = t[this] + dt[this]
set fh = sinZ[this] * t[this] - g[this] * t[this] * t[this] / 2. - z + dfh[this]
if t[this] < tEnd[this] then
set b = false
if colDD[this] > 0 then
call SetRect(rct, x-colDD[this], y-colDD[this], x+colDD[this], y+colDD[this])
call EnumDestructablesInRect(rct, function DestructableFilter, null)
endif
if fh < colUZ[this] and not b then
set flh = fh
call GroupEnumUnitsInRange(enu, x, y, MAX_RAD, null)
call GroupRemoveUnit(enu, u[this])
loop
set un = FirstOfGroup(enu)
exitwhen un == null or b
if IsUnitInRange(un, u[this], col[this]+1) and not IsUnitType(un, UNIT_TYPE_DEAD) and not IsUnitType(un, UNIT_TYPE_FLYING) then
set b = true
set un = null
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
call GroupClear(enu)
else
call GroupRemoveUnit(enu, un)
endif
endloop
if not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
endif
elseif not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
else
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
endif
call SetUnitFlyHeight(u[this], fh, 0)
else
static if PATHING_LAND then
call SetUnitPosition(u[this], endX[this], endY[this])
else
call SetUnitX(u[this], endX[this])
call SetUnitY(u[this], endY[this])
endif
static if LOCK_FACING then
call SetUnitTurnSpeed(u[this], ts[this])
endif
call SetUnitPropWindow(u[this], pw[this])
call SetUnitFlyHeight(u[this], dfh[this], 0)
set EVENT_JUMP_UNIT = u[this]
set EVENT_JUMP_FINISH = 0
set EVENT_JUMP_FINISH = 1
set EVENT_JUMP_UNIT = null
set u[this] = null
call destroy()
endif
implement CTLNull
implement CTLEnd
static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
local thistype this = create()
local real x0 = GetUnitX(un)
local real y0 = GetUnitY(un)
local real angle = Atan2(y1-y0, x1-x0)
local real dist = SquareRoot((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))
local real speed = dist/time * 0.031250000
local real z1 = GetLocZ(x1, y1)
set u[this] = un
set t[this] = 0
set endX[this] = x1
set endY[this] = y1
set g[this] = gravity
set z0[this] = GetLocZ(x0, y0)
set sx[this] = Cos(angle) * speed
set sy[this] = Sin(angle) * speed
set dfh[this] = GetUnitDefaultFlyHeight(un)
static if LIBRARY_GetUnitCollision then
set col[this] = GetUnitCollision(un)
else
set col[this] = U_COL_D
endif
set colDD[this] = D_COL_D
set colUZ[this] = U_COL_Z
if z0[this] < z1 then
set maxZ = maxZ + z1 - z0[this]
endif
set sinZ[this] = SquareRoot(maxZ*2*gravity)
set tEnd[this] = (sinZ[this]+SquareRoot(sinZ[this]*sinZ[this]-2*gravity*(z1-z0[this]))) / gravity
set dt[this] = 0.03125000*(tEnd[this]-t[this]) / time
static if LOCK_FACING then
set ts[this] = GetUnitTurnSpeed(un)
call SetUnitTurnSpeed(un, 0)
endif
set pw[this] = GetUnitPropWindow(un)
call SetUnitPropWindow(un, 0)
if UnitAddAbility(un, 'Arav') and UnitRemoveAbility(un, 'Arav') then
endif
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope JumpSpellvJASS
globals
private string EFF = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
private constant integer AID = 'A000'
private constant integer DID = 'e000'
private constant integer OID = 852121
private unit HARVESTER
private group ENU = CreateGroup()
private constant real GRAVITY = 100
private constant real SPEED = 500
private constant real MAX_HEIGHT = 250
private constant real AOE = 200
private rect REC = Rect(0, 0, 0, 0)
private Table TAB
private ShadowTrail ST = 0
endglobals
struct JumpingStomp extends array
private static method DestructableFilter takes nothing returns boolean
if GetDestructableLife(GetFilterDestructable()) > 0 then
call IssueTargetOrder(HARVESTER, "harvest", GetFilterDestructable())
if GetUnitCurrentOrder(HARVESTER) == OrderId("harvest") then
call KillDestructable(GetFilterDestructable())
endif
call IssueImmediateOrder(HARVESTER, "stop")
endif
return false
endmethod
private static method onFinish takes nothing returns boolean
local real x
local real y
if not IsUnitType(EVENT_JUMP_UNIT, UNIT_TYPE_DEAD) then
set x = GetUnitX(EVENT_JUMP_UNIT)
set y = GetUnitY(EVENT_JUMP_UNIT)
call DestroyEffect(AddSpecialEffect(EFF, x, y))
call SetRect(REC, x-AOE, y-AOE, x+AOE, y+AOE)
call EnumDestructablesInRect(REC, function thistype.DestructableFilter, null)
endif
set ST = TAB[GetHandleId(EVENT_JUMP_UNIT)]
call ST.remove()
return false
endmethod
private static method onCast takes nothing returns boolean
local unit u = GetTriggerUnit()
local real x0 = GetUnitX(u)
local real y0 = GetUnitY(u)
local real x1 = GetSpellTargetX()
local real y1 = GetSpellTargetY()
// Here I make each jump take at least 0.5 seconds. The distance add to the jump time with 0.5 factor.
local real time = 0.5 + 0.5 * SquareRoot( (x1-x0)*(x1-x0) + (y1-y0)*(y1-y0) ) / SPEED
call Jump.start(GetTriggerUnit(), GetSpellTargetX(), GetSpellTargetY(), MAX_HEIGHT, time, GRAVITY)
/* --------- Moving Shadow Trail ---------- /
set ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_MOTION, 8)
call ST.setupMovingTrail(5, 20, 0.85)
call ST.setColor(200, 200, 200, 200)
call ST.setAnimationIndex(2)
call ST.setFadeRate(10, true)
/ ---------------------------------------- */
/* --------- Static Shadow Trail ---------- /
set ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_STATIC, 0)
call ST.setInterval(0.06250)
call ST.setColor(150, 150, 150, 150)
call ST.setAnimationIndex(6)
call ST.setFadeRate(8, true)
call ST.setPlayerColor(GetPlayerColor(Player(15)))
/ ---------------------------------------- */
// set TAB[GetHandleId(GetTriggerUnit())] = ST
set u = null
return false
endmethod
private static method onOrder takes nothing returns boolean
if GetIssuedOrderId() == OID and not IsPointJumpable(GetOrderPointX(), GetOrderPointY()) then
call PauseUnit(GetTriggerUnit(), true)
call IssueImmediateOrder(GetTriggerUnit(), "stop")
call PauseUnit(GetTriggerUnit(), false)
call SimError(GetTriggerPlayer(), "Can't jump there.")
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterVariableEvent(t, "EVENT_JUMP_FINISH", EQUAL, 1)
call TriggerAddCondition(t, function thistype.onFinish)
set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
call TriggerAddCondition(t, function thistype.onOrder)
call RegisterSpellEffectEvent(AID, function thistype.onCast)
set HARVESTER = CreateUnit(Player(15), 'hpea', 0, 0, 0)
call UnitAddAbility(HARVESTER, 'Aloc')
call ShowUnit(HARVESTER, false)
set TAB = Table.create()
endmethod
endstruct
endscope
//TESH.scrollpos=6
//TESH.alwaysfold=0
library CTL /* v1.2.0.1
*************************************************************************************
*
* CTL or Constant Timer Loop provides a loop for constant merged timers of timeout .03125
*
* Similar to T32 but pauses timer when no structs have instances and removes structs
* from timer trigger when those structs have no instances.
*
* This can also create new timers after destroying a previous timer and generates less
* code in the module. It also generates no triggers so long as the module is implemented
* at the top of the struct.
*
************************************************************************************
*
* module CTL
*
* Allows creation/destruction of timers in a struct. Provides instancing of those timers.
*
* - static method create takes nothing returns thistype
* - method destroy takes nothing returns nothing
*
* CTL (optional)
* local variables, code before running any timers
* CTLExpire (not optional)
* timer code
* CTLNull (optional)
* null any locals, runs after all timers
* CTLEnd (not optional)
*
* module CT32
*
* Converts struct into a timer group. Allows the timer group to be started and stopped.
* Instancing and looping through active timers is up to the user.
*
* - static method start takes nothing returns nothing
* - static method stop takes nothing returns nothing
*
* CT32 (not optional)
* timer code
* CT32End (not optional)
*
* struct TimerGroup32 extends array
*
* Allows for the creation of timer groups. Timer instancing and looping is entirely up
* to the user.
*
* - static method create takes code func returns thistype
* - method destroy takes nothing returns nothing
* - method start takes nothing returns nothing
* - method stop takes nothing returns nothing
*
************************************************************************************/
globals
private integer tgc = 0 //timer group count
private integer array tgr //timer group recycler
private integer ic=0 //instance count
private integer tc=0 //timer count
private integer array rf //root first
private integer array n //next
private integer array p //previous
private integer array th //timer head
private integer array ns //next stack
private trigger t=CreateTrigger()
private timer m=CreateTimer()
private triggercondition array ct
private conditionfunc array rc
private boolean array e32 //enabled
private integer array i32r //ct32 recycler
private integer i32cr = 0 //ct32 count recycler
private boolean array ir32 //is recycling
private boolean array id32 //is destroying
endglobals
private function E takes nothing returns nothing
local integer i=ns[0]
set ns[0]=0
loop
exitwhen 0==i
if (0==p[i]) then
if (0==n[i]) then
call TriggerRemoveCondition(t,ct[th[i]])
set ct[th[i]]=null
set tc=tc-1
set rf[th[i]]=0
else
set rf[th[i]]=n[i]
set p[n[i]]=0
endif
else
set p[n[i]]=p[i]
set n[p[i]]=n[i]
endif
set n[i]=n[0]
set n[0]=i
set i=ns[i]
endloop
loop
exitwhen 0 == i32cr
set i32cr = i32cr - 1
set i = i32r[i32cr]
if (not e32[i]) then
call TriggerRemoveCondition(t,ct[i])
set ct[i] = null
if (id32[i]) then
set tgr[i] = tgr[0]
set tgr[0] = i
set id32[i] = false
set e32[i] = false
set ir32[i] = false
endif
endif
endloop
if (0==tc) then
call PauseTimer(m)
else
call TriggerEvaluate(t)
endif
endfunction
private function CT takes integer r returns integer
local integer i
local integer f
if (0==n[0]) then
set i=ic+1
set ic=i
else
set i=n[0]
set n[0]=n[i]
endif
set th[i]=r
set ns[i]=-1
set f=rf[r]
if (0==f) then
set n[i]=0
set p[i]=0
set rf[r]=i
set ct[r]=TriggerAddCondition(t,rc[r])
//set ct[r] = null
if (0==tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc=tc+1
else
set n[i]=f
set p[i]=0
set p[f]=i
set rf[r]=i
endif
return i
endfunction
private function DT takes integer t returns nothing
debug if (0>ns[t]) then
set ns[t]=ns[0]
set ns[0]=t
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"TIMER LOOP ERROR: ATTEMPT TO DESTROY NULL TIMER")
debug endif
endfunction
private function A takes code c returns integer
local integer i = tgr[0]
if (0 == i) then
set i = tgc + 1
set tgc = i
else
set tgr[0] = tgr[i]
endif
set rc[i]=Condition(c)
return i
endfunction
private function A32 takes integer i returns nothing
if (not e32[i]) then
if (not ir32[i] and not id32[i]) then
set ct[i] = TriggerAddCondition(t, rc[i])
endif
if (0 == tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc = tc + 1
set e32[i] = true
endif
endfunction
private function SR32 takes integer i returns nothing
if (e32[i]) then
if (not ir32[i] and not id32[i]) then
set i32r[i32cr] = i
set i32cr = i32cr + 1
set ir32[i] = true
endif
set e32[i] = false
set tc = tc - 1
endif
endfunction
private function DT32 takes integer i returns nothing
if (not id32[i]) then
if (not ir32[i]) then
set ir32[i] = true
set tc = tc - 1
set i32r[i32cr] = i
set i32cr = i32cr + 1
set e32[i] = false
endif
set id32[i] = true
endif
endfunction
private keyword r
private keyword e
module CTL
static integer rctl32
static method create takes nothing returns thistype
return CT(rctl32)
endmethod
method destroy takes nothing returns nothing
call DT(this)
endmethod
static method ectl32 takes nothing returns boolean
local thistype this=rf[rctl32]
endmodule
module CTLExpire
implement CTL
loop
exitwhen 0==this
endmodule
module CTLNull
set this=n[this]
endloop
endmodule
module CTLEnd
implement CTLNull
return false
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
module CT32
static integer rctl32
static method ectl32 takes nothing returns boolean
endmodule
module CT32End
return false
endmethod
static method start takes nothing returns nothing
call A32(rctl32)
endmethod
static method stop takes nothing returns nothing
call SR32(rctl32)
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
struct TimerGroup32 extends array
static method create takes code c returns thistype
return A(c)
endmethod
method destroy takes nothing returns nothing
call DT32(this)
endmethod
method start takes nothing returns nothing
call A32(this)
endmethod
method stop takes nothing returns nothing
call SR32(this)
endmethod
endstruct
endlibrary
//TESH.scrollpos=272
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
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
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")
//! 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 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)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, 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
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//Thanks to anitarf and Vexorian @ wc3c.net for this library, it makes things easier.
// Edited by Maker
library IsTerrainWalkable initializer Init
globals
// this value is how far from a point the item may end up for the point to be considered pathable
private constant real MAX_RANGE=1.
// the following two variables are set to the position of the item after each pathing check
// that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
public real X=0.
public real Y=0.
private rect r
private item check
private item array hidden
private integer hiddenMax=0
endglobals
private function Init takes nothing returns nothing
set check=CreateItem('ciri',0,0)
call SetItemVisible(check,false)
set r=Rect(0.0,0.0,128.0,128.0)
endfunction
private function HideBothersomeItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set hidden[hiddenMax]=GetEnumItem()
call SetItemVisible(hidden[hiddenMax],false)
set hiddenMax=hiddenMax+1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
// first, hide any items in the area so they don't get in the way of our item
call MoveRectTo(r,x,y)
call EnumItemsInRect(r,null,function HideBothersomeItem)
// try to move the check item and get it's coordinates
call SetItemPosition(check,x,y)//this unhides the item...
set X=GetItemX(check)-x
set Y=GetItemY(check)-y
call SetItemVisible(check,false)//...so we must hide it again
// before returning, unhide any items that got hidden at the start
loop
exitwhen hiddenMax<=0
set hiddenMax=hiddenMax-1
call SetItemVisible(hidden[hiddenMax],true)
set hidden[hiddenMax]=null
endloop
// return pathability status
return X*X+Y*Y<MAX_RANGE
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library GetUnitCollision /* v2.0.1.0
*************************************************************************************
*
* Retrieves collision size for a unit (different from pathing map)
*
* Assumes collision will always be an integer
*
* 100% accurate to 1 decimal for collision sizes >= 5.1
*
*************************************************************************************
*
* */uses/*
*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
*************************************************************************************
*
* Functions
*
* function GetUnitCollision takes unit whichUnit returns real
*
************************************************************************************/
globals
private Table uc
endglobals
private function C takes unit u, real x, real y, integer i returns real
local real l = 0
local real h = 300
local real m = 150
local real nm
loop
if (IsUnitInRangeXY(u, x+m, y, 0)) then
set l = m
else
set h = m
endif
set nm = (l+h)/2
exitwhen nm+.001 > m and nm-.001 < m
set m = nm
endloop
set m = R2I(m*10)/10.
set uc.real[i] = m
return m
endfunction
function GetUnitCollision takes unit u returns real
local integer i = GetUnitTypeId(u)
if (uc.real.has(i)) then
return uc.real[i]
endif
return C(u, GetUnitX(u), GetUnitY(u), i)
endfunction
private module Initializer
private static method onInit takes nothing returns nothing
set uc = Table.create()
endmethod
endmodule
private struct init extends array
implement Initializer
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//============================================================================
// SpellEffectEvent
// - Version 1.1.0.0
//
// API
// ---
// RegisterSpellEffectEvent(integer abil, code onCast)
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
// Optional
// --------
// Table: hiveworkshop.com/forums/showthread.php?t=188084
//
library SpellEffectEvent requires RegisterPlayerUnitEvent, optional Table
//============================================================================
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable ht = InitHashtable()
endif
static method onCast takes nothing returns nothing
static if LIBRARY_Table then
call TriggerEvaluate(.tb.trigger[GetSpellAbilityId()])
else
call TriggerEvaluate(LoadTriggerHandle(.ht, 0, GetSpellAbilityId()))
endif
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set .tb = Table.create()
endif
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.onCast)
endmethod
endmodule
//============================================================================
private struct S extends array
implement M
endstruct
//============================================================================
function RegisterSpellEffectEvent takes integer abil, code onCast returns nothing
static if LIBRARY_Table then
if not S.tb.handle.has(abil) then
set S.tb.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(S.tb.trigger[abil], Filter(onCast))
else
if not HaveSavedHandle(S.ht, 0, abil) then
call SaveTriggerHandle(S.ht, 0, abil, CreateTrigger())
endif
call TriggerAddCondition(LoadTriggerHandle(S.ht, 0, abil), Filter(onCast))
endif
endfunction
endlibrary
//TESH.scrollpos=29
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v5.1.0.1
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must either
* return a boolean (false) or nothing. (Which is a Pro)
*
* Warning:
* --------
*
* - Don't use TriggerSleepAction inside registered code.
* - Don't destroy a trigger unless you really know what you're doing.
*
* API:
* ----
*
* - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
* - Registers code that will execute when an event fires.
* - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
* - Registers code that will execute when an event fires for a certain player.
* - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
* - Returns the trigger corresponding to ALL functions of a playerunitevent.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
if t[i] == null then
set t[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return t[GetHandleId(p)]
endfunction
endlibrary
//TESH.scrollpos=4
//TESH.alwaysfold=0
library SimError initializer init
//**************************************************************************************************
//*
//* SimError
//*
//* Mimic an interface error message
//* call SimError(ForPlayer, msg)
//* ForPlayer : The player to show the error
//* msg : The error
//*
//* To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************
//==================================================================================================
globals
private sound error
endglobals
//====================================================================================================
function SimError takes player ForPlayer, string msg returns nothing
set msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+msg+"|r"
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call DisplayTimedTextToPlayer( ForPlayer, 0.52, 0.96, 2.00, msg )
call StartSound( error )
endif
endfunction
private function init takes nothing returns nothing
set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Jump requires CTL, IsTerrainWalkable optional GetUnitCollision, Table
/*
* Jumping v. 1.0.0.4 by Maker
* -Does not pause units
* -Allows jumping in place
* -Real life physics equation for the jump arc
* -Supports collision with destructables and units
*
* function IsPointJumpable takes real x, real y returns boolean
* -Tells if the point is walkable
*
* static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
* - un = unit that jumps
* - x1, y1 = coordinates to jump to
* - maxZ = height of the arc
* - time = duration of the jump
* - gravity = well, duh
*
* You can catch the ending of the jump and register it for a trigger like this:
* call TriggerRegisterVariableEvent(trigger, "EVENT_JUMP_FINISH", EQUAL, 1)
*
* Import this library and required CTL and IsTerrainWalkable libraries from resources folder.
* I recommend also importing GetUnitCollision and Table libraries from resources folder.
*
* Credits
* CTL, GetUniCollision : Nestharus
* IsTerrainWalkable : anitarf and Vexorian
* Table : Bribe
*/
globals
// Tolerance distance for pathability
private constant real TOL = 1
// Minimum flying heigh for colliding with units. If set to 0 then won't collide with units.
private constant real U_COL_Z = 100
// Collision distance with units. Uses this if GetUnitCollision library is not used
private constant real U_COL_D = 96
// Collision distance with destructables. If set to 0 then won't collide with destructables.
private constant real D_COL_D = 96
// Maximum collision radius of units in the map. 196 for tier 3 Town Halls etc.
private constant real MAX_RAD = 196
// Moves the unit to nearest pathable point when landing
private constant boolean PATHING_LAND = false
// Is the turn speed locked when jumping
private constant boolean LOCK_FACING = false
private rect rct = Rect(0,0,0,0)
private group enu = CreateGroup()
private location loc = Location(0,0)
real EVENT_JUMP_FINISH = 0
unit EVENT_JUMP_UNIT = null
private real flh = 0
private boolean b = false
endglobals
private function GetLocZ takes real x, real y returns real
call MoveLocation(loc, x, y)
return GetLocationZ(loc)
endfunction
private function DestructableFilter takes nothing returns boolean
if GetDestructableLife(GetFilterDestructable()) > 0 and GetDestructableOccluderHeight(GetFilterDestructable()) > flh then
set b = true
endif
return false
endfunction
function IsPointJumpable takes real x, real y returns boolean
if not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then
return IsTerrainWalkable(x, y)
endif
return false
endfunction
struct Jump extends array
private static unit array u // Jumping unit
private static real array z0 // Location Z at jump origin point
private static real array sx // The x component of speed
private static real array sy // The y component of speed
private static real array t // Elapsed jump time
private static real array dt // How much "time" is passed during each loop
private static real array g // Gravity
private static real array sinZ // Z angle
private static real array endX // Targeted x
private static real array endY // Targeted y
private static real array tEnd // Jump end time
private static real array dfh // Default flying height
private static real array col // Collision size of the unit
private static real array pw // Propulsion window of the unit
implement CTL
local real x
local real y
local real z
local real fh
local unit un
implement CTLExpire
set x = GetUnitX(u[this]) + sx[this]
set y = GetUnitY(u[this]) + sy[this]
set z = GetLocZ(x, y) - z0[this]
set t[this] = t[this] + dt[this]
set fh = sinZ[this] * t[this] - g[this] * t[this] * t[this] / 2. - z + dfh[this]
if t[this] < tEnd[this] then
set b = false
if D_COL_D != 0 then
call SetRect(rct, x-D_COL_D, y-D_COL_D, x+D_COL_D, y+D_COL_D)
call EnumDestructablesInRect(rct, function DestructableFilter, null)
endif
if fh < U_COL_Z and not b then
set flh = fh
call GroupEnumUnitsInRange(enu, x, y, MAX_RAD, null)
call GroupRemoveUnit(enu, u[this])
loop
set un = FirstOfGroup(enu)
exitwhen un == null or b
if IsUnitInRange(un, u[this], col[this]) and not IsUnitType(un, UNIT_TYPE_DEAD) and not IsUnitType(un, UNIT_TYPE_FLYING) then
set b = true
set un = null
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
call GroupClear(enu)
else
call GroupRemoveUnit(enu, un)
endif
endloop
if not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
endif
elseif not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
else
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
endif
call SetUnitFlyHeight(u[this], fh, 0)
else
static if PATHING_LAND then
call SetUnitPosition(u[this], endX[this], endY[this])
else
call SetUnitX(u[this], endX[this])
call SetUnitY(u[this], endY[this])
endif
static if LOCK_FACING then
call SetUnitTurnSpeed(u[this], GetUnitDefaultTurnSpeed(u[this]) * bj_DEGTORAD)
endif
call SetUnitPropWindow(u[this], pw[this])
call SetUnitFlyHeight(u[this], dfh[this], 0)
set EVENT_JUMP_UNIT = u[this]
set EVENT_JUMP_FINISH = 0
set EVENT_JUMP_FINISH = 1
set EVENT_JUMP_UNIT = null
set u[this] = null
call destroy()
endif
implement CTLNull
implement CTLEnd
static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
local thistype this = create()
local real x0 = GetUnitX(un)
local real y0 = GetUnitY(un)
local real angle = Atan2(y1-y0, x1-x0)
local real dist = SquareRoot((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))
local real speed = dist/time * 0.031250000
local real z1 = GetLocZ(x1, y1)
set u[this] = un
set t[this] = 0
set endX[this] = x1
set endY[this] = y1
set g[this] = gravity
set z0[this] = GetLocZ(x0, y0)
set sx[this] = Cos(angle) * speed
set sy[this] = Sin(angle) * speed
set dfh[this] = GetUnitDefaultFlyHeight(un)
static if LIBRARY_GetUnitCollision then
set col[this] = GetUnitCollision(un)
else
set col[this] = U_COL_D
endif
if z0[this] < z1 then
set maxZ = maxZ + z1 - z0[this]
endif
set sinZ[this] = SquareRoot(maxZ*2*gravity)
set tEnd[this] = (sinZ[this]+SquareRoot(sinZ[this]*sinZ[this]-2*gravity*(z1-z0[this]))) / gravity
set dt[this] = 0.03125000*(tEnd[this]-t[this]) / time
static if LOCK_FACING then
call SetUnitTurnSpeed(un, 0)
endif
set pw[this] = GetUnitPropWindow(un)
call SetUnitPropWindow(un, 0)
if UnitAddAbility(un, 'Arav') and UnitRemoveAbility(un, 'Arav') then
endif
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=235
//TESH.alwaysfold=0
/**********************************************************
*
* Shadow Trail System v 1.1.1.5 by Maker
*
* Creates a trail of units behind the caster
*
* To use this system, copy this library,
* and then Table and CTL from Resources folder into your map.
*
* struct ShadowTrail
* static method add takes unit target, integer trailType, real duration returns thistype
* - target is the unit to attach the trail to
* - trailType, 0 = units are created repeatedly, 1 = uses the same units. Test which suits your spell better
* - duration is how long the trail lasts in seconds. 0 = lasts until the unit dies
*
* method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
* - use this only if the trail type is 1, TRAIL_TYPE_MOTION
* - must be used if trail type is 1
* - count is how many units are in the trail. More units -> longer trail
* - separation is the distance between units.
* - alphaFactor is the transparency multiplier between units. The further away the trail unit is from the main unit,
* the more transparent it will be. Use values between 0 and 1.
*
* method setInterval takes real timee returns nothing
* - only affects trail type 0, TRAIL_TYPE_STATIC
* - must be used with trail type 0
* - timee is how often new units are created
*
* method setFadeRate takes real rate, boolean flatMode returns nothing
* - rate is how quickly the units fade out after the trail is terminated
* - flatMode == true, units fade at a constant rate. Transparency = transparency - rate. Try values around 10. Higher value, faster fading.
* - flatMode == false, units fade out at multiplicative rate. Transparency = transparency*(1-rate). Use values around 0.9. Lower value, faster fading-
*
* method setAnimationSpeed takes real r returns nothing
* - how quickly the animations of the trail units are played. Default value is 1.
*
* method setAnimationIndex takes integer k returns nothing
* - what animation index the trail units play
*
* method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
* - sets the colouring of the trail units. Use values between 0 and 255.
* - if alpha is 0, the unit is completely transparent, 255 means it is fully visible
*
* method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
* - attaches a special effect to the trail units and the main unit
* - model = the path of a effect to attach
* - attachPoint is the attachment point
* - attachToShadows, if set to true will attach the effect to the trail units and the main unit, if
* set to false then the effect is only attached to the main unit
*
* method remove takes nothing returns nothing
* - destroys/removes/ends the trail
* - you can use this to remove the trail before the duration ends.
* - trails are automatically detroyed when the duration ends so there is no need to use this
*
* method setPlayerColor takes playercolor pColor returns nothing
* - Sets the player color of the dummy units
*
*
* Examples
*
* / --------- Moving Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_MOTION, 8) // Lasts 8 seconds
* call ST.setupMovingTrail(5, 20, 0.85) // This method affects only trail type 1, must use
* call ST.setAnimationIndex(2) // Recommended to set
* call ST.setFadeRate(10, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
*
* ---------------------------------------- /
*
*
* /--------- Static Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_STAITC, 8) // Lasts 8 seconds
* call ST.setInterval(0.06250) // This method affects only trail type 0, must use
* call ST.setAnimationIndex(6) // Recommended to set
* call ST.setFadeRate(7, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
* ----------------------------------------/
*
*
* Credits
* Bribe : Table
* Nestharus : CTL
*
***********************************************************/
library ShadowTrail requires Table, CTL
globals
// Does it use the team color of the owner of the main unit
private constant boolean COLOUR_OWNER = true
// Default player colour for shadows, used if COLOUR_OWNER is false
private constant playercolor PCOL = GetPlayerColor(Player(15))
constant integer TRAIL_TYPE_STATIC = 0
constant integer TRAIL_TYPE_MOTION = 1
// The image to use as shadows for the dummies. No need to change this as the image will be hidden
private constant string SHADOWPATH = "Textures\\white.blp"
private Table tab
private integer dc = 0 // Dummy count
private unit u
endglobals
// Credit to Deaod, edited by Maker
private function CreateUnitWithoutShadow takes player owner, integer uid, real x, real y, real facing, string shadowfile returns unit
local image i = CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // creates a dummy image
if GetHandleId(i) == -1 then // if the new shadow is invalid, abort, it can screw up the game
debug call BJDebugMsg("CreateUnitWithShadow: Invalid path for new shadow!") // it could also be caused by an imageType of 0, but thats a less common cause
return null // since the image is invalid, we dont need to destroy it
endif
call DestroyImage(i) // destroy the dummy.
set u = CreateUnit(owner, uid, x, y, facing) // create the unit. this also creates a new image which functions as the shadow of the unit. The shadow will use the ID of the dummy image.
call DestroyImage(i) // destroy the shadow of the unit
call CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // this creates the new shadow for the unit, note that i dont need to overwrite "i" as the id this image will get is predictable
call SetImageRenderAlways(i, false) // Hides the shadow
call SetImageColor(i, 0, 0, 0, 0) // Makes the shadow invisible
// no need to null "i", as images dont use ref-counting
return u
endfunction
// Fades out units over time
private struct Alpha extends array
private static unit array u // The unit
private static integer array aMax // Maximum alpha value
private static integer array a // Current alpha value
private static integer array r // Red
private static integer array g // Green
private static integer array b // Blue
private static integer array rf // Flat alpha rate
private static real array rs // Multiplicative alpha rate
private static boolean array bl // Is fading flat
private static boolean array rem // Is the unit removed in the end
private static boolean array sync // Prevents overlapping fade in and fade out
private static effect array e // Effect
implement CTLExpire
if tab.boolean[GetHandleId(u[this])] == sync[this] then
if bl[this] then
set a[this] = a[this] + rf[this]
else
set a[this] = R2I(a[this] +rs[this]*50 + (aMax[this] - a[this]) * rs[this])
endif
if a[this] > 0 and a[this] < aMax[this] then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], a[this])
else
if rem[this] then
if e[this] != null then
call DestroyEffect(e[this])
set e[this] = null
endif
call RemoveUnit(u[this])
set dc = dc - 1
if dc == 0 then
call tab.flush()
endif
elseif a[this] <= 0 then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], 0)
call ShowUnit(u[this], false)
else
call SetUnitVertexColor(u[this], r[this], g[this], b[this], aMax[this])
endif
set e[this] = null
set u[this] = null
call destroy()
endif
else
set e[this] = null
set u[this] = null
call destroy()
endif
implement CTLEnd
static method start takes unit un, integer rate1, real rate2, integer maxAlpha, integer red, integer grn, integer blu, integer alpha, boolean flatFade, boolean remove, boolean synch, effect eff returns nothing
local thistype this = create()
set u[this] = un
set a[this] = alpha
set aMax[this] = maxAlpha
set r[this] = red
set g[this] = grn
set b[this] = blu
set rf[this] = rate1
set rs[this] = rate2
set bl[this] = flatFade
set rem[this] = remove
set sync[this] = synch
set e[this] = eff
endmethod
endstruct
struct ShadowTrail extends array
private static unit array main // The unit with the trail
private static real array dur // How long the trail lasts
private static real array xm // X of main during the previous loop
private static real array ym // Y of main during the previous loop
private static real array ts // Animation speed, time scale
private static real array fd // follow distance
private static real array fp // How quickly the shadow fades, multiplicative
private static real array time // Calculates the interval time
private static real array interval // How often a new shadow is created
private static real array af // Alpha factor between moving shadows
private static real array d // Distance between moving shadows
private static integer array tc // Number of moving shadows
private static integer array fr // How quickly the shadow fades, flat
private static integer array r // Red of shadows
private static integer array g // Green of shadows
private static integer array b // Blue of shadows
private static integer array a // Transparency of shadows
private static integer array uid // Unit type if of shadows
private static integer array anim // Animation index to play for the shadows
private static integer array id // Shadow Trail type
private static string array eff // Special effect on copies
private static string array att // Special effect attach point
private static boolean array bo1 // True = flat fading time, false = multiplicative fading time
private static boolean array bo2 // Is the specified effect created on dummies also
private static boolean array h // Are moving trail units hidden
private static boolean array perm // Is the trail permanent
private static Table array ta // For shadow copy units
private static Table array tb // For shadow copy effects
private static playercolor array pc // Player colour of the shadows
implement CTL
local real x
local real y
local real an
local real f
local unit u
local unit s
local effect e = null // Passing unitialized variable to Alpha.start causes problems, null is good.
local integer i
local integer j
implement CTLExpire
if not IsUnitType(main[this], UNIT_TYPE_DEAD) and (dur[this] >= 0 or perm[this]) and GetUnitTypeId(main[this]) != 0 then
if not perm[this] then
set dur[this] = dur[this] - 0.031250
endif
set x = GetUnitX(main[this])
set y = GetUnitY(main[this])
if x != xm[this] or y != ym[this] then
if id[this] == TRAIL_TYPE_STATIC then // Is moving, static trail
set time[this] = time[this] + 0.031250
if time[this] >= interval[this] then
set u = CreateUnitWithoutShadow(Player(15), uid[this], x, y, GetUnitFacing(main[this]), SHADOWPATH)
set dc = dc + 1
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
call PauseUnit(u, true)
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitTimeScale(u, ts[this])
call SetUnitColor(u, pc[this])
call SetUnitVertexColor(u, r[this], g[this], b[this], a[this])
call SetUnitAnimationByIndex(u, anim[this])
call SetUnitFlyHeight(u, GetUnitFlyHeight(main[this]), 0)
if bo2[this] then
set e = AddSpecialEffectTarget(eff[this], u, att[this])
endif
set tab.boolean[GetHandleId(u)] = false
call Alpha.start(u, -fr[this], -fp[this], 255, r[this], g[this], b[this], a[this], bo1[this], true, false, e)
set time[this] = 0
set u = null
set e = null
endif
else // Is moving, moving trail (type 1)
set i = tc[this]
loop
exitwhen i == 0
set s = ta[this].unit[i]
set u = ta[this].unit[i-1]
set f = GetUnitFacing(u)
set an = (f+180)*bj_DEGTORAD
if IsUnitHidden(s) then // If units are hidden, they should be set to visible
set tab.boolean[GetHandleId(s)] = true
call Alpha.start(s, fr[this], fp[this], R2I(a[this]*Pow(af[this], i-1)), r[this], g[this], b[this], 0, bo1[this], false, true, e)
call ShowUnit(s, true)
call UnitRemoveAbility(s, 'Aloc') // Showing unit makes units with Locust selectable
call UnitAddAbility(s, 'Aloc') // Must apply Locust again
call SetUnitAnimationByIndex(s, anim[this])
endif
call SetUnitX(s, GetUnitX(u) + d[this] * Cos(an))
call SetUnitY(s, GetUnitY(u) + d[this] * Sin(an))
call SetUnitFacing(s, f)
call SetUnitFlyHeight(s, GetUnitFlyHeight(u), 0)
set i = i - 1
endloop
if h[this] then
set h[this] = false
endif
set s = null
set u = null
endif
elseif not h[this] and id[this] == TRAIL_TYPE_MOTION then // Is not moving, trail is visible, trail type 1
set i = tc[this]
loop
exitwhen i == 0
set j = R2I(a[this]*Pow(af[this], i-1))
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], false, false, null)
set i = i - 1
endloop
set h[this] = true
endif
set xm[this] = x
set ym[this] = y
else
set i = tc[this]
loop
exitwhen i == 0
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set j = R2I(a[this]*Pow(af[this], i-1)) - 1
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], true, false, null)
set i = i - 1
endloop
if tb[this].effect[0] != null then
call DestroyEffect(tb[this].effect[0])
endif
set main[this] = null
call ta[this].flush()
call tb[this].flush()
call destroy()
endif
implement CTLEnd
method remove takes nothing returns nothing
set dur[this] = 0
set perm[this] = false
endmethod
method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
local integer i = 1
set eff[this] = model
set att[this] = attachPoint
set bo2[this] = attachToShadows
if attachToShadows then
loop
exitwhen ta[this].unit[i] == null
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[i] = AddSpecialEffectTarget(model, ta[this].unit[i], attachPoint)
set i = i + 1
endloop
endif
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[0] = AddSpecialEffectTarget(model, main[this], attachPoint)
endmethod
method setPlayerColor takes playercolor pColor returns nothing
local integer i = 1
set pc[this] = pColor
loop
exitwhen ta[this].unit[i] == null
call SetUnitColor(ta[this].unit[i], pc[this])
set i = i + 1
endloop
endmethod
method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
local integer i = 1
set r[this] = red
set g[this] = grn
set b[this] = blu
set a[this] = alpha
loop
exitwhen ta[this].unit[i] == null
if id[this] == TRAIL_TYPE_STATIC or not h[this] then
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, R2I(a[this]*Pow(af[this], i-1)))
else
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, 0)
endif
set i = i + 1
endloop
endmethod
method setAnimationIndex takes integer k returns nothing
local integer i = 1
set anim[this] = k
loop
exitwhen ta[this].unit[i] == null
call SetUnitAnimationByIndex(ta[this].unit[i], k)
set i = i + 1
endloop
endmethod
method setAnimationSpeed takes real r returns nothing
local integer i = 1
set ts[this] = r
loop
exitwhen ta[this].unit[i] == null
call SetUnitTimeScale(ta[this].unit[i], r)
set i = i + 1
endloop
endmethod
method setFadeRate takes real rate, boolean flatMode returns nothing
if flatMode then
set fr[this] = R2I(rate)
else
set fp[this] = 1-rate
endif
set bo1[this] = flatMode
endmethod
method setInterval takes real timee returns nothing
set time[this] = 0
set interval[this] = timee
endmethod
method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
local integer i
local unit u
local real x = GetUnitX(main[this])
local real y = GetUnitY(main[this])
local real f = GetUnitFacing(main[this])
if id[this] == TRAIL_TYPE_MOTION then
if count > 0 then
set d[this] = separation
set tc[this] = count
set h[this] = false
set af[this] = alphaFactor
set xm[this] = GetUnitX(main[this])
set ym[this] = GetUnitY(main[this])
set ta[this] = Table.create()
set i = 1
loop
set u = CreateUnitWithoutShadow(Player(15), uid[this], x, y, f, SHADOWPATH)
call ShowUnit(u, false)
call SetUnitVertexColor(u, r[this], g[this], b[this], 0)
set dc = dc + 1
call SetUnitColor(u, pc[this])
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
call PauseUnit(u, true)
set ta[this].unit[i] = u
exitwhen i == count
set i = i + 1
endloop
set h[this] = true
set ta[this].unit[0] = main[this]
set u = null
else
debug call BJDebugMsg("Tried to use setupMovingTrail method with invalid dummy unit count. (Less than 1)")
endif
debug else
debug call BJDebugMsg("Tried to use setupMovingTrail method with instance that has a wrong shadow trail type.")
endif
endmethod
static method add takes unit target, integer trailType, real duration returns thistype
local thistype this = 0
if trailType == TRAIL_TYPE_MOTION or trailType == TRAIL_TYPE_STATIC then
set this = create()
set main[this] = target
set uid[this] = GetUnitTypeId(target)
set id[this] = trailType
set dur[this] = duration
set tc[this] = 0
set perm[this] = duration == 0
call this.setColor(255, 255, 255, 255)
call this.setAnimationIndex(0)
call this.setAnimationSpeed(1)
call this.setFadeRate(0, true)
call this.setFadeRate(0, false)
call this.setInterval(0.2)
call this.setEffect(null, null, false)
static if COLOUR_OWNER then
set pc[this] = GetPlayerColor(GetOwningPlayer(target))
else
set pc[this] = PCOL
endif
debug else
debug call BJDebugMsg("Invalid shadow trail type.")
endif
return this
endmethod
private static method onInit takes nothing returns nothing
set tab = Table.create()
endmethod
endstruct
endlibrary
//TESH.scrollpos=48
//TESH.alwaysfold=0
library Jump requires CTL, IsTerrainWalkable optional GetUnitCollision, Table
/*
* Jumping v. 1.0.0.3 by Maker
* -Does not pause units
* -Allows jumping in place
* -Real life physics equation for the jump arc
* -Supports collision with destructables and units
*
* function IsPointJumpable takes real x, real y returns boolean
* -Tells if the point is walkable
*
* static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
* - un = unit that jumps
* - x1, y1 = coordinates to jump to
* - maxZ = height of the arc
* - time = duration of the jump
* - gravity = well, duh
*
* You can catch the ending of the jump and register it for a trigger like this:
* call TriggerRegisterVariableEvent(trigger, "EVENT_JUMP_FINISH", EQUAL, 1)
*
* Import this library and require CTL and IsTerrainWalkable libraries from resources folder.
* I recommend also importing GetUnitCollision and Table libraries from resources folder.
*
* Credits
* CTL, GetUniCollision : Nestharus
* IsTerrainWalkable : anitarf and Vexorian
* Table : Bribe
*/
globals
// Tolerance distance for pathability
private constant real TOL = 1
// Minimum flying heigh for colliding with units. If set to 0 then won't collide with units.
private constant real U_COL_Z = 100
// Collision distance with units. Uses this if GetUnitCollision library is not used
private constant real U_COL_D = 96
// Collision distance with destructables. If set to 0 then won't collide with destructables.
private constant real D_COL_D = 96
// Maximum collision radius of units in the map. 196 for tier 3 Town Halls etc.
private constant real MAX_RAD = 196
// Moves the unit to nearest pathable point when landing
private constant boolean PATHING_LAND = false
// Is the turn speed locked when jumping
private constant boolean LOCK_FACING = false
private rect rct = Rect(0, 0, 0, 0)
private group enu = CreateGroup()
private location loc = Location(0,0)
real EVENT_JUMP_FINISH = 0
unit EVENT_JUMP_UNIT = null
private real flh = 0
private boolean b = false
endglobals
private function GetLocZ takes real x, real y returns real
call MoveLocation(loc, x, y)
return GetLocationZ(loc)
endfunction
private function DestructableFilter takes nothing returns boolean
if GetDestructableLife(GetFilterDestructable()) > 0 and GetDestructableOccluderHeight(GetFilterDestructable()) > flh then
set b = true
endif
return false
endfunction
function IsPointJumpable takes real x, real y returns boolean
if not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then
return IsTerrainWalkable(x, y)
endif
return false
endfunction
struct Jump extends array
private static unit array u // Jumping unit
private static real array z0 // Location Z at jump origin point
private static real array sx // The x component of speed
private static real array sy // The y component of speed
private static real array t // Elapsed jump time
private static real array dt // How much "time" is passed during each loop
private static real array g // Gravity
private static real array sinZ // Z angle
private static real array endX // Targeted x
private static real array endY // Targeted y
private static real array tEnd // Jump end time
private static real array dfh // Default flying height
private static real array col // Collision size of the unit
implement CTL
local real x
local real y
local real z
local real fh
local unit un
implement CTLExpire
set x = GetUnitX(u[this]) + sx[this]
set y = GetUnitY(u[this]) + sy[this]
set z = GetLocZ(x, y) - z0[this]
set t[this] = t[this] + dt[this]
set fh = sinZ[this] * t[this] - g[this] * t[this] * t[this] / 2. - z + dfh[this]
if t[this] < tEnd[this] then
set b = false
if D_COL_D != 0 then
call SetRect(rct, x-D_COL_D, y-D_COL_D, x+D_COL_D, y+D_COL_D)
call EnumDestructablesInRect(rct, function DestructableFilter, null)
endif
if fh < U_COL_Z and not b then
set flh = fh
call GroupEnumUnitsInRange(enu, x, y, MAX_RAD, null)
call GroupRemoveUnit(enu, u[this])
loop
set un = FirstOfGroup(enu)
exitwhen un == null or b
if IsUnitInRangeXY(un, x, y, col[this]) and not IsUnitType(un, UNIT_TYPE_DEAD) and not IsUnitType(un, UNIT_TYPE_FLYING) then
set b = true
set un = null
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
call GroupClear(enu)
else
call GroupRemoveUnit(enu, un)
endif
endloop
if not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
endif
elseif not b then
call SetUnitX(u[this], x)
call SetUnitY(u[this], y)
else
set sx[this] = 0
set sy[this] = 0
set endX[this] = GetUnitX(u[this])
set endY[this] = GetUnitY(u[this])
endif
call SetUnitFlyHeight(u[this], fh, 0)
else
static if PATHING_LAND then
call SetUnitPosition(u[this], endX[this], endY[this])
else
call SetUnitX(u[this], endX[this])
call SetUnitY(u[this], endY[this])
endif
static if LOCK_FACING then
call SetUnitTurnSpeed(u[this], GetUnitDefaultTurnSpeed(u[this]) * bj_DEGTORAD)
endif
call SetUnitPropWindow(u[this], GetUnitDefaultPropWindow(u[this]))
call SetUnitFlyHeight(u[this], dfh[this], 0)
set EVENT_JUMP_UNIT = u[this]
set EVENT_JUMP_FINISH = 0
set EVENT_JUMP_FINISH = 1
set EVENT_JUMP_UNIT = null
set u[this] = null
call destroy()
endif
implement CTLNull
implement CTLEnd
static method start takes unit un, real x1, real y1, real maxZ, real time, real gravity returns thistype
local thistype this = create()
local real x0 = GetUnitX(un)
local real y0 = GetUnitY(un)
local real angle = Atan2(y1-y0, x1-x0)
local real dist = SquareRoot((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0))
local real speed = dist/time * 0.031250000
local real z1 = GetLocZ(x1, y1)
set u[this] = un
set t[this] = 0
set endX[this] = x1
set endY[this] = y1
set g[this] = gravity
set z0[this] = GetLocZ(x0, y0)
set sx[this] = Cos(angle) * speed
set sy[this] = Sin(angle) * speed
set dfh[this] = GetUnitDefaultFlyHeight(un)
if LIBRARY_GetUnitCollision then
set col[this] = GetUnitCollision(un)
else
set col[this] = U_COL_D
endif
if z0[this] < z1 then
set maxZ = maxZ + z1 - z0[this]
endif
set sinZ[this] = SquareRoot(maxZ*2*gravity)
set tEnd[this] = (sinZ[this]+SquareRoot(sinZ[this]*sinZ[this]-2*gravity*(z1-z0[this]))) / gravity
set dt[this] = 0.03125000*(tEnd[this]-t[this]) / time
static if LOCK_FACING then
call SetUnitTurnSpeed(un, 0)
endif
call SetUnitPropWindow(un, 0)
if UnitAddAbility(un, 'Arav') and UnitRemoveAbility(un, 'Arav') then
endif
return this
endmethod
endstruct
endlibrary
//TESH.scrollpos=249
//TESH.alwaysfold=0
/**********************************************************
*
* Shadow Trail System v 1.1.1.5 by Maker
*
* Creates a trail of units behind the caster
*
* To use this system, copy this library,
* and then Table and CTL from Resources folder into your map.
*
* struct ShadowTrail
* static method add takes unit target, integer trailType, real duration returns thistype
* - target is the unit to attach the trail to
* - trailType, 0 = units are created repeatedly, 1 = uses the same units. Test which suits your spell better
* - duration is how long the trail lasts in seconds. 0 = lasts until the unit dies
*
* method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
* - use this only if the trail type is 1, TRAIL_TYPE_MOTION
* - must be used if trail type is 1
* - count is how many units are in the trail. More units -> longer trail
* - separation is the distance between units.
* - alphaFactor is the transparency multiplier between units. The further away the trail unit is from the main unit,
* the more transparent it will be. Use values between 0 and 1.
*
* method setInterval takes real timee returns nothing
* - only affects trail type 0, TRAIL_TYPE_STATIC
* - must be used with trail type 0
* - timee is how often new units are created
*
* method setFadeRate takes real rate, boolean flatMode returns nothing
* - rate is how quickly the units fade out after the trail is terminated
* - flatMode == true, units fade at a constant rate. Transparency = transparency - rate. Try values around 10. Higher value, faster fading.
* - flatMode == false, units fade out at multiplicative rate. Transparency = transparency*(1-rate). Use values around 0.9. Lower value, faster fading-
*
* method setAnimationSpeed takes real r returns nothing
* - how quickly the animations of the trail units are played. Default value is 1.
*
* method setAnimationIndex takes integer k returns nothing
* - what animation index the trail units play
*
* method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
* - sets the colouring of the trail units. Use values between 0 and 255.
* - if alpha is 0, the unit is completely transparent, 255 means it is fully visible
*
* method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
* - attaches a special effect to the trail units and the main unit
* - model = the path of a effect to attach
* - attachPoint is the attachment point
* - attachToShadows, if set to true will attach the effect to the trail units and the main unit, if
* set to false then the effect is only attached to the main unit
*
* method remove takes nothing returns nothing
* - destroys/removes/ends the trail
* - you can use this to remove the trail before the duration ends.
* - trails are automatically detroyed when the duration ends so there is no need to use this
*
* method setPlayerColor takes playercolor pColor returns nothing
* - Sets the player color of the dummy units
*
*
* Examples
*
* / --------- Moving Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_MOTION, 8) // Lasts 8 seconds
* call ST.setupMovingTrail(5, 20, 0.85) // This method affects only trail type 1, must use
* call ST.setAnimationIndex(2) // Recommended to set
* call ST.setFadeRate(10, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
*
* ---------------------------------------- /
*
*
* /--------- Static Shadow Trail ----------
* local ShadowTrail ST = ShadowTrail.add(GetTriggerUnit(), TRAIL_TYPE_STAITC, 8) // Lasts 8 seconds
* call ST.setInterval(0.06250) // This method affects only trail type 0, must use
* call ST.setAnimationIndex(6) // Recommended to set
* call ST.setFadeRate(7, true) // Optional method call, recommended
* call ST.setAnimationSpeed(1.0) // Optional method call
* call ST.setColor(200, 200, 200, 200) // Optional method call
* call ST.setEffect(EFF, "chest", false) // Optional, EFF = variable holding the model path
* ----------------------------------------/
*
*
* Credits
* Bribe : Table
* Nestharus : CTL
*
***********************************************************/
library ShadowTrail requires Table, CTL
globals
// Does it use the team color of the owner of the main unit
private constant boolean COLOUR_OWNER = true
// Default player colour for shadows, used if COLOUR_OWNER is false
private constant playercolor PCOL = GetPlayerColor(Player(15))
// Dummies are created here and then isntantly placed at the hero's position
private constant real CREATE_X = 0
private constant real CREATE_Y = 0
private constant player OWNER = Player(PLAYER_NEUTRAL_PASSIVE) // 15
private constant player SIGHT = Player(bj_PLAYER_NEUTRAL_VICTIM) // 13, 14 = EXTRA
constant integer TRAIL_TYPE_STATIC = 0
constant integer TRAIL_TYPE_MOTION = 1
// The image to use as shadows for the dummies. No need to change this as the image will be hidden
private constant string SHADOWPATH = "Textures\\white.blp"
private Table tab
private integer dc = 0 // Dummy count
private unit ug
endglobals
// Credit to Deaod, edited by Maker
private function CreateUnitWithoutShadow takes integer uid, real facing, string shadowfile returns unit
local image i = CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // creates a dummy image
if GetHandleId(i) == -1 then // if the new shadow is invalid, abort, it can screw up the game
debug call BJDebugMsg("CreateUnitWithShadow: Invalid path for new shadow!") // it could also be caused by an imageType of 0, but thats a less common cause
return null // since the image is invalid, we dont need to destroy it
endif
call DestroyImage(i) // destroy the dummy.
set ug = CreateUnit(OWNER, uid, CREATE_X, CREATE_Y, facing) // create the unit. this also creates a new image which functions as the shadow of the unit. The shadow will use the ID of the dummy image.
call UnitAddAbility(ug, 'Aloc')
call DestroyImage(i) // destroy the shadow of the unit
call CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // this creates the new shadow for the unit, note that i dont need to overwrite "i" as the id this image will get is predictable
call SetImageRenderAlways(i, false) // Hides the shadow
call SetImageColor(i, 0, 0, 0, 0) // Makes the shadow invisible
// no need to null "i", as images dont use ref-counting
return ug
endfunction
// Fades out units over time
private struct Alpha extends array
private static unit array u // The unit
private static integer array aMax // Maximum alpha value
private static integer array a // Current alpha value
private static integer array r // Red
private static integer array g // Green
private static integer array b // Blue
private static integer array rf // Flat alpha rate
private static real array rs // Multiplicative alpha rate
private static boolean array bl // Is fading flat
private static boolean array rem // Is the unit removed in the end
private static boolean array sync // Prevents overlapping fade in and fade out
private static effect array e // Effect
implement CTLExpire
if tab.boolean[GetHandleId(u[this])] == sync[this] then
if bl[this] then
set a[this] = a[this] + rf[this]
else
set a[this] = R2I(a[this] +rs[this]*50 + (aMax[this] - a[this]) * rs[this])
endif
if a[this] > 0 and a[this] < aMax[this] then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], a[this])
else
if rem[this] then
if e[this] != null then
call DestroyEffect(e[this])
set e[this] = null
endif
call RemoveUnit(u[this])
set dc = dc - 1
if dc == 0 then
call tab.flush()
endif
elseif a[this] <= 0 then
call SetUnitVertexColor(u[this], r[this], g[this], b[this], 0)
//call ShowUnit(u[this], false)
else
call SetUnitVertexColor(u[this], r[this], g[this], b[this], aMax[this])
endif
set e[this] = null
set u[this] = null
call destroy()
endif
else
set e[this] = null
set u[this] = null
call destroy()
endif
implement CTLEnd
static method start takes unit un, integer rate1, real rate2, integer maxAlpha, integer red, integer grn, integer blu, integer alpha, boolean flatFade, boolean remove, boolean synch, effect eff returns nothing
local thistype this = create()
set u[this] = un
set a[this] = alpha
set aMax[this] = maxAlpha
set r[this] = red
set g[this] = grn
set b[this] = blu
set rf[this] = rate1
set rs[this] = rate2
set bl[this] = flatFade
set rem[this] = remove
set sync[this] = synch
set e[this] = eff
endmethod
endstruct
struct ShadowTrail extends array
private static unit array main // The unit with the trail
private static real array dur // How long the trail lasts
private static real array xm // X of main during the previous loop
private static real array ym // Y of main during the previous loop
private static real array ts // Animation speed, time scale
private static real array fd // follow distance
private static real array fp // How quickly the shadow fades, multiplicative
private static real array time // Calculates the interval time
private static real array interval // How often a new shadow is created
private static real array af // Alpha factor between moving shadows
private static real array d // Distance between moving shadows
private static integer array tc // Number of moving shadows
private static integer array fr // How quickly the shadow fades, flat
private static integer array r // Red of shadows
private static integer array g // Green of shadows
private static integer array b // Blue of shadows
private static integer array a // Transparency of shadows
private static integer array uid // Unit type if of shadows
private static integer array anim // Animation index to play for the shadows
private static integer array id // Shadow Trail type
private static string array eff // Special effect on copies
private static string array att // Special effect attach point
private static boolean array bo1 // True = flat fading time, false = multiplicative fading time
private static boolean array bo2 // Is the specified effect created on dummies also
private static boolean array h // Are moving trail units hidden
private static boolean array perm // Is the trail permanent
private static Table array ta // For shadow copy units
private static Table array tb // For shadow copy effects
private static playercolor array pc // Player colour of the shadows
implement CTL
local real x
local real y
local real an
local real f
local unit u
local unit s
local effect e = null // Passing unitialized variable to Alpha.start causes problems, null is good.
local integer i
local integer j
implement CTLExpire
if not IsUnitType(main[this], UNIT_TYPE_DEAD) and (dur[this] >= 0 or perm[this]) and GetUnitTypeId(main[this]) != 0 then
if not perm[this] then
set dur[this] = dur[this] - 0.031250
endif
set x = GetUnitX(main[this])
set y = GetUnitY(main[this])
if x != xm[this] or y != ym[this] then
if id[this] == TRAIL_TYPE_STATIC then // Is moving, static trail
set time[this] = time[this] + 0.031250
if time[this] >= interval[this] then
set u = CreateUnitWithoutShadow(uid[this], GetUnitFacing(main[this]), SHADOWPATH)
set dc = dc + 1
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
//call UnitRemoveAbility(u, 'Amov')
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitTimeScale(u, ts[this])
call SetUnitColor(u, pc[this])
call SetUnitVertexColor(u, r[this], g[this], b[this], a[this])
call SetUnitAnimationByIndex(u, anim[this])
call SetUnitFlyHeight(u, GetUnitFlyHeight(main[this]), 0)
call SetUnitTurnSpeed(u, 1000)
if bo2[this] then
set e = AddSpecialEffectTarget(eff[this], u, att[this])
endif
set tab.boolean[GetHandleId(u)] = false
call Alpha.start(u, -fr[this], -fp[this], 255, r[this], g[this], b[this], a[this], bo1[this], true, false, e)
set time[this] = 0
set u = null
set e = null
endif
else // Is moving, moving trail (type 1)
set i = tc[this]
loop
exitwhen i == 0
set s = ta[this].unit[i]
set u = ta[this].unit[i-1]
set f = GetUnitFacing(u)
set an = (f+180)*bj_DEGTORAD
if h[this] then // If units are hidden, they should be set to visible
set tab.boolean[GetHandleId(s)] = true
call Alpha.start(s, fr[this], fp[this], R2I(a[this]*Pow(af[this], i-1)), r[this], g[this], b[this], 0, bo1[this], false, true, e)
call SetUnitAnimationByIndex(s, anim[this])
endif
call SetUnitX(s, GetUnitX(u) + d[this] * Cos(an))
call SetUnitY(s, GetUnitY(u) + d[this] * Sin(an))
call SetUnitFacing(s, f)
call SetUnitFlyHeight(s, GetUnitFlyHeight(u), 0)
set i = i - 1
endloop
if h[this] then
set h[this] = false
endif
set s = null
set u = null
endif
elseif not h[this] and id[this] == TRAIL_TYPE_MOTION then // Is not moving, trail is visible, trail type 1
set i = tc[this]
loop
exitwhen i == 0
set j = R2I(a[this]*Pow(af[this], i-1))
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], false, false, null)
set i = i - 1
endloop
set h[this] = true
endif
set xm[this] = x
set ym[this] = y
else
set i = tc[this]
loop
exitwhen i == 0
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set j = R2I(a[this]*Pow(af[this], i-1)) - 1
set tab.boolean[GetHandleId(ta[this].unit[i])] = false
call Alpha.start(ta[this].unit[i], -fr[this], -fp[this], j, r[this], g[this], b[this], j, bo1[this], true, false, null)
set i = i - 1
endloop
if tb[this].effect[0] != null then
call DestroyEffect(tb[this].effect[0])
endif
set main[this] = null
call ta[this].flush()
call tb[this].flush()
call destroy()
endif
implement CTLEnd
method remove takes nothing returns nothing
set dur[this] = 0
set perm[this] = false
endmethod
method setEffect takes string model, string attachPoint, boolean attachToShadows returns nothing
local integer i = 1
set eff[this] = model
set att[this] = attachPoint
set bo2[this] = attachToShadows
if attachToShadows then
loop
exitwhen ta[this].unit[i] == null
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[i] = AddSpecialEffectTarget(model, ta[this].unit[i], attachPoint)
set i = i + 1
endloop
endif
if tb[this].effect[i] != null then
call DestroyEffect(tb[this].effect[i])
endif
set tb[this].effect[0] = AddSpecialEffectTarget(model, main[this], attachPoint)
endmethod
method setPlayerColor takes playercolor pColor returns nothing
local integer i = 1
set pc[this] = pColor
loop
exitwhen ta[this].unit[i] == null
call SetUnitColor(ta[this].unit[i], pc[this])
set i = i + 1
endloop
endmethod
method setColor takes integer red, integer grn, integer blu, integer alpha returns nothing
local integer i = 1
set r[this] = red
set g[this] = grn
set b[this] = blu
set a[this] = alpha
loop
exitwhen ta[this].unit[i] == null
if id[this] == TRAIL_TYPE_STATIC or not h[this] then
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, R2I(a[this]*Pow(af[this], i-1)))
else
call SetUnitVertexColor(ta[this].unit[i], red, grn, blu, 0)
endif
set i = i + 1
endloop
endmethod
method setAnimationIndex takes integer k returns nothing
local integer i = 1
set anim[this] = k
loop
exitwhen ta[this].unit[i] == null
call SetUnitAnimationByIndex(ta[this].unit[i], k)
set i = i + 1
endloop
endmethod
method setAnimationSpeed takes real r returns nothing
local integer i = 1
set ts[this] = r
loop
exitwhen ta[this].unit[i] == null
call SetUnitTimeScale(ta[this].unit[i], r)
set i = i + 1
endloop
endmethod
method setFadeRate takes real rate, boolean flatMode returns nothing
if flatMode then
set fr[this] = R2I(rate)
else
set fp[this] = 1-rate
endif
set bo1[this] = flatMode
endmethod
method setInterval takes real timee returns nothing
set time[this] = 0
set interval[this] = timee
endmethod
method setupMovingTrail takes integer count, real separation, real alphaFactor returns nothing
local integer i
local unit u
local real x = GetUnitX(main[this])
local real y = GetUnitY(main[this])
local real f = GetUnitFacing(main[this])
if id[this] == TRAIL_TYPE_MOTION then
if count > 0 then
set d[this] = separation
set tc[this] = count
set h[this] = false
set af[this] = alphaFactor
set xm[this] = GetUnitX(main[this])
set ym[this] = GetUnitY(main[this])
set ta[this] = Table.create()
set i = 1
loop
set u = CreateUnitWithoutShadow(uid[this], f, SHADOWPATH)
call SetUnitVertexColor(u, r[this], g[this], b[this], 0)
set dc = dc + 1
call SetUnitColor(u, pc[this])
call UnitAddAbility(u, 'Arav')
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Amov')
call SetUnitUseFood(u, false)
call SetUnitX(u, x)
call SetUnitY(u, y)
set ta[this].unit[i] = u
exitwhen i == count
set i = i + 1
endloop
set h[this] = true
set ta[this].unit[0] = main[this]
set u = null
else
debug call BJDebugMsg("Tried to use setupMovingTrail method with invalid dummy unit count. (Less than 1)")
endif
debug else
debug call BJDebugMsg("Tried to use setupMovingTrail method with instance that has a wrong shadow trail type.")
endif
endmethod
static method add takes unit target, integer trailType, real duration returns thistype
local thistype this = 0
if trailType == TRAIL_TYPE_MOTION or trailType == TRAIL_TYPE_STATIC then
set this = create()
set main[this] = target
set uid[this] = GetUnitTypeId(target)
set id[this] = trailType
set dur[this] = duration
set tc[this] = 0
set perm[this] = duration == 0
call this.setColor(255, 255, 255, 255)
call this.setAnimationIndex(0)
call this.setAnimationSpeed(1)
call this.setFadeRate(0, true)
call this.setFadeRate(0, false)
call this.setInterval(0.2)
call this.setEffect(null, null, false)
static if COLOUR_OWNER then
set pc[this] = GetPlayerColor(GetOwningPlayer(target))
else
set pc[this] = PCOL
endif
debug else
debug call BJDebugMsg("Invalid shadow trail type.")
endif
return this
endmethod
private static method onInit takes nothing returns nothing
set tab = Table.create()
endmethod
endstruct
endlibrary