//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
//TESH.scrollpos=25
//TESH.alwaysfold=0
library ARGB initializer init
//******************************************************************************
//*
//* ARGB 1.2
//* ====
//* For your color needs.
//*
//* An ARGB object is a by-value struct, this means that assigning copies the
//* contents of the struct and that you don't have to use .destroy(), the
//* downside is that you cannot assign its members (can't do set c.r= 123 )
//*
//* This library should have plenty of uses, for example, if your spell involves
//* some unit recoloring you can allow users to input the color in the config
//* section as 0xAARRGGBB and you can then use this to decode that stuff.
//*
//* You can also easily merge two colors and make fading effects using ARGB.mix
//*
//* There's ARGB.fromPlayer which gets an ARGB object containing the player's
//* color. Then you can use the previous utilities on it.
//*
//* The .str() instance method can recolor a string, and the recolorUnit method
//* will apply the ARGB on a unit
//*
//* For other uses, you can use the .red, .green, .blue and .alpha members to get
//* an ARGB object's color value (from 0 to 255).
//*
//* structs that have a recolor method that takes red,green,blue and alpha as 0.255
//* integers can implement the ARGBrecolor module to gain an ability to quickly
//* recolor using an ARGB object.
//*
//********************************************************************************
//=================================================================================
globals
private string array i2cc
endglobals
//this double naming stuff is beginning to make me insane, if only TriggerEvaluate() wasn't so slow...
struct ARGB extends array
static method create takes integer a, integer r, integer g, integer b returns ARGB
return ARGB(b + g*0x100 + r*0x10000 + a*0x1000000)
endmethod
// not really part of the exported stuff, I may remove it in the future, so please don't call this textmacro
//! textmacro ARGB_PLAYER_COLOR_2_ARGB
if(pc==PLAYER_COLOR_RED) then
return 0xFFFF0303
elseif(pc==PLAYER_COLOR_BLUE) then
return 0xFF0042FF
elseif(pc==PLAYER_COLOR_CYAN) then
return 0xFF1CE6B9
elseif(pc==PLAYER_COLOR_PURPLE) then
return 0xFF540081
elseif(pc==PLAYER_COLOR_YELLOW) then
return 0xFFFFFC01
elseif(pc==PLAYER_COLOR_ORANGE) then
return 0xFFFE8A0E
elseif(pc==PLAYER_COLOR_GREEN) then
return 0xFF20C000
elseif(pc==PLAYER_COLOR_PINK) then
return 0xFFE55BB0
elseif(pc==PLAYER_COLOR_LIGHT_GRAY) then
return 0xFF959697
elseif(pc==PLAYER_COLOR_LIGHT_BLUE) then
return 0xFF7EBFF1
elseif(pc==PLAYER_COLOR_AQUA) then
return 0xFF106246
elseif(pc==PLAYER_COLOR_BROWN) then
return 0xFF4E2A04
endif
return 0xFF111111
//! endtextmacro
static method fromPlayerColor takes playercolor pc returns ARGB
//! runtextmacro ARGB_PLAYER_COLOR_2_ARGB()
endmethod
static method fromPlayer takes player p returns ARGB
local playercolor pc=GetPlayerColor(p)
//! runtextmacro ARGB_PLAYER_COLOR_2_ARGB()
endmethod
method operator alpha takes nothing returns integer
if( integer(this) <0) then
return 0x80+(-(-integer(this)+0x80000000))/0x1000000
else
return (integer(this))/0x1000000
endif
endmethod
method operator alpha= takes integer na returns ARGB
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
return ARGB(b + g*0x100 + r*0x10000 + na*0x1000000)
endmethod
method operator red takes nothing returns integer
local integer c=integer(this)*0x100
if(c<0) then
return 0x80+(-(-c+0x80000000))/0x1000000
else
return c/0x1000000
endif
endmethod
method operator red= takes integer nr returns ARGB
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
return ARGB(b + g*0x100 + nr*0x10000 + a*0x1000000)
endmethod
method operator green takes nothing returns integer
local integer c=integer(this)*0x10000
if(c<0) then
return 0x80+(-(-c+0x80000000))/0x1000000
else
return c/0x1000000
endif
endmethod
method operator green= takes integer ng returns ARGB
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
return ARGB(b + ng*0x100 + r*0x10000 + a*0x1000000)
endmethod
//=======================================================
//
//
method operator blue takes nothing returns integer
local integer c=integer(this)*0x1000000
if(c<0) then
return 0x80+(-(-c+0x80000000))/0x1000000
else
return c/0x1000000
endif
endmethod
method operator blue= takes integer nb returns ARGB
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
return ARGB(nb + g*0x100 + r*0x10000 + a*0x1000000)
endmethod
//====================================================================
// Mixes two colors, s would be a number 0<=s<=1 that determines
// the weight given to color c2.
//
// mix(c1,c2,0) = c1
// mix(c1,c2,1) = c2
// mix(c1,c2,0.5) = Mixing the colors c1 and c2 in equal proportions.
//
static method mix takes ARGB c1, ARGB c2, real s returns ARGB
//widest function ever
return ARGB( R2I(c2.blue*s+c1.blue*(1-s)+0.5) + R2I(c2.green*s+c1.green*(1-s)+0.5)*0x100 + R2I(c2.red*s+c1.red*(1-s)+0.5)*0x10000 + R2I(c2.alpha*s+c1.alpha*(1-s)+0.5)*0x1000000)
endmethod
method str takes string s returns string
return "|c"+i2cc[.alpha]+i2cc[.red]+i2cc[.green]+i2cc[.blue]+s+"|r"
endmethod
method recolorUnit takes unit u returns nothing
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
call SetUnitVertexColor(u,r,g,b,a)
endmethod
endstruct
module ARGBrecolor
method ARGBrecolor takes ARGB color returns nothing
local integer a
local integer r
local integer g
local integer b
local integer col=integer(this)
if (col<0) then
set col=-(-col+0x80000000)
set a=0x80+col/0x1000000
set col=col-(a-0x80)*0x1000000
else
set a=col/0x1000000
set col=col-a*0x1000000
endif
set r=col/0x10000
set col=col-r*0x10000
set g=col/0x100
set b=col-g*0x100
call this.recolor(r, g , b, a)
endmethod
endmodule
private function init takes nothing returns nothing
local integer i=0
// Don't run textmacros you don't own!
//! textmacro ARGB_CHAR takes int, chr
set i=0
loop
exitwhen i==16
set i2cc[$int$*16+i]="$chr$"+i2cc[$int$*16+i]
set i2cc[i*16+$int$]=i2cc[i*16+$int$]+"$chr$"
set i=i+1
endloop
//! endtextmacro
//! runtextmacro ARGB_CHAR( "0","0")
//! runtextmacro ARGB_CHAR( "1","1")
//! runtextmacro ARGB_CHAR( "2","2")
//! runtextmacro ARGB_CHAR( "3","3")
//! runtextmacro ARGB_CHAR( "4","4")
//! runtextmacro ARGB_CHAR( "5","5")
//! runtextmacro ARGB_CHAR( "6","6")
//! runtextmacro ARGB_CHAR( "7","7")
//! runtextmacro ARGB_CHAR( "8","8")
//! runtextmacro ARGB_CHAR( "9","9")
//! runtextmacro ARGB_CHAR("10","A")
//! runtextmacro ARGB_CHAR("11","B")
//! runtextmacro ARGB_CHAR("12","C")
//! runtextmacro ARGB_CHAR("13","D")
//! runtextmacro ARGB_CHAR("14","E")
//! runtextmacro ARGB_CHAR("15","F")
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library IconLibrary/*
****************************************************************************************
*
* ************************************************************************************
*
* */ uses /*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
* ************************************************************************************
*
* IconLibrary
* ___________
* v1.0.0.0
* by Thelordmarshall
*
*
* Define yours icons.
*
* Functions:
* __________
* - function SaveIcon takes integer rawCode, string icon returns nothing
* - takes unit or item rawCode and string icon.
* - function GetUnitIcon takes unit u returns string
* - returns icon of unit previusly saved.
* - function GetItemIcon takes item i returns string
* - returns icon of item previusly saved.
****************************************************************************************/
globals
private constant string DEFAULT_ICON = "UI\\Widgets\\Console\\Undead\\undead-inventory-slotfiller.blp"
private Table h
endglobals
function SaveIcon takes integer rawCode, string icon returns nothing
if(not h.string.has(rawCode))then
set h.string[rawCode]=icon
endif
endfunction
function GetUnitIcon takes unit u returns string
local integer id=GetUnitTypeId(u)
if(h.string.has(id))then
return h.string[id]
endif
return DEFAULT_ICON
endfunction
function GetItemIcon takes item i returns string
local integer id=GetItemTypeId(i)
if(h.string.has(id))then
return h.string[id]
endif
return DEFAULT_ICON
endfunction
private module Init
private static method onInit takes nothing returns nothing
set h=Table.create()
endmethod
endmodule
private struct i extends array
implement Init
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library MultiboardTools/*
****************************************************************************************
*
* ************************************************************************************
*
* */ uses /*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
* ************************************************************************************
*
* MultiboardTools
* _______________
* v1.1.2.4
* by Thelordmarshall
*
* Easy way to manage a multiboard:
*
* set myBoard = Multiboard.create("my board title",rows,columns)
* set myBoard[0][1].text = GetPlayerName(somePlayer)
* set myBoard[0][1].icon = "some\\path\\icon.blp"
*
* API:
* ____
* struct Multiboard extends array
* - static method create takes string title, integer row, integer column returns Multiboard
* - creates Multiboard.
* - method destroy takes nothing returns nothing
* - destroy it.
* - method clear takes nothing returns nothing
* - method setStyle takes boolean showValue, boolean showIcon returns nothing
* - method operator [] takes integer i returns thistype
* - use for Multiboard row and column ej: set board[0][5].text="your text"
* - method operator width= takes real width returns nothing
* - method operator text= takes string text returns nothing
* - method operator icon= takes string icon returns nothing
* - method operator title= takes string s returns nothing
* - method operator title takes nothing returns string
* - method operator show= takes boolean b returns nothing
* - method operator displayed takes nothing returns boolean
* - method operator row= takes integer i returns nothing
* - method operator column= takes integer i returns nothing
* - method operator minimized= takes boolean b returns nothing
* - method operator minimized takes nothing returns boolean
*
* Credits:
* ________
* -
****************************************************************************************/
struct Multiboard extends array
private static Table h=0
private static integer n=0
private static integer size=0
private static integer array list
private multiboard m
private integer r
private integer c
private integer t
private player p
private player l
debug private string s
method operator [] takes integer i returns thistype
set .t=.t+1
debug set .s=.s+"["+I2S(i)+"]"
if(.t<=2)then
if(n==0)then
set .r=i
set n=1
elseif(n==1)then
set .c=i
set n=0
endif
endif
return this
endmethod
private method createCache takes nothing returns nothing
local integer i=MultiboardGetRowCount(.m)
local integer g=MultiboardGetColumnCount(.m)
local integer o=g
loop
loop
set h.multiboarditem[(this*0x200+i)*0x200+o]=MultiboardGetItem(.m,i,o)
exitwhen(0==o)
set o=o-1
endloop
set o=g
exitwhen(0==i)
set i=i-1
endloop
endmethod
private method destroyCache takes nothing returns nothing
local integer i=MultiboardGetRowCount(.m)
local integer g=MultiboardGetColumnCount(.m)
local integer o=g
loop
loop
call MultiboardReleaseItem(h.multiboarditem[(this*0x200+i)*0x200+o])
call h.handle.remove((this*0x200+i)*0x200+o)
exitwhen(0==o)
set o=o-1
endloop
set o=g
exitwhen(0==i)
set i=i-1
endloop
endmethod
private method debug takes string m returns boolean
local boolean b=.t==2
if(not(b))then
set n=0
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,60.,"[MultiboardTools] error: unable to set "+m+" on row/column: "+.s)
endif
set .t=0
debug set .s=""
return b
endmethod
//! textmacro Mb_debug takes STRING
if(not debug("$STRING$"))then
return
endif
//! endtextmacro
//! textmacro Mb_operator takes METHOD,ARGUMENT,RETURN,ACTION1,ACTION2
method $METHOD$ takes $ARGUMENT$ returns $RETURN$
$ACTION1$
$ACTION2$
endmethod
//! endtextmacro
//! runtextmacro Mb_operator("operator local=","player p","nothing","set .p=p","set .l=GetLocalPlayer()")
//! runtextmacro Mb_operator("operator title=","string s","nothing","call MultiboardSetTitleText(.m,s)","")
//! runtextmacro Mb_operator("operator title","nothing","string","return MultiboardGetTitleText(.m)","")
//! runtextmacro Mb_operator("operator show=","boolean b","nothing","call MultiboardDisplay(.m,b)","")
//! runtextmacro Mb_operator("operator displayed","nothing","boolean","return IsMultiboardDisplayed(.m)","")
//! runtextmacro Mb_operator("operator row=","integer i","nothing","call MultiboardSetRowCount(.m,i)","")
//! runtextmacro Mb_operator("operator column=","integer i","nothing","call MultiboardSetColumnCount(.m,i)","")
//! runtextmacro Mb_operator("operator minimized=","boolean b","nothing","call MultiboardMinimize(.m,b)","")
//! runtextmacro Mb_operator("operator minimized","nothing","boolean","return IsMultiboardMinimized(.m)","")
//! runtextmacro Mb_operator("clear","nothing","nothing","call MultiboardClear(.m)","")
method operator width= takes real width returns nothing
local integer o=MultiboardGetRowCount(.m)
//! runtextmacro Mb_debug("width")
if(.r==0)then
loop
call MultiboardSetItemWidth(h.multiboarditem[(this*0x200+o)*0x200+.c],width/100.)
exitwhen(0==o)
set o=o-1
endloop
elseif(.r>0)then
call MultiboardSetItemWidth(h.multiboarditem[(this*0x200+.r)*0x200+.c],width/100.)
endif
endmethod
method operator text= takes string text returns nothing
//! runtextmacro Mb_debug("text")
call MultiboardSetItemValue(h.multiboarditem[(this*0x200+.r)*0x200+.c],text)
endmethod
method operator icon= takes string icon returns nothing
//! runtextmacro Mb_debug("icon")
call MultiboardSetItemIcon(h.multiboarditem[(this*0x200+.r)*0x200+.c],icon)
call MultiboardSetItemStyle(h.multiboarditem[(this*0x200+.r)*0x200+.c],true,true)
endmethod
method setStyle takes boolean showValue, boolean showIcon returns nothing
local integer i=MultiboardGetRowCount(.m)
local integer g=MultiboardGetColumnCount(.m)
local integer o=g
//! runtextmacro Mb_debug("style")
if(.r==0 and .c==0)then
loop
loop
call MultiboardSetItemStyle(h.multiboarditem[(this*0x200+i)*0x200+o],showValue,showIcon)
exitwhen(0==o)
set o=o-1
endloop
set o=g
exitwhen(0==i)
set i=i-1
endloop
elseif(.r>0 or .c>0)then
call MultiboardSetItemStyle(h.multiboarditem[(this*0x200+.r)*0x200+.c],showValue,showIcon)
endif
endmethod
static method create takes string title, integer row, integer column returns Multiboard
local thistype this=list[0]
if(this==0)then
set this=size+1
set size=this
else
set list[0]=list[this]
endif
set .m=CreateMultiboard()
call MultiboardSetTitleText(.m,title)
call MultiboardSetRowCount(.m,row)
call MultiboardSetColumnCount(.m,column)
call .createCache()
return this
endmethod
method destroy takes nothing returns nothing
set list[this]=list[0]
set list[0]=this
call .destroyCache()
call DestroyMultiboard(.m)
set .m=null
endmethod
private static method onInit takes nothing returns nothing
set h=Table.create()
endmethod
endstruct
endlibrary
//TESH.scrollpos=21
//TESH.alwaysfold=0
//============================================================================
// OrderEvent by Bribe, special thanks to Nestharus and Azlier, version 2.1.0.0
//
// API
// ---
// RegisterOrderEvent(integer orderId, code eventFunc)
// RegisterAnyOrderEvent(code eventFunc) //Runs for point/target/instant for any order
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
library OrderEvent requires RegisterPlayerUnitEvent
globals
private trigger array t
endglobals
//============================================================================
function RegisterOrderEvent takes integer orderId, code c returns nothing
set orderId = orderId - 851968
if t[orderId] == null then
set t[orderId] = CreateTrigger()
endif
call TriggerAddCondition(t[orderId], Filter(c))
endfunction
//============================================================================
function RegisterAnyOrderEvent takes code c returns nothing
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, c)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, c)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, c)
endfunction
//============================================================================
private function OnOrder takes nothing returns nothing
call TriggerEvaluate(t[GetIssuedOrderId() - 851968])
endfunction
//============================================================================
private module M
private static method onInit takes nothing returns nothing
call RegisterAnyOrderEvent(function OnOrder)
endmethod
endmodule
private struct S extends array
implement M
endstruct
endlibrary
//TESH.scrollpos=73
//TESH.alwaysfold=0
library TeamIndex/*
****************************************************************************************
*
* ************************************************************************************
*
* */ uses /*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
* ************************************************************************************
*
* TeamIndex
* _________
* v1.1.2.4
* by Thelordmarshall
*
* Previously TeamReforce...
*
* Useful to get indexes of each team in the map, find out how many players
* there are in map, detect when alliances are changed, etc...
*
* Important:
* __________
*
* In order that it work correctly go to: Scenario/Player Properties/Forces
* and select the box "Allied" of each force of your map.
*
* Functions:
* __________
*
* - function GetStartPlayers takes nothing returns integer
* - get count starting players in map.
* - function GetCountPlayers takes nothing returns integer
* - get count active players in map.
* - function CountMapTeams takes nothing returns integer
* - returns the number of teams in your map.
* - function GetPlayerForce takes player whichPlayer returns force
* - returns the force of the player.
* - function GetPlayerForceId takes player whichPlayer returns integer
* - returns the force index of the player.
* - function GetPlayerIdInForce takes player whichPlayer returns integer
* - returns player id in force.
* - function CountPlayersInForce takes integer forceId returns integer
* - similar to CountPlayersInForceBJ, returns the numbers of players in force.
* - function RegisterEventAllianceChange takes code c returns nothing
* - register event when alliance is changed.
***************************************************************************************/
globals
private TableArray ht=0
private timer m=CreateTimer()
private trigger t=CreateTrigger()
private trigger e=CreateTrigger()
endglobals
function GetStartPlayers takes nothing returns integer
return ht[5].integer[0]
endfunction
function GetCountPlayers takes nothing returns integer
return ht[0].integer[0]
endfunction
function CountMapTeams takes nothing returns integer
return ht[0].integer[1]
endfunction
function GetPlayerForce takes player whichPlayer returns force
return ht[1].force[GetPlayerId(whichPlayer)]
endfunction
function GetPlayerForceId takes player whichPlayer returns integer
return ht[4].integer[GetPlayerId(whichPlayer)]
endfunction
function GetPlayerIdInForce takes player whichPlayer returns integer
return ht[2].integer[GetPlayerId(whichPlayer)]
endfunction
function CountPlayersInForce takes integer forceId returns integer
return ht[3].integer[forceId]
endfunction
function RegisterEventAllianceChange takes code c returns nothing
call TriggerAddCondition(t,Filter(c))
endfunction
//Core
private function RefreshData takes nothing returns nothing
local integer c=-1
local integer i=5
local integer h=0
local integer x=0
local player p
local player p2
local playerslotstate s
loop
call ht[i].flush()
exitwhen(0==i)
set i=i-1
endloop
loop
exitwhen(i==bj_MAX_PLAYERS)
set p=Player(i)
if(GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING)then
set ht[0].integer[0]=ht[0].integer[0]+1
endif
if(GetPlayerController(p)!=MAP_CONTROL_NONE)then
set ht[5].integer[0]=ht[5].integer[0]+1
if(not ht[1].has(i))then
set ht[0].force[h]=CreateForce()
set ht[0].integer[1]=ht[0].integer[1]+1
loop
exitwhen(x==bj_MAX_PLAYERS)
set p2=Player(x)
set s=GetPlayerSlotState(p2)
if((s==PLAYER_SLOT_STATE_PLAYING or s==PLAYER_SLOT_STATE_LEFT) and GetPlayerController(p2)!=MAP_CONTROL_NONE and IsPlayerAlly(p2,p) and not ht[1].has(x))then
call ForceAddPlayer(ht[0].force[h],p2)
set c=c+1
set ht[2].integer[x]=c
set ht[4].integer[x]=h
set ht[1].force[x]=ht[0].force[h]
set ht[3].integer[h]=ht[3].integer[h]+1
set ht[1].integer[x]=x
endif
set x=x+1
endloop
set x=0
set h=h+1
endif
endif
set i=i+1
endloop
set s=null
call PauseTimer(m)
call TriggerEvaluate(t)
endfunction
//! textmacro Force_hook takes FUNCTION_1,FUNCTION_2,ARGUMENTS,H
private function $FUNCTION_1$ takes $ARGUMENTS$ returns nothing
call TimerStart(m,0.,false,function RefreshData)
endfunction
$H$hook $FUNCTION_2$ $FUNCTION_1$
//! endtextmacro
//! runtextmacro Force_hook("Hook_Alliance","SetPlayerAlliance","player p1, player p2, alliancetype s, boolean b","")
//! runtextmacro Force_hook("Hook_PlayerTeam","SetPlayerTeam","player p, integer t","")
//! runtextmacro Force_hook("Hook_AllianceBJ","SetPlayerAllianceStateBJ","player p1, player p2, integer a","")
//! runtextmacro Force_hook("Hook_StateAllyBJ","SetPlayerAllianceStateAllyBJ","player p1, player p2, boolean b","")
//! runtextmacro Force_hook("Hook_StateVisionBJ","SetPlayerAllianceStateVisionBJ","player p1, player p2, boolean b","")
//! runtextmacro Force_hook("Hook_StateControlBJ","SetPlayerAllianceStateControlBJ","player p1, player p2, boolean b","")
//! runtextmacro Force_hook("Hook_StateFullControlBJ","SetPlayerAllianceStateFullControlBJ","player p1, player p2, boolean b","")
//! runtextmacro Force_hook("EventCondition","","nothing","//")
private module Init
static method onInit takes nothing returns nothing
local code c=function EventCondition
local integer i=12
loop
call TriggerRegisterPlayerEvent(e,Player(i),EVENT_PLAYER_LEAVE)
exitwhen(i==0)
set i=i-1
endloop
call TriggerAddCondition(e,Filter(c))
set ht=TableArray[6]
call TimerStart(m,0.,false,function RefreshData)
set c=null
endmethod
endmodule
private struct i extends array
implement Init
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TimerUtilsEx requires optional Table
/*************************************************
*
* TimerUtilsEx
* v2.1.0.2
* By Vexorian, Bribe & Magtheridon96
*
* Original version by Vexorian.
*
* Flavors:
* Hashtable:
* - RAM: Minimal
* - TimerData: Slow
*
* Array:
* - RAM: Maximal
* - TimerData: Fast
*
* All the functions have O(1) complexity.
* The Array version is the fastest, but the hashtable
* version is the safest. The Array version is still
* quite safe though, and I would recommend using it.
* The system is much slower in debug mode.
*
* Optional Requirement:
* - Table by Bribe
* - hiveworkshop.com/forums/showthread.php?t=188084
*
* API:
* ----
* - function NewTimer takes nothing returns timer
* - Returns a new timer from the stack.
* - function NewTimerEx takes integer i returns timer
* - Returns a new timer from the stack and attaches a value to it.
* - function ReleaseTimer takes timer t returns integer
* - Throws a timer back into the stack. Also returns timer data.
* - function SetTimerData takes timer t, integer value returns nothing
* - Attaches a value to a timer.
* - function GetTimerData takes timer t returns integer
* - Returns the attached value.
*
*************************************************/
// Configuration
globals
// Use hashtable, or fast array?
private constant boolean USE_HASH = true
// Max Number of Timers Held in Stack
private constant integer QUANTITY = 1024
endglobals
globals
private timer array tT
private integer tN = 0
endglobals
private module Init
private static method onInit takes nothing returns nothing
static if not USE_HASH then
local integer i = QUANTITY
loop
set i = i - 1
set tT[i] = CreateTimer()
exitwhen i == 0
endloop
set tN = QUANTITY
elseif LIBRARY_Table then
set tb = Table.create()
endif
endmethod
endmodule
// JassHelper doesn't support static ifs for globals.
private struct Data extends array
static if not USE_HASH then
static integer array data
endif
static if LIBRARY_Table then
static Table tb = 0
else
static hashtable ht = InitHashtable()
endif
implement Init
endstruct
// Double free protection
private function ValidTimer takes integer i returns boolean
static if LIBRARY_Table then
return Data.tb.boolean[-i]
else
return LoadBoolean(Data.ht, i, 1)
endif
endfunction
private function Get takes integer id returns integer
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to get data from invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
return Data.tb[id]
else
return LoadInteger(Data.ht, id, 0)
endif
else
return Data.data[id - 0x100000]
endif
endfunction
private function Set takes integer id, integer data returns nothing
debug if not ValidTimer(id) then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to attach data to invalid timer.")
debug endif
static if USE_HASH then
static if LIBRARY_Table then
set Data.tb[id] = data
else
call SaveInteger(Data.ht, id, 0, data)
endif
else
set Data.data[id - 0x100000] = data
endif
endfunction
function SetTimerData takes timer t, integer data returns nothing
call Set(GetHandleId(t), data)
endfunction
function GetTimerData takes timer t returns integer
return Get(GetHandleId(t))
endfunction
function NewTimerEx takes integer data returns timer
local integer id
if tN == 0 then
static if USE_HASH then
set tT[0] = CreateTimer()
else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: No Timers In The Stack! You must increase 'QUANTITY'")
return null
endif
else
set tN = tN - 1
endif
set id = GetHandleId(tT[tN])
static if LIBRARY_Table then
set Data.tb.boolean[-id] = true
else
call SaveBoolean(Data.ht, id, 1, true)
endif
call Set(id, data)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
function ReleaseTimer takes timer t returns integer
local integer id = GetHandleId(t)
local integer data = 0
// Pause the timer just in case.
call PauseTimer(t)
// Make sure the timer is valid.
if ValidTimer(id) then
// Get the timer's data.
set data = Get(id)
// Unmark handle id as a valid timer.
static if LIBRARY_Table then
call Data.tb.boolean.remove(-id)
else
call RemoveSavedBoolean(Data.ht, id, 1)
endif
//If it's not run in USE_HASH mode, this next block is useless.
static if USE_HASH then
//At least clear hash memory while it's in the recycle stack.
static if LIBRARY_Table then
call Data.tb.remove(id)
else
call RemoveSavedInteger(Data.ht, id, 0)
endif
// If the recycle limit is reached
if tN == QUANTITY then
// then we destroy the timer.
call DestroyTimer(t)
return data
endif
endif
//Recycle the timer.
set tT[tN] = t
set tN = tN + 1
//Tried to pass a bad timer.
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, "[TimerUtils]Error: Tried to release non-active timer!")
endif
//Return Timer Data.
return data
endfunction
endlibrary
library TimerUtils requires TimerUtilsEx
endlibrary
//TESH.scrollpos=229
//TESH.alwaysfold=0
library ReviveEvent/*
**************************************************************************************************
*
* **********************************************************************************************
*
* */ uses /*
* */ TimerUtilsEx /* hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
* */ WorldBounds /* github.com/nestharus/JASS/blob/master/jass/Systems/WorldBounds/script.j
* */ UnitIndexer /* old version (v4.0.2.8)
* */ optional ReTimerdialog /* hiveworkshop.com/forums/submissions-414/snippet-reviveevent-263628/#post2663325
* */ optional ReLeaderboard /* hiveworkshop.com/forums/submissions-414/snippet-reviveevent-263628/#post2663325
*
* **********************************************************************************************
*
* ReviveEvent
* ___________
* v2.1.2.2
* by Thelordmarshall
*
* You can:
* ________
*
* - Revive units.
* - Use custom fx on revived units.
* - See the cooldown in timerdialog or leaderboard.
* - Detect when hero/unit is revived.
*
* API:
* ____
*
* struct Revive extends array:
* - method execute takes nothing returns boolean
* - method getCooldown takes nothing returns real
*
* method operator:
* - method operator onX= takes real x returns nothing
* - method operator onY= takes real y returns nothing
* - method operator awakenFx= takes string fx returns nothing
* - method operator cooldown= takes real cooldown returns nothing
* - method operator select= takes boolean select returns nothing
* - instantly select unit on revive.
* - method operator showTd= takes boolean show returns nothing
* - show Timerdialog.
* - method operator showLd= takes boolean show returns nothing
* - show Leaderboard.
* - method operator simpleLd= takes boolean simple returns nothing
* - when is enabled only show the timer of player units in the leaderboard
* and not the timer of the other players units.
*
* Functions:
* __________
*
* - function ReviveUnit takes unit whichUnit, real x, real y, string fx returns nothing
* - function GetLastRevivedUnit takes nothing returns unit
* - function IsUnitDead takes unit whichUnit returns boolean
* - function ReviveGetCooldown takes unit whichUnit returns real
* - function SetReviveUnitAutomatic takes unit whichUnit, real x, real y, string fx, real cd, boolean upCd, boolean select returns nothing
* - function ReviveUnitReset takes unit whichUnit returns nothing
* - function RegisterReviveEvent takes code c returns nothing
*
* Credits:
* ________
*
* - Nestharus: UnitIndexer, WorldBounds.
* - Vexorian, Bribe & Magtheridon96: TimerUtils.
* - Special thanks to Bannar, IcemanBo and BPower.
**************************************************************************************************/
//CONFIGURATION
//=====================================================================================
globals
// Public awaken fx
constant string DEFAULT_AWAKEN_FX = "Abilities\\Spells\\Other\\Awaken\\Awaken.mdl"
endglobals
// Cooldown for each lvl
private function CooldownFactor takes real base, integer lvl returns real
return base/*cooldown base*/+ 4.00/*cooldown per lvl*/*I2R(lvl)/*lvl of unit*/
endfunction
//=====================================================================================
//ENDCONFIGURATION
globals
private trigger r=CreateTrigger()
private trigger t=CreateTrigger()
private trigger o=CreateTrigger()
private trigger p=CreateTrigger()
unit re_lastRevivedUnit=null
endglobals
//Core.
struct Revive extends array
private unit u
private real x
private real y
private real c
private real l
private string f
private boolean re_upCooldown
private boolean re_instSelect
implement optional re_Timerdialog
implement optional re_Leaderboard
static method operator [] takes unit u returns thistype
local thistype this=GetUnitId(u)
set .u=u
return this
endmethod
method getCooldown takes nothing returns real
return .l
endmethod
private static method hook_removeUnit takes unit u returns nothing
set thistype(GetUnitId(u)).u=null
endmethod
private method selectUnit takes nothing returns nothing
if(.re_instSelect and GetLocalPlayer()==GetOwningPlayer(.u))then
call PanCameraToTimed(.x,.y,0.)
call ClearSelection()
call SelectUnit(re_lastRevivedUnit,true)
endif
endmethod
private method addAwaken takes nothing returns nothing
if(.f!=null or .f!="")then
call DestroyEffect(AddSpecialEffectTarget(.f,.u,"origin"))
endif
endmethod
method execute takes nothing returns boolean
local player p=GetOwningPlayer(.u)
local thistype newId=GetUnitTypeId(.u)
local boolean done
if(IsUnitType(.u,UNIT_TYPE_DEAD) and not (newId==0))then
if(IsUnitType(.u,UNIT_TYPE_HERO))then
set done=ReviveHero(.u,.x,.y,false)
if(done)then
call .addAwaken()
call .selectUnit()
endif
return done
else
set re_lastRevivedUnit=CreateUnit(p,newId,0.,0.,0.)
set newId=GetUnitId(re_lastRevivedUnit)
set newId.u=re_lastRevivedUnit
set newId.f=.f
set newId.x=.x
set newId.y=.y
set newId.c=.c
set newId.re_upCooldown=.re_upCooldown
set newId.re_instSelect=.re_instSelect
static if(LIBRARY_ReTimerdialog)then
set newId.re_showDialog=.re_showDialog
endif
static if(LIBRARY_ReLeaderboard)then
set newId.re_showBoard=.re_showBoard
set newId.re_simpleBoard=.re_simpleBoard
endif
call RemoveUnit(.u)
call SetUnitX(re_lastRevivedUnit,newId.x)
call SetUnitY(re_lastRevivedUnit,newId.y)
call newId.addAwaken()
call newId.selectUnit()
call TriggerEvaluate(r)
set .u=null
return true
endif
endif
return false
endmethod
private static method onDeathLoop takes nothing returns nothing
local timer t=GetExpiredTimer()
local thistype this=GetTimerData(t)
set .l=.l-.03125
if(.l<=0. or not IsUnitType(.u,UNIT_TYPE_DEAD))then
call .execute()
call ReleaseTimer(t)
endif
set t=null
endmethod
private static method onDeath takes nothing returns boolean
local unit u=GetTriggerUnit()
local thistype this=GetUnitId(u)
if(.c>0.)then
if(.re_upCooldown and IsUnitType(u,UNIT_TYPE_HERO))then
set .l=CooldownFactor(.c,GetUnitLevel(u))
else
set .l=.c
endif
static if(LIBRARY_ReTimerdialog)then
if(.re_showDialog)then
call .startDialog(.l)
endif
endif
static if(LIBRARY_ReLeaderboard)then
if(.re_showBoard)then
call .startBoard(.l)
endif
endif
call TimerStart(NewTimerEx(this),.03125,true,function thistype.onDeathLoop)
endif
set u=null
return false
endmethod
private static method runEvent takes nothing returns boolean
set re_lastRevivedUnit=GetTriggerUnit()
return TriggerEvaluate(r)
endmethod
private static method onEnter takes nothing returns boolean
call TriggerRegisterUnitStateEvent(p,GetTriggerUnit(),UNIT_STATE_LIFE,GREATER_THAN,.405)
return false
endmethod
//! textmacro re_Operator takes NAME,VAR_TYPE,VAR_NAME
method operator $NAME$= takes $VAR_TYPE$ v returns nothing
set .$VAR_NAME$=v
endmethod
//! endtextmacro
//! runtextmacro re_Operator("onX","real","x")
//! runtextmacro re_Operator("onY","real","y")
//! runtextmacro re_Operator("awakenFx","string","f")
//! runtextmacro re_Operator("cooldown","real","c")
//! runtextmacro re_Operator("upCooldown","boolean","re_upCooldown")
//! runtextmacro re_Operator("select","boolean","re_instSelect")
//! runtextmacro optional re_td_Operator("showTd","boolean","re_showDialog")
//! runtextmacro optional re_lb_Operator("showLd","boolean","re_showBoard")
//! runtextmacro optional re_lb_Operator("simpleLd","boolean","re_simpleBoard")
private static method onInit takes nothing returns nothing
local group g=CreateGroup()
local unit u
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t,function thistype.onDeath)
call TriggerRegisterEnterRegion(o,WorldBounds.worldRegion,null)
call TriggerAddCondition(o,function thistype.onEnter)
call GroupEnumUnitsInRect(g,WorldBounds.world,null)
loop
set u=FirstOfGroup(g)
exitwhen(u==null)
call GroupRemoveUnit(g,u)
call TriggerRegisterUnitStateEvent(p,u,UNIT_STATE_LIFE,GREATER_THAN,.405)
endloop
call TriggerAddCondition(p,function thistype.runEvent)
call DestroyGroup(g)
set g=null
endmethod
endstruct
hook RemoveUnit Revive.hook_removeUnit
function ReviveUnit takes unit whichUnit, real x, real y, string fx returns boolean
set Revive[whichUnit].onX=x
set Revive[whichUnit].onY=y
set Revive[whichUnit].awakenFx=fx
return Revive[whichUnit].execute()
endfunction
function GetLastRevivedUnit takes nothing returns unit
return re_lastRevivedUnit
endfunction
function IsUnitDead takes unit whichUnit returns boolean
return IsUnitType(whichUnit,UNIT_TYPE_DEAD)
endfunction
function ReviveGetCooldown takes unit whichUnit returns real
return Revive[whichUnit].getCooldown()
endfunction
function SetReviveUnitAutomatic takes unit whichUnit, real x, real y, string fx, real cd, boolean upCd, boolean select returns nothing
set Revive[whichUnit].onX=x
set Revive[whichUnit].onY=y
set Revive[whichUnit].awakenFx=fx
set Revive[whichUnit].cooldown=cd
set Revive[whichUnit].upCooldown=upCd
set Revive[whichUnit].select=select
endfunction
function ReviveUnitReset takes unit whichUnit returns nothing
if(not(Revive[whichUnit].getCooldown()>0.))then
set Revive[whichUnit].onX=0.
set Revive[whichUnit].onY=0.
set Revive[whichUnit].awakenFx=DEFAULT_AWAKEN_FX
set Revive[whichUnit].cooldown=0.
static if LIBRARY_ReTimerdialog then
set Revive[whichUnit].showTd=false
endif
static if LIBRARY_ReLeaderboard then
set Revive[whichUnit].showLd=false
endif
endif
endfunction
function RegisterReviveEvent takes code c returns nothing
call TriggerAddCondition(r,Filter(c))
endfunction
endlibrary
//TESH.scrollpos=30
//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=291
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.3
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")
//New textmacro to allow table.integer[] syntax for compatibility with textmacros that might desire it.
//! runtextmacro NEW_ARRAY_BASIC("Integer", "Integer", "integer")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement integerm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
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 UnitIndexer /* v4.0.2.8
*************************************************************************************
*
* Assigns unique indexes to units via unit user data.
*
*************************************************************************************
*
* */uses/*
*
* */ WorldBounds /* hiveworkshop.com/forums/jass-functions-413/snippet-worldbounds-180494/
* */ Event /* hiveworkshop.com/forums/submissions-414/snippet-event-186555/
*
************************************************************************************
*
* Functions
*
* function RegisterUnitIndexEvent takes boolexpr codeToRegister, Event unitIndexEvent returns nothing
* function TriggerRegisterUnitIndexEvent takes trigger triggerToRegister, Event unitIndexEvent returns nothing
*
* function GetUnitById takes integer index returns unit
* - Returns unit given a unit index
* function GetUnitId takes unit u returns integer
* - Returns unit index given a unit
*
* function IsUnitIndexed takes unit u returns boolean
* function IsUnitDeindexing takes unit u returns boolean
*
* function GetIndexedUnitId takes nothing returns integer
* function GetIndexedUnit takes nothing returns unit
*
************************************************************************************
*
* module UnitIndexStructMethods
* static method operator [] takes unit u returns thistype
* - Return GetUnitUserData(u)
*
* readonly unit unit
* - The indexed unit of the struct
*
************************************************************************************
*
* module UnitIndexStruct extends UnitIndexStructMethods
*
* - A pseudo module interface that runs a set of methods if they exist and provides
* - a few fields and operators. Runs on static ifs to minimize code.
*
* readonly boolean allocated
* - Is unit allocated for the struct
*
* Interface:
*
* - These methods don't have to exist. If they don't exist, the code
* - that calls them won't even be in the module.
*
* private method index takes nothing returns nothing
* - called when a unit is indexed and passes the filter.
* -
* - thistype this: Unit's index
* private method deindex takes nothing returns nothing
* - called when a unit is deindexed and is allocated for struct
* -
* - thistype this: Unit's index
* private static method filter takes unit unitToIndex returns boolean
* - Determines whether or not to allocate struct for unit
* -
* - unit unitToIndex: Unit being filtered
*
************************************************************************************
*
* struct UnitIndexer extends array
*
* - Controls the unit indexer system.
*
* static constant Event UnitIndexer.INDEX
* static constant Event UnitIndexer.DEINDEX
* - Don't register functions and triggers directly to the events. Register them via
* - RegisterUnitIndexEvent and TriggerRegisterUnitIndexEvent.
*
* static boolean enabled
* - Enables and disables unit indexing. Useful for filtering out dummy units.
*
************************************************************************************
*
* struct UnitIndex extends UnitIndexStructMethods
*
* - Constrols specific unit indexes.
*
* method lock takes nothing returns nothing
* - Locks an index. When an index is locked, it will not be recycled
* - when the unit is deindexed until all locks are removed. Deindex
* - events still fire at the appropriate times, the index just doesn't
* - get thrown into the recycler.
* method unlock takes nothing returns nothing
* - Unlocks an index.
*
************************************************************************************/
globals
private constant integer ABILITIES_UNIT_INDEXER = 'A000'
private trigger q=CreateTrigger()
private trigger l=CreateTrigger()
private unit array e
private integer r=0
private integer y=0
private integer o=0
private boolean a=false
private integer array n
private integer array p
private integer array lc
endglobals
function GetIndexedUnitId takes nothing returns integer
return o
endfunction
function GetIndexedUnit takes nothing returns unit
return e[o]
endfunction
//! runtextmacro optional UNIT_LIST_LIB()
private struct PreLoader extends array
public static method run takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
set a=true
endmethod
public static method eval takes trigger t returns nothing
local integer f=n[0]
local integer d=o
loop
exitwhen 0==f
if (IsTriggerEnabled(t)) then
set o=f
if (TriggerEvaluate(t)) then
call TriggerExecute(t)
endif
else
exitwhen true
endif
set f=n[f]
endloop
set o=d
endmethod
public static method evalb takes boolexpr c returns nothing
local trigger t=CreateTrigger()
local thistype f=n[0]
local integer d=o
call TriggerAddCondition(t,c)
loop
exitwhen 0==f
set o=f
call TriggerEvaluate(t)
set f=n[f]
endloop
call DestroyTrigger(t)
set t=null
set o=d
endmethod
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO()
private module UnitIndexerInit
private static method onInit takes nothing returns nothing
local integer i=15
local boolexpr bc=Condition(function thistype.onLeave)
local boolexpr bc2=Condition(function thistype.onEnter)
local group g=CreateGroup()
local player p
set INDEX=CreateEvent()
set DEINDEX=CreateEvent()
call TriggerRegisterEnterRegion(q,WorldBounds.worldRegion,bc2)
loop
set p=Player(i)
call TriggerRegisterPlayerUnitEvent(l,p,EVENT_PLAYER_UNIT_ISSUED_ORDER,bc)
call SetPlayerAbilityAvailable(p,ABILITIES_UNIT_INDEXER,false)
call GroupEnumUnitsOfPlayer(g,p,bc2)
exitwhen 0==i
set i=i-1
endloop
call DestroyGroup(g)
set bc=null
set g=null
set bc2=null
set p=null
call TimerStart(CreateTimer(),0,false,function PreLoader.run)
endmethod
endmodule
struct UnitIndex extends array
method lock takes nothing returns nothing
debug if (null!=e[this]) then
set lc[this]=lc[this]+1
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO LOCK NULL INDEX")
debug endif
endmethod
method unlock takes nothing returns nothing
debug if (0<lc[this]) then
set lc[this]=lc[this]-1
if (0==lc[this] and null==e[this]) then
set n[this]=y
set y=this
endif
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"UNIT INDEXER ERROR: ATTEMPT TO UNLOCK UNLOCKED INDEX")
debug endif
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
static method operator [] takes unit whichUnit returns thistype
return GetUnitUserData(whichUnit)
endmethod
endstruct
struct UnitIndexer extends array
readonly static Event INDEX
readonly static Event DEINDEX
static method operator enabled takes nothing returns boolean
return IsTriggerEnabled(q)
endmethod
static method operator enabled= takes boolean b returns nothing
if (b) then
call DisableTrigger(q)
call DisableTrigger(l)
else
call EnableTrigger(q)
call EnableTrigger(l)
endif
endmethod
private static method onEnter takes nothing returns boolean
local unit Q=GetFilterUnit()
local integer i
local integer d=o
if (Q!=e[GetUnitUserData(Q)] and 0==GetUnitUserData(Q)) then
if (0==y) then
set r=r+1
set i=r
else
set i=y
set y=n[y]
endif
call UnitAddAbility(Q,ABILITIES_UNIT_INDEXER)
call UnitMakeAbilityPermanent(Q,true,ABILITIES_UNIT_INDEXER)
call SetUnitUserData(Q,i)
set e[i]=Q
static if not LIBRARY_UnitList then
if (not a)then
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
endif
else
set p[i]=p[0]
set n[p[0]]=i
set n[i]=0
set p[0]=i
call GroupAddUnit(g,e[i])
endif
set o=i
call FireEvent(INDEX)
set o=d
endif
set Q=null
return false
endmethod
private static method onLeave takes nothing returns boolean
static if LIBRARY_UnitEvent then
implement optional UnitEventModule
else
local unit u=GetFilterUnit()
local integer i=GetUnitUserData(u)
local integer d=o
if (0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER) and u==e[i]) then
static if not LIBRARY_UnitList then
if (not a)then
set n[p[i]]=n[i]
set p[n[i]]=p[i]
endif
else
set n[p[i]]=n[i]
set p[n[i]]=p[i]
call GroupRemoveUnit(g,e[i])
endif
set o=i
call FireEvent(DEINDEX)
set o=d
if (0==lc[i]) then
set n[i]=y
set y=i
endif
set e[i]=null
endif
set u=null
endif
return false
endmethod
implement UnitIndexerInit
endstruct
//! runtextmacro optional UNIT_EVENT_MACRO_2()
function RegisterUnitIndexEvent takes boolexpr c,integer ev returns nothing
call RegisterEvent(c, ev)
if (not a and ev==UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.evalb(c)
endif
endfunction
function TriggerRegisterUnitIndexEvent takes trigger t,integer ev returns nothing
call TriggerRegisterEvent(t,ev)
if (not a and ev == UnitIndexer.INDEX and 0!=n[0]) then
call PreLoader.eval(t)
endif
endfunction
function GetUnitById takes integer W returns unit
return e[W]
endfunction
function GetUnitId takes unit u returns integer
return GetUnitUserData(u)
endfunction
function IsUnitIndexed takes unit u returns boolean
return u==e[GetUnitUserData(u)]
endfunction
function IsUnitDeindexing takes unit u returns boolean
return IsUnitIndexed(u) and 0==GetUnitAbilityLevel(u,ABILITIES_UNIT_INDEXER)
endfunction
module UnitIndexStructMethods
static method operator [] takes unit u returns thistype
return GetUnitUserData(u)
endmethod
method operator unit takes nothing returns unit
return e[this]
endmethod
endmodule
module UnitIndexStruct
implement UnitIndexStructMethods
static if thistype.filter.exists then
static if thistype.index.exists then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return filter(e[this])
endmethod
endif
elseif (thistype.index.exists) then
static if thistype.deindex.exists then
readonly boolean allocated
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
else
method operator allocated takes nothing returns boolean
return this==GetUnitUserData(e[this])
endmethod
endif
static if thistype.index.exists then
private static method onIndexEvent takes nothing returns boolean
static if thistype.filter.exists then
if (filter(e[o])) then
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
else
static if thistype.deindex.exists then
set thistype(o).allocated=true
endif
call thistype(o).index()
endif
return false
endmethod
endif
static if thistype.deindex.exists then
private static method onDeindexEvent takes nothing returns boolean
static if thistype.filter.exists then
static if thistype.index.exists then
if (thistype(o).allocated) then
set thistype(o).allocated=false
call thistype(o).deindex()
endif
else
if (filter(e[o])) then
call thistype(o).deindex()
endif
endif
else
static if thistype.index.exists then
set thistype(o).allocated=false
endif
call thistype(o).deindex()
endif
return false
endmethod
endif
static if thistype.index.exists then
static if thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
else
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onIndexEvent),UnitIndexer.INDEX)
endmethod
endif
elseif thistype.deindex.exists then
private static method onInit takes nothing returns nothing
call RegisterUnitIndexEvent(Condition(function thistype.onDeindexEvent),UnitIndexer.DEINDEX)
endmethod
endif
endmodule
endlibrary
//TESH.scrollpos=12
//TESH.alwaysfold=0
library Event
//2.0.0.1
/////////////////////////////////////////////////////////////////////////
//function CreateEvent takes nothing returns integer
//function TriggerRegisterEvent takes trigger t, integer ev returns nothing
//function RegisterEvent takes boolexpr c, integer ev returns nothing
//function FireEvent takes integer ev returns nothing
//struct Event extends array
//static method create takes nothing returns thistype
//method registerTrigger takes trigger t returns nothing
//method register takes boolexpr c returns nothing
//method fire takes nothing returns nothing
/////////////////////////////////////////////////////////////////////////
globals
private real q=0
endglobals
struct Event extends array
private static integer w=0
private static trigger array e
static method create takes nothing returns thistype
set w=w+1
set e[w]=CreateTrigger()
return w
endmethod
method registerTrigger takes trigger t returns nothing
call TriggerRegisterVariableEvent(t,SCOPE_PRIVATE+"q",EQUAL,this)
endmethod
method register takes boolexpr c returns nothing
call TriggerAddCondition(e[this],c)
endmethod
method fire takes nothing returns nothing
set q=0
set q=this
call TriggerEvaluate(e[this])
endmethod
endstruct
function CreateEvent takes nothing returns Event
return Event.create()
endfunction
function TriggerRegisterEvent takes trigger t,Event ev returns nothing
call ev.registerTrigger(t)
endfunction
function RegisterEvent takes boolexpr c,Event ev returns nothing
call ev.register(c)
endfunction
function FireEvent takes Event ev returns nothing
call ev.fire()
endfunction
endlibrary
//TESH.scrollpos=14
//TESH.alwaysfold=0
library WorldBounds
//struct WorldBounds extends array
//static readonly rect world
// same as GetWorldBounds()
//static readonly region worldRegion
// contains world for triggers
//static readonly real maxX
//static readonly real maxY
//static readonly real minX
//static readonly real minY
//static readonly real centerX
//static readonly real centerY
private module WorldBoundInit
private static method onInit takes nothing returns nothing
set world=GetWorldBounds()
set maxX=GetRectMaxX(world)
set maxY=GetRectMaxY(world)
set minX=GetRectMinX(world)
set minY=GetRectMinY(world)
set centerX=(maxX+minX)/2
set centerY=(minY+maxY)/2
set worldRegion=CreateRegion()
call RegionAddRect(worldRegion,world)
endmethod
endmodule
struct WorldBounds extends array
readonly static real maxX
readonly static real maxY
readonly static real minX
readonly static real minY
readonly static real centerX
readonly static real centerY
readonly static rect world
readonly static region worldRegion
implement WorldBoundInit
endstruct
endlibrary
//TESH.scrollpos=285
//TESH.alwaysfold=0
library AdvBoard/*
*********************************************************************************************************************
*
* *****************************************************************************************************************
*
* */ uses /*
* */ ARGB /* wc3c.net/showthread.php?t=101858
* */ IconLibrary /* hiveworkshop.com/forums/submissions-414/snipet-iconlibrary-264329/
* */ MultiboardTools /* hiveworkshop.com/forums/submissions-414/snipet-multiboardtools-263709/#post2664244
* */ OrderEvent /* hiveworkshop.com/forums/jass-resources-412/snippet-order-event-190871/
* */ TeamIndex /* hiveworkshop.com/forums/submissions-414/snippet-teamreforce-257915/
* */ TimerUtils /* hiveworkshop.com/forums/graveyard-418/system-timerutilsex-204500/
* */ ReviveEvent /* hiveworkshop.com/forums/submissions-414/snippet-reviveevent-263628/
* */ RegisterPlayerUnitEvent /* hiveworkshop.com/forums/showthread.php?t=203338
*
* *****************************************************************************************************************
*
* AdvBoard
* ________
* v2.0.0.0
* by Thelordmarshall
*
*
* AdvBoard (AdvanceMultiboard) is designed to work in any map, inspired from dota
* multiboard; you can see all the basic information in it: player name, unit icon,
* levels, cooldown, kill, deaths, gold, etc....
*
* One could say that the system is still in beta phase, in previous versions
* I found a lots of bugs that i fixed with success. Maybe this version contains
* some bugs.
*
* IMPORTANT:
* __________
*
* - In order that it work correctly go to: Scenario/Player Properties/Forces
* and select the box "Allied" of each force of your map.
*
* Pros:
* _____
*
* - Designed for ANY map.
* - The multiboard is refreshed in separated methods, this prevent the short
* period of lag caused for update ALL multiboard data at the same time.
* - The teams can see your private DATA.
* - No EMPTY slots.
*
* API:
* ____
*
* struct AdvBoard:
* - static method operator title= takes string s returns nothing
* - change multiboard title.
* - static method operator title takes nothing returns string
* - get current title.
* - method operator teamTitle= takes string name returns nothing
* - change any team name: set AdvBoard[teamIndex].teamTitle=teamTitle
* - method operator teamTitle takes nothing returns string
* - current team title: AdvBoard[teamIndex].teamTitle
* - static method operator unit= takes unit u returns nothing
* - synchronize unit to multiboard.
* - method operator cooldown= takes integer c returns nothing
* - start cooldown for player: set AdvBoard[playerId].cooldown=20.
* - static method show takes boolean show returns nothing
* - show/hide multiboard.
*
* Credits:
* ________
*
* - Bribe: OrderEvent.
* - Vexorian: ARGB, TimerUtils.
* - Magtheridon96: RegisterPlayerUnitEvent.
*********************************************************************************************************************/
//CONFIGURATION
//============================================================================
globals
//Names
private constant string DEFAULT_BOARD_TITLE = "AdvBoard v2.0"
private constant string DEFAULT_TEAM_NAME = "Team"
private constant string COOLDOWN_NAME = "CD"
private constant string LEVEL_NAME = "lvl"
private constant string KILL_NAME = "K"
private constant string DEATH_NAME = "D"
//Icons
private constant string GOLD_ICON = "UI\\Feedback\\Resources\\ResourceGold.blp"
private constant string LUMBER_ICON = "UI\\Feedback\\Resources\\ResourceLumber.blp"
private constant string FOOD_ICON = "UI\\Feedback\\Resources\\ResourceSupply.blp"
//ARGB Colors
private ARGB DEFAULT_COLOR = 0x22222222
private ARGB KILL_DEATH_COLOR = 0xffaaaaaa
private ARGB CD_COLOR = 0x00C1C1C1
private ARGB LVL_COLOR = 0x00797979
private ARGB KILL_COLOR = 0x008000FF
private ARGB DEATH_COLOR = 0x00F43535
private ARGB GOLD_COLOR = 0xffffcc00
private ARGB LUMBER_COLOR = 0x00006C00
private ARGB FOOD_COLOR = 0x00CA6500
private ARGB ITEM_COLOR = 0x008080C0
endglobals
//============================================================================
//ENDCONFIGURATION
globals
private Multiboard mb=0
private string mbTitle=""
private constant integer COLUMN_COUNT=14
private integer array level
private integer array kills
private integer array deaths
private integer array teamKills
private integer array teamDeaths
private integer array teamIndex
private unit array boardUnit
private string array teamName
private real array cd
private trigger array t
endglobals
//! textmacro ADV_MULTIBOARD_STATE takes FUNC,STATE,RETURN
private function $FUNC$ takes player p returns $RETURN$
return $STATE$
endfunction
//! endtextmacro
//! runtextmacro ADV_MULTIBOARD_STATE("IsPlaying","GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING","boolean")
//! runtextmacro ADV_MULTIBOARD_STATE("IsLeft","GetPlayerSlotState(p)==PLAYER_SLOT_STATE_LEFT","boolean")
//! runtextmacro ADV_MULTIBOARD_STATE("GetGold","GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)","integer")
//! runtextmacro ADV_MULTIBOARD_STATE("GetLumber","GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)","integer")
//! runtextmacro ADV_MULTIBOARD_STATE("GetPlayerFoodUsed","GetPlayerState(p,PLAYER_STATE_RESOURCE_FOOD_USED)","integer")
//! runtextmacro ADV_MULTIBOARD_STATE("GetFoodCap","GetPlayerState(p,PLAYER_STATE_RESOURCE_FOOD_CAP)","integer")
private function UpdateResource takes player p, integer c, string r returns nothing
if(IsPlaying(p) and IsPlayerAlly(p,GetLocalPlayer()))then
set mb[2+GetPlayerForceId(p)+GetPlayerIdInForce(p)][c].text=r
endif
endfunction
private function UpdateGold takes nothing returns nothing
local player p=GetTriggerPlayer()
call UpdateResource(p,5,GOLD_COLOR.str(I2S(GetGold(p))))
endfunction
private function UpdateLumber takes nothing returns nothing
local player p=GetTriggerPlayer()
call UpdateResource(p,6,LUMBER_COLOR.str(I2S(GetLumber(p))))
endfunction
private function UpdateFood takes nothing returns nothing
local player p=GetTriggerPlayer()
call UpdateResource(p,7,FOOD_COLOR.str(I2S(GetPlayerFoodUsed(p))+"/"+I2S(GetFoodCap(p))))
endfunction
private function FoodOnRevive takes nothing returns nothing
local unit u=GetLastRevivedUnit()
local player p=GetOwningPlayer(u)
if(GetUnitFoodUsed(u)>0 or GetUnitFoodMade(u)>0)then
call UpdateResource(p,7,FOOD_COLOR.str(I2S(GetPlayerFoodUsed(p))+"/"+I2S(GetFoodCap(p))))
endif
set u=null
endfunction
private function UpdateKillsDeaths takes nothing returns nothing
local unit d=GetDyingUnit()
local unit k=GetKillingUnit()
local player l=GetLocalPlayer()
local player p1=GetOwningPlayer(d)
local player p2=GetOwningPlayer(k)
local integer id1=GetPlayerId(p1)
local integer id2=GetPlayerId(p2)
local integer t1=GetPlayerForceId(p1)
local integer t2=GetPlayerForceId(p2)
local integer row1=2+GetPlayerForceId(p1)+GetPlayerIdInForce(p1)
local integer row2=2+GetPlayerForceId(p2)+GetPlayerIdInForce(p2)
local boolean b=IsPlayerEnemy(p1,p2)
if(p1==GetOwningPlayer(boardUnit[id1]) and b)then
set deaths[id1]=deaths[id1]+1
set teamDeaths[t1]=teamDeaths[t1]+1
set mb[row1][4].text=DEATH_COLOR.str(I2S(deaths[id1]))
set mb[teamIndex[t1]][4].text=DEATH_COLOR.str(I2S(teamDeaths[t1]))
if(l==p1)then
set mb.title=KILL_DEATH_COLOR.str(I2S(kills[id1])+"/"+I2S(deaths[id1]))+" - "+mbTitle
endif
endif
if(p2==GetOwningPlayer(boardUnit[id2]) and b)then
set kills[id2]=kills[id2]+1
set teamKills[t2]=teamKills[t2]+1
set mb[row2][3].text=KILL_COLOR.str(I2S(kills[id2]))
set mb[teamIndex[t2]][3].text=KILL_COLOR.str(I2S(teamKills[t2]))
if(l==p2)then
set mb.title=KILL_DEATH_COLOR.str(I2S(kills[id2])+"/"+I2S(deaths[id2]))+" - "+mbTitle
endif
endif
set d=null
set k=null
endfunction
private function UpdateLevel takes nothing returns nothing
local unit u=GetTriggerUnit()
local player p=GetTriggerPlayer()
local integer id=GetPlayerId(p)
local integer row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
if(u==boardUnit[id] and IsUnitType(u,UNIT_TYPE_HERO))then
set level[id]=GetUnitLevel(u)
set mb[row][2].text=LVL_COLOR.str(I2S(level[id]))
endif
set u=null
endfunction
private function UpdateAllSlotsIcons takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer id=GetTimerData(t)
local player p=Player(id)
local integer row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
local integer i=0
loop
exitwhen(i==bj_MAX_INVENTORY)
set mb[row][8+i].icon=GetItemIcon(UnitItemInSlot(boardUnit[id],i))
set i=i+1
endloop
call ReleaseTimer(t)
endfunction
private function UpdateSlots takes nothing returns nothing
local unit u=GetTriggerUnit()
local integer id=GetPlayerId(GetOwningPlayer(u))
if(u==boardUnit[id])then
call TimerStart(NewTimerEx(id),0,false,function UpdateAllSlotsIcons)
endif
set u=null
endfunction
struct AdvBoard extends array
static method operator [] takes integer this returns thistype
return this
endmethod
static method operator show= takes boolean show returns nothing
set mb.show=show
endmethod
static method operator title takes nothing returns string
return mbTitle
endmethod
static method operator title= takes string s returns nothing
local player l=GetLocalPlayer()
local integer i=0
set mbTitle=s
loop
exitwhen(i==bj_MAX_PLAYERS)
if(l==Player(i))then
set mb.title=KILL_DEATH_COLOR.str(I2S(kills[i])+"/"+I2S(deaths[i]))+" - "+mbTitle
endif
set i=i+1
endloop
endmethod
method operator teamTitle= takes string name returns nothing
if(this>=0 and this<=CountMapTeams()-1)then
set teamName[this]=name
set mb[teamIndex[this]][0].text=teamName[this]
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,60.,"[AdaptiveMultiboard] Error: unable to change name to nonexistent teamId ["+I2S(this)+"]")
endif
endmethod
method operator teamTitle takes nothing returns string
return teamName[this]
endmethod
static method operator unit= takes unit u returns nothing
local player p=GetOwningPlayer(u)
local integer id=GetPlayerId(p)
local integer row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
if(IsPlaying(p))then
set boardUnit[id]=u
set mb[row][0].icon=GetUnitIcon(u)
set mb[row][2].text=LVL_COLOR.str(I2S(GetUnitLevel(u)))
call TimerStart(NewTimerEx(id),0,false,function UpdateAllSlotsIcons)
endif
endmethod
method operator cooldown= takes integer c returns nothing
local player p=Player(this)
if(IsPlaying(p) and cd[this]<=1.)then
set cd[this]=I2R(c)+1.
call TimerStart(NewTimerEx(this),.03125,true,function thistype.onCooldown)
debug elseif(cd[this]>1.)then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0.,0.,60.,"[AdaptiveMultiboard] Error: "+ARGB.fromPlayer(p).str(GetPlayerName(p))+" cooldown is allready started.")
endif
endmethod
private static method onCooldown takes nothing returns nothing
local timer t=GetExpiredTimer()
local integer id=GetTimerData(t)
local player p=Player(id)
local integer row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
set cd[id]=cd[id]-.03125
set mb[row][1].text=CD_COLOR.str(I2S(R2I(cd[id])))
if(cd[id]<=1.)then
set mb[row][1].text=DEFAULT_COLOR.str(I2S(R2I(cd[id])))
call ReleaseTimer(t)
endif
endmethod
endstruct
private function ClearMultiboard takes nothing returns nothing
local integer l=1+CountMapTeams()+GetStartPlayers()
local integer i=1
local integer h=1
loop
exitwhen(i==l)
loop
exitwhen(h==8)
set mb[i][h].text=""
set h=h+1
endloop
set h=1
set i=i+1
endloop
call mb[0][0].setStyle(true,false)
set mb[0][5].icon=GOLD_ICON
set mb[0][6].icon=LUMBER_ICON
set mb[0][7].icon=FOOD_ICON
endfunction
private function InitTeams takes nothing returns nothing
local integer c=CountMapTeams()
local integer n=0
local integer i=0
local integer row=1
loop
exitwhen(i==c)
if(i>0)then
set n=n+CountPlayersInForce(i-1)
set row=1+n+i
endif
set teamIndex[i]=row
if(teamName[i]==null)then
set teamName[i]=DEFAULT_TEAM_NAME+" "+I2S(i+1)
endif
set mb[row][0].text=ARGB(0xffffcc00).str(teamName[i])
set mb[row][3].text=KILL_COLOR.str(I2S(teamKills[i]))
set mb[row][4].text=DEATH_COLOR.str(I2S(teamDeaths[i]))
set i=i+1
endloop
endfunction
private function InitPlayers takes nothing returns nothing
local player l=GetLocalPlayer()
local integer i=0
local integer row
local player p
local string s
loop
exitwhen(i==bj_MAX_PLAYERS)
set p=Player(i)
set row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
if(IsLeft(p))then
set s=DEFAULT_COLOR.str(GetPlayerName(p))
else
set s=ARGB.fromPlayer(p).str(GetPlayerName(p))
endif
if(IsPlaying(p) or IsLeft(p))then
set mb[row][0].icon=GetUnitIcon(boardUnit[i])
call mb[row][0].setStyle(true,true)
set mb[row][0].text=s
set mb[row][1].text=DEFAULT_COLOR.str(I2S(R2I(cd[i])))
set mb[row][2].text=DEFAULT_COLOR.str(I2S(level[i]))
set mb[row][3].text=KILL_COLOR.str(I2S(kills[i]))
set mb[row][4].text=DEATH_COLOR.str(I2S(deaths[i]))
if(IsPlayerAlly(p,l))then
set mb[row][5].text=GOLD_COLOR.str(I2S(GetGold(p)))
set mb[row][6].text=LUMBER_COLOR.str(I2S(GetLumber(p)))
set mb[row][7].text=FOOD_COLOR.str(I2S(GetPlayerFoodUsed(p))+"/"+I2S(GetFoodCap(p)))
endif
endif
set i=i+1
endloop
endfunction
private function InitItemsIcons takes nothing returns nothing
local integer h=0
local integer n=8
local integer s=0
local integer row
local player p
loop
exitwhen(h==bj_MAX_PLAYERS)
set p=Player(h)
set row=2+GetPlayerForceId(p)+GetPlayerIdInForce(p)
loop
exitwhen(n==14)
set mb[row][n].icon=GetItemIcon(UnitItemInSlot(boardUnit[h],s))
call mb[row][n].setStyle(true,true)
set s=s+1
set n=n+1
endloop
set s=0
set n=8
set h=h+1
endloop
call ReleaseTimer(GetExpiredTimer())
endfunction
private function InitMultiboard takes nothing returns nothing
set mbTitle=DEFAULT_BOARD_TITLE
set mb=Multiboard.create(KILL_DEATH_COLOR.str("0"+"/"+"0"+"|r - ")+mbTitle,1+CountMapTeams()+GetCountPlayers(),COLUMN_COUNT)
call mb[0][0].setStyle(true,false)
set mb[0][0].width=10.20//player name
set mb[0][1].width=1.80 //cooldown
set mb[0][2].width=1.80 //levels
set mb[0][3].width=1.30 //kills
set mb[0][4].width=1.30 //deaths
set mb[0][5].width=3.00 //gold
set mb[0][6].width=3.00 //lumber
set mb[0][7].width=3.00 //food
set mb[0][8].width=1.10 //items slots
set mb[0][9].width=1.10
set mb[0][10].width=1.10
set mb[0][11].width=1.10
set mb[0][12].width=1.10
set mb[0][13].width=1.10//items slots end
set mb[0][1].text=CD_COLOR.str(COOLDOWN_NAME)
set mb[0][2].text=LVL_COLOR.str(LEVEL_NAME)
set mb[0][3].text=KILL_COLOR.str(KILL_NAME)
set mb[0][4].text=DEATH_COLOR.str(DEATH_NAME)
set mb[0][5].icon=GOLD_ICON
set mb[0][6].icon=LUMBER_ICON
set mb[0][7].icon=FOOD_ICON
set mb[0][9].text=ITEM_COLOR.str("ite")
set mb[0][10].text=ITEM_COLOR.str("ms")
set mb.show=false
endfunction
private function RenderBoard takes nothing returns nothing
if(mb==0)then
call InitMultiboard()
else
call ClearMultiboard()
endif
call InitTeams()
call InitPlayers()
call TimerStart(NewTimer(),0,false,function InitItemsIcons)
endfunction
private function RegisterStateEvent takes playerstate s, code c returns nothing
local integer h=GetHandleId(s)
local integer i=15
local integer r
local player p
set t[h]=CreateTrigger()
loop
set p=Player(i)
set r=GetPlayerState(p,s)
call TriggerRegisterPlayerStateEvent(t[h],p,s,GREATER_THAN,r)
call TriggerRegisterPlayerStateEvent(t[h],p,s,LESS_THAN,r)
exitwhen(0==i)
set i=i-1
endloop
call TriggerAddCondition(t[h],Filter(c))
endfunction
private module Init
private static method onInit takes nothing returns nothing
local integer i=0
loop
exitwhen(i==bj_MAX_INVENTORY)
call RegisterOrderEvent(852002+i,function UpdateSlots)
set i=i+1
endloop
call RegisterReviveEvent(function FoodOnRevive)
call RegisterEventAllianceChange(function RenderBoard)
call RegisterStateEvent(PLAYER_STATE_RESOURCE_GOLD,function UpdateGold)
call RegisterStateEvent(PLAYER_STATE_RESOURCE_LUMBER,function UpdateLumber)
call RegisterStateEvent(PLAYER_STATE_RESOURCE_FOOD_CAP,function UpdateFood)
call RegisterStateEvent(PLAYER_STATE_RESOURCE_FOOD_USED,function UpdateFood)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH,function UpdateKillsDeaths)
call RegisterPlayerUnitEvent(EVENT_PLAYER_HERO_LEVEL,function UpdateLevel)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_PICKUP_ITEM,function UpdateSlots)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DROP_ITEM,function UpdateKillsDeaths)
endmethod
endmodule
private struct i extends array
implement Init
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library InitIcons initializer Init uses IconLibrary
private function Init takes nothing returns nothing
//Units
call SaveIcon('Hblm',"ReplaceableTextures\\CommandButtons\\BTNHeroBloodElfPrince.blp")
call SaveIcon('Hpal',"ReplaceableTextures\\CommandButtons\\BTNHeroPaladin.blp")
call SaveIcon('Obla',"ReplaceableTextures\\CommandButtons\\BTNHeroBlademaster.blp")
call SaveIcon('Edem',"ReplaceableTextures\\CommandButtons\\BTNHeroDemonHunter.blp")
call SaveIcon('Ewar',"ReplaceableTextures\\CommandButtons\\BTNHeroWarden.blp")
call SaveIcon('Udea',"ReplaceableTextures\\CommandButtons\\BTNHeroDeathKnight.blp")
call SaveIcon('Ucrl',"ReplaceableTextures\\CommandButtons\\BTNHeroCryptLord.blp")
call SaveIcon('Otch',"ReplaceableTextures\\CommandButtons\\BTNHeroTaurenChieftain.blp")
call SaveIcon('Nalc',"ReplaceableTextures\\CommandButtons\\BTNHeroAlchemist.blp")
call SaveIcon('Nbrn',"ReplaceableTextures\\CommandButtons\\BTNBansheeRanger.blp")
call SaveIcon('Nfir',"ReplaceableTextures\\CommandButtons\\BTNHeroAvatarOfFlame.blp")
call SaveIcon('Nplh',"ReplaceableTextures\\CommandButtons\\BTNPitLord.blp")
//Items
call SaveIcon('stwp',"ReplaceableTextures\\CommandButtons\\BTNScrollUber.blp")
call SaveIcon('bspd',"ReplaceableTextures\\CommandButtons\\BTNBootsOfSpeed.blp")
call SaveIcon('dust',"ReplaceableTextures\\CommandButtons\\BTNDustOfAppearance.blp")
call SaveIcon('tret',"ReplaceableTextures\\CommandButtons\\BTNTomeOfRetraining.blp")
call SaveIcon('prvt',"ReplaceableTextures\\CommandButtons\\BTNPeriapt.blp")
call SaveIcon('cnob',"ReplaceableTextures\\CommandButtons\\BTNCirclet.blp")
call SaveIcon('stel',"ReplaceableTextures\\CommandButtons\\BTNStaffOfTeleportation.blp")
call SaveIcon('pnvl',"ReplaceableTextures\\CommandButtons\\BTNLesserInvulneralbility.blp")
call SaveIcon('shea',"ReplaceableTextures\\CommandButtons\\BTNScrollOfTownPortal.blp")
call SaveIcon('spro',"ReplaceableTextures\\CommandButtons\\BTNScroll.blp")
call SaveIcon('pinv',"ReplaceableTextures\\CommandButtons\\BTNLesserInvisibility.blp")
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SynchronizingUnit initializer Init uses TimerUtils
private function Synchro takes nothing returns nothing
set AdvBoard.unit=gg_unit_Hblm_0000
set AdvBoard.unit=gg_unit_Hpal_0013
set AdvBoard.unit=gg_unit_Obla_0017
set AdvBoard.unit=gg_unit_Edem_0020
set AdvBoard.unit=gg_unit_Ewar_0015
set AdvBoard.unit=gg_unit_Udea_0019
set AdvBoard.unit=gg_unit_Ucrl_0016
set AdvBoard.unit=gg_unit_Otch_0021
set AdvBoard.unit=gg_unit_Nalc_0018
set AdvBoard.unit=gg_unit_Nbrn_0024
set AdvBoard.unit=gg_unit_Nfir_0022
set AdvBoard.unit=gg_unit_Nplh_0023
endfunction
private function Init takes nothing returns nothing
call TimerStart(NewTimer(),1.,false,function Synchro)
endfunction
endlibrary
//TESH.scrollpos=9
//TESH.alwaysfold=0
library StartingCooldown initializer Init requires TimerUtils, AdvBoard
globals
private unit array deathUnit
endglobals
private function OnRevive takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer this = GetTimerData(t)
local real x = GetUnitX(deathUnit[this])
local real y = GetUnitY(deathUnit[this])
call ReviveHero(deathUnit[this],x,y,true)
set deathUnit[this] = null
call ReleaseTimer(t)
set t = null
endfunction
private function OnDeath takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer this = GetPlayerId(GetOwningPlayer(u))
local integer cooldown = 20
//if IsUnitType(u,UNIT_TYPE_HERO) then
set deathUnit[this] = u
call TimerStart(NewTimerEx(this),I2R(cooldown),false,function OnRevive)
//call AdvBoard.startCooldown(cooldown,GetOwningPlayer(u)) //The cooldown.
set AdvBoard[this].cooldown=cooldown//GetOwningPlayer(u)
//endif
set u = null
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddCondition(t,function OnDeath)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library ARGBDegrade uses ARGB
function DegradeStr takes string s, ARGB a, ARGB b returns string
local integer l=StringLength(s)
local integer i=0
local string r=""
if(l==1)then
return ARGB.mix(a,b,.5).str(s)
endif
loop
exitwhen(i>=l)
set r=r+ARGB.mix(a,b,i*(1./(l-1))).str(SubString(s,i,i+1))
set i=i+1
endloop
return r
endfunction
endlibrary