function SaveLoad_InitialSetup takes nothing returns nothing
local integer i = 0
local integer j = 0
loop
set udg_SaveLoad_Compress[i + 48] = j
set udg_SaveLoad_Uncompress[i] = i + 48
set j = j + 1
set i = i + 1
exitwhen i >= 10
endloop
set i = 0
loop
set udg_SaveLoad_Compress[i + 97] = j
set udg_SaveLoad_Compress[i + 65] = j + 26
set udg_SaveLoad_Uncompress[i + 10] = i + 97
set udg_SaveLoad_Uncompress[i + 26 + 10] = i + 65
set j = j + 1
set i = i + 1
exitwhen i >= 26
endloop
endfunction
function SaveLoad_Id2CId takes integer n returns integer
local integer i = n / (256 * 256 * 256)
local integer r
set n = n - i * (256 * 256 * 256)
set r = udg_SaveLoad_Compress[i]
set i = n / (256 * 256)
set n = n - i * (256 * 256)
set r = r * 64 + udg_SaveLoad_Compress[i]
set i = n / 256
set r = r * 64 + udg_SaveLoad_Compress[i]
return r * 64 + udg_SaveLoad_Compress[n - i * 256]
endfunction
function SaveLoad_CId2Id takes integer n returns integer
local integer i = n / (64 * 64 * 64)
local integer r
set n = n - i * (64 * 64 * 64)
set r = udg_SaveLoad_Uncompress[i]
set i = n / (64 * 64)
set n = n - i * (64 * 64)
set r = r * 256 + udg_SaveLoad_Uncompress[i]
set i = n / 64
set r = r * 256 + udg_SaveLoad_Uncompress[i]
return r * 256 + udg_SaveLoad_Uncompress[n - i * 64]
endfunction
function SaveLoad_Unit2Integer takes unit u returns integer
local integer i = 0
local integer n = GetUnitTypeId(u)
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
loop
set i = i + 1
exitwhen i > udg_SaveLoad_Heroes_LastIndex
if udg_SaveLoad_Heroes[i] == n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Unit takes integer i returns integer
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
if i <= udg_SaveLoad_Heroes_LastIndex then
return udg_SaveLoad_Heroes[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Item2Integer takes item t returns integer
local integer i = 0
local integer n = GetItemTypeId(t)
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
loop
set i = i + 1
exitwhen i > udg_SaveLoad_Items_LastIndex
if udg_SaveLoad_Items[i] == n then
return i
endif
endloop
return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Item takes integer i returns integer
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
if i <= udg_SaveLoad_Items_LastIndex then
return udg_SaveLoad_Items[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Ability2Integer takes integer a returns integer
local integer i = 0
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
loop
set i = i + 1
exitwhen i > udg_SaveLoad_Abilities_LastIndex
if udg_SaveLoad_Abilities[i] == a then
return i
endif
endloop
return SaveLoad_Id2CId(a)
endfunction
function SaveLoad_Integer2Ability takes integer i returns integer
if udg_SaveLoad_Initialized == false then
set udg_SaveLoad_Initialized = true
call SaveLoad_InitialSetup()
endif
if i <= udg_SaveLoad_Abilities_LastIndex then
return udg_SaveLoad_Abilities[i]
endif
return SaveLoad_CId2Id(i)
endfunction
function SaveLoad_Color takes string s returns string
local integer i = StringLength(s)
local string c
local string r = ""
loop
set i = i - 1
set c = SubString(s,i,i + 1)
if c == "0" or c == "1" or c == "2" or c == "3" or c == "4" or c == "5" or c == "6" or c == "7" or c == "8" or c == "9" then
set r = "|cffff9999" + c + "|r" + r
elseif c == "-" then
set r = "|cffdddddd-|r" + r
elseif c == "a" or c == "b" or c == "c" or c == "d" or c == "e" or c == "f" or c == "g" or c == "h" or c == "i" or c == "j" or c == "k" or c == "l" or c == "m" or c == "n" or c == "o" or c == "p" or c == "q" or c == "r" or c == "s" or c == "t" or c == "u" or c == "v" or c == "w" or c == "x" or c == "y" or c == "z" then
set r = "|cff99ff99" + c + "|r" + r
elseif c == "A" or c == "B" or c == "C" or c == "D" or c == "E" or c == "F" or c == "G" or c == "H" or c == "I" or c == "J" or c == "K" or c == "L" or c == "M" or c == "N" or c == "O" or c == "P" or c == "Q" or c == "R" or c == "S" or c == "T" or c == "U" or c == "V" or c == "W" or c == "X" or c == "Y" or c == "Z" then
set r = "|cff9999ff" + c + "|r" + r
else
set r = c + r
endif
exitwhen i <= 0
endloop
return r
endfunction
function SaveLoad_EncodeChar takes string n returns integer
local integer i = 0
local string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local string s2 = "abcdefghijklmnopqrstuvwxyz"
local string s3 = "0123456789"
loop
if SubString(s1,i,i + 1) == n then
return i
endif
if SubString(s2,i,i + 1) == n then
return i
endif
set i = i + 1
exitwhen i >= 26
endloop
set i = 0
loop
if SubString(s3,i,i + 1) == n then
return i
endif
set i = i + 1
exitwhen i >= 10
endloop
return 0
endfunction
function SaveLoad_EncodeVerify takes string buffer returns integer
local integer i = 0
local integer j = 0
local string name = GetPlayerName(GetTriggerPlayer())
if udg_SaveLoad_UsePlayername == true then
loop
set j = j + SaveLoad_EncodeChar(SubString(name,i,i + 1))
set i = i + 1
exitwhen i >= StringLength(name)
endloop
endif
set i = 0
loop
set j = j + SaveLoad_EncodeChar(SubString(buffer,i,i + 1))
set i = i + 1
exitwhen i >= StringLength(buffer)
endloop
return j
endfunction
function SaveLoad_EncodeValues takes nothing returns string
local integer i
local integer j
local integer k
local integer l
local integer m
local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
local integer array a
local string buffer = ""
local string c = ""
local integer skip = 0
local integer CONST = 1000000
local string abc = "0123456789"
set i = 0
loop
set i = i + 1
exitwhen i > udg_SaveCount
set buffer = buffer + I2S(udg_Save[i]) + "-"
endloop
set buffer = buffer + I2S(SaveLoad_EncodeVerify(buffer))
if udg_Save[1] == 0 then
set buffer = "-" + buffer
endif
set i = 0
loop
set a[i] = 0
set i = i + 1
exitwhen i >= 100
endloop
set m = 0
set i = 0
loop
set j = 0
loop
set a[j] = a[j] * 11
set j = j + 1
exitwhen j > m
endloop
set l = 0
set c = SubString(buffer,i,i + 1)
loop
exitwhen SubString(abc,l,l + 1) == c
set l = l + 1
exitwhen l > 9
endloop
set a[0] = a[0] + l
set j = 0
loop
set k = a[j] / CONST
set a[j] = a[j] - k * CONST
set a[j + 1] = a[j + 1] + k
set j = j + 1
exitwhen j > m
endloop
if k > 0 then
set m = m + 1
endif
set i = i + 1
exitwhen i >= StringLength(buffer)
endloop
set buffer = ""
loop
exitwhen m < 0
set j = m
loop
exitwhen j <= 0
set k = a[j] / CodeLength
set a[j - 1] = a[j - 1] + (a[j] - k * CodeLength) * CONST
set a[j] = k
set j = j - 1
endloop
set k = a[j] / CodeLength
set i = a[j] - k * CodeLength
set buffer = buffer + SubString(udg_SaveLoad_Alphabet,i,i + 1)
set a[j] = k
if a[m] == 0 then
set m = m - 1
endif
endloop
set i = StringLength(buffer)
set skip = 0
set c = ""
loop
set i = i - 1
set c = c + SubString(buffer,i,i + 1)
set skip = skip + 1
if skip == 4 and i > 0 then
set c = c + "-"
set skip = 0
endif
exitwhen i <= 0
endloop
return c
endfunction
function SaveLoad_DecodeValues takes string s returns boolean
local integer i
local integer j
local integer k
local integer l
local integer SaveCode = 0
local integer m
local integer array a
local string buffer = ""
local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
local integer skip = -1
local integer CONST = 1000000
local string abc = "0123456789-"
local string c
set i = 0
loop
set a[i] = 0
set i = i + 1
exitwhen i >= 100
endloop
set m = 0
set i = 0
loop
set j = 0
loop
set a[j] = a[j] * CodeLength
set j = j + 1
exitwhen j > m
endloop
set skip = skip + 1
if skip == 4 then
set skip = 0
set i = i + 1
endif
set l = CodeLength
set c = SubString(s,i,i + 1)
loop
set l = l - 1
exitwhen l < 1
exitwhen SubString(udg_SaveLoad_Alphabet,l,l + 1) == c
endloop
set a[0] = a[0] + l
set j = 0
loop
set k = a[j] / CONST
set a[j] = a[j] - k * CONST
set a[j + 1] = a[j + 1] + k
set j = j + 1
exitwhen j > m
endloop
if k > 0 then
set m = m + 1
endif
set i = i + 1
exitwhen i >= StringLength(s)
endloop
loop
exitwhen m < 0
set j = m
loop
exitwhen j <= 0
set k = a[j] / 11
set a[j - 1] = a[j - 1] + (a[j] - k * 11) * CONST
set a[j] = k
set j = j - 1
endloop
set k = a[j] / 11
set i = a[j] - k * 11
set buffer = SubString(abc,i,i + 1) + buffer
set a[j] = k
if a[m] == 0 then
set m = m - 1
endif
endloop
set i = 0
set j = 0
loop
loop
exitwhen i >= StringLength(buffer)
exitwhen i > 0 and SubString(buffer,i,i + 1) == "-" and SubString(buffer,i - 1,i) != "-"
set i = i + 1
endloop
if i < StringLength(buffer) then
set k = i
endif
set SaveCode = SaveCode + 1
set udg_Save[SaveCode] = S2I(SubString(buffer,j,i))
set j = i + 1
set i = i + 1
exitwhen i >= StringLength(buffer)
endloop
set j = SaveLoad_EncodeVerify(SubString(buffer,0,k))
set udg_SaveCount = SaveCode - 1
if j == udg_Save[SaveCode] then
return true
endif
return false
endfunction
function SaveLoad_Encode takes nothing returns string
if udg_SaveLoad_CaseSensitive == false then
set udg_SaveLoad_Alphabet = StringCase(udg_SaveLoad_Alphabet,true)
endif
return SaveLoad_Color(SaveLoad_EncodeValues())
endfunction
function SaveLoad_Decode takes string s returns boolean
if udg_SaveLoad_CaseSensitive == false then
set udg_SaveLoad_Alphabet = StringCase(udg_SaveLoad_Alphabet,true)
set s = StringCase(s,true)
endif
if SaveLoad_DecodeValues(s) then
return true
endif
return false
endfunction
Name | Type | is_array | initial_value |
AbominationGroup | group | No | |
Ancient01Timer01 | timer | No | |
Ancient02Timer01 | timer | No | |
Ancient03Timer01 | timer | No | |
Archer01 | unit | No | |
Archer02 | unit | No | |
ArcherCamp01 | unit | No | |
ArcherCamp02 | unit | No | |
ArcherCamp03 | unit | No | |
ArcherCamp04 | unit | No | |
ArcherCamp05 | unit | No | |
ArcherCamp06 | unit | No | |
ArcherWell01 | unit | No | |
ArcherWell02 | unit | No | |
Archimonde | unit | No | |
AttackOrcTownGroup | group | No | |
BlightGroup | group | No | |
BonusesFound | integer | No | |
BonusesTotal | integer | No | |
CaveGroup01 | group | No | |
CaveGroup02 | group | No | |
Code | string | No | |
CodeError | boolean | No | |
CreepingDoomInt | integer | No | 0 |
CreepingDoomTimer | timer | No | |
DiffInteger | integer | No | |
Doom01 | unit | No | |
Doom01Start | unit | No | |
Doom02 | unit | No | |
Doom02Start | unit | No | |
Doom03 | unit | No | |
Doom03New | unit | No | |
Doom03Start | unit | No | |
Doom04 | unit | No | |
Doom05 | unit | No | |
Doom06 | unit | No | |
Doom07 | unit | No | |
Doom08 | unit | No | |
Doom09 | unit | No | |
Doom10 | unit | No | |
Doom11 | unit | No | |
DoomGuardBlight | unit | No | |
DoomguardCampPatrol | unit | No | |
DoomguardPatrol | unit | No | |
DoomguardTimer | timer | No | |
EchangeHint | boolean | No | |
EndingCancelled | boolean | No | false |
EXTAS | integer | No | |
EXTRAStotal | integer | No | |
FootmanTent | unit | No | |
FootmenAmbushGroup | group | No | |
FurbolgCamp01 | group | No | |
GameOver | boolean | No | false |
GAMEOVER | boolean | No | |
GameSelection | boolean | No | |
GDD__Integers | integer | Yes | |
GDD__LeftMapGroup | group | No | |
GDD__TriggerArray | trigger | Yes | |
GDD__UnitArray | unit | Yes | |
GDD_Damage | real | No | |
GDD_DamagedUnit | unit | No | |
GDD_DamageSource | unit | No | |
GDD_Event | real | No | |
GhoulGroup01 | group | No | |
GhoulGroup02 | group | No | |
GhoulRushGroup | group | No | |
Hero1 | unit | No | |
Hero1Inventory | string | No | |
Hero2 | unit | No | |
Hero2Inventory | string | No | |
HumanGroup01 | group | No | |
Huntress01 | unit | No | |
Huntress02 | unit | No | |
Huntress03 | unit | No | |
Huntress04 | unit | No | |
HuntressShadeSpotter01 | unit | No | |
HuntressShadeSpotter02 | unit | No | |
HuntressShadeSpotter03 | unit | No | |
Hydralisk | unit | No | |
Infernal01 | unit | No | |
infernalboom | unit | No | |
InfernalSpawn01 | unit | No | |
InfernalSpawn02 | unit | No | |
InfernalSpawn03 | unit | No | |
InsaneMode | boolean | No | |
LevelsPlayedWithThisCode | integer | No | |
light | weathereffect | No | |
LocalPlayer | player | No | |
Moon | weathereffect | No | |
OpeningCancelled | boolean | No | false |
OpeningVisibility | fogmodifier | No | |
OverallScoreLimit | integer | Yes | |
OverallScoreMax | integer | No | |
PlayerGroup | group | No | |
QuestEscape | quest | No | |
QuestEscapeReq | questitem | No | |
QuestSideFurbolg | quest | No | |
RandomSound | integer | No | |
RankInteger | integer | No | |
Save | integer | Yes | |
SaveCount | integer | No | |
SaveLoad_Abilities | abilcode | Yes | |
SaveLoad_Abilities_LastIndex | integer | No | |
SaveLoad_Alphabet | string | No | |
SaveLoad_CaseSensitive | boolean | No | |
SaveLoad_Compress | integer | Yes | |
SaveLoad_Heroes | unitcode | Yes | |
SaveLoad_Heroes_LastIndex | integer | No | |
SaveLoad_Initialized | boolean | No | |
SaveLoad_Items | itemcode | Yes | |
SaveLoad_Items_LastIndex | integer | No | |
SaveLoad_Uncompress | integer | Yes | |
SaveLoad_UsePlayername | boolean | No | |
ScoreBonuses | integer | No | |
ScoreExtra | integer | No | |
ScoreLimit | integer | Yes | |
ScoreMax | integer | No | |
ScoreRank | string | No | |
ScoreSecret | integer | No | |
ScoreTime | integer | No | |
ScoreTotal | integer | No | |
SecretsFound | integer | No | |
SecretsTotal | integer | No | |
Sentinel01 | unit | No | |
Sentinel02 | unit | No | |
Sentinel03 | unit | No | |
Sentinel04 | unit | No | |
Sentinel05 | unit | No | |
Shandris | unit | No | UnitNull |
ShandrisLevels | integer | Yes | |
SumRank | integer | No | |
Suura | unit | No | |
TauntDoom02 | boolean | No | true |
TauntDoom04 | boolean | No | true |
TauntDoom07 | boolean | No | true |
TauntDoom08 | boolean | No | true |
TauntDoom09 | boolean | No | true |
TempEffect | effect | Yes | |
TempInteger | integer | No | |
TempItem | item | No | |
TempItemType | itemcode | No | |
TempP1Group | force | No | |
TempP2Group | force | No | |
TempPlayer | player | No | |
TempUGroup1 | group | No | |
TempUnit | unit | No | |
Tichondrius | unit | No | |
TimeMax | real | No | |
TimeMin | real | No | |
TimeRange | real | No | |
TimerHours | integer | No | |
TimerMinutes | integer | No | |
TimerSeconds | integer | No | |
TimerString | string | No | |
TimerStringHours | string | No | |
TimerStringMinutes | string | No | |
TimerStringSeconds | string | No | |
TimerTotal | integer | No | |
TimeTotal | integer | No | |
Tyrande | unit | No | |
Validate | boolean | No | |
VisibilityAncient | fogmodifier | No | |
VisibilityFootmanGhoul | fogmodifier | No | |
VisibilityOrcTown | fogmodifier | No | |
VoteNew1 | boolean | No | |
VoteNew2 | boolean | No | |
VoteSkip1 | boolean | No | false |
VoteSkip2 | boolean | No | false |
VoteSkipFinal | boolean | No | false |
//TESH.scrollpos=15
//TESH.alwaysfold=0
scope Sneak initializer onInit
globals
// This is the actual hero ability's rawcode
private constant integer SPELL_ID = 'A004'
// This is the slow dummy ability's rawcode
private constant integer SLOW_ID = 'S000'
// This is the stealth dummy ability's rawcode
private constant integer STEALTH_ID = 'A003'
private unit caster
endglobals
private function timeout takes nothing returns nothing
call UnitRemoveAbility(caster, STEALTH_ID)
call ReleaseTimer(GetExpiredTimer())
set caster = null
endfunction
private function onCast takes nothing returns boolean
local integer id = GetSpellAbilityId()
local integer lvl
local timer t
if id == SPELL_ID then
set caster = GetTriggerUnit()
set lvl = GetUnitAbilityLevel(caster, SPELL_ID)
set t = NewTimer()
call UnitAddAbility(caster, SLOW_ID)
call SetUnitAbilityLevel(caster, SLOW_ID, lvl)
call UnitRemoveAbility(caster, SLOW_ID)
call UnitAddAbility(caster, STEALTH_ID)
call TimerStart(t, 5 + lvl*5, false, function timeout)
endif
return false
endfunction
private function onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t, Player(10), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
call TriggerAddCondition(t, function onCast)
endfunction
endscope
//TESH.scrollpos=12
//TESH.alwaysfold=0
//! zinc
library HuntersMark
{
function HuntersMark()
{
integer a;
if (GetUnitAbilityLevel(udg_GDD_DamageSource, 'A002') > 0 && udg_GDD_Damage > 0.00)
{
if (GetUnitAbilityLevel(udg_GDD_DamageSource, 'A002') < 3)
{
a = GetRandomInt(1, 10);
if ( a == 1 )
{
DisableTrigger(GetTriggeringTrigger());
UnitDamageTarget(udg_GDD_DamageSource, udg_GDD_DamagedUnit, GetUnitAbilityLevel(udg_GDD_DamageSource, 'A002') * GetHeroAgi(udg_GDD_DamageSource, true), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS);
EnableTrigger(GetTriggeringTrigger());
}
}
}
else
{
a = GetRandomInt(1, 20);
if ( a <= 3)
{
DisableTrigger(GetTriggeringTrigger());
UnitDamageTarget(udg_GDD_DamageSource, udg_GDD_DamagedUnit, 3 * GetHeroAgi(udg_GDD_DamageSource, true), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS);
EnableTrigger(GetTriggeringTrigger());
}
}
}
function onInit()
{
gg_trg_HuntersMark = CreateTrigger();
TriggerRegisterVariableEvent(gg_trg_HuntersMark, "udg_GDD_Event", EQUAL, 0);
TriggerAddAction(gg_trg_HuntersMark, function HuntersMark);
}
}
//! endzinc
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TimerUtils initializer init
//*********************************************************************
//* TimerUtils (red+blue+orange flavors for 1.24b+) 2.0
//* ----------
//*
//* To implement it , create a custom text trigger called TimerUtils
//* and paste the contents of this script there.
//*
//* To copy from a map to another, copy the trigger holding this
//* library to your map.
//*
//* (requires vJass) More scripts: htt://www.wc3c.net
//*
//* For your timer needs:
//* * Attaching
//* * Recycling (with double-free protection)
//*
//* set t=NewTimer() : Get a timer (alternative to CreateTimer)
//* set t=NewTimerEx(x) : Get a timer (alternative to CreateTimer), call
//* Initialize timer data as x, instead of 0.
//*
//* ReleaseTimer(t) : Relese a timer (alt to DestroyTimer)
//* SetTimerData(t,2) : Attach value 2 to timer
//* GetTimerData(t) : Get the timer's value.
//* You can assume a timer's value is 0
//* after NewTimer.
//*
//* Multi-flavor:
//* Set USE_HASH_TABLE to true if you don't want to complicate your life.
//*
//* If you like speed and giberish try learning about the other flavors.
//*
//********************************************************************
//================================================================
globals
//How to tweak timer utils:
// USE_HASH_TABLE = true (new blue)
// * SAFEST
// * SLOWEST (though hash tables are kind of fast)
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = true (orange)
// * kinda safe (except there is a limit in the number of timers)
// * ALMOST FAST
//
// USE_HASH_TABLE = false, USE_FLEXIBLE_OFFSET = false (red)
// * THE FASTEST (though is only faster than the previous method
// after using the optimizer on the map)
// * THE LEAST SAFE ( you may have to tweak OFSSET manually for it to
// work)
//
private constant boolean USE_HASH_TABLE = true
private constant boolean USE_FLEXIBLE_OFFSET = false
private constant integer OFFSET = 0x100000
private integer VOFFSET = OFFSET
//Timers to preload at map init:
private constant integer QUANTITY = 256
//Changing this to something big will allow you to keep recycling
// timers even when there are already AN INCREDIBLE AMOUNT of timers in
// the stack. But it will make things far slower so that's probably a bad idea...
private constant integer ARRAY_SIZE = 8190
endglobals
//==================================================================================================
globals
private integer array data[ARRAY_SIZE]
private hashtable ht
endglobals
//It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
function SetTimerData takes timer t, integer value returns nothing
static if(USE_HASH_TABLE) then
// new blue
call SaveInteger(ht,0,GetHandleId(t), value)
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-VOFFSET]=value
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
set data[GetHandleId(t)-OFFSET]=value
endif
endfunction
function GetTimerData takes timer t returns integer
static if(USE_HASH_TABLE) then
// new blue
return LoadInteger(ht,0,GetHandleId(t) )
elseif (USE_FLEXIBLE_OFFSET) then
// orange
static if (DEBUG_MODE) then
if(GetHandleId(t)-VOFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-VOFFSET]
else
// new red
static if (DEBUG_MODE) then
if(GetHandleId(t)-OFFSET<0) then
call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
endif
endif
return data[GetHandleId(t)-OFFSET]
endif
endfunction
//==========================================================================================
globals
private timer array tT[ARRAY_SIZE]
private integer tN = 0
private constant integer HELD=0x28829022
//use a totally random number here, the more improbable someone uses it, the better.
private boolean didinit = false
endglobals
private keyword init
//==========================================================================================
// I needed to decide between duplicating code ignoring the "Once and only once" rule
// and using the ugly textmacros. I guess textmacros won.
//
//! textmacro TIMERUTIS_PRIVATE_NewTimerCommon takes VALUE
// On second thought, no.
//! endtextmacro
function NewTimerEx takes integer value returns timer
if (tN==0) then
if (not didinit) then
//This extra if shouldn't represent a major performance drawback
//because QUANTITY rule is not supposed to be broken every day.
call init.evaluate()
set tN = tN - 1
else
//If this happens then the QUANTITY rule has already been broken, try to fix the
// issue, else fail.
debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, make sure all timers are getting recycled correctly")
set tT[0]=CreateTimer()
static if( not USE_HASH_TABLE) then
debug call BJDebugMsg("In case of errors, please increase it accordingly, or set TimerUtils_USE_HASH_TABLE to true")
static if( USE_FLEXIBLE_OFFSET) then
if (GetHandleId(tT[0])-VOFFSET<0) or (GetHandleId(tT[0])-VOFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
else
if (GetHandleId(tT[0])-OFFSET<0) or (GetHandleId(tT[0])-OFFSET>=ARRAY_SIZE) then
//all right, couldn't fix it
call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably set TimerUtils_USE_HASH_TABLE to true or fix timer leaks.")
return null
endif
endif
endif
endif
else
set tN=tN-1
endif
call SetTimerData(tT[tN],value)
return tT[tN]
endfunction
function NewTimer takes nothing returns timer
return NewTimerEx(0)
endfunction
//==========================================================================================
function ReleaseTimer takes timer t returns nothing
if(t==null) then
debug call BJDebugMsg("Warning: attempt to release a null timer")
return
endif
if (tN==ARRAY_SIZE) then
debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
//stack is full, the map already has much more troubles than the chance of bug
call DestroyTimer(t)
else
call PauseTimer(t)
if(GetTimerData(t)==HELD) then
debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
return
endif
call SetTimerData(t,HELD)
set tT[tN]=t
set tN=tN+1
endif
endfunction
private function init takes nothing returns nothing
local integer i=0
local integer o=-1
local boolean oops = false
if ( didinit ) then
return
else
set didinit = true
endif
static if( USE_HASH_TABLE ) then
set ht = InitHashtable()
loop
exitwhen(i==QUANTITY)
set tT[i]=CreateTimer()
call SetTimerData(tT[i], HELD)
set i=i+1
endloop
set tN = QUANTITY
else
loop
set i=0
loop
exitwhen (i==QUANTITY)
set tT[i] = CreateTimer()
if(i==0) then
set VOFFSET = GetHandleId(tT[i])
static if(USE_FLEXIBLE_OFFSET) then
set o=VOFFSET
else
set o=OFFSET
endif
endif
if (GetHandleId(tT[i])-o>=ARRAY_SIZE) then
exitwhen true
endif
if (GetHandleId(tT[i])-o>=0) then
set i=i+1
endif
endloop
set tN = i
exitwhen(tN == QUANTITY)
set oops = true
exitwhen not USE_FLEXIBLE_OFFSET
debug call BJDebugMsg("TimerUtils_init: Failed a initialization attempt, will try again")
endloop
if(oops) then
static if ( USE_FLEXIBLE_OFFSET) then
debug call BJDebugMsg("The problem has been fixed.")
//If this message doesn't appear then there is so much
//handle id fragmentation that it was impossible to preload
//so many timers and the thread crashed! Therefore this
//debug message is useful.
elseif(DEBUG_MODE) then
call BJDebugMsg("There were problems and the new timer limit is "+I2S(i))
call BJDebugMsg("This is a rare ocurrence, if the timer limit is too low:")
call BJDebugMsg("a) Change USE_FLEXIBLE_OFFSET to true (reduces performance a little)")
call BJDebugMsg("b) or try changing OFFSET to "+I2S(VOFFSET) )
endif
endif
endif
endfunction
endlibrary
// GUI-Friendly Damage Detection -- v1.2.1 -- by Weep
// http:// www.thehelper.net/forums/showthread.php?t=137957
//
// Requires: only this trigger and its variables.
//
// -- What? --
// This snippet provides a leak-free, GUI-friendly implementation of an "any unit takes
// damage" event. It requires no JASS knowledge to use.
//
// It uses the Game - Value Of Real Variable event as its method of activating other
// triggers, and passes the event responses through a few globals.
//
// -- Why? --
// The traditional GUI method of setting up a trigger than runs when any unit is damaged
// leaks trigger events. This snippet is easy to implement and removes the need to do
// you own GUI damage detection setup.
//
// -- How To Implement --
// 0. Before you copy triggers that use GDD into a new map, you need to copy over GDD
// with its GDD Variable Creator trigger, or there will be a problem: the variables
// won't be automatically created correctly.
//
// 1. Be sure "Automatically create unknown variables while pasting trigger data" is
// enabled in the World Editor general preferences.
// 2. Copy this trigger category ("GDD") and paste it into your map.
// (Alternately: create the variables listed in the globals block below, create a
// trigger named "GUI Friendly Damage Detection", and paste in this entire text.)
// 3. Create your damage triggers using Game - Value Of Real Variable as the event,
// select GDD_Event as the variable, and leave the rest of the settings to the default
// "becomes Equal to 0.00".
// The event responses are the following variables:
// GDD_Damage is the amount of damage, replacing Event Response - Damage Taken.
// GDD_DamagedUnit is the damaged unit, replacing Event Response - Triggering Unit.
// Triggering Unit can still be used, if you need to use waits.
// Read the -- Notes -- section below for more info.
// GDD_DamageSource is the damaging unit, replacing Event Response - Damage Source.
//
// -- Notes --
// GDD's event response variables are not wait-safe; you can't use them after a wait in
// a trigger. If you need to use waits, Triggering Unit (a.k.a. GetTriggerUnit()) can
// be used in place of GDD_DamageSource. There is no usable wait-safe equivalent to
// Event Damage or Damage Source; you'll need to save the values yourself.
//
// Don't write any values to the variables used as the event responses, or it will mess
// up any other triggers using this snippet for their triggering. Only use their values.
//
// This uses arrays, so can detect damage for a maximum of 8190 units at a time, and
// cleans up data at a rate of 33.33 per second, by default. This should be enough for
// most maps, but if you want to change the rate, change the value returned in the
// GDD_RecycleRate function at the top of the code, below.
//
// By default, GDD will not register units that have Locust at the moment of their
// entering the game, and will not recognize when they take damage (which can only
// happen if the Locust ability is later removed from the unit.) To allow a unit to have
// Locust yet still cause GDD damage events if Locust is removed, you can either design
// the unit to not have Locust by default and add it via triggers after creation, or
// edit the GDD_Filter function at the top of the code, below.
//
// -- Credits --
// Captain Griffin on wc3c.net for the research and concept of GroupRefresh.
//
// Credit in your map not needed, but please include this README.
//
// -- Version History --
// 1.2.1: Minor code cleaning. Added configuration functions. Updated documentation.
// 1.2.0: Made this snippet work properly with recursive damage.
// 1.1.1: Added a check in order to not index units with the Locust ability (dummy units).
// If you wish to check for damage taken by a unit that is unselectable, do not
// give the unit-type Locust in the object editor; instead, add the Locust ability
// 'Aloc' via a trigger after its creation, then remove it.
// 1.1.0: Added a check in case a unit gets moved out of the map and back.
// 1.0.0: First release.
//===================================================================
// Configurables.
function GDD_RecycleRate takes nothing returns real //The rate at which the system checks units to see if they've been removed from the game
return 0.03
endfunction
function GDD_Filter takes unit u returns boolean //The condition a unit has to pass to have it registered for damage detection
return GetUnitAbilityLevel(u, 'Aloc') == 0 //By default, the system ignores Locust units, because they normally can't take damage anyway
endfunction
//===================================================================
// This is just for reference.
// If you use JassHelper, you could uncomment this section instead of creating the variables in the trigger editor.
// globals
// real udg_GDD_Event = 0.
// real udg_GDD_Damage = 0.
// unit udg_GDD_DamagedUnit
// unit udg_GDD_DamageSource
// trigger array udg_GDD__TriggerArray
// integer array udg_GDD__Integers
// unit array udg_GDD__UnitArray
// group udg_GDD__LeftMapGroup = CreateGroup()
// endglobals
//===================================================================
// System code follows. Don't touch!
function GDD_Event takes nothing returns boolean
local unit damagedcache = udg_GDD_DamagedUnit
local unit damagingcache = udg_GDD_DamageSource
local real damagecache = udg_GDD_Damage
set udg_GDD_DamagedUnit = GetTriggerUnit()
set udg_GDD_DamageSource = GetEventDamageSource()
set udg_GDD_Damage = GetEventDamage()
set udg_GDD_Event = 1.
set udg_GDD_Event = 0.
set udg_GDD_DamagedUnit = damagedcache
set udg_GDD_DamageSource = damagingcache
set udg_GDD_Damage = damagecache
set damagedcache = null
set damagingcache = null
return false
endfunction
function GDD_AddDetection takes nothing returns boolean
// if(udg_GDD__Integers[0] > 8190) then
// call BJDebugMsg("GDD: Too many damage events! Decrease number of units present in the map or increase recycle rate.")
// ***Recycle rate is specified in the GDD_RecycleRate function at the top of the code. Smaller is faster.***
// return
// endif
if(IsUnitInGroup(GetFilterUnit(), udg_GDD__LeftMapGroup)) then
call GroupRemoveUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
elseif(GDD_Filter(GetFilterUnit())) then
set udg_GDD__Integers[0] = udg_GDD__Integers[0]+1
set udg_GDD__UnitArray[udg_GDD__Integers[0]] = GetFilterUnit()
set udg_GDD__TriggerArray[udg_GDD__Integers[0]] = CreateTrigger()
call TriggerRegisterUnitEvent(udg_GDD__TriggerArray[udg_GDD__Integers[0]], udg_GDD__UnitArray[udg_GDD__Integers[0]], EVENT_UNIT_DAMAGED)
call TriggerAddCondition(udg_GDD__TriggerArray[udg_GDD__Integers[0]], Condition(function GDD_Event))
endif
return false
endfunction
function GDD_PreplacedDetection takes nothing returns nothing
local group g = CreateGroup()
local integer i = 0
loop
call GroupEnumUnitsOfPlayer(g, Player(i), Condition(function GDD_AddDetection))
set i = i+1
exitwhen i == bj_MAX_PLAYER_SLOTS
endloop
call DestroyGroup(g)
set g = null
endfunction
function GDD_GroupRefresh takes nothing returns nothing
// Based on GroupRefresh by Captain Griffen on wc3c.net
if (bj_slotControlUsed[5063] == true) then
call GroupClear(udg_GDD__LeftMapGroup)
set bj_slotControlUsed[5063] = false
endif
call GroupAddUnit(udg_GDD__LeftMapGroup, GetEnumUnit())
endfunction
function GDD_Recycle takes nothing returns nothing
if(udg_GDD__Integers[0] <= 0) then
return
elseif(udg_GDD__Integers[1] <= 0) then
set udg_GDD__Integers[1] = udg_GDD__Integers[0]
endif
if(GetUnitTypeId(udg_GDD__UnitArray[udg_GDD__Integers[1]]) == 0) then
call DestroyTrigger(udg_GDD__TriggerArray[udg_GDD__Integers[1]])
set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = null
set udg_GDD__TriggerArray[udg_GDD__Integers[1]] = udg_GDD__TriggerArray[udg_GDD__Integers[0]]
set udg_GDD__UnitArray[udg_GDD__Integers[1]] = udg_GDD__UnitArray[udg_GDD__Integers[0]]
set udg_GDD__UnitArray[udg_GDD__Integers[0]] = null
set udg_GDD__Integers[0] = udg_GDD__Integers[0]-1
endif
set udg_GDD__Integers[1] = udg_GDD__Integers[1]-1
endfunction
function GDD_LeaveMap takes nothing returns boolean
local boolean cached = bj_slotControlUsed[5063]
if(udg_GDD__Integers[2] < 64) then
set udg_GDD__Integers[2] = udg_GDD__Integers[2]+1
else
set bj_slotControlUsed[5063] = true
call ForGroup(udg_GDD__LeftMapGroup, function GDD_GroupRefresh)
set udg_GDD__Integers[2] = 0
endif
call GroupAddUnit(udg_GDD__LeftMapGroup, GetFilterUnit())
set bj_slotControlUsed[5063] = cached
return false
endfunction
// ===========================================================================
function InitTrig_GUI_Friendly_Damage_Detection takes nothing returns nothing
local region r = CreateRegion()
call RegionAddRect(r, GetWorldBounds())
call TriggerRegisterEnterRegion(CreateTrigger(), r, Condition(function GDD_AddDetection))
call TriggerRegisterLeaveRegion(CreateTrigger(), r, Condition(function GDD_LeaveMap))
call GDD_PreplacedDetection()
call TimerStart(CreateTimer(), GDD_RecycleRate(), true, function GDD_Recycle)
set r = null
endfunction
//TESH.scrollpos=21
//TESH.alwaysfold=0
//! zinc
library GiveResource{
function GiveResource(){
playerstate ps;
integer i, a;
player p1 = GetTriggerPlayer(), p2;
string tmp, resource, message = GetEventPlayerChatString(), gold = SubString(message, 0, 6), lumber = SubString(message, 0, 8);
if (gold == "-gold " || lumber == "-lumber "){
if (p1 == Player(1))
p2 = Player(2);
else
p2 = Player(1);
if (gold == "-gold "){
resource = "gold";
ps = PLAYER_STATE_RESOURCE_GOLD;
a = S2I(SubString(message, 6, StringLength(message)));
}
else{
resource = "lumber";
ps = PLAYER_STATE_RESOURCE_LUMBER;
a = S2I(SubString(message, 8, StringLength(message)));
}
i = GetPlayerState(p1, ps);
if (a > i)
a = i;
if (a > 0){
tmp = I2S(a);
SetPlayerState(p1, ps, i - a);
SetPlayerState(p2, ps, GetPlayerState(p2, ps) + a);
DisplayTextToPlayer(p2, 0, 0, "|cffcc6600ALLIES|r - " + tmp + " " + resource + " received from " + GetPlayerName(p1) + ".");
DisplayTextToPlayer(p1, 0, 0, "|cffcc6600ALLIES|r - " + tmp + " " + resource + " sent to " + GetPlayerName(p2) + ".");
StartSound(gg_snd_ItemReceived);
}
else
DisplayTextToPlayer(p2, 0, 0, "|cffcc6600ALLIES|r - Not enough " + resource + ".");
}
ps = null;
p1 = null;
p2 = null;
}
function onInit(){
gg_trg_GiveResource = CreateTrigger();
TriggerRegisterPlayerChatEvent(gg_trg_GiveResource, Player(1), "-gold ", false);
TriggerRegisterPlayerChatEvent(gg_trg_GiveResource, Player(10), "-gold ", false);
TriggerRegisterPlayerChatEvent(gg_trg_GiveResource, Player(1), "-lumber ", false);
TriggerRegisterPlayerChatEvent(gg_trg_GiveResource, Player(10), "-lumber ", false);
TriggerAddAction(gg_trg_GiveResource, function GiveResource);
}
}
//! endzinc