Name | Type | is_array | initial_value |
//TESH.scrollpos=236
//TESH.alwaysfold=0
library CTL /* v1.2.0.2
*************************************************************************************
*
* 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
endif
set ir32[i] = false
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] or id32[i])) then
if (ir32[i]) then
set ir32[i] = false
else
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] or 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=121
//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
//============================================================================
// 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=6
//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=0
//TESH.alwaysfold=0
//===========================================================================
// Blizzard ( Ability ) by BPower.
// - Version 1.2.1
//===========================================================================
//
// Calls down waves of freezing ice shards that damage units in a target area.
//
//===========================================================================
//
// Requirements:
//
// CTL - github.com/nestharus/JASS/tree/master/jass/Systems/ConstantTimerLoop32
// Table - hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
// SpellEffectEvent - hiveworkshop.com/forums/jass-resources-412/snippet-spelleffectevent-187193/
//
//===========================================================================
//
// Credits:
//
// To Nestharus for CTL
// To Bribe for Table and SpellEffectEvent
// To Vexorian for dummy.mdx
//
//===========================================================================
native UnitAlive takes unit id returns boolean
scope Blizzard initializer Init
// User settings:
// ==============
globals
// Object editor fields:
private constant integer BLIZZARD_ABILITY = 'A000'
private constant integer DUMMY_UNIT_ID = 'dumi'
// Damage options:
private constant attacktype ATTACK_TYPE = ATTACK_TYPE_NORMAL
private constant damagetype DAMAGE_TYPE = DAMAGE_TYPE_MAGIC
// Effect options:
private constant real NEEDLE_FX_DURATION = 0.8// Requires testing. Try and error.
private constant string NEEDLE_FX = "war3mapImported\\SnowyBlizzardTarget.mdx"
private constant string GROUND_FX = "war3mapImported\\FreezingField.mdx"
// Balance options:
// Bring structure into the chaos, by dividing the area of effect into sectors.
// New needles will be created in random unique sectors to
// ensure a better distribution of spawned effects.
private constant integer DISTRIBUTION_FACTOR = 10
// Accuracy options:
// Maximum collision size in your map.
private constant real MAX_COLLISION_SIZE = 64.
private constant real NEEDLE_COLLISION_SIZE = 48.
endglobals
// Filter valid targets.
private function TargetFilter takes unit target, player owner returns boolean
return UnitAlive(target) and not IsUnitType(target, UNIT_TYPE_MAGIC_IMMUNE) and not IsUnitType(target, UNIT_TYPE_STRUCTURE) and IsUnitEnemy(target, owner)
endfunction
// Returns the damage amount per needle.
private function GetImpactDamage takes integer level returns real
return GetRandomReal(10., 15.) + 20.*level
endfunction
// Returns the amount of needles created per seconds.
private constant function GetNeedlesPerSecond takes integer level returns integer
return 1 + 2*level
endfunction
// Returns the total spell duration in seconds.
private constant function GetSpellDuration takes integer level returns real
return 3. + 2.*level
endfunction
// Returns the radius of the blizzard field.
private constant function GetFieldRadius takes integer level returns real
return 200. + 50.*level
endfunction
// Returns the duration of the frost buff.
private constant function GetBuffDuration takes integer level returns real
return 4. + 0.*level
endfunction
// Returns the proper scaling of the ground effect. Eventually requires try and error.
private constant function GetFieldEffectScale takes real fieldSize returns real
return fieldSize/400.
endfunction
private function IsChanneling takes unit caster, integer level returns boolean
return true
endfunction
// Global condition to keep the spell running.
private function CasterCondition takes unit caster returns boolean
return UnitAlive(caster)
endfunction
// The following struct "Buff" creates the buff- and frostnova effect.
// Adjust the constants to your needs.
private struct Buff
// Buff type settings.
private static constant integer BUFF_ORDER_ID = 852226
private static constant integer BUFF_ABILITY = 'A001'
private static constant integer BUFF = 'Bfro'
//
private static constant integer CASTER_UNIT_ID = 'n000'
private static constant player NEUTRAL_PLAYER = Player(bj_PLAYER_NEUTRAL_EXTRA)
private static constant timer TIMER = CreateTimer()
private static constant real TIMER_TIMEOUT = .03125
private static constant integer LOCUST_ABILITY = 'Aloc'
private static thistype array prev
private static thistype array next
private static unit caster
private static Table table
private unit source
private real time
static method unitHasBuff takes unit whichUnit returns boolean
return GetUnitAbilityLevel(whichUnit, BUFF) != 0
endmethod
method destroy takes nothing returns nothing
call UnitRemoveAbility(source, BUFF)
call table.remove(GetHandleId(source))
call deallocate()
set next[prev[this]] = next[this]
set prev[next[this]] = prev[this]
if next[0] == 0 then
call PauseTimer(TIMER)
endif
set source = null
endmethod
private static method onPeriodic takes nothing returns nothing
local thistype this = next[0]
loop
exitwhen this == 0
if time > 0. and UnitAlive(source) and unitHasBuff(source) then
set time = time - TIMER_TIMEOUT
else
call destroy()
endif
set this = next[this]
endloop
endmethod
static method apply takes player owner, unit target, real duration returns nothing
local integer id = GetHandleId(target)
local thistype this
if table.has(id) then
set this = table[id]
if unitHasBuff(source) then
set time = duration
return
endif
call destroy()
endif
call IssueTargetOrderById(caster, BUFF_ORDER_ID, target)
set this = allocate()
set table[id] = this
set source = target
set time = duration
set next[this] = 0
set prev[this] = prev[0]
set next[prev[0]] = this
set prev[0] = this
if prev[this] == 0 then
call TimerStart(TIMER, TIMER_TIMEOUT, true, function thistype.onPeriodic)
endif
endmethod
private static method onInit takes nothing returns nothing
set table = Table.create()
set caster = CreateUnit(NEUTRAL_PLAYER, CASTER_UNIT_ID, 0., 0., 0.)
call SetUnitPosition(caster, 2147483647, 2147483647)
call UnitAddAbility(caster, BUFF_ABILITY)
call UnitAddAbility(caster, LOCUST_ABILITY)
call ShowUnit(caster, false)
endmethod
endstruct
//================================================================
// Blizzard source code. Make changes carefully.
//================================================================
private function Random takes nothing returns real
return GetRandomReal(0., 1.)
endfunction
private function GetRandomRange takes real radius returns real
local real r = Random() + Random()
if r > 1. then
return (2 - r)*radius
endif
return r*radius
endfunction
private struct Needle
real x
real y
real time
static method create takes real centerX, real centerY, real maxRange, integer factor returns thistype
local thistype this = thistype.allocate()
local real spacing = 2*bj_PI/DISTRIBUTION_FACTOR
local real min = spacing*factor
local real max = min + spacing
local real theta = GetRandomReal(min, max)
local real radius = GetRandomRange(maxRange)
set x = centerX + radius*Cos(theta)
set y = centerY + radius*Sin(theta)
set time = NEEDLE_FX_DURATION
call DestroyEffect(AddSpecialEffect(NEEDLE_FX, x, y))
return this
endmethod
endstruct
private struct Blizzard extends array
static constant group ENUM_GROUP = CreateGroup()
static constant real TIMER_TIMEOUT = .03125
static constant real DUMMY_DEATH_TIME = .01
static constant integer TIMED_LIFE = 'BTLF'
static constant integer TABLE_OFFSET = 0x2710
Table table
integer size
integer sectors
unit source
unit dummy
effect fx
player user
real radius
real time
real timeout
real centerX
real centerY
real duration
integer level
integer order
boolean channel
method getRandomSector takes nothing returns integer
local integer random
local integer sector
if DISTRIBUTION_FACTOR == 1 then
return 0
// Fills up the table with unique integers from 0 to DISTRIBUTION_FACTOR.
elseif sectors == 0 then
loop
exitwhen sectors == DISTRIBUTION_FACTOR
set table[TABLE_OFFSET + sectors] = sectors
set sectors = sectors + 1
endloop
endif
// Get an unique integer from the table.
set sectors = sectors - 1
set random = GetRandomInt(0, sectors)
set sector = table[TABLE_OFFSET + random]
set table[TABLE_OFFSET + random] = table[TABLE_OFFSET + sectors]
return sector
endmethod
implement CTL
local unit u
local Needle needle
local integer index
local real damage
local real slow
implement CTLExpire
if not CasterCondition(source) or duration <= 0. or (channel and GetUnitCurrentOrder(source) != order) then
if size == 0 then
call destroy()
call table.destroy()
call DestroyEffect(fx)
call UnitApplyTimedLife(dummy, TIMED_LIFE, DUMMY_DEATH_TIME)
set fx = null
set user = null
set dummy = null
set source = null
endif
else
set duration = duration - TIMER_TIMEOUT
set time = time + TIMER_TIMEOUT
loop
exitwhen time < timeout
set table[size] = Needle.create(centerX, centerY, radius, getRandomSector())
set size = size + 1
set time = time - timeout
endloop
endif
// Loop over all falling needles.
set index = 0
loop
exitwhen index == size
set needle = table[index]
if needle.time > 0. then
set needle.time = needle.time - TIMER_TIMEOUT
set index = index + 1
else
set damage = GetImpactDamage(level)
set slow = GetBuffDuration(level)
call GroupEnumUnitsInRange(ENUM_GROUP, needle.x, needle.y, NEEDLE_COLLISION_SIZE + MAX_COLLISION_SIZE, null)
loop
set u = FirstOfGroup(ENUM_GROUP)
exitwhen u == null
call GroupRemoveUnit(ENUM_GROUP, u)
if IsUnitInRangeXY(u, needle.x, needle.y, NEEDLE_COLLISION_SIZE*1.5) and TargetFilter(u, user) then
if UnitDamageTarget(source, u, damage, false, false, ATTACK_TYPE, DAMAGE_TYPE, null) then
call Buff.apply(user, u, slow)
endif
endif
endloop
call needle.destroy()
set size = size - 1
set table[index] = table[size]
endif
endloop
implement CTLEnd
static method onEffect takes nothing returns nothing
local thistype this = thistype.create()
set user = GetTriggerPlayer()
set source = GetTriggerUnit()
set centerX = GetSpellTargetX()
set centerY = GetSpellTargetY()
set level = GetUnitAbilityLevel(source, BLIZZARD_ABILITY)
set radius = GetFieldRadius(level)
set duration = GetSpellDuration(level)
set timeout = 1./IMaxBJ(1, GetNeedlesPerSecond(level))
set channel = IsChanneling(source, level)
set order = GetUnitCurrentOrder(source)
set dummy = CreateUnit(user, DUMMY_UNIT_ID, centerX, centerY, 2*bj_PI*Random())
set fx = AddSpecialEffectTarget(GROUND_FX, dummy, "origin")
set table = Table.create()
set time = 0.
set sectors = 0// Available sectors. Like cutting a piece of cake.
call SetUnitScale(dummy, GetFieldEffectScale(radius), 0., 0.)
endmethod
endstruct
private function Init takes nothing returns nothing
debug local string text
debug if DISTRIBUTION_FACTOR <= 0 then
debug set text = "|cffffa500Error:|r |cff99b4d1In trigger Blizzard, scope Blizzard!|r\n"
debug set text = text + "|cffffa500Global user settings: |cff99b4d1constant integer DISTRIBUTION_FACTOR = " + I2S(DISTRIBUTION_FACTOR) + "!|r\n"
debug set text = text + "|cffffa500Solution: |cff99b4d1DISTRIBUTION_FACTOR must be bigger than 0!|r"
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.00, 0.00, 3600.00, text)
debug endif
//
call RegisterSpellEffectEvent(BLIZZARD_ABILITY, function Blizzard.onEffect)
endfunction
endscope
//TESH.scrollpos=218
//TESH.alwaysfold=0
//=====================================================================
// DemoMap is a script for proper spell / system source code presentation.
// - Version 1.0 by BPower.
//=====================================================================
//
// Requirements:
// Jass NewGen Pack - blizzardmodding.info/4263/the-jass-newgen-pack-jngp-2-0/
//
//=====================================================================
library DemoMap initializer Init
// Configuration:
// - Edit the following fields to your needs.
private constant function GetMapName takes nothing returns string
return "Blizzard"
endfunction
private constant function GetMapVersion takes nothing returns string
return "1.2.1"
endfunction
private constant function GetAuthorName takes nothing returns string
return "BPower"
endfunction
private constant function GetCredits takes nothing returns string
return "Bribe, Magtheridon96, Nestharus, Vexorian"
endfunction
private constant function GetMapInfo takes nothing returns string
return null
endfunction
//================================================================
private constant function GetFogState takes nothing returns fogstate
return FOG_OF_WAR_VISIBLE
endfunction
private constant function EscRestoresHero takes nothing returns boolean
return true
endfunction
private constant function GetInitialHeroLevel takes nothing returns integer
return 10
endfunction
//================================================================
private constant function InitCreateCamps takes nothing returns boolean
return true
endfunction
private constant function ReviveCreepsAfterTime takes nothing returns real
return 20.
endfunction
//================================================================
private constant function GetAbilityId takes nothing returns integer
return 'A000'
endfunction
private function GetOrderString takes nothing returns string
return "blizzard"
endfunction
//===================================================================
// Configuration end.
//===================================================================
globals
private constant hashtable HASH = InitHashtable()
private constant trigger ACTION = CreateTrigger()
private constant group UNITS = CreateGroup()
private constant real CLASH_X = 2400.
private constant real CLASH_Y = -1050.
private key UNIT_LOC
private unit hero = null
endglobals
private constant function GetUser takes nothing returns player
return Player(0)
endfunction
private constant function GetColorBlue takes nothing returns string
return "|cff99b4d1"
endfunction
private constant function GetColorGold takes nothing returns string
return "|cffdaa520"
endfunction
private function Print takes string text returns nothing
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0., 0., 30., text)
endfunction
private function CastSpell takes unit source, unit target returns boolean
return IssuePointOrder(source, GetOrderString(), GetUnitX(target), GetUnitY(target))
endfunction
private function FilterLocust takes nothing returns boolean
return GetUnitAbilityLevel(GetTriggerUnit(), 'Aloc') == 0
endfunction
private function FilterHero takes nothing returns boolean
return IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO)
endfunction
private function ActionFilter takes nothing returns boolean
return not IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) and IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(hero))
endfunction
private function OnCast takes nothing returns nothing
call GroupEnumUnitsInRange(bj_lastCreatedGroup, GetUnitX(hero), GetUnitY(hero), 600, Filter(function ActionFilter))
if GroupPickRandomUnit(bj_lastCreatedGroup) != null then
if not CastSpell(hero, bj_groupRandomCurrentPick) then
call IssuePointOrder(hero, "attack", CLASH_X, CLASH_Y)
endif
elseif GetUnitCurrentOrder(hero) == 0 then
call IssuePointOrder(hero, "attack", CLASH_X, CLASH_Y)
endif
endfunction
//==================================================================
// Get and cache data of preplaced units.
//==================================================================
private struct UnitLoc
integer unitId
real unitX
real unitY
real face
boolean add
static method create takes unit source returns thistype
local thistype this = thistype.allocate()
set unitId = GetUnitTypeId(source)
set unitX = GetUnitX(source)
set unitY = GetUnitY(source)
set face = GetUnitFacing(source)
set add = IsUnitOwnedByPlayer(source, Player(10)) or IsUnitOwnedByPlayer(source, Player(11))
set add = add and not IsUnitType(source, UNIT_TYPE_STRUCTURE)
if add then
call GroupAddUnit(UNITS, source)
if IsUnitType(source, UNIT_TYPE_HERO) then
call UnitAddAbility(source, GetAbilityId())
call UnitModifySkillPoints(source, 1)
call SelectHeroSkill(source, GetAbilityId())
endif
endif
return this
endmethod
endstruct
private function CacheUnitData takes nothing returns nothing
local unit picked = GetEnumUnit()
call SaveInteger(HASH, UNIT_LOC, GetHandleId(picked), UnitLoc.create(picked))
if IsUnitOwnedByPlayer(picked, GetUser()) and IsUnitType(picked, UNIT_TYPE_HERO) then
call SetHeroLevel(picked, GetInitialHeroLevel(), true)
call ClearSelection()
call SelectUnit(picked, true)
call SetCameraPosition(GetUnitX(picked), GetUnitY(picked))
call UnitAddAbility(picked, 'AEbl')
endif
set picked = null
endfunction
private function CachePreplacedUnits takes nothing returns nothing
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, Filter(function FilterLocust))
call ForGroup(bj_lastCreatedGroup, function CacheUnitData)
endfunction
private function AttackEnum takes nothing returns nothing
local unit source = GetEnumUnit()
if IsUnitType(source, UNIT_TYPE_HERO) then
set hero = source
call TriggerExecute(ACTION)
elseif GetUnitCurrentOrder(source) == 0 then
call IssuePointOrder(source, "attack", 2400, -1050)
endif
set source = null
endfunction
private function Attack takes nothing returns nothing
call ForGroup(UNITS, function AttackEnum)
endfunction
//==================================================================
// Restore units on death event.
//==================================================================
private function OnUnitDeath takes nothing returns nothing
local unit source = GetTriggerUnit()
local player owner = GetTriggerPlayer()
local UnitLoc this = LoadInteger(HASH, UNIT_LOC, GetHandleId(source))
local real sleep = ReviveCreepsAfterTime()
if this != 0 then
if IsUnitOwnedByPlayer(source, GetUser()) then
set sleep = 5.
endif
call TriggerSleepAction(sleep)
if IsUnitType(source, UNIT_TYPE_HERO) then
call ReviveHero(source, this.unitX, this.unitY, true)
else
set source = CreateUnit(owner, this.unitId, this.unitX, this.unitY, this.face)
call SaveInteger(HASH, UNIT_LOC, GetHandleId(source), this)
if this.add then
call GroupAddUnit(UNITS, source)
endif
endif
endif
set owner = null
set source = null
endfunction
private function CreateDeathEvent takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(trig, Condition(function FilterLocust))
call TriggerAddAction(trig, function OnUnitDeath)
endfunction
//=========================================================
// Code to restore hero cooldown, hp and mana at any time.
//=========================================================
private function OnEscEnum takes nothing returns nothing
local unit picked = GetEnumUnit()
call UnitResetCooldown(picked)
call SetWidgetLife(picked, GetUnitState(picked, UNIT_STATE_MAX_LIFE))
call SetUnitState(picked, UNIT_STATE_MANA, GetUnitState(picked, UNIT_STATE_MAX_MANA))
set picked = null
endfunction
private function OnEsc takes nothing returns nothing
call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, GetUser(), Filter(function FilterHero))
call ForGroup(bj_lastCreatedGroup, function OnEscEnum)
endfunction
private function CreateEscEvent takes nothing returns nothing
local trigger trig
if not EscRestoresHero() then
return
endif
set trig = CreateTrigger()
call TriggerRegisterPlayerEvent(trig, GetUser(), EVENT_PLAYER_END_CINEMATIC)
call TriggerAddAction(trig, function OnEsc)
call Print(GetColorGold() + "Cheats:|r")
call Print(GetColorBlue() + " > Press Esc to refresh cooldowns, health and mana!|r")
endfunction
//==================================================================
// Map visibility.
//==================================================================
private function SetFogOfWar takes nothing returns nothing
call FogModifierStart(CreateFogModifierRect(GetUser(), GetFogState(), bj_mapInitialPlayableArea, false, false))
endfunction
//==================================================================
// Say hi.
//==================================================================
private function GetStarString takes string headline returns string
local integer chars = (32 - StringLength(headline))/2
local string str = "*"
loop
exitwhen chars <= 0
set str = str + "*"
set chars = chars - 1
endloop
return str
endfunction
private function DisplayWelcome takes nothing returns nothing
local string star = GetStarString(GetMapName())
call Print(star + " " + GetColorGold() + GetMapName() + " |r" + star)
call Print("*")
call Print("*" + GetColorBlue() + " > Version: " + GetMapVersion() + "|r")
call Print("*" + GetColorBlue() + " > Author: " + GetAuthorName() + "|r" )
if StringLength(GetCredits()) > 0 then
call Print("*" + GetColorBlue() + " > Credits: " + GetCredits() + "|r")
endif
call Print("*")
call Print("****")
if StringLength(GetMapInfo()) > 0 then
call Print(GetColorGold() + "Further information:|r")
call Print(GetMapInfo())
call Print(" ")
endif
call Print(GetColorGold() + "Please give credits to:|r")
call Print(" >> " + GetAuthorName() + " <<")
call Print(" ")
endfunction
//===========================================================================
private function Init takes nothing returns nothing
call DisplayWelcome()
call SetFogOfWar()
call CreateEscEvent()
call CreateDeathEvent()
call CachePreplacedUnits()
call TimerStart(CreateTimer(), 5., true, function Attack)
call TriggerAddAction(ACTION, function OnCast)
call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY, true, Player(10))
call SetPlayerFlagBJ(PLAYER_STATE_GIVES_BOUNTY, true, Player(11))
endfunction
endlibrary