Name | Type | is_array | initial_value |
YourPoint | location | Yes | |
YourUnit | unit | Yes |
//TESH.scrollpos=102
//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
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+) 2.0
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: http://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* set t=NewTimerEx(x) : Get a timer (alternative to CreateTimer), call
//* Initialize timer data as x, instead of 0.
//*
//* ReleaseTimer(t) : Release a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
private boolean didinit = false
endglobals
private keyword init
//==========================================================================================
// I needed to decide between duplicating code ignoring the "Once and only once" rule
// and using the ugly textmacros. I guess textmacros won.
//
//! textmacro TIMERUTIS_PRIVATE_NewTimerCommon takes VALUE
// On second thought, no.
//! endtextmacro
function NewTimerEx takes integer value returns timer
if (tN==0) then
if (not didinit) then
//This extra if shouldn't represent a major performance drawback
//because QUANTITY rule is not supposed to be broken every day.
call init.evaluate()
set tN = tN - 1
else
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
set tT[0]=CreateTimer()
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],value)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
if ( didinit ) then
return
else
set didinit = true
endif
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
//TESH.scrollpos=126
//TESH.alwaysfold=0
library Fireblaze initializer init uses TimerUtils
//====================================================================================
/* FIREBLAZE by F1ashB0nd */
//
/* Credits to: Vexorian (dummy.mdx, TimerUtils)
Bribe (NewTable/Table) */
//
// How to implement:
//
// Step 1:
// Create a new trigger and name it whatever you want (preferably "Fireblaze")
// and then go to [Edit -> "Convert to Custom Text"]. Replace everything in the
// newly created trigger with this code.
//
// Step 2:
// Now you have to implement TimerUtils and Table into your map. If you already have
// them, just skip this step. If you don't have it, copy and paste both triggers
// from the test map into your map.
// (Note: TimerUtils is made by Vexorian and Table by Bribe. Give them credits if you
// use these systems.)
//
// Step 3:
// Import dummy.mdx into your map. You can export the dummy.mdx file and then
// import it into your map.
// (Again, dummy.mdx is also by Vexorian, so give credits when used.)
//
// Step 4:
// If you don't have any dummy units that uses Vexorian's dummy.mdx, you can copy
// and paste the dummy from the test map.
//
// Step 5:
// Create a new ability and configure the settings below (including the raw code of
// the dummy unit and the raw code of the ability.) Feel free to copy and paste
// the ability in the test map but you still have to configure the dummy raw code
// and ability raw code in the settings below.
//
// Note: The only ability you will need if you decide to copy it from my map, is the
// channel-based ability "Fireblaze". The other abilities classified under
// specials are part of the test map itself.
//====================================================================================
native UnitAlive takes unit id returns boolean
globals
//The rawcode of the ability that will trigger this spell (ability-type should be point-target or unit-target)
private constant integer ABILITY_ID = 'A000'
//The rawcode of the dummy unit
private constant integer DUMMY_ID = 'dumy'
//TOTAL VALUE = BASE + (INCREMENT x ABILITY LEVEL)
//-
//The damage of the explosion at the end.
private constant real EXPLOSION_DAMAGE_BASE = 130
private constant real EXPLOSION_DAMAGE_INCREMENT = 45
//The radius of the explosion at the end.
private constant real EXPLOSION_RADIUS_BASE = 325
private constant real EXPLOSION_RADIUS_INCREMENT = 0
//The damage of the projectile (or phoenix) as it touches units.
private constant real PROJECTILE_DAMAGE_BASE = 40
private constant real PROJECTILE_DAMAGE_INCREMENT = 25
//The radius of the projectile (or phoenix) where units around it will be detected.
private constant real PROJECTILE_RADIUS_BASE = 190
private constant real PROJECTILE_RADIUS_INCREMENT = 0
//The damage per second of the afterburn.
private constant real FIRE_DAMAGE_BASE = 20
private constant real FIRE_DAMAGE_INCREMENT = 5
//The radius of the fire's damaging zone.
private constant real FIRE_RADIUS_BASE = 150
private constant real FIRE_RADIUS_INCREMENT = 0
//The duration of the fire/afterburn.
private constant real FIRE_DURATION_BASE = 5
private constant real FIRE_DURATION_INCREMENT = 0
//The speed of the projectile (or phoenix) in units per second.
private constant real SPEED_BASE = 1500
private constant real SPEED_INCREMENT = 0
//The time elapsed before the afterburn starts.
private constant real FIRE_DELAY_BASE = 1.4
private constant real FIRE_DELAY_INCREMENT = 0
//------------------
//Additional Options
//------------------
//Choose to enable/disable the fire from taking place in water.
//However, while disabled, the radius of the fire on land may reach still reach the nearby plot of water.
private constant boolean FIRE_IN_WATER = false
//Choose whether to allow filtered units of the projectile and explosion to be able to take damage from both sources.
//If set to FALSE, the damage units take from the projectile and explosion will not go beyond the damage of the explosion.
private constant boolean PROJECTILE_EXPLOSION_DAMAGE = true
//The attack-type and damage-type of the damage done with this spell.
private constant attacktype ATK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DMG_TYPE = DAMAGE_TYPE_UNIVERSAL
//The interval where the spell effects happen (excluding the fire's damage interval)
private constant real INTERVAL = 0.02
//The interval where units inside the fire gets damaged. Preset at a moderate value to avoid lag.
private constant real FIRE_DAMAGE_INTERVAL = 0.20
//The size of the fire model.
private constant real FIRE_SCALE = 2.10
//The height of the projectile (or phoenix) above ground.
private constant real PROJECTILE_HEIGHT = 85
//The size of the projectile (or phoenix).
private constant real PROJECTILE_SCALE = 1.80
//The model path for the projectile
private constant string PROJECTILE_MODEL = "units\\human\\phoenix\\phoenix.mdl"
//The model path for the afterburn
private constant string FIRE_MODEL = "Environment\\LargeBuildingFire\\LargeBuildingFire1.mdl"
//Additional on-target special effects can be edited below.
//Specify whether or not to preload the models of the projectile and fire.
private constant boolean PRELOAD = true
endglobals
globals //These are globals used throughout this spell that shouldn't be configurated/changed by external functions.
private group G = CreateGroup()
private integer fb_inst = 0
private constant integer PRIMARY_ID = 0 // ID for projectile
private constant integer SEC_ID = 1 // ID for fire
private constant integer FD_ID = 2 //FIRE_DUMMY_ID
private constant integer FD_SFX_ID = 3 //FIRE_DUMMY_EFFECT_ID
private constant integer FD_DUR_ID = 4 //FIRE_DUMMY_DURATION_ID
endglobals
public constant function GetInstances takes nothing returns integer //Returns the amount of instances of this spell.
return fb_inst
endfunction
//Unit damage filter for the fire's damage per second.
// unit u = the unit about to be damaged, player p = owner of the caster
private function fireFilter takes unit u, player p returns boolean
return not IsUnitType(u, UNIT_TYPE_STRUCTURE) and UnitAlive(u) and GetUnitTypeId(u) != DUMMY_ID and IsUnitEnemy(u, p) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//Unit damage filter for the projectile (or phoenix).
// unit u = the unit about to be damaged, player p = owner of the caster
private function projectileFilter takes unit u, player p returns boolean
return not IsUnitType(u, UNIT_TYPE_STRUCTURE) and UnitAlive(u) and GetUnitTypeId(u) != DUMMY_ID and IsUnitEnemy(u, p) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
//Unit damage filter for the explosion.
// unit u = the unit about to be damaged, player p = owner of the caster
private function explosionFilter takes unit u, player p returns boolean
return not IsUnitType(u, UNIT_TYPE_STRUCTURE) and UnitAlive(u) and GetUnitTypeId(u) != DUMMY_ID and IsUnitEnemy(u, p)
endfunction
//Edit the special effect that appears on a unit that is about to be damaged by the projectile.
//unit u = unit about to be damaged, player p = owner of the caster.
private function projectileEffectsTarget takes unit u, player p returns nothing
//Insert custom special effects here.
endfunction
//Edit the explosion special effects here.
//unit dummy = the dummy unit at the center of the explosion.
private function explosionEffects takes unit caster, unit dummy returns nothing
call SetUnitScale(dummy, 1.4, 1.4, 1.4)
call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HCancelDeath\\HCancelDeath.mdl", dummy, "origin"))
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Doom\\DoomDeath.mdl", dummy, "origin"))
endfunction
//Edit the explosion special effects.
//unit u = the unit about to be damaged, player p = owner of the caster.
private function explosionEffectsTarget takes unit u, player p returns nothing
//Insert custom special effects here.
endfunction
//--------------------------------------------------------------------------------
private struct Fireblaze
player owner
unit dummy
unit caster
effect projectile
integer level
integer fireDummyCount
real targetX
real targetY
real x
real x2
real y
real y2
real speed
real fireDuration
real burnDuration
real delay
real explosionDamage
real fireDamage
real burnDamage
real projectileDamage
real fireDistance
real angle
real explosionRadius
real fireRadius
real projectileRadius
real sinA
real cosA
TableArray tbArray
boolean isFireDone
boolean isExplosionDone
private method clear takes nothing returns nothing
call tbArray.flush()
set owner = null
set dummy = null
set caster = null
set projectile = null
set fb_inst = fb_inst - 1
call this.destroy()
endmethod
private static method fireDamageOverTime takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local unit u
local integer i = 1
local integer deadDummies = 0
local real dur
loop //Here comes the dangerous UnitGroup loops
exitwhen i > fireDummyCount
set dur = tbArray[FD_DUR_ID].real[i] - FIRE_DAMAGE_INTERVAL
set tbArray[FD_DUR_ID].real[i] = dur
if dur > 0 then
//fire damage
call GroupEnumUnitsInRange(G, GetUnitX(tbArray[FD_ID].unit[i]), GetUnitY(tbArray[FD_ID].unit[i]), fireRadius, null)
loop //Another loop
set u = FirstOfGroup(G)
exitwhen u == null
call GroupRemoveUnit(G, u)
//the fires' area overlaps with each other so we need a table to determine which unit has already been damaged.
//the reason for the overlap is simple: to improve the accuracy of the linear unit detection. (empty space between the circular areas reduced)
if fireFilter(u, owner) and not tbArray[SEC_ID].has(GetHandleId(u)) then
call UnitDamageTarget(caster, u, fireDamage * FIRE_DAMAGE_INTERVAL, true, false, ATK_TYPE, DMG_TYPE, null)
set tbArray[SEC_ID][GetHandleId(u)] = 1
endif
endloop
if dur - FIRE_DAMAGE_INTERVAL <= 0 then
call DestroyEffect(tbArray[FD_SFX_ID].effect[i])
//Add expiration timer so that the effect finishes playing its death animation instead of poofing just like that.
call UnitApplyTimedLife(tbArray[FD_ID].unit[i], 'BTLF', 0.1)
endif
else
set deadDummies = deadDummies + 1 //Mark the fire as 'dead'.
endif
set i = i + 1
endloop
if deadDummies == fireDummyCount and isFireDone and isExplosionDone then
call ReleaseTimer(GetExpiredTimer())
call this.clear()
return
endif
call tbArray[SEC_ID].flush()
endmethod
private static method fireCallback takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local unit u
local integer i = 1
local real X
local real Y
if delay > 0. then
set delay = delay - INTERVAL
return
endif
set x2 = x2 + speed * cosA
set y2 = y2 + speed * sinA
set fireDistance = fireDistance + speed
if fireDistance >= fireRadius then
set fireDistance = fireDistance - fireRadius
if FIRE_IN_WATER or (not FIRE_IN_WATER and IsTerrainPathable(x2, y2, PATHING_TYPE_FLOATABILITY)) then
//offset the position back by the difference left by fireDistance, so that the fires will be uniformly distributed.
set u = CreateUnit(owner, DUMMY_ID, x2 - fireDistance * cosA, y2 - fireDistance * sinA, angle * bj_RADTODEG)
set fireDummyCount = fireDummyCount + 1
if fireDummyCount == 1 then
call TimerStart(NewTimerEx(this), FIRE_DAMAGE_INTERVAL, true, function thistype.fireDamageOverTime)
endif
call SetUnitScale(u, FIRE_SCALE, 0, 0)
set tbArray[FD_ID].unit[fireDummyCount] = u
set tbArray[FD_SFX_ID].effect[fireDummyCount] = AddSpecialEffectTarget(FIRE_MODEL, u, "origin")
set tbArray[FD_DUR_ID].real[fireDummyCount] = fireDuration
endif
endif
set X = targetX - x2
set Y = targetY - y2
if X*X + Y*Y < fireRadius*fireRadius then
call ReleaseTimer(GetExpiredTimer())
set isFireDone = true
endif
set u = null
endmethod
private static method projectileCallback takes nothing returns nothing
local thistype this = GetTimerData(GetExpiredTimer())
local unit u
set x = x + speed * cosA
set y = y + speed * sinA
//I had to do speed * 1.001 because the projectile would go on infinitely if the caster targeted himself.
//A 0.1% uncertainty won't really affect anything.
if not IsUnitInRangeXY(dummy, targetX, targetY, speed * 1.001) then
call SetUnitX(dummy, x)
call SetUnitY(dummy, y)
//projectile damage
call GroupEnumUnitsInRange(G, x, y, projectileRadius, null)
loop
set u = FirstOfGroup(G)
exitwhen u == null
call GroupRemoveUnit(G, u)
if projectileFilter(u, owner) and not tbArray[PRIMARY_ID].has(GetHandleId(u)) then
call UnitDamageTarget(caster, u, projectileDamage, true, false, ATK_TYPE, DMG_TYPE, null)
set tbArray[PRIMARY_ID][GetHandleId(u)] = 1
call projectileEffectsTarget(u, owner)
endif
endloop
else
call SetUnitX(dummy, targetX)
call SetUnitY(dummy, targetY)
//explode
call DestroyEffect(projectile)
call UnitApplyTimedLife(dummy, 'BTLF', 0.5)
call ReleaseTimer(GetExpiredTimer())
call explosionEffects(caster, dummy)
call GroupEnumUnitsInRange(G, targetX, targetY, explosionRadius, null)
loop
set u = FirstOfGroup(G)
exitwhen u == null
call GroupRemoveUnit(G, u)
if explosionFilter(u, owner) then
static if PROJECTILE_EXPLOSION_DAMAGE then
call UnitDamageTarget(caster, u, explosionDamage, true, false, ATK_TYPE, DMG_TYPE, null)
else
if tbArray[PRIMARY_ID].has(GetHandleId(u)) then
call UnitDamageTarget(caster, u, explosionDamage - projectileDamage, true, false, ATK_TYPE, DMG_TYPE, null)
else
call UnitDamageTarget(caster, u, explosionDamage, true, false, ATK_TYPE, DMG_TYPE, null)
endif
endif
call explosionEffectsTarget(u, owner)
endif
endloop
set isExplosionDone = true
endif
endmethod
method startEffect takes nothing returns nothing
set tbArray = TableArray[5]
set angle = Atan2(targetY - y, targetX - x)
set sinA = Sin(angle)
set cosA = Cos(angle)
set dummy = CreateUnit(owner, DUMMY_ID, x, y, angle * bj_RADTODEG)
set fireDummyCount = 0
set isFireDone = false
set isExplosionDone = false
//Move the unit to the position of the caster again because the dummy was created with collision taken into account
call SetUnitX(dummy, x)
call SetUnitY(dummy, y)
set projectile = AddSpecialEffectTarget(PROJECTILE_MODEL, dummy, "origin")
//Add crow form so that the dummy's height can be adjusted
if UnitAddAbility(dummy, 'Arav') then
call UnitRemoveAbility(dummy, 'Arav')
endif
call SetUnitFlyHeight(dummy, PROJECTILE_HEIGHT, 0)
call SetUnitScale(dummy, PROJECTILE_SCALE, 0, 0)
call TimerStart(NewTimerEx(this), INTERVAL, true, function thistype.projectileCallback)
call TimerStart(NewTimerEx(this), INTERVAL, true, function thistype.fireCallback)
endmethod
endstruct
//------------------------------------------------------------------------------------------
private function Actions takes nothing returns boolean //The Action part of the trigger. Sets up the nesessary configurations for the spell.
local Fireblaze fb
if GetSpellAbilityId() == ABILITY_ID then
set fb = Fireblaze.create()
set fb.owner = GetTriggerPlayer()
set fb.caster = GetTriggerUnit()
set fb.targetX = GetSpellTargetX()
set fb.targetY = GetSpellTargetY()
set fb.x = GetUnitX(fb.caster)
set fb.y = GetUnitY(fb.caster)
set fb.x2 = fb.x
set fb.y2 = fb.y
set fb.level = GetUnitAbilityLevel(fb.caster, ABILITY_ID)
//A minimum speed of 100. With 0 or negative speed, the spell will go on forever!
set fb.speed = (SPEED_BASE + (SPEED_INCREMENT * fb.level) ) * INTERVAL
if fb.speed < (100 * INTERVAL) then
set fb.speed = (100 * INTERVAL)
endif
set fb.fireDuration = FIRE_DURATION_BASE + (FIRE_DURATION_INCREMENT * fb.level)
if fb.fireDuration < 0 then
set fb.fireDuration = 0
endif
set fb.delay = FIRE_DELAY_BASE + (FIRE_DELAY_INCREMENT * fb.level)
if fb.delay < 0 then
set fb.delay = 0
endif
set fb.explosionDamage = EXPLOSION_DAMAGE_BASE + (EXPLOSION_DAMAGE_INCREMENT * fb.level)
set fb.fireDamage = FIRE_DAMAGE_BASE + (FIRE_DAMAGE_INCREMENT * fb.level)
set fb.projectileDamage = PROJECTILE_DAMAGE_BASE + (PROJECTILE_DAMAGE_INCREMENT * fb.level)
set fb.explosionRadius = EXPLOSION_RADIUS_BASE + (EXPLOSION_RADIUS_INCREMENT * fb.level)
set fb.fireRadius = FIRE_RADIUS_BASE + (FIRE_RADIUS_INCREMENT * fb.level)
set fb.projectileRadius = PROJECTILE_RADIUS_BASE + (PROJECTILE_RADIUS_INCREMENT * fb.level)
set fb_inst = fb_inst + 1
call fb.startEffect()
endif
return false
endfunction
private function init takes nothing returns nothing //The initializing function for the library. Creates a trigger that detects the spell effect event.
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, function Actions)
static if PRELOAD then
call Preload( PROJECTILE_MODEL )
call Preload( FIRE_MODEL )
endif
endfunction
endlibrary