Name | Type | is_array | initial_value |
AttackedUnit | unit | Yes | |
AttackingUnit | unit | Yes | |
Combat_Angle | real | Yes | |
Combat_AttackedPosition | location | Yes | |
Combat_AttackingPosition | location | Yes | |
Combat_Chance | integer | Yes | |
CombatStance_Boolean | boolean | Yes | |
FistCrusher_Caster | unit | Yes | |
FistCrusher_Damage | integer | Yes | |
FistCrusher_EffectChance | integer | Yes | |
FistCrusher_Target | unit | Yes | |
RagingThrow_Boolean | boolean | Yes | |
RagingThrow_Caster | unit | Yes | |
RagingThrow_Damage | integer | Yes | |
RagingThrow_EffectChance | integer | Yes | |
RagingThrow_Target | unit | Yes | |
RockSpinner_Boolean | boolean | Yes | |
RockSpinner_Caster | unit | Yes | |
RockSpinner_Damage | integer | Yes | |
RockSpinner_Target | unit | Yes | |
SwiftSlam_Boolean | boolean | Yes | |
SwiftSlam_Caster | unit | Yes | |
SwiftSlam_Damage | integer | Yes | |
SwiftSlam_Target | unit | Yes |
//TESH.scrollpos=0
//TESH.alwaysfold=0
//***************************************************************************************************************
//* *
//* K N O C K B A C K *
//* Actual Code *
//* v1.02 *
//* *
//* By: Rising_Dusk *
//* *
//***************************************************************************************************************
library Knockback initializer KnockbackSystemInit
globals
//*********************************************************
//* These are the configuration constants for the system
//*
//* EffectLocation: Where on the unit the effect attaches
//* EffectPath_Water: What special effect to attach over water
//* EffectPath_Ground: What special effect to attach over ground
//* Dest_Radius: Radius around which destructs die
//*
private constant string EffectLocation = "origin"
private constant string EffectPath_Water = "MDX\\KnockbackWater.mdx"
private constant string EffectPath_Ground = "MDX\\KnockbackDust.mdx"
private constant real Dest_Radius = 180.
//*********************************************************
//* These are static constants used by the system and shouldn't be changed
//*
//* Timer: The timer that runs all of the effects for the spell
//* Counter: The counter for how many KB instances exist
//* Knockers: The array of all struct instances that exist
//* TimerInterval: The interval for the timer that gets run
//* Boolexpr: The boolean expression used for finding destructs
//* DestRect: The rect used to check for destructables
//*
private timer Timer = CreateTimer()
private integer Counter = 0
private integer array Knockers
private constant real TimerInterval = 0.05
private boolexpr Boolexpr
private rect DestRect = Rect(0,0,1,1)
//* Temporary variables used by the system
private real Temp1
private real Temp2
endglobals
//*********************************************************
//* Functions for the destructable destruction
private function KillDests_Check takes nothing returns boolean
local real x = GetDestructableX(GetFilterDestructable())
local real y = GetDestructableY(GetFilterDestructable())
return (Temp1-x)*(Temp1-x) + (Temp2-y)*(Temp2-y) <= Dest_Radius*Dest_Radius
endfunction
private function KillDests takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
endfunction
//*********************************************************
//* Struct for the system, I recommend leaving it alone
private struct knocker
unit Target
effect KBEffect
integer FXMode
boolean KillDest
real Decrement
real Speed
real SinA
real CosA
public method checkterrain takes knocker n returns integer
local real x = GetUnitX(n.Target)
local real y = GetUnitY(n.Target)
if IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) then
return 1
elseif not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) then
return 2
endif
return 0
endmethod
static method create takes unit targ, real angle, real startspeed, real decrement, boolean killDestructables returns knocker
local knocker n = knocker.allocate()
set n.Target = targ
set n.FXMode = n.checkterrain(n)
if n.FXMode == 1 then
set n.KBEffect = AddSpecialEffectTarget(EffectPath_Ground, n.Target, EffectLocation)
elseif n.FXMode == 2 then
set n.KBEffect = AddSpecialEffectTarget(EffectPath_Water, n.Target, EffectLocation)
debug else
debug call BJDebugMsg("System Error (On Create): Unknown Terrain Type")
endif
set n.KillDest = killDestructables
set n.Decrement = decrement
set n.Speed = startspeed
set n.SinA = Sin(angle)
set n.CosA = Cos(angle)
return n
endmethod
private method onDestroy takes nothing returns nothing
call DestroyEffect(this.KBEffect)
endmethod
endstruct
//******************************************************************************
//* The system code itself.
private function Update takes nothing returns nothing
local unit u
local rect r
local knocker n = 0
local integer i = Counter - 1
local integer j = 0
local integer mode
local real speed
local real xi
local real yi
local real xf
local real yf
loop
exitwhen i < 0
set n = Knockers[i]
set u = n.Target
set mode = n.FXMode
set xi = GetUnitX(u)
set yi = GetUnitY(u)
if n.Speed <= 0 then
call n.destroy()
set Counter = Counter - 1
if Counter < 0 then
call PauseTimer(Timer)
set Counter = 0
else
set Knockers[i] = Knockers[Counter]
endif
else
set xf = xi + (n.Speed) * n.CosA
set yf = yi + (n.Speed) * n.SinA
call SetUnitPosition(u, xf, yf)
set n.FXMode = n.checkterrain(n)
if n.FXMode == 1 and mode == 2 then
call DestroyEffect(n.KBEffect)
set n.KBEffect = AddSpecialEffectTarget(EffectPath_Ground, n.Target, EffectLocation)
elseif n.FXMode == 2 and mode == 1 then
call DestroyEffect(n.KBEffect)
set n.KBEffect = AddSpecialEffectTarget(EffectPath_Water, n.Target, EffectLocation)
debug elseif n.FXMode == 0 then
debug call BJDebugMsg("System Error (In Update): Unknown Terrain Type")
endif
set n.Speed = n.Speed - n.Decrement
//* Destroy destructables if desired
if n.KillDest then
set Temp1 = GetUnitX(u)
set Temp2 = GetUnitY(u)
call SetRect(DestRect, xf-Dest_Radius, yf-Dest_Radius, xf+Dest_Radius, yf+Dest_Radius)
call EnumDestructablesInRect(DestRect, Boolexpr, function KillDests)
endif
endif
set i = i - 1
endloop
set u = null
endfunction
function KnockbackStop takes unit targ returns boolean
local integer i = Counter - 1
local knocker n = 0
local boolean b = false
loop
exitwhen i < 0
set n = Knockers[i]
if n.Target == targ then
call n.destroy(n)
set Counter = Counter - 1
if Counter < 0 then
call PauseTimer(Timer)
set Counter = 0
else
set Knockers[i] = Knockers[Counter]
endif
set b = true
endif
set i = i - 1
endloop
return b
endfunction
function IsKnockedBack takes unit targ returns boolean
local integer i = Counter - 1
local knocker n = 0
loop
exitwhen i < 0
set n = Knockers[i]
if n.Target == targ then
return true
endif
set i = i - 1
endloop
return false
endfunction
function KnockbackTarget takes unit targ, real angle, real startspeed, real decrement, boolean killDestructables returns boolean
local knocker n = 0
//* Protect users from themselves
if decrement == 0 or startspeed == 0 or targ == null then
debug call BJDebugMsg("System Error: Invalid Starting Conditions")
return false
endif
set n = knocker.create(targ, bj_DEGTORAD*angle, startspeed*TimerInterval, decrement*TimerInterval, killDestructables)
if Counter == 0 then
call TimerStart(Timer, TimerInterval, true, function Update)
endif
set Knockers[Counter] = n
set Counter = Counter + 1
return true
endfunction
private function KnockbackSystemInit takes nothing returns nothing
set Boolexpr = Condition(function KillDests_Check)
endfunction
public function InitTrig takes nothing returns nothing
endfunction
endlibrary