Name | Type | is_array | initial_value |
abilityHash | hashtable | No | |
AIPaused | boolean | No | |
assignmentData | hashtable | No | |
assignmentDataParent | integer | No | |
assignmentDataPlayerInt | integer | No | |
Beacon01 | unit | No | |
Beacon02 | unit | No | |
Beacon03 | unit | No | |
Beacon04 | unit | No | |
Beacons | group | No | |
BronzeDragon | unit | No | |
BronzeDragons | group | No | |
CameraFocusIndex_CurrentCamera | integer | No | |
ChildOfAir | unit | No | |
ChildOfAirDefeated | boolean | No | |
ChildOfAirGroup | group | No | |
cine_fireOgre | timer | No | |
CineCam | unit | No | |
CineEric | unit | No | |
CineHerodin | unit | No | |
CineKael | unit | No | |
CineLilith | unit | No | |
CinematicGroup | group | No | |
CinematicGroup01 | group | No | |
CinematicGroup02 | group | No | |
CinematicModeOn | boolean | No | |
CinematicTimer | timer | No | |
CinematicTransmissionTime | boolean | No | |
CinematicTransmissionTimer | timer | No | |
CineMyrax | unit | No | |
CineSaira | unit | No | |
CineUnit | unit | No | |
CineWell | unit | No | |
const_trainingQueueSize | integer | No | 5 |
cT_dataFound | unit | No | |
cT_speaker | unit | No | |
cT_speakerFound | unit | No | |
cT_speakerName | string | No | |
cT_txt | string | No | |
CurrentMusicList | string | No | |
DarkRangerLilith | unit | No | |
DeathKnight | unit | No | |
DeathKnightGroup | group | No | |
DefeatElementalLords | quest | No | |
DefeatGustivus | quest | No | |
Dhjeri | unit | No | |
dT_trackingData | hashtable | No | |
DwarfBridgeDefenders | group | No | |
EarthKing | unit | No | |
EarthKingDefeated | boolean | No | |
Eclipsa | unit | No | |
ElementalAttackTimer | timer | No | |
ElementalGroup01 | group | No | |
ElementalGroup02 | group | No | |
ElementalPlayers | force | No | |
ElementalSpawnTimer | timer | No | |
Eric_Dest | location | No | |
Eric_Group | group | No | |
Eric_HomeDefense | group | No | |
Eric_ImproveParty | boolean | No | |
Eric_MainTown | rect | No | |
Eric_NeedUnits | boolean | No | |
Eric_Outposts | group | No | |
Eric_PartyHealthQuotient | real | No | |
Eric_PartyNumWanted | integer | No | 6 |
Eric_PartyReady | boolean | No | |
Eric_PartyRemainingHealth | real | No | |
Eric_PartyStartingHealth | real | No | |
Eric_PartyStartingNumbers | integer | No | |
Eric_Point01 | location | No | |
Eric_Point02 | location | No | |
Eric_ReturnHome | boolean | No | |
Eric_ScoutMode | boolean | No | true |
Eric_Timer01 | timer | No | |
Eric_Timer02 | timer | No | |
Eric_Timer03 | timer | No | |
Eric_Workers | group | No | |
ericFirstTH | unit | No | |
EricGroup | group | No | |
ericPlayerID | integer | No | 3 |
EricRevive | timer | No | |
EricsForces_Wave_Level | integer | No | |
execTrainingFuncHash | hashtable | No | |
FireElementals | group | No | |
FireOgre | unit | No | |
fireOgre_firstAttack | boolean | No | true |
fireOgre_vis | rect | No | |
FireOgreDefeated | boolean | No | |
fO_tauntText | texttag | No | |
g_attackSound | sound | No | |
G_FText | texttag | No | |
GaleDefeated | boolean | No | |
GaleWinterFreeze | unit | No | |
gameloop | real | No | 0.06 |
gameloop_fx | real | No | 0.06 |
gameloop_x2 | real | No | 0.06 |
generalHash | hashtable | No | |
GFight_Heroes | group | No | |
gravityZ | real | No | -0.10 |
Gustivus | unit | No | |
Gustivus_RestartOn | boolean | No | |
Herodin | unit | No | |
Herodin_Dest | location | No | |
Herodin_Group | group | No | |
Herodin_HomeDefense | group | No | |
Herodin_ImproveParty | boolean | No | |
Herodin_MainTown | rect | No | |
Herodin_NeedUnits | boolean | No | |
Herodin_Outposts | group | No | |
Herodin_PartyHealthQuotient | real | No | |
Herodin_PartyNumWanted | integer | No | 6 |
Herodin_PartyReady | boolean | No | |
Herodin_PartyRemainingHealth | real | No | |
Herodin_PartyStartingHealth | real | No | |
Herodin_PartyStartingNumbers | integer | No | |
Herodin_Point01 | location | No | |
Herodin_Point02 | location | No | |
Herodin_ReturnHome | boolean | No | |
Herodin_ScoutMode | boolean | No | true |
Herodin_Timer01 | timer | No | |
Herodin_Timer02 | timer | No | |
Herodin_Timer03 | timer | No | |
Herodin_Workers | group | No | |
herodinFirstTH | unit | No | |
herodinPlayerID | integer | No | 3 |
HeroGroup | group | No | |
HxNumOfRiflemen | integer | No | |
Kael | unit | No | |
lastCDLS | string | No | |
lastCHash | hashtable | No | |
lastCheckedCondition | string | No | |
lastCPassed | boolean | No | |
LastCreatedOrderHashT | hashtable | No | |
LastCreatedOrderID | integer | No | |
LastCreatedOrderParentPath | string | No | |
LastCreatedOrderPath | string | No | |
LastCreatedOrderPlayerID | integer | No | |
LastCreatedTownChildPath | integer | No | |
LastCreatedTownHash | hashtable | No | |
LastCreatedTownInt | integer | No | |
LastCreatedTownParentPath | integer | No | |
lastCreatedTownPlayerIndex | integer | Yes | |
LastCreatedVUnitHashT | hashtable | No | |
LastCreatedVUnitParentPath | string | No | |
LastCreatedVUnitPath | string | No | |
LastCreatedWarPartyInt | integer | No | |
lastOrderDLS | string | No | |
lastOrderHash | hashtable | No | |
lastPLS | string | No | |
LastSavedParameterHash | hashtable | No | |
LastSavedParameterNameS | string | No | |
LastSavedParameterParentS | string | No | |
lastUsedAddDataHashIndex | integer | No | |
lastUsedAddDataRootName | string | No | |
lFinalAssault | group | No | |
lilithArmy | group | No | |
lilithSpawnWait | real | No | 120.00 |
LordEricPaladin | unit | No | |
MacroAbilities | button | No | |
MacroAbilitiesDialog | dialog | No | |
MaleRanger | unit | No | |
Name_Alucard | string | No | Alucard |
Name_AlucardInfernalForm | string | No | Infernal |
Name_Dhjeri | string | No | Dhjeri |
Name_Dragonblight | string | No | Dragonblight |
name_Gustivus | string | No | Gustivus the Cyclope |
Name_Herodin | string | No | Herodin Mountainkiller |
Name_Kael | string | No | Kael |
Name_LilithDarkRanger | string | No | Lilith |
Name_LordEricPaladin | string | No | Lord Eric the Mighty |
Name_PitlordSauresh | string | No | Sauresh the Divider of Brothers |
Name_Saira | string | No | Saira |
Name_Scout1 | string | No | Elven Scout |
paramString_building | string | No | _building_ |
paramString_Units | string | No | Units_ |
Phoenix | unit | No | |
PhoenixEgg | unit | No | |
PitlordKagreshCleaver | unit | No | |
PlayerAI | hashtable | Yes | |
PlayerConstructionWorkers | group | Yes | |
PlayerFightingWorkers | group | Yes | |
PlayerGoldWorkers | group | Yes | |
PlayerIdleWorkers | group | Yes | |
PlayerLumberWorkers | group | Yes | |
primalstone | item | No | |
PrinceAlucard | unit | No | |
PrinceAlucardInfernal | unit | No | |
QuitCinematic | boolean | No | |
ReportPosts | group | No | |
Rescued_Mari | boolean | No | |
Return_Eric | location | No | |
Return_Kael | location | No | |
Return_Saira | location | No | |
ReturnHeroes | boolean | No | |
rocks | group | No | |
sAI_g | group | No | |
sAI_g_count | integer | No | |
sAI_g_count2 | integer | No | |
sAI_g_i | integer | No | |
sAI_g_iC | integer | No | |
sAI_HashLocationData | hashtable | No | |
sAI_lastCreatedBaseID | integer | No | |
sAIClaimedGoldMines | group | Yes | |
Saira | unit | No | |
SairaEscorts | boolean | No | |
Sauresh | unit | No | |
savedCam | camerasetup | No | |
SavedCameraPosition | integer | No | |
savedSairaMain | unit | No | |
Scout1 | unit | No | |
SkipTrigger | trigger | No | |
SpiderQueen | unit | No | |
SpiderQueen_Dest | location | No | |
SpiderQueen_EmergeTimer | timer | No | |
SpiderQueen_Enemies | boolean | No | |
SpiderQueen_HasHammer | boolean | No | |
SpiderQueen_Hidden | boolean | No | |
SpiderQueen_Impatience | timer | No | |
SpiderQueen_LaunchFX | effect | No | |
SpiderQueen_Rocks | integer | No | 4 |
SpiderQueen_RockTimer | timer | No | |
SpiderQueen_Spell | string | No | |
SpiderQueen_SpellFinished | boolean | No | |
SpiderQueen_SpiderSpawn | integer | No | 3 |
StormWyrms | group | No | |
str_attack | string | No | attack |
str_emerge | string | No | retreat |
str_ensnare | string | No | ensnare |
str_getHammer | string | No | gethammer |
str_laser | string | No | laser |
str_move | string | No | move |
str_musicAlucard | string | No | musicAlucard |
str_musicAlucardMega | string | No | musicAlucard |
str_musicMain | string | No | musicMain |
str_retreat | string | No | retreat |
str_returnStart | string | No | returnstart |
str_rockFall | string | No | rockfall |
str_spawnSpiders | string | No | spawnspiders |
str_throwHammer | string | No | throwhammer |
string_harvestGoldMineTarget | string | No | harvestGoldMineTarget |
SummonedDragonBlight | unit | No | |
TeleportationStoneActive | boolean | No | |
TeleportStoneSiteLimit | integer | No | 3 |
temp_real_global | real | No | |
temp_real_global_dividend | real | No | |
temp_real_global_mod | real | No | |
tempAvailableGoldMines | group | No | |
tempBoolean | boolean | No | |
tempDestructable | destructable | No | |
tempEffect | effect | No | |
tempGroup | group | No | |
tempGroup2 | group | No | |
tempHash | hashtable | No | |
tempHashData | hashtable | No | |
tempHighestReal | real | No | |
tempInt | integer | No | |
tempInt2 | integer | No | |
tempLightning | lightning | No | |
tempLoc | location | No | |
tempLoc2 | location | No | |
tempLoc_clear | boolean | No | |
tempOrder | ordercode | No | |
tempParentString | string | No | |
tempPlayerInt | integer | No | |
tempReal | real | No | |
tempReal2 | real | No | |
tempRegion | rect | No | |
tempRootName | string | No | |
tempString | string | No | |
tempTimer | timer | No | |
tempTrigger | trigger | No | |
tempTriggerUnit | unit | No | |
tempUnit | unit | No | |
tempUnit2 | unit | No | |
tempX | integer | No | |
tempY | integer | No | |
tempZ | integer | No | |
Terms | hashtable | Yes | |
time | timer | No | |
Timer_CoA_Detect | timer | No | |
Timer_CoA_EndlessWinds | timer | No | |
Timer_CoA_EndlessWinds_Cycle | timer | No | |
Timer_CoA_Skystorm | timer | No | |
Timer_CoA_Skystorm_Cycle | timer | No | |
Timer_Dragons_Detect | timer | No | |
Timer_Dragons_TimeSave | timer | No | |
Timer_Dragons_Timesphere | timer | No | |
Timer_EK_AttackCycle | timer | No | |
Timer_EK_Attacking | timer | No | |
Timer_EK_Blipped | timer | No | |
Timer_EK_Detect | timer | No | |
Timer_EK_Retreat | timer | No | |
Timer_EK_Returning | timer | No | |
Timer_EK_Stampede | timer | No | |
Timer_EK_Stampeding | timer | No | |
Timer_FireOgre_Detect | timer | No | |
Timer_FireOgre_RockThrow | timer | No | |
Timer_FireOgre_Taunt | timer | No | |
Timer_G_FirebreathRecharge | timer | No | |
Timer_G_TentaclesRecharge | timer | No | |
Timer_Gale_Detect | timer | No | |
Timer_Gale_FreezingBlast | timer | No | |
Timer_Gale_WinterFreeze | timer | No | |
Timer_Gustivus_Earthquake | timer | No | |
Timer_Gustivus_EpicLaser | timer | No | |
Timer_Gustivus_Firebreath | timer | No | |
Timer_Gustivus_Laserballs | timer | No | |
Timer_Gustivus_SpawnTentacles | timer | No | |
Timer_Gustivus_Spiritbomb | timer | No | |
Timer_Lilith_AI | timer | No | |
Timer_Lilith_SpawnArmy | timer | No | |
Timer_StormWyrms_AI | timer | No | |
Timer_StormWyrms_Attack | timer | No | |
Timer_StormWyrms_Spawn | timer | No | |
townIndex | integer | No | |
TrainingQueues | hashtable | Yes | |
TransmissionFinished | boolean | No | |
TransmissionTimerStarted | boolean | No | |
uAI_aOUnit | unit | No | |
uAI_uIS | string | No | |
uAI_Unit | unit | No | |
undeadBluePlayerID | integer | No | 3 |
undeadGreyPlayerID | integer | No | 3 |
undeadVioletPlayerID | integer | No | 3 |
UnitAI | hashtable | No | |
Waygate | unit | No | |
WaygateDest | rect | No | |
WaygateRegion | rect | No | |
wisp | unit | No | |
Yeorn | unit | No | |
zoetropeT | timer | No | |
zT_ang | real | No | |
zT_dist | real | No | |
zT_endLoc | location | No | |
zT_environmentG | group | No | |
zT_on | boolean | No | |
zT_on2 | boolean | No | true |
zT_speed | real | No | |
zT_startLoc | location | No | |
zT_unitGroup | group | No | |
zTxCreateGroup | integer | No | |
zTxCreateGroup_num | integer | No | 8 |
function cs_CameraFocus takes real p_startingfocaltarget, real p_startingfocusspread, real p_focaltarget, real p_focusspread, real p_time returns nothing
local integer i = 1
local real focaldiff = p_focaltarget - p_startingfocaltarget
local real DOPscalediff = p_focusspread - p_startingfocusspread
local real focalincrement = 0
local real DOPincrement = 0
local real currentFocalDist = 0
local real currentDOPScale = 0
local real increments = 0
local real lv_fps = 8.00
local real lv_waittime = 0
set increments = focaldiff / p_time * lv_fps
set lv_waittime = 1 / focaldiff / p_time
// 1 second divided into the amount of frames every second. It should be 1/8, I think.
set focalincrement = focaldiff / increments
set DOPincrement = DOPscalediff / increments
call CameraSetFocalDistance( p_startingfocaltarget )
call CameraSetDepthOfFieldScale( p_startingfocusspread )
loop
exitwhen i >= increments
set currentFocalDist = currentFocalDist + focalincrement
set currentDOPScale = currentDOPScale + DOPincrement
call CameraSetFocalDistance( currentFocalDist )
call CameraSetDepthOfFieldScale( currentDOPScale )
call PolledWait( 1/lv_fps )
//this is probably dicey, it could be inaccurate at certain levels, so make sure it's simple (in fact, just change it to timer, sir)
set i = i + 1
endloop
set i = 0
set focaldiff = 0
set DOPscalediff = 0
set focalincrement = 0
set DOPincrement = 0
set currentFocalDist = 0
set currentDOPScale = 0
set increments = 0
set lv_fps = 0
set lv_waittime = 0
endfunction
function cs_CameraFocus takes real p_startingfocaltarget, real p_startingfocusspread, real p_focaltarget, real p_focusspread, real p_time returns nothing
local integer i = 1
local real focaldiff = p_focaltarget - p_startingfocaltarget
local real DOPscalediff = p_focusspread - p_startingfocusspread
local real focalincrement = 0
local real DOPincrement = 0
local real currentFocalDist = 0
local real currentDOPScale = 0
local real increments = 0
local real lv_fps = 8.00
local real lv_waittime = 0
set increments = focaldiff / p_time * lv_fps
set lv_waittime = 1 / focaldiff / p_time
// 1 second divided into the amount of frames every second. It should be 1/8, I think.
set focalincrement = focaldiff / increments
set DOPincrement = DOPscalediff / increments
call CameraSetFocalDistance( p_startingfocaltarget )
call CameraSetDepthOfFieldScale( p_startingfocusspread )
loop
exitwhen i >= increments
set currentFocalDist = currentFocalDist + focalincrement
set currentDOPScale = currentDOPScale + DOPincrement
call CameraSetFocalDistance( currentFocalDist )
call CameraSetDepthOfFieldScale( currentDOPScale )
call PolledWait( 1/lv_fps )
//this is probably dicey, it could be inaccurate at certain levels, so make sure it's simple
set i = i + 1
endloop
set i = 0
set focaldiff = 0
set DOPscalediff = 0
set focalincrement = 0
set DOPincrement = 0
set currentFocalDist = 0
set currentDOPScale = 0
set increments = 0
set lv_fps = 0
set lv_waittime = 0
endfunction
function sAI_sairaMBStunExpire takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = LoadUnitHandleBJ(0, StringHashBJ(I2S(GetHandleId(t)) + "_unit"), udg_tempHash )
//MAIN PART
if (udg_CinematicModeOn == false) then
call PauseUnitBJ( false, u)
endif
call FlushChildHashtableBJ( StringHashBJ(I2S(GetHandleId(t)) + "_unit"), udg_tempHash )
call DestroyTimer(t)
//PLUG LEAKS
set t = null
set u = null
endfunction
function sAI_animationReset takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tID = GetHandleId(t)
local unit u = LoadUnitHandleBJ(0, StringHashBJ(I2S(tID) + "_unit"), udg_tempHash)
// MAIN PART
call ResetUnitAnimation( u )
call FlushChildHashtableBJ( StringHashBJ(I2S(tID) + "_unit"), udg_tempHash )
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tID = 0
set u = null
endfunction
constant native GetUnitX takes unit whichUnit returns real
constant native GetUnitY takes unit whichUnit returns real
native IssueTargetOrder takes unit whichUnit, string order, widget targetWidget returns boolean
native GetUnitCurrentOrder takes unit whichUnit returns integer
native GetResourceAmount takes unit whichUnit returns integer
native IssueInstantPointOrder takes unit whichUnit, string order, real x, real y, widget instantTargetWidget returns boolean
native IssueInstantPointOrderById takes unit whichUnit, integer order, real x, real y, widget instantTargetWidget returns boolean
native IssueInstantTargetOrder takes unit whichUnit, string order, widget targetWidget, widget instantTargetWidget returns boolean
native IssueInstantTargetOrderById takes unit whichUnit, integer order, widget targetWidget, widget instantTargetWidget returns boolean
native TimerStart takes timer whichTimer, real timeout, boolean periodic, code handlerFunc returns nothing
native IssueImmediateOrder takes unit whichUnit, string order returns boolean
native IssueImmediateOrderById takes unit whichUnit, integer order returns boolean
native IssuePointOrder takes unit whichUnit, string order, real x, real y returns boolean
native IssuePointOrderLoc takes unit whichUnit, string order, location whichLocation returns boolean
native IssuePointOrderById takes unit whichUnit, integer order, real x, real y returns boolean
native IssuePointOrderByIdLoc takes unit whichUnit, integer order, location whichLocation returns boolean
native IssueTargetOrder takes unit whichUnit, string order, widget targetWidget returns boolean
native IssueTargetOrderById takes unit whichUnit, integer order, widget targetWidget returns boolean
native IssueInstantPointOrder takes unit whichUnit, string order, real x, real y, widget instantTargetWidget returns boolean
native IssueInstantPointOrderById takes unit whichUnit, integer order, real x, real y, widget instantTargetWidget returns boolean
native IssueInstantTargetOrder takes unit whichUnit, string order, widget targetWidget, widget instantTargetWidget returns boolean
native IssueInstantTargetOrderById takes unit whichUnit, integer order, widget targetWidget, widget instantTargetWidget returns boolean
native IssueBuildOrder takes unit whichPeon, string unitToBuild, real x, real y returns boolean
native IssueBuildOrderById takes unit whichPeon, integer unitId, real x, real y returns boolean
native GetUnitCurrentOrder takes unit whichUnit returns integer
BlzGetUnitAbilityByIndex takes unit whichUnit, integer index returns ability // will just have to loop until it returns nothing
//========================================================================================
globals
hashtable udg_TypeCastHashtable = InitHashtable()
endglobals
library TypeCasting
function Widget2Handle takes widget i returns handle
return i
endfunction
function Agent2Handle takes agent i returns handle
return i
endfunction
function Integer2BooleanExpr takes integer i returns boolexpr
call SaveFogStateHandle(udg_TypeCastHashtable, 0, 0, ConvertFogState(i))
return LoadBooleanExprHandle(udg_TypeCastHashtable, 0, 0)
endfunction
function Handle2BooleanExpr takes handle h returns boolexpr
return Integer2BooleanExpr(GetHandleId(h))
endfunction
function BooleanExpr2Handle takes boolexpr b returns handle
return b
endfunction
endlibrary
scope Example
globals
private hashtable hashData = InitHashtable()
endglobals
struct s_data
unit u = null
unit t = null
real x
real y
integer i
endstruct
function MCADelayed takes nothing returns nothing
local timer t=GetExpiredTimer()
local s_data d=s_data(LoadInteger(hashData, GetHandleId(t), 1))
local player p=GetOwningPlayer(d.u)
local unit u
loop
exitwhen (d.i==0)
set u=CreateUnit(p, 'nmrl', d.x, d.y, 0)
call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl",u,"overhead"))
call IssueTargetOrder(u, "attack", d.t)
set d.i=d.i-1
endloop
call RemoveSavedInteger(hashData, GetHandleId(t), 1)
call d.destroy()
set p=null
set u=null
set t=null
endfunction
endscope
function sAI_saveStringParameter takes string data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveStringBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("string", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addStringParameter takes string data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveStringBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("string", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("string", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveRealParameter takes real data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveRealBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("real", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addRealParameter takes real data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveRealBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types - Honestly, I'm not certain what to save an add name as, doesn't even matter I guess
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("real", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("real", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveIntegerParameter takes integer data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveIntegerBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("integer", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addIntegerParameter takes integer data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveIntegerBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("integer", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("integer", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveDestructibleParameter takes destructable data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveDestructableHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("destructible", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addDestructibleParameter takes destructable data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveDestructableHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("unit", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("destructible", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveBooleanParameter takes boolean data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveBooleanBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("boolean", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addBooleanParameter takes boolean data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveBooleanBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("integer", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("boolean", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveUnitParameter takes unit data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveUnitHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("unit", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addUnitParameter takes unit data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveUnitHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("unit", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("unit", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveLocationParameter takes location data, string lp_addName, string lp_parentString, hashtable ht returns nothing
// The Child key is a function of indexing and that's all. Always 0 in SaveParameter.
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveLocationHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("location", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addLocationParameter takes location data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveLocationHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("location", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("location", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveGroupParameter takes group data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveGroupHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("group", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addGroupParameter takes group data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveGroupHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("group", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("group", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveRegionParameter takes region data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveRegionHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("region", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addRegionParameter takes region data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveRegionHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("region", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("region", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveRectParameter takes rect data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveRectHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("rect", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addRectParameter takes rect data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveRectHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("rect", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("rect", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveTimerParameter takes timer data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveTimerHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("timer", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addTimerParameter takes timer data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveTimerHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("timer", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("timer", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveEffectParameter takes effect data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveEffectHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("effect", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addEffectParameter takes effect data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveEffectHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("effect", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("effect", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveLightningParameter takes lightning data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveLightningHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("lightning", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addLightningParameter takes lightning data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveLightningHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("lightning", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("lightning", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_saveTriggerParameter takes trigger data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
call SaveTriggerHandleBJ(data, 0, StringHashBJ(parentString), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then // check if the name alreadyexists
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("trigger", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_addTriggerParameter takes trigger data, string lp_addName, string lp_parentString, hashtable ht returns nothing
local string addName = ""
local string parentString = ""
local integer metaI = 0
local integer metaIC = 0
local integer i = 0
local integer iC = 0
local string iS = ""
local boolean nameAlreadyExists = false
//==================================
//===================================================================================
//ZHULI DO THE THING
//===================================================================================
if (lp_addName != "") then
set addName = "_" + lp_addName
endif
set parentString = lp_parentString + addName
//Indexing Part//===========
set iC = LoadIntegerBJ(0, StringHashBJ(parentString + "_indexCount"), ht)
set iC = iC + 1
set iS = I2S(iC)
call SaveIntegerBJ(iC, 0, StringHashBJ(parentString + "_indexCount"), ht)
//===========================
call SaveTriggerHandleBJ(data, 0, StringHashBJ(parentString + "_" + iS), ht)
//===================================================================================
//ADD META
//===================================================================================
if (HaveSavedValue(0, bj_HASHTABLE_STRING, StringHashBJ(parentString + "_dataName"), ht)) then // hopefully this doesn't create any issues w different types
set nameAlreadyExists = true
endif
if ((lp_addName != "") and (nameAlreadyExists == false)) then
set metaIC = LoadIntegerBJ(0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
set metaIC = metaIC + 1
call SaveIntegerBJ(metaIC, 0, StringHashBJ(lp_parentString + "_metaList_indexCount"), ht)
call SaveStringBJ(lp_addName, 0, StringHashBJ(lp_parentString + "_metaList_" + I2S(metaIC)), ht)
call SaveStringBJ(I2S(metaIC), 0, StringHashBJ(lp_parentString + "_metaList_" + lp_addName), ht) // The double naming thing. Also we I2S because that's what we need for that.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_dataName"), ht)
call SaveStringBJ("trigger", 0, StringHashBJ(parentString + "_dataType"), ht)
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_rootDir"), ht)
endif
//There is always an index.
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_dataName"), ht) // hopefully no flush conflicts
call SaveStringBJ("trigger", 0, StringHashBJ(parentString + "_" + iS + "_dataType"), ht)
if (lp_addName != "") then
call SaveStringBJ(lp_addName, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
else
call SaveStringBJ(lp_parentString, 0, StringHashBJ(parentString + "_" + iS + "_rootDir"), ht)
endif
set parentString = parentString + "_" + iS //this is so it adds the index name
// Save Last Created/Added/Saved Parameter
set udg_lastPLS = parentString
set udg_LastSavedParameterNameS = lp_addName
set udg_LastSavedParameterParentS = lp_parentString
set udg_LastSavedParameterHash = ht
endfunction
function sAI_convertUnitAbilitiesToHashKnowledge takes integer lp_playerID, unit lp_unit returns nothing
local integer i = 0
local integer lv_indexCount = 0
local ability lv_abil = null
local string lv_abilString = ""
loop
exitwhen i > lv_indexCount
set lv_abil = BlzGetUnitAbilityByIndex(lp_unit, i)
set lv_abilString = I2S(GetHandleIdBJ(lv_abil))
call sAI_addStringParameterToHash("", "PlayerAI_terms", "ability", lv_abilString, udg_PlayerAI[lp_playerID])
endloop
endfunction
function sAI_deleteDataTree takes string targetLocString, hashtable ht returns nothing
local integer indexI = 0
local integer indexIC = 0
local integer metaI = 0
local integer metaIC = 0
local string rootString = ""
local string name = ""
local string str = ""
local string fieldString = ""
local string prefix = ""
local boolean processingIndex = false
//================
local hashtable dT_trackingData = udg_dT_trackingData
local integer dT_i = 0
local string dT_targetLocString = ""
local string dT_iString = ""
local string dT_prefix = ""
local integer dT_iC = 0
//================
local integer targetLocStringIC = 0
local integer dT_fieldI = 0
local string dT_fieldIString = ""
local integer dT_fieldIC = 0
local integer dT_fieldMetaI = 0
local integer dT_fieldMetaIC = 0
local string dT_fieldMetaIString = ""
local string dT_fieldMetaNameString = ""
local integer targetLocStringMIC = 0
//================
local string dT_rootName = ""
local string dT_saveRootName = ""
local string dT_name = ""
local string dT_saveName = ""
local string dT_addName = ""
local boolean processFinished = false
local boolean backstep = false
local boolean hitLastEntry = false
local boolean transfer = false
local integer deleteSL = 0
local integer i = 0
local string iS = ""
local string filterString = ""
local boolean isIndexed = false
local boolean forward = false
local integer entriesDeleted = 0
local integer debugInt = 0
local integer childKey = 0
local string addName = ""
local string dataType = ""
//============================================
//MAIN PART
//============================================
//=====================================
//=====================================
set processFinished = false
//=====================================
set dT_rootName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_rootDir"), ht)
set dT_targetLocString = targetLocString
//==========================================
//==========================================
//==========================================
//==========================================
//MAIN FUNCTION
loop
exitwhen (processFinished == true)
set dT_fieldIC = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_indexCount"), ht)
set dT_fieldMetaIC = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_metaList_indexCount"), ht)
set dT_fieldI = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_currentIndex"), dT_trackingData)
set dT_fieldMetaI = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_currentMetaIndex"), dT_trackingData)
//==========================================
// ACTUAL TRANSFER PROCESS
//==========================================
if (dT_targetLocString == targetLocString) then // This is the stop function, so it doesn't delete prior to target locString
elseif (LoadBooleanBJ(0, StringHashBJ(dT_targetLocString + "_transferred"), dT_trackingData) != true) then
call SaveBooleanBJ(true, 0, StringHashBJ( dT_targetLocString + "_transferred"), dT_trackingData) // still need this
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//ACTUAL PROCESS
//DELETE DATA HERE (REMOVE MEMORY LEAKS)
if (dataType == "group") then
call DestroyGroup(LoadGroupHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "location") then
call RemoveLocation(LoadLocationHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "region") then
call RemoveRegion(LoadRegionHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "rect") then
call RemoveRect(LoadRectHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "effect") then
call DestroyEffect(LoadEffectHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "timer") then
call DestroyTimer(LoadTimerHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "group") then
call DestroyGroup(LoadGroupHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
// I think I do need to read type, actually, if I save memory using things like locations i need to destroy before flushing hash.
// At the moment I just have string parameters so no big, I'm pretty sure.
// Key memory leaks are taken care of by Flush.
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//FLUSH DATA HASHTABLE
set addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_dataName"), ht )
set dataType = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_dataType"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString), ht ) // might not need the previous , flushing an entire index should be fine
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_indexCount"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_dataName"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_dataType"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_rootDir"), ht )
//might add these to a generalHash list to loop apply
//And delete all the in-built and all the meta, too.
// I think this checks off everything.
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_metaList_" + LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + addName), ht) ), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_metaList_" + addName), ht )
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
set entriesDeleted = entriesDeleted + 1
else
set backstep = false
endif
//ITERATION
if ( ( (LoadIntegerBJ(0, StringHashBJ(dT_targetLocString + "_indexCount"), ht) == 0) and (LoadIntegerBJ(0, StringHashBJ(dT_targetLocString + "_metaList_indexCount"), ht) == 0) ) or ((dT_fieldI >= dT_fieldIC) and (dT_fieldMetaI >= dT_fieldMetaIC)) ) then
set backstep = true
else
set dT_rootName = dT_targetLocString
if (dT_fieldI < dT_fieldIC) then
set dT_fieldI = dT_fieldI + 1
set dT_fieldIString = (I2S(dT_fieldI))
set dT_addName = dT_fieldIString
else
if (dT_fieldMetaI < dT_fieldMetaIC) then
set dT_fieldMetaI = dT_fieldMetaI + 1
set dT_fieldMetaIString = (I2S(dT_fieldMetaI))
set dT_addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + dT_fieldMetaIString), ht)
else
set dT_fieldMetaIString = (I2S(dT_fieldMetaI))
set dT_addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + dT_fieldMetaIString), ht)
endif
endif
endif
call SaveIntegerBJ(dT_fieldI, 0, StringHashBJ(dT_targetLocString + "_currentIndex"), dT_trackingData)
call SaveIntegerBJ(dT_fieldMetaI, 0, StringHashBJ(dT_targetLocString + "_currentMetaIndex"), dT_trackingData)
//==================================
//==================================
//TRACKING - FORWARD OR BACKWARDS
//==================================
//==================================
if (((dT_targetLocString == "") or ( dT_targetLocString == targetLocString)) and (backstep == true)) then
set processFinished = true
elseif (debugInt > 100) then
set processFinished = true
else
set debugInt = debugInt + 1
endif
//=====================================
//=====================================
//=====================================
if (backstep == true) then
set dT_targetLocString = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_rootDir"), ht)
else
set dT_targetLocString = dT_rootName + "_" + dT_addName
endif
endloop
call FlushParentHashtableBJ(dT_trackingData)
//============================================
//PLUG LEAKS
//============================================
set indexI = 0
set indexIC = 0
set metaI = 0
set metaIC = 0
set rootString = ""
set name = ""
set str = ""
set fieldString = ""
set prefix = ""
set processingIndex = false
//================
set dT_trackingData = null
set dT_i = 0
set dT_targetLocString = ""
set dT_iString = ""
set dT_prefix = ""
set dT_iC = 0
//================
set targetLocStringIC = 0
set dT_fieldI = 0
set dT_fieldIString = ""
set dT_fieldIC = 0
set dT_fieldMetaI = 0
set dT_fieldMetaIC = 0
set dT_fieldMetaIString = ""
set dT_fieldMetaNameString = ""
set targetLocStringMIC = 0
//================
set dT_rootName = ""
set dT_saveRootName = ""
set dT_name = ""
set dT_saveName = ""
set dT_addName = ""
set processFinished = false
set backstep = false
set hitLastEntry = false
set transfer = false
set deleteSL = 0
set i = 0
set iS = ""
set filterString = ""
set isIndexed = false
set forward = false
set entriesDeleted = 0
set debugInt = 0
set childKey = 0
set addName = ""
set dataType = ""
endfunction
function sAI_copyDataTree takes string targetLocString, hashtable ht returns nothing
local integer indexI = 0
local integer indexIC = 0
local integer metaI = 0
local integer metaIC = 0
local string rootString = ""
local string name = ""
local string str = ""
local string fieldString = ""
local string prefix = ""
local boolean processingIndex = false
//================
local hashtable dT_trackingData = udg_dT_trackingData
local integer dT_i = 0
local string dT_targetLocString = ""
local string dT_iString = ""
local string dT_prefix = ""
local integer dT_iC = 0
//================
local integer targetLocStringIC = 0
local integer dT_fieldI = 0
local string dT_fieldIString = ""
local integer dT_fieldIC = 0
local integer dT_fieldMetaI = 0
local integer dT_fieldMetaIC = 0
local string dT_fieldMetaIString = ""
local string dT_fieldMetaNameString = ""
local integer targetLocStringMIC = 0
//================
local string dT_rootName = ""
local string dT_saveRootName = ""
local string dT_name = ""
local string dT_saveName = ""
local string dT_addName = ""
local boolean processFinished = false
local boolean backstep = false
local boolean hitLastEntry = false
local boolean transfer = false
local integer deleteSL = 0
local integer i = 0
local string iS = ""
local string filterString = ""
local boolean isIndexed = false
local boolean forward = false
local integer entriesDeleted = 0
local integer debugInt = 0
local integer childKey = 0
local string addName = ""
local string dataType = ""
//============================================
//MAIN PART
//============================================
//=====================================
//=====================================
set processFinished = false
//=====================================
set dT_rootName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_rootDir"), ht)
set dT_targetLocString = targetLocString
//==========================================
//==========================================
//==========================================
//==========================================
//MAIN FUNCTION
loop
exitwhen (processFinished == true)
set dT_fieldIC = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_indexCount"), ht)
set dT_fieldMetaIC = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_metaList_indexCount"), ht)
set dT_fieldI = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_currentIndex"), dT_trackingData)
set dT_fieldMetaI = LoadIntegerBJ( 0, StringHashBJ(dT_targetLocString + "_currentMetaIndex"), dT_trackingData)
//==========================================
// ACTUAL TRANSFER PROCESS
//==========================================
if (dT_targetLocString == targetLocString) then // This is the stop function, so it doesn't delete prior to target locString
elseif (LoadBooleanBJ(0, StringHashBJ(dT_targetLocString + "_transferred"), dT_trackingData) != true) then
call SaveBooleanBJ(true, 0, StringHashBJ( dT_targetLocString + "_transferred"), dT_trackingData) // still need this
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//ACTUAL PROCESS
//DELETE DATA HERE (REMOVE MEMORY LEAKS)
if (dataType == "group") then
call DestroyGroup(LoadGroupHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "location") then
call RemoveLocation(LoadLocationHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "region") then
call RemoveRegion(LoadRegionHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "rect") then
call RemoveRect(LoadRectHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "effect") then
call DestroyEffect(LoadEffectHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "timer") then
call DestroyTimer(LoadTimerHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
if (dataType == "group") then
call DestroyGroup(LoadGroupHandleBJ(0, StringHashBJ(dT_targetLocString), ht))
endif
// I think I do need to read type, actually, if I save memory using things like locations i need to destroy before flushing hash.
// At the moment I just have string parameters so no big, I'm pretty sure.
// Key memory leaks are taken care of by Flush.
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//FLUSH DATA HASHTABLE
set addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_dataName"), ht )
set dataType = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_dataType"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString), ht ) // might not need the previous , flushing an entire index should be fine
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_indexCount"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_dataName"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_dataType"), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_rootDir"), ht )
//might add these to a generalHash list to loop apply
//And delete all the in-built and all the meta, too.
// I think this checks off everything.
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_metaList_" + LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + addName), ht) ), ht )
call FlushChildHashtableBJ( StringHashBJ(dT_targetLocString + "_metaList_" + addName), ht )
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
//==========================================
set entriesDeleted = entriesDeleted + 1
else
set backstep = false
endif
//ITERATION
if ( ( (LoadIntegerBJ(0, StringHashBJ(dT_targetLocString + "_indexCount"), ht) == 0) and (LoadIntegerBJ(0, StringHashBJ(dT_targetLocString + "_metaList_indexCount"), ht) == 0) ) or ((dT_fieldI >= dT_fieldIC) and (dT_fieldMetaI >= dT_fieldMetaIC)) ) then
set backstep = true
else
set dT_rootName = dT_targetLocString
if (dT_fieldI < dT_fieldIC) then
set dT_fieldI = dT_fieldI + 1
set dT_fieldIString = (I2S(dT_fieldI))
set dT_addName = dT_fieldIString
else
if (dT_fieldMetaI < dT_fieldMetaIC) then
set dT_fieldMetaI = dT_fieldMetaI + 1
set dT_fieldMetaIString = (I2S(dT_fieldMetaI))
set dT_addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + dT_fieldMetaIString), ht)
else
set dT_fieldMetaIString = (I2S(dT_fieldMetaI))
set dT_addName = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_metaList_" + dT_fieldMetaIString), ht)
endif
endif
endif
call SaveIntegerBJ(dT_fieldI, 0, StringHashBJ(dT_targetLocString + "_currentIndex"), dT_trackingData)
call SaveIntegerBJ(dT_fieldMetaI, 0, StringHashBJ(dT_targetLocString + "_currentMetaIndex"), dT_trackingData)
//==================================
//==================================
//TRACKING - FORWARD OR BACKWARDS
//==================================
//==================================
if (((dT_targetLocString == "") or ( dT_targetLocString == targetLocString)) and (backstep == true)) then
set processFinished = true
elseif (debugInt > 100) then
set processFinished = true
else
set debugInt = debugInt + 1
endif
//=====================================
//=====================================
//=====================================
if (backstep == true) then
set dT_targetLocString = LoadStringBJ(0, StringHashBJ(dT_targetLocString + "_rootDir"), ht)
else
set dT_targetLocString = dT_rootName + "_" + dT_addName
endif
endloop
call FlushParentHashtableBJ(dT_trackingData)
//============================================
//PLUG LEAKS
//============================================
set indexI = 0
set indexIC = 0
set metaI = 0
set metaIC = 0
set rootString = ""
set name = ""
set str = ""
set fieldString = ""
set prefix = ""
set processingIndex = false
//================
set dT_trackingData = null
set dT_i = 0
set dT_targetLocString = ""
set dT_iString = ""
set dT_prefix = ""
set dT_iC = 0
//================
set targetLocStringIC = 0
set dT_fieldI = 0
set dT_fieldIString = ""
set dT_fieldIC = 0
set dT_fieldMetaI = 0
set dT_fieldMetaIC = 0
set dT_fieldMetaIString = ""
set dT_fieldMetaNameString = ""
set targetLocStringMIC = 0
//================
set dT_rootName = ""
set dT_saveRootName = ""
set dT_name = ""
set dT_saveName = ""
set dT_addName = ""
set processFinished = false
set backstep = false
set hitLastEntry = false
set transfer = false
set deleteSL = 0
set i = 0
set iS = ""
set filterString = ""
set isIndexed = false
set forward = false
set entriesDeleted = 0
set debugInt = 0
set childKey = 0
set addName = ""
set dataType = ""
endfunction
function sAI_iDLS takes string dls, string parent returns nothing
// searches for "_" within the given dls and creates the appropriate yggdrasilling
endfunction
function d_tL takes nothing returns nothing
call RemoveLocation(udg_tempLoc)
set udg_tempLoc = null
endfunction
function s_tDL_s takes location data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveLocationParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDG_s takes group data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveGroupParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDU_s takes unit data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveUnitParameter(data, path, tIS, udg_tempHash)
//PLUG LEAKS
set data = null
set s = ""
set tIS = ""
set path = ""
//RETURN
endfunction
function s_tDI_s takes integer data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveIntegerParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = 0
//RETURN
endfunction
function s_tDR_s takes real data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveRealParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = 0
//RETURN
endfunction
function s_tDS_s takes string data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveStringParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = ""
//RETURN
endfunction
function s_tDB_s takes boolean data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveBooleanParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = false
//RETURN
endfunction
function s_tDLE_s takes lightning data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveLightningParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDE_s takes effect data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveEffectParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDT_s takes timer data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveTimerParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDTR_s takes trigger data, string tIS, string path returns nothing
local string s = ""
//MAIN PART
call sAI_saveTriggerParameter(data, path , tIS, udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
set data = null
//RETURN
endfunction
function s_tDL takes string tIS, string path returns location
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempLoc = LoadLocationHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempLoc
endfunction
function s_tDG takes string tIS, string path returns group
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempGroup = LoadGroupHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempGroup
endfunction
function s_tDU takes string tIS, string path returns unit
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempUnit = LoadUnitHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempUnit
endfunction
function s_tDI takes string tIS, string path returns integer
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempInt = LoadIntegerBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempInt
endfunction
function s_tDR takes string tIS, string path returns real
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempReal = LoadRealBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempReal
endfunction
function s_tDS takes string tIS, string path returns string
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempString = LoadStringBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempString
endfunction
function s_tDB takes string tIS, string path returns boolean
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempBoolean = LoadBooleanBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempBoolean
endfunction
function s_tDLE takes string tIS, string path returns lightning
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempLightning = LoadLightningHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempLightning
endfunction
function s_tDE takes string tIS, string path returns effect
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempEffect = LoadEffectHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempEffect
endfunction
function s_tDT takes string tIS, string path returns timer
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempTimer = LoadTimerHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempTimer
endfunction
function s_tDTR takes string tIS, string path returns trigger
local string s = ""
//MAIN PART
if (path != "") then
set s = "_" + path
else
set s = ""
endif
set udg_tempTrigger = LoadTriggerHandleBJ(0, StringHashBJ(tIS + s), udg_tempHash)
//PLUG LEAKS
set s = ""
set tIS = ""
set path = ""
//RETURN
return udg_tempTrigger
endfunction
function s_uDL takes unit u, string s returns location
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempLoc = LoadLocationHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempLoc
endfunction
function s_uDG takes unit u, string s returns group
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempGroup = LoadGroupHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempGroup
endfunction
function s_uDU takes unit u, string s returns unit
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempUnit = LoadUnitHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempUnit
endfunction
function s_uDI takes unit u, string s returns integer
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempInt = LoadIntegerBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempInt
endfunction
function s_uDR takes unit u, string s returns real
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempReal = LoadRealBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempReal
endfunction
function s_uDS takes unit u, string s returns string
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempString = LoadStringBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempString
endfunction
function s_uDB takes unit u, string s returns boolean
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempBoolean = LoadBooleanBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempBoolean
endfunction
function s_uDLE takes unit u, string s returns lightning
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempLightning = LoadLightningHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempLightning
endfunction
function s_uDE takes unit u, string s returns effect
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempEffect = LoadEffectHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempEffect
endfunction
function s_uDT takes unit u, string s returns timer
local string uIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempTimer = LoadTimerHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempTimer
endfunction
function s_uDTR takes unit u, string s returns trigger
local integer uI = GetHandleId(u)
local string uIDS = I2S(uI)
//MAIN PART
set udg_tempTrigger = LoadTriggerHandleBJ(0, StringHashBJ("Units_" + uIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set uI = 0
set uIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempTrigger
endfunction
function s_uDDE takes unit u, string s returns destructable
local string dIDS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempDestructable = LoadDestructableHandleBJ(0, StringHashBJ("Units_" + dIDS + "_" + s), udg_UnitAI)
//PLUG LEAKS
set dIDS = ""
set s = ""
set u = null
//RETURN
return udg_tempDestructable
endfunction
function s_uDL_s takes location data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveLocationParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDG_s takes group data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveGroupParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDU_s takes unit data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveUnitParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDI_s takes integer data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveIntegerParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = 0
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDR_s takes real data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveRealParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = 0
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDS_s takes string data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveStringParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = ""
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDB_s takes boolean data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveBooleanParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = false
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDLE_s takes lightning data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveLightningParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDE_s takes effect data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveEffectParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDT_s takes timer data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveTimerParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDTR_s takes trigger data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveTriggerParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDDE_s takes destructable data, string uIS, string path returns nothing
//MAIN PART
call sAI_saveDestructibleParameter(data, path, "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set data = null
set uIS = ""
set path = ""
//RETURN
endfunction
function s_uDI_i takes integer i, unit u, string name, string parent returns nothing
local string s = ""
//MAIN PART
if (parent == "") then
//
else
set s = parent
endif
if (name == "") then
//
elseif (parent != "") then
set s = s + "_" + name
else
set s = name
endif
call sAI_saveIntegerParameter(s_uDI(u, s) + i, name, parent, udg_UnitAI)
//PLUG LEAKS
set s = ""
set i = 0
set u = null
set name = ""
set parent = ""
endfunction
function s_uDR_i takes real r, unit u, string name, string parent returns nothing
local string s = ""
//MAIN PART
if (parent == "") then
//
else
set s = parent
endif
if (name == "") then
//
elseif (parent != "") then
set s = s + "_" + name
else
set s = name
endif
call sAI_saveRealParameter(s_uDR(u, s) + r, name, parent, udg_UnitAI)
//PLUG LEAKS
set s = ""
set r = 0
set u = null
set name = ""
set parent = ""
endfunction
function s_sTimer takes timer t, string tIS returns nothing
call sAI_saveTimerParameter(t, "", tIS, udg_tempHash)
endfunction
function s_stunExpire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = LoadUnitHandleBJ(0, StringHashBJ(tIS + "_unit"), udg_tempHash)
local integer stunStack = 0
//MAIN PART
call s_uDI_i(-1, u, "stun", "state")
set stunStack = s_uDI(u, "state_stun")
if ((stunStack <= 0)) then
call PauseUnitBJ( false, u )
endif
call DestroyEffectBJ( s_tDE(tIS, "effect") )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set stunStack = 0
set u = null
set tIS = ""
set u = null
endfunction
function s_stun takes unit u, real time returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call s_uDI_i(1, u, "stun", "state")
call TimerStart(t, time, false, function s_stunExpire)
call s_tDU_s(u, tIS, "unit")
call PauseUnitBJ( true, u )
call AddSpecialEffectTargetUnitBJ( "overhead", u, "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl" )
call s_tDE_s(bj_lastCreatedEffect, tIS, "effect")
//PLUG LEAKS
set t = null
set u = null
set tIS = ""
set u = null
set time = 0
endfunction
function s_clearOrders takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call sAI_deleteDataTree(("Units_" + uIS + "_order"), udg_UnitAI)
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function s_addOrder takes unit u, string s, trigger t, location l, boolean terminated returns nothing
local string uIS = I2S(GetHandleId(u))
local string oDLS = ""
local integer oI = 0
local integer oIC = 0
//MAIN PART
call sAI_addStringParameter(s, "order", "Units_" + uIS, udg_UnitAI)
set oDLS = udg_lastPLS
call sAI_addTriggerParameter(t, "trigger", oDLS, udg_UnitAI) // this saves to "order_[X]_trigger", not the order name which is also seperate
call sAI_saveBooleanParameter(terminated, "terminated", oDLS, udg_UnitAI)
//call DisplayTextToForce(GetPlayersAll(), "added order")
//call DisplayTextToForce(GetPlayersAll(), I2S(LoadIntegerBJ(0, StringHash("Units_" + uIS + "_order_indexCount"), udg_UnitAI)))
//call DisplayTextToForce(GetPlayersAll(), "odls: " + oDLS)
//call DisplayTextToForce(GetPlayersAll(), "trig count: " + I2S(LoadIntegerBJ(0, StringHash(oDLS + "_trigger_indexCount"), udg_UnitAI)))
//GLOBAL VARS
set udg_lastOrderDLS = oDLS
set udg_lastOrderHash = udg_UnitAI
//PLUG LEAKS
set u = null
set s = ""
set t = null
set l = null
set terminated = false
set oDLS = ""
set oI = 0
set oIC = 0
set uIS = ""
endfunction
//additional triggers
function s_addOrderTrigger takes unit u, string oDLS, trigger t returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call sAI_addTriggerParameter(t, "trigger", oDLS, udg_UnitAI)
//PLUG LEAKS
set u = null
set t = null
set oDLS = ""
set uIS = ""
endfunction
function sP_addOrder takes integer pI, string s, trigger t, location l, boolean terminated returns nothing
local string pIS = I2S(pI)
local string oDLS = ""
local integer oI = 0
local integer oIC = 0
//MAIN PART
call sAI_addStringParameter(s, "order", "Player_" + pIS, udg_PlayerAI[pI])
set oDLS = udg_lastPLS
call sAI_addTriggerParameter(t, "trigger", oDLS, udg_PlayerAI[pI]) // this saves to "order_[X]_trigger", not the order name which is also seperate
call sAI_saveBooleanParameter(terminated, "terminated", oDLS, udg_PlayerAI[pI])
call sAI_saveLocationParameter(l, "loc", oDLS, udg_PlayerAI[pI]) // prob not needed here
//GLOBAL VARS
set udg_lastOrderDLS = oDLS
set udg_lastOrderHash = udg_PlayerAI[pI]
//PLUG LEAKS
set pI = 0
set s = ""
set t = null
set l = null
set terminated = false
set pIS = ""
set oDLS = ""
set oI = 0
set oIC = 0
endfunction
function sP_addOrderTrigger takes integer pI, string oDLS, trigger t returns nothing
//MAIN PART
call sAI_addTriggerParameter(t, "trigger", oDLS, udg_PlayerAI[pI]) // this saves to "order_[X]_trigger", not the order name which is also seperate
//PLUG LEAKS
set pI = 0
set t = null
set oDLS = ""
endfunction
function sP_addCondition takes integer pI, string s, trigger t returns nothing
local string pIS = I2S(pI)
local string cDLS = ""
local integer cI = 0
local integer cIC = 0
//MAIN PART
call sAI_addStringParameter(s, "condition", "Player_" + pIS, udg_PlayerAI[pI])
set cDLS = udg_lastPLS
call sAI_saveTriggerParameter(t, "trigger", cDLS, udg_PlayerAI[pI]) // this saves to "order_[X]_trigger", not the order name which is also seperate
//GLOBAL VARS
set udg_lastCDLS = cDLS
set udg_lastCHash = udg_PlayerAI[pI]
//PLUG LEAKS
set pI = 0
set s = ""
set t = null
set pIS = ""
set cDLS = ""
set cI = 0
set cIC = 0
endfunction
function sAI_Condition_timeElapsed takes real lp_time returns nothing
// just takes current game time, checks the difference, and returns if yea
endfunction
function sC_checkArmyRangeCentre takes nothing returns real
local string dLS = udg_tempString
local unit u = null
local string uIS = I2S(GetHandleId(u))
//
local group g = null
local location l = null
//
local real tRange = 0
local real nUnits = 0
local real aRange = 0
local group g2 = CreateGroup()
local unit eU = null
local location eUL = null
//MAIN PART
call GroupAddGroup(g2, g)
set eU = FirstOfGroup(g2)
set eUL = GetUnitLoc(eU)
loop
exitwhen (eU == null)
set tRange = tRange + (DistanceBetweenPoints(eUL, l))
set nUnits = nUnits + 1
call GroupRemoveUnit(g2, eU)
call RemoveLocation(eUL)
set eU = FirstOfGroup(g2)
set eUL = GetUnitLoc(eU)
endloop
set udg_tempReal = tRange / nUnits
//PLUG LEAKS
call DestroyGroup(g2)
set l = null
set g = null
set u = null
set uIS = ""
//RETURN
return udg_tempReal
endfunction
function sC_checkRangeCentre takes nothing returns real
local string dLS = udg_tempString
local unit u = udg_tempUnit
local string uIS = I2S(GetHandleId(u))
//
local group g = null
local location l = udg_tempLoc
//
local real tRange = 0
local real nUnits = 0
local real aRange = 0
local group g2 = CreateGroup()
local unit eU = null
local location eUL = null
//MAIN PART
call GroupAddGroup(g2, g)
set eU = FirstOfGroup(g2)
set eUL = GetUnitLoc(eU)
loop
exitwhen (eU == null)
set tRange = tRange + (DistanceBetweenPoints(eUL, l))
set nUnits = nUnits + 1
call GroupRemoveUnit(g2, eU)
call RemoveLocation(eUL)
set eU = FirstOfGroup(g2)
set eUL = GetUnitLoc(eU)
endloop
set udg_tempReal = tRange / nUnits
//PLUG LEAKS
call DestroyGroup(g2)
set l = null
set g = null
set u = null
set uIS = ""
//RETURN
return udg_tempReal
endfunction
function s_conditionAdd_range takes string s, group g, location l, real r, boolean b returns nothing
local string oDLS = s
local hashtable ht = udg_lastOrderHash
//
local string cDLS = ""
local integer cI = 0
local integer cIC = 0
local trigger tR = gg_trg_sC_x_Check_Range
//MAIN PART
//
set cIC = LoadIntegerBJ(0, StringHashBJ(oDLS + "_condition_indexCount"), ht)
set cIC = cIC + 1
call SaveIntegerBJ(cIC, 0, StringHashBJ(oDLS + "_condition_indexCount"), ht) // we use these because they ARE meta, they don't create it (assumed in the system)
set cDLS = oDLS + "_condition_" + I2S(cIC)
//
call sAI_saveStringParameter("range", "", cDLS, ht) // just autofills this
call sAI_addTriggerParameter(tR, "trigger", cDLS, ht)
call sAI_saveRealParameter(r, "range", cDLS, ht)
call sAI_saveBooleanParameter(b, "if", cDLS, ht)
//PLUG LEAKS
set oDLS = ""
set ht = null
endfunction
function s_conditionAdd_state takes string dls, string data, boolean b returns nothing
local string oDLS = dls
local hashtable ht = udg_lastOrderHash
//
local string cDLS = ""
local integer cI = 0
local integer cIC = 0
//MAIN PART
//
set cIC = LoadIntegerBJ(0, StringHashBJ(oDLS + "_condition_indexCount"), ht)
set cIC = cIC + 1
call SaveIntegerBJ(cIC, 0, StringHashBJ(oDLS + "_condition_indexCount"), ht)
set cDLS = oDLS + "_condition_" + I2S(cIC)
//
call sAI_saveStringParameter(data, "", cDLS, ht)
call sAI_saveBooleanParameter(b, "if", cDLS, ht)
//PLUG LEAKS
set oDLS = ""
set ht = null
endfunction
function s_conditionAdd_timer takes string dls, real data, boolean b returns nothing
local string oDLS = dls
local hashtable ht = udg_lastOrderHash
//
local string cDLS = ""
local integer cI = 0
local integer cIC = 0
//MAIN PART
//
set cIC = LoadIntegerBJ(0, StringHashBJ(oDLS + "_condition_indexCount"), ht)
set cIC = cIC + 1
call SaveIntegerBJ(cIC, 0, StringHashBJ(oDLS + "_condition_indexCount"), ht)
set cDLS = oDLS + "_condition_" + I2S(cIC)
//
call sAI_saveRealParameter(data, "time", cDLS, ht)
call sAI_saveTimerParameter(CreateTimer(), "timer", cDLS, ht)
call sAI_saveBooleanParameter(b, "if", cDLS, ht)
//PLUG LEAKS
set oDLS = ""
set ht = null
endfunction
//=======================================================================================
//=======================================================================================
//=======================================================================================
//=======================================================================================
//=======================================================================================
//=======================================================================================
function sAI_unitDetectUnits takes unit u, real r returns nothing
local real radius = 900
local integer i = GetHandleIdBJ(u)
local string unitIDString = I2S(i)
local integer dls_i = 0
local hashtable ht = udg_UnitAI
local group sortGroup = GetUnitsInRangeOfLocAll(200.00, GetUnitLoc(u))
local unit enumUnit = null
local integer num = 0
//MAIN PART
// add a condition for visibility, set rad to unit sight range
set enumUnit = FirstOfGroup(sortGroup)
loop
exitwhen (enumUnit == null)
if (IsPlayerEnemy(GetOwningPlayer(enumUnit), (GetOwningPlayer(u))) == true) then
if (IsUnitType(enumUnit, UNIT_TYPE_STRUCTURE) == false ) then
set num = num + 1
endif
endif
call GroupRemoveUnitSimple(enumUnit, sortGroup)
set enumUnit = FirstOfGroup(sortGroup)
endloop
set dls_i = S2I("Units_" + unitIDString + "_detectedUnits_count")
call SaveIntegerBJ(num, 0, dls_i, ht)
//PLUG LEAKS
set u = null
set i = 0
set unitIDString = ""
set dls_i = 0
set ht = null
set radius = 0
call DestroyGroup(sortGroup)
set enumUnit = null
set num = 0
endfunction
function sP_queueMoveArmy_slow takes integer pI, string dLS, group g, location l returns nothing
local string pIS = I2S(pI)
local string tS = dLS
//MAIN PART
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", dLS, udg_PlayerAI[pI])
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_PlayerAI[pI])
call sAI_saveLocationParameter(l, "loc", tS, udg_PlayerAI[pI])
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
//=======================
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", dLS, udg_PlayerAI[pI])
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
//PLUG LEAKS
set pI = 0
set pIS = ""
set l = null
set g = null
endfunction
function s_findWord takes string s, string word returns integer
local string eS = ""
local integer i = 0
local integer i2 = 0
local integer sL = StringLength(s)
// MAIN PART
set udg_tempInt = -1 // if nowhere
loop
exitwhen ((i > sL) or (udg_tempInt != -1))
set eS = SubStringBJ(s, i, i2)
if (eS == word) then
set udg_tempInt = i
endif
set i2 = i2 + 1
if (i2 > sL) then
set i2 = 1
set i = i + 1
endif
endloop
//PLUG LEAKS
set eS = ""
set i = 0
set i2 = 0
set s = ""
set word = ""
// RETURN
return udg_tempInt
endfunction
function s_findWord takes string s, hashtable ht returns integer
local string word = ""
local string eS = ""
local integer i = 0
local integer i2 = 0
local integer sL = StringLength(s)
// MAIN PART
set udg_tempInt = -1 // if nowhere
loop
exitwhen ((i > sL) or (udg_tempInt != -1))
set eS = SubStringBJ(s, i, i2)
if (eS == word) then
set udg_tempInt = i
endif
set i2 = i2 + 1
if (i2 > sL) then
set i2 = 1
set i = i + 1
endif
endloop
//PLUG LEAKS
set eS = ""
set i = 0
set i2 = 0
set s = ""
set word = ""
// RETURN
return udg_tempInt
endfunction
function s_basicGroupOrderLoc takes group g, string s, location l returns nothing
local group g2 = CreateGroup()
local unit eU = FirstOfGroup(g)
//MAIN PART
call GroupAddGroup(g2, g)
loop
exitwhen (eU == null)
call IssuePointOrderLoc(eU, s, l)
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
//PLUG LEAKS
call DestroyGroup(g2)
set g2 = null
set g = null
set l = null
set s = ""
set eU = null
endfunction
function s_groupOrderLoc takes boolean clear, group g, string s, trigger t, location l, boolean b returns nothing
local group g2 = CreateGroup()
local unit eU = FirstOfGroup(g)
//MAIN PART
call GroupAddGroup(g2, g)
loop
exitwhen (eU == null)
if (clear == true) then
call s_clearOrders(eU)
endif
call s_addOrder(eU, s, t, l, b)
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
//PLUG LEAKS
call DestroyGroup(g2)
set g2 = null
set g = null
set l = null
set s = ""
set eU = null
endfunction
function pA_sendArmy takes nothing returns nothing
local string oIS = udg_tempString
local string oS = LoadStringBJ(0, StringHashBJ(oIS + "_order"), udg_UnitAI) // easy to create a generic order func wid dis
local unit u = LoadUnitHandleBJ(0, StringHashBJ(oIS + "_unit"), udg_UnitAI)
local string uIS = I2S(GetHandleId(u))
//
local integer pI = udg_tempInt
local location l = null
local group g = LoadGroupHandleBJ(0, StringHashBJ(oIS + "_group"), udg_PlayerAI[pI])
//
local integer lCount = 0
local integer cI = 0
local string s = ""
local string cDLS = "" // condition dls
local boolean conditionsPassed = false
//MAIN PART
set s = oIS
set l = LoadLocationHandleBJ(0, StringHashBJ(s + "_targetLoc"), udg_PlayerAI[pI])
set lCount = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_indexCount"), udg_PlayerAI[pI])
set cI = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
call s_basicGroupOrderLoc(g, "move", l)
set udg_tempGroup = g // can probably still put these into parameters
set udg_tempLoc = l
call SaveIntegerBJ(cI, 0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set oIS = ""
set oS = ""
set lCount = 0
set cI = 0
set s = ""
set cDLS = ""
set conditionsPassed = false
endfunction
function pA_armyGuard_area takes nothing returns nothing
local string oIS = udg_tempString
local string oS = LoadStringBJ(0, StringHashBJ(oIS + "_order"), udg_UnitAI) // easy to create a generic order func wid dis
local unit u = LoadUnitHandleBJ(0, StringHashBJ(oIS + "_unit"), udg_UnitAI)
local string uIS = I2S(GetHandleId(u))
//
local integer pI = udg_tempInt
local location l = null
local group g = LoadGroupHandleBJ(0, StringHashBJ(oIS + "_group"), udg_PlayerAI[pI])
//
local integer lCount = 0
local integer cI = 0
local string s = ""
local string cDLS = "" // condition dls
local boolean conditionsPassed = false
//MAIN PART
set s = oIS
set l = LoadLocationHandleBJ(0, StringHashBJ(s + "_targetLoc"), udg_PlayerAI[pI])
set lCount = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_indexCount"), udg_PlayerAI[pI])
set cI = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
call s_basicGroupOrderLoc(g, "move", l)
set udg_tempGroup = g // can probably still put these into parameters
set udg_tempLoc = l
call SaveIntegerBJ(cI, 0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set oIS = ""
set oS = ""
set lCount = 0
set cI = 0
set s = ""
set cDLS = ""
set conditionsPassed = false
endfunction
function pA_sendArmy takes nothing returns nothing
local string oIS = udg_tempString
local string oS = LoadStringBJ(0, StringHashBJ(oIS + "_order"), udg_UnitAI) // easy to create a generic order func wid dis
local unit u = LoadUnitHandleBJ(0, StringHashBJ(oIS + "_unit"), udg_UnitAI)
local string uIS = I2S(GetHandleId(u))
//
local integer pI = udg_tempInt
local location l = null
local group g = LoadGroupHandleBJ(0, StringHashBJ(oIS + "_group"), udg_PlayerAI[pI])
//
local integer lCount = 0
local integer cI = 0
local string s = ""
local string cDLS = "" // condition dls
local boolean conditionsPassed = false
//MAIN PART
set s = oIS
set l = LoadLocationHandleBJ(0, StringHashBJ(s + "_targetLoc"), udg_PlayerAI[pI])
set lCount = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_indexCount"), udg_PlayerAI[pI])
set cI = LoadIntegerBJ(0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
call s_basicGroupOrderLoc(g, "move", l)
set udg_tempGroup = g // can probably still put these into parameters
set udg_tempLoc = l
call SaveIntegerBJ(cI, 0, StringHashBJ(s + "_targetLoc_currentIndex"), udg_PlayerAI[pI])
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set oIS = ""
set oS = ""
set lCount = 0
set cI = 0
set s = ""
set cDLS = ""
set conditionsPassed = false
endfunction
function uA_moveTo takes nothing returns nothing
local string oIS = udg_tempString
local string oS = LoadStringBJ(0, StringHashBJ(oIS + "_order"), udg_UnitAI) // easy to create a generic order func wid dis
local unit u = LoadUnitHandleBJ(0, StringHashBJ(oIS + "_unit"), udg_UnitAI)
local string uIS = I2S(GetHandleId(u))
local location l = null
local group g = null
//
local integer lCount = 0
local integer cI = 0
local string s = ""
local string cDLS = "" // condition dls
local boolean conditionsPassed = false
//MAIN PART
// this should probably actually be pulling from orders
// can run a condition check trigger
set s = oIS
set l = s_uDL(u, s + "_targetLoc")
set lCount = s_uDI(u, s + "_targetLoc_indexCount")
set cI = s_uDI(u, s + "_targetLoc_currentIndex")
call IssuePointOrderLoc(u, "move", l)
set cI = cI + 1
if (cI > lCount) then
if (s_uDB(u, s + "_loop") == true) then
set cI = 1
endif
endif
call s_uDI_s(cI, uIS, s + "_targetLoc_currentIndex")
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set oIS = ""
set oS = ""
set lCount = 0
set cI = 0
set s = ""
set cDLS = ""
set conditionsPassed = false
endfunction
function s_checkConditions takes string dLS returns boolean
local trigger t = null
//
local string cDLS = dLS + "_condition"
local boolean b = true
local boolean b2 = false
local integer cI = 1
local integer cIC = LoadIntegerBJ(0, StringHashBJ(dLS + "_condition_indexCount"), udg_UnitAI)
local string cIS = ""
//MAIN PART
set udg_tempLoc = LoadLocationHandleBJ(0, StringHashBJ(dLS + "_loc"), udg_UnitAI)
set udg_tempString = dLS
//These should be available for use, as the containing Order function should already have collected its info.
set cIC = LoadIntegerBJ(0, StringHashBJ(dLS + "_condition_indexCount"), udg_UnitAI)
loop
exitwhen (cI > cIC)
set cDLS = dLS + "_condition_" + cIS
set t = LoadTriggerHandleBJ(0, StringHashBJ(cDLS + "_trigger"), udg_UnitAI)
call TriggerExecute(t)
set cI = cI + 1
set cIS = I2S(cI)
endloop
//PLUG LEAKS
set dLS = ""
set b = false
set b2 = false
set cI = 0
set cIC = 0
set cIS = ""
set cDLS = ""
//RETURN
return udg_tempBoolean
endfunction
function u_orderStart takes unit u, string oIS returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDB_s(true, uIS, oIS + "_currentlyExecuting")
//PLUG LEAKS
set u = null
set oIS = ""
set uIS = ""
endfunction
function u_orderFinish takes unit u, string oIS returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDB_s(false, uIS, oIS + "_currentlyExecuting")
//PLUG LEAKS
set u = null
set oIS = ""
set uIS = ""
endfunction
function u_orderCheckExec takes unit u, string oDLS returns boolean
local string uIS = I2S(GetHandleId(u))
//MAIN PART
set udg_tempBoolean = s_uDB(u, oDLS + "_currentlyExecuting")
//PLUG LEAKS
set u = null
set oDLS = ""
set uIS = ""
//RETURN
return udg_tempBoolean
endfunction
function sU_executeOrder takes unit u, string oDLS returns nothing
local trigger t = null
local string oS = LoadStringBJ(0, StringHashBJ(oDLS), udg_UnitAI)
local integer sI = StringHash(oDLS + "_trigger_indexCount")
local integer tRI = 1
local integer tRIC = LoadIntegerBJ(0, sI, udg_UnitAI)
local string tRIS = I2S(tRI)
local boolean cReturn = false
local boolean cWanted = false
//MAIN PART
set udg_uAI_Unit = u
set udg_uAI_uIS = I2S(GetHandleId(u))
set udg_tempLoc = LoadLocationHandleBJ(0, StringHashBJ(oDLS + "_loc"), udg_UnitAI)
set udg_tempString = oDLS
//call DisplayTextToForce(GetPlayersAll(), "executing order 1")
//call DisplayTextToForce(GetPlayersAll(), I2S(tRIC))
//call DisplayTextToForce(GetPlayersAll(), "odls: " + oDLS)
loop
exitwhen (tRI > tRIC)
set sI = StringHash(oDLS + "_trigger_" + tRIS)
set t = LoadTriggerHandleBJ(0, sI, udg_UnitAI)
//set cWanted = LoadBooleanBJ(0, StringHash(oDLS + "_trigger_" + tRIS + "_if"), udg_UnitAI)
//set cReturn = s_checkConditions(oDLS + "_trigger_" + tRIS + "_if")
//if (cReturn == cWanted) then
//call DisplayTextToForce(GetPlayersAll(), "executing trigger")
call TriggerExecute(t)
//endif
set tRI = tRI + 1
set tRIS = I2S(tRI)
endloop
//PLUG LEAKS
set u = null
set oDLS = ""
set sI = 0
set t = null
set oS = ""
set tRI = 0
set tRIC = 0
set tRIS = ""
set cReturn = false
set cWanted = false
endfunction
function sP_executeOrder takes integer pI, string oDLS returns nothing
local trigger t = null
local string oS = LoadStringBJ(0, StringHashBJ(oDLS + "_order"), udg_UnitAI)
local integer tRI = 1
local integer tRIC = LoadIntegerBJ(0, StringHashBJ(oDLS + "_trigger_indexCount"), udg_UnitAI)
local string tRIS = I2S(tRI)
local boolean cReturn = false
local boolean cWanted = false
//MAIN PART
set udg_tempInt = pI
set udg_tempLoc = LoadLocationHandleBJ(0, StringHashBJ(oDLS + "_loc"), udg_UnitAI)
set udg_tempString = oDLS
loop
exitwhen (tRI > tRIC)
set t = LoadTriggerHandleBJ(0, StringHashBJ(oDLS + "_trigger_" + tRIS), udg_UnitAI)
//
set cWanted = LoadBooleanBJ(0, StringHashBJ(oDLS + "_trigger_" + tRIS + "_if"), udg_UnitAI)
set cReturn = s_checkConditions(oDLS + "_trigger_" + tRIS + "_if")
if (cReturn == cWanted) then
call TriggerExecute(t)
endif
set tRI = tRI + 1
set tRIS = I2S(tRI)
endloop
//PLUG LEAKS
set pI = 0
set oDLS = ""
endfunction
function sU_executeAllOrders takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
local string oS = ""
local integer sI = StringHash("Units_" + uIS + "_order_indexCount")
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, sI, udg_UnitAI)
local string oIS = I2S(oI)
local integer cI = s_uDI(u, "order_currentIndex")
local boolean break = false
//MAIN PART
set udg_uAI_Unit = u
//call DisplayTextToForce(GetPlayersAll(), "a unit executing orders")
//call DisplayTextToForce( GetPlayersAll(), "loop" )
//call DisplayTextToForce( GetPlayersAll(), uIS )
//call DisplayTextToForce( GetPlayersAll(), R2S(GetTimeOfDay()) )
if oIC > 0 then
//call DisplayTextToForce(GetPlayersAll(), I2S(oIC))
endif
loop
exitwhen (oI > oIC) or break == true
//call DisplayTextToForce(GetPlayersAll(), "a unit executing order")
call s_uDI_s(oI, uIS, "order_currentIndex")
set oS = "Units_" + uIS + "_order_" + oIS
// s check
//call u_orderStart(u, oS)
call sU_executeOrder(u, oS)
//if (u_orderCheckExec(u, oS)) == true then
//set break = true
//endif
set oI = oI + 1
set oIS = I2S(oI)
endloop
//PLUG LEAKS
set u = null
set uIS = ""
set oS = ""
set sI = 0
set oI = 0
set oIC = 0
set oIS = ""
set cI = 0
set break = false
endfunction
function sP_executeAllOrders takes integer pI returns nothing
local string pIS = I2S(pI)
local string oS = ""
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, StringHashBJ("Player_" + pIS + "_order_indexCount"), udg_UnitAI)
local string oIS = I2S(oI)
//MAIN PART
set udg_tempInt = pI
loop
exitwhen (oI > oIC)
set oS = LoadStringBJ(0, StringHashBJ("Player_" + pIS + "_order_" + oIS), udg_UnitAI)
// s check
call sP_executeOrder(pI, oS)
set oI = oI + 1
set oIS = I2S(oI)
endloop
//PLUG LEAKS
set pI = 0
set pIS = ""
set oS = ""
set oI = 0
set oIC = 0
set oIS = ""
endfunction
function sP_lilithOrderArmy takes integer pI, group g returns nothing
local string pIS = I2S(pI)
local string oS = ""
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, StringHashBJ("Player_" + pIS + "_order_indexCount"), udg_PlayerAI[pI])
local string oIS = I2S(oI)
local location l = GetRectCenter(gg_rct_KaelTH)
local string tS = ""
//MAIN PART
//to add a waiting period to this, we add a trigger to the order, and create condition ifs to switch
set l = GetRectCenter(gg_rct_LilithArmy01)
// conditions == false it immediately terminates, THEN starts next trigger/order?
call sP_addOrder(pI, "attack", gg_trg_sP_x_sendArmy, l, true) // "true" means when it reaches the end it does not loop
call sAI_saveGroupParameter(g, "group", udg_lastOrderDLS, udg_lastOrderHash)
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_LilithArmy02)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_LilithArmy03)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_KaelTH)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//PLUG LEAKS
set pI = 0
set pIS = ""
set oS = ""
set oI = 0
set oIC = 0
set oIS = ""
call RemoveLocation(l)
set l = null
endfunction
function sP_elementalsOrderArmy takes integer pI, group g returns nothing
local string pIS = I2S(pI)
local string oS = ""
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, StringHashBJ("Player_" + pIS + "_order_indexCount"), udg_PlayerAI[pI])
local string oIS = I2S(oI)
local location l = GetRectCenter(gg_rct_KaelTH)
local string tS = ""
//MAIN PART
//to add a waiting period to this, we add a trigger to the order, and create condition ifs to switch
set l = GetRectCenter(gg_rct_LilithArmy01)
// conditions == false it immediately terminates, THEN starts next trigger/order?
call sP_addOrder(pI, "attack", gg_trg_sP_x_sendArmy, l, true) // "true" means when it reaches the end it does not loop
call sAI_saveGroupParameter(g, "group", udg_lastOrderDLS, udg_lastOrderHash)
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_LilithArmy02)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_LilithArmy03)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_KaelTH)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//PLUG LEAKS
set pI = 0
set pIS = ""
set oS = ""
set oI = 0
set oIC = 0
set oIS = ""
call RemoveLocation(l)
set l = null
endfunction
function sP_stormWyrmsOrderArmy takes integer pI, group g returns nothing
local string pIS = I2S(pI)
local string oS = ""
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, StringHashBJ("Player_" + pIS + "_order_indexCount"), udg_PlayerAI[pI])
local string oIS = I2S(oI)
local location l = GetRectCenter(gg_rct_KaelTH)
local string tS = ""
//MAIN PART
set l = GetRectCenter(gg_rct_StormWyrms_Path_01)
call sP_addOrder(pI, "attack", gg_trg_sP_x_sendArmy, l, true) // "true" means when it reaches the end it does not loop
call sAI_saveGroupParameter(g, "group", udg_lastOrderDLS, udg_lastOrderHash)
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_StormWyrms_Path_02)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
//PLUG LEAKS
set pI = 0
set pIS = ""
set oS = ""
set oI = 0
set oIC = 0
set oIS = ""
call RemoveLocation(l)
set l = null
endfunction
function sP_stormWyrmsOrderArmy takes integer pI, group g returns nothing
local string pIS = I2S(pI)
local string oS = ""
local integer oI = 1
local integer oIC = LoadIntegerBJ(0, StringHashBJ("Player_" + pIS + "_order_indexCount"), udg_PlayerAI[pI])
local string oIS = I2S(oI)
local location l = GetRectCenter(gg_rct_KaelTH)
local string tS = ""
//MAIN PART
set l = GetRectCenter(gg_rct_StormWyrms_Path_01)
call sP_addOrder(pI, "attack", gg_trg_sP_x_sendArmy, l, true) // "true" means when it reaches the end it does not loop
call sAI_saveGroupParameter(g, "group", udg_lastOrderDLS, udg_lastOrderHash)
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
set l = GetRectCenter(gg_rct_StormWyrms_Path_02)
call sAI_addTriggerParameter(gg_trg_sP_x_sendArmy, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call sAI_saveGroupParameter(g, "group", tS, udg_lastOrderHash)
call sAI_saveLocationParameter(l, "loc", tS, udg_lastOrderHash)
call s_conditionAdd_range(tS, g, l, 200, false) // add to trigger, false should mean this activates until timer expires
call sAI_addTriggerParameter(gg_trg_sP_x_armyGuardArea, "trigger", udg_lastOrderDLS, udg_lastOrderHash)
set tS = udg_lastPLS
call s_conditionAdd_timer(tS, 15, false) // add to trigger, false should mean this activates until timer expires
call RemoveLocation(l)
//=======================
//PLUG LEAKS
set pI = 0
set pIS = ""
set oS = ""
set oI = 0
set oIC = 0
set oIS = ""
call RemoveLocation(l)
set l = null
endfunction
native GetUnitGoldCost takes integer unitid returns integer
native GetUnitWoodCost takes integer unitid returns integer
native GetUnitBuildTime takes integer unitid returns integer
function udf_playerCanAffordUnit takes integer unitid, integer p returns boolean
local integer goldCost = GetUnitGoldCost(unitid)
local integer lumberCost = GetUnitWoodCost(unitid)
local integer currentGold = GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD)
local integer currentLumber = GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER)
local integer foodRemaining = (GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_FOOD_CAP) - GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_FOOD_USED))
local integer foodCost = GetFoodUsed(unitid)
if (goldCost < currentGold) and (lumberCost < currentLumber) and (foodCost < foodRemaining) then
return true
else
return false
endif
endfunction
//=====================================================================
// Finds the nearest Town Hall to unit
function udf_getClosestPlayerTHToPointFunction1 takes nothing returns nothing
local real lv_dist = 0
set lv_dist = DistanceBetweenPoints(GetUnitLoc(GetEnumUnit()), udg_tempLocation)
if lv_dist < udg_tempHighestReal then
set udg_tempHighestReal = lv_dist
set udg_tempUnit = GetEnumUnit()
endif
endfunction
function udf_getClosestPlayerTHToPointCondition1 takes nothing returns boolean
return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_TOWNHALL) == true )
endfunction
function udf_getClosestPlayerTHToPoint takes location lp_p returns unit
set udg_tempLocation = lp_p
set udg_tempUnit = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function udf_getClosestPlayerTHToPointCondition1)), function udf_getClosestPlayerTHToPointFunction1 )
set udg_tempLocation = null
set udg_tempHighestReal = 0.0
return udg_tempUnit
//presumably these functions call in a row, and temps won't conflict
endfunction
//=====================================================================
//=====================================================================
// Finds the nearest gold mine to loc
function udf_getClosestGoldMineToPointFunction1 takes nothing returns nothing
local real lv_dist = 0
set lv_dist = DistanceBetweenPoints(GetUnitLoc(GetEnumUnit()), udg_tempLocation)
if lv_dist < udg_tempHighestReal then
set udg_tempHighestReal = lv_dist
set udg_tempUnit = GetEnumUnit()
endif
endfunction
function udf_getClosestGoldMineToPointCondition1 takes nothing returns boolean
return (GetUnitTypeId(GetFilterUnit()) == 'ngol')
endfunction
function udf_getClosestGoldMineToPoint takes location lp_p returns unit
set udg_tempLocation = lp_p
set udg_tempUnit = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function udf_getClosestGoldMineToPointCondition1)), function udf_getClosestGoldMineToPointFunction1 )
set udg_tempLocation = null
set udg_tempHighestReal = 0.0
return udg_tempUnit
//presumably these functions call in a row, and temps won't conflict
endfunction
//=====================================================================
//=====================================================================
function udf_getClosestUnitOfGroupToPointFunction1 takes nothing returns nothing
local real lv_dist = 0
set lv_dist = DistanceBetweenPoints(GetUnitLoc(GetEnumUnit()), udg_tempLocation)
if lv_dist < udg_tempHighestReal then
set udg_tempHighestReal = lv_dist
set udg_tempUnit = GetEnumUnit()
endif
endfunction
function udf_getClosestUnitOfGroupToPoint takes group lp_g, location lp_p returns unit
set udg_tempLocation = lp_p
set udg_tempUnit = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
call ForGroupBJ( lp_g, function udf_getClosestUnitOfGroupToPointFunction1 )
set udg_tempLocation = null
set udg_tempHighestReal = 0.0
return udg_tempUnit
//presumably these functions call in a row, and temps won't conflict
endfunction
//=====================================================================
//=====================================================================
// Finds the nearest claimed Forest/Tree
//woops, need dest type as well
function udf_getClosestTreeToPointFunction1 takes nothing returns nothing
local real lv_dist = 0
set lv_dist = DistanceBetweenPoints(GetDestructableLoc(GetEnumDestructable()), udg_tempLocation)
if (lv_dist < udg_tempHighestReal) and (GetDestructableTypeId(GetEnumDestructable()) == 'LTlt') then
set udg_tempHighestReal = lv_dist
set udg_tempDestructable = GetEnumDestructable()
endif
endfunction
//=====================================================================
//=====================================================================
function udf_getClosestTreeToPoint takes location lp_p returns destructable
set udg_tempLocation = lp_p
set udg_tempDestructable = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
call EnumDestructablesInRectAll( GetPlayableMapRect(), function udf_getClosestTreeToPointFunction1 )
set udg_tempLocation = null
set udg_tempHighestReal = 0.0
return udg_tempDestructable
//presumably these functions call in a row, and temps won't conflict
endfunction
//=====================================================================
function udf_getPlayerHarvestersOfMineCondition1 takes nothing returns boolean
return (LoadUnitHandleBJ(StringHashBJ("harvestGoldMineTarget"), GetHandleIdBJ(GetFilterUnit()), udg_UnitAI) == udg_tempUnit)
endfunction
function udf_getPlayerHarvestersOfMine takes integer lp_playerInt, unit lp_mine returns group
set udg_tempUnit = lp_mine
return GetUnitsOfPlayerMatching(Player(lp_playerInt), Condition(function udf_getPlayerHarvestersOfMineCondition1))
endfunction
function udf_getUnmaxedPlayerMinesFunction1 takes nothing returns nothing
if (CountUnitsInGroup(udf_getPlayerHarvestersOfMine(udg_tempInt, GetEnumUnit())) < 5) then
call GroupAddUnitSimple( GetEnumUnit(), udg_tempGroup )
endif
endfunction
function udf_getUnmaxedPlayerMines takes integer lp_playerInt, location lp_loc returns group
set udg_tempLocation = lp_loc
set udg_tempUnit = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
set udg_tempInt = lp_playerInt
call GroupClear( udg_tempGroup )
call ForGroupBJ(udg_sAIClaimedGoldMines[lp_playerInt], function udf_getUnmaxedPlayerMinesFunction1)
//REMOVE LEAKS//========================
// (These are Globals, but doesn't hurt to clear them anyway.)
set udg_tempLocation = null
set udg_tempUnit = null
set udg_tempHighestReal = 0.0
set udg_tempInt = 0
//======================================
return udg_tempGroup
endfunction
function udf_getClosestUnmaxedPlayerMineToLocFunction1 takes nothing returns nothing
local real lv_dist = 0
set lv_dist = DistanceBetweenPoints(GetUnitLoc(GetEnumUnit()), udg_tempLocation)
if (lv_dist < udg_tempHighestReal) and (CountUnitsInGroup(udf_getPlayerHarvestersOfMine(udg_tempInt, GetEnumUnit())) < 5) then
set udg_tempHighestReal = lv_dist
set udg_tempUnit = GetEnumUnit()
endif
endfunction
function udf_getClosestUnmaxedPlayerMineToLoc takes integer lp_playerInt, location lp_loc returns unit
set udg_tempLocation = lp_loc
set udg_tempUnit = null
set udg_tempHighestReal = 1000.0 //Just to get the ball rolling.
set udg_tempInt = lp_playerInt
call ForGroupBJ(udg_sAIClaimedGoldMines[lp_playerInt], function udf_getClosestUnmaxedPlayerMineToLocFunction1)
return udg_tempUnit // theoretically could return a null so keep that in mind
endfunction
function sAI_AIClaimsNewMine takes integer lp_playerID, unit lp_mine returns nothing
local integer lv_hashSetIteration = 0 //the place where the info gets saved
local integer lv_currentListSize = 0
local string lv_parentString = ""
local string lv_stringPreFix = ""
set lv_currentListSize = LoadIntegerBJ(StringHashBJ("numberOfEntries"), StringHashBJ("goldMine"), udg_PlayerAI[lp_playerID]) + 1
set lv_hashSetIteration = lv_currentListSize
call SaveUnitHandleBJ( lp_mine, lv_hashSetIteration, StringHashBJ("goldMine"), udg_PlayerAI[lp_playerID] )
//pretty simple
endfunction
function sAI_addNewMineSuggestionToAI takes integer lp_playerID, location lp_townCentrePoint, real lp_radius returns nothing
local string lv_prestring = "mine"
local string lv_parentString = "AI_SuggestedActions"
local integer lv_currentNumOfEntries = LoadIntegerBJ(StringHashBJ(lv_prestring + "_indexCount"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
local string lv_aITown_prestring = ""
local string lv_aITown_ParentString = ""
local integer i = 1
if i <= lv_currentNumOfEntries then
call SaveIntegerBJ (1, StringHashBJ(lv_prestring + "_indexCount"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
call SaveLocationHandleBJ (lp_townCentrePoint, StringHashBJ(lv_prestring + "_loc"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
call SaveRealBJ (lp_radius, StringHashBJ(lv_prestring + "_" + I2S(i) + "_radius"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
endif
endfunction
function sAI_addNewTownSuggestion takes integer lp_playerID, location lp_townCentrePoint, real lp_radius returns nothing
local string lv_prestring = "town"
local string lv_parentString = "townSuggestion"
local integer lv_currentNumOfEntries = LoadIntegerBJ(StringHashBJ(lv_prestring + "_NumEntries"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
local boolean lv_suggestionEnabled = false //so you can pre-create and then trigger appropriately.
//Save Town Suggestion in an easily findable way. Even Loc based
// this may also save information such as improving an existing town, thus it saves towns, iterations, and such. However you want to use it.
// Actually that wouldn't be under suggestions probably, but keep the idea in mind.
local string lv_aITown_prestring = ""
local string lv_aITown_ParentString = ""
local integer lv_aiTownID = 0
// This is presumably for the PlayerAI's created town information, as opposed to just suggested.
// Maybe the AI will just maintain both. If it fulfills the conditions for one, it meets the suggestion, which is a "virtual" information set.
local integer i = 1
//============================================================================
if i <= lv_currentNumOfEntries then
call SaveIntegerBJ (1, StringHashBJ(lv_prestring + "_NumEntries"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
call SaveLocationHandleBJ (lp_townCentrePoint, StringHashBJ(lv_prestring + "_loc"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
call SaveRealBJ (lp_radius, StringHashBJ(lv_prestring + "_" + I2S(i) + "_radius"), StringHashBJ(lv_parentString), udg_PlayerAI[lp_playerID])
//radius might be superfluous for at least some things
//============================================================================
//STORE LAST CREATED TOWN SUGGESTION
//============================================================================
endif
endfunction
function sAI_addVUnitToTownSuggestion takes integer lp_playerID, integer lp_town, string lp_unitType, integer numOfUnits returns nothing
local integer lv_numOfSuggestedUnits = LoadIntegerBJ(StringHashBJ("town_" + I2S(lp_town) + "_numOfUnits"), StringHashBJ("townSuggestion"), udg_PlayerAI[lp_playerID])
local integer lv_suggestedUnitIteration = lv_numOfSuggestedUnits + 1
local string lv_savePathPreString = ""
local string lv_savePathString = ""
local string lv_savePathParentString = ""
//=======================================================================================================
//
//=======================================================================================================
// The following is basically just empty empty promises. Reminders of the kind of data they'll be saved with.
//=======================================================================================================
// UNIT ROLE VARIABLES
//=======================================================================================================
//=======================================================================================================
// UNIT POSITION VARIABLES
//=======================================================================================================
//=======================================================================================================
// UNIT ORDERS VARIABLES
//=======================================================================================================
// These probably get added via sAI add data functions.
//=======================================================================================================
//=======================================================================================================
//=======================================================================================================
//=======================================================================================================
//=======================================================================================================
//=======================================================================================================
set lv_numOfSuggestedUnits = lv_suggestedUnitIteration
set lv_savePathPreString = "town_" + I2S(lp_town)
set lv_savePathString = lv_savePathPreString + "_suggestedUnit_" + I2S(lv_suggestedUnitIteration)
set lv_savePathParentString = "townSuggestion"
call SaveStringBJ( lp_unitType, StringHashBJ(lv_savePathString + "_unitType"), StringHashBJ(lv_savePathParentString), udg_PlayerAI[lp_playerID] )
//=======================================================================================================
//SAVE LAST CREATED VIRTUAL UNIT
//=======================================================================================================
set udg_LastCreatedVUnitPath = lv_savePathString
set udg_LastCreatedVUnitParentPath = lv_savePathParentString
set udg_LastCreatedVUnitHashT = udg_PlayerAI[lp_playerID]
// store last created virtual unit so we can add data to it
//=======================================================================================================
//=======================================================================================================
// I think let's save them individually, so we have individual data. I may need to change later, if there's like 100 footmen, etc. But keep in mind.
//=======================================================================================================
//GET UNIT POSITIONING DATA
//=======================================================================================================
// More data details. Where a soldier is going to guard or patrol, etc. Let's start simple.
// This is going to include the potential of attachment like data. Is it a global position, or a local offset, if it's escorting, etc.
// IF NO ADDITIONAL DATA IS ADDED, THE COMPUTER JUST CREATES THESE UNITS FOR THE TOWN AND DOES WHAT IT WANTS.
// I think they are automatically added to the defensive force, by default. Probably can customise.
//=======================================================================================================
//=======================================================================================================
endfunction
//Huh. Pretty simple too.
function sAI_addVUnitDataJob takes string lp_jobType, integer lp_jobTarget returns nothing
// add data to last created unit
local string lv_vUnitPath = udg_LastCreatedVUnitPath
local string lv_vUnitParentPath = udg_LastCreatedVUnitParentPath
local hashtable lv_hashTable = udg_LastCreatedVUnitHashT
local string lv_unitJobType = "" // guard, worker, etc
local integer lv_jobTarget = 0 //convert and use, it... should work out? Gets Handle Id or whatev.
//============================================================================
// ADVANCED
//============================================================================
local group lv_addToGroup = null // prob in actual unit creation
local string lv_customAIDataPath = "" // a pointer to more complex info for the data
//============================================================================
//============================================================================
//SAVE VIRTUAL UNIT'S JOB
//============================================================================
call SaveStringBJ(lv_unitJobType, StringHashBJ(lv_vUnitPath + "jobType"), StringHashBJ(lv_vUnitParentPath), lv_hashTable)
call SaveIntegerBJ(lv_jobTarget, StringHashBJ(lv_vUnitPath + "jobTarget"), StringHashBJ(lv_vUnitParentPath), lv_hashTable)
// This needs to mesh with Unit job data. When an actual unit is created.
//============================================================================
//SAVE LAST CREATED DATA PATH (if necessary)
//============================================================================
endfunction
function sAI_addVUnitDataOrder takes string lp_order returns nothing // this could get more complex, but simple for now
local string lv_vUnitPath = udg_LastCreatedVUnitPath
local string lv_vUnitParentPath = udg_LastCreatedVUnitParentPath
local hashtable lv_hashTable = udg_LastCreatedVUnitHashT
local string lv_orderTypePath = ""
local integer lv_orderTypeIteration = 0 // Basically some pointers to some pre-made type of orders, to simplify it fo nao.
// Or could just have it parent-child created here, so it can be modified.
local integer lv_orderTarget = 0 // wonder if I would use a hash table to store this info
endfunction
function sAI_createOrder takes integer lp_playerID, unit lp_forUnit returns nothing // this would probably work for an order
// basically an order, but it's for a specific purpose
// Perhaps this function will create an order for each input. Like, order_index as well as order_unit_index, etc, etc, for fast future ref
local integer lv_unitTag = GetHandleId(lp_forUnit)
local string lv_orderHashString = ""
local integer lv_numOrders = 0
local string lv_parent = "orders"
local integer lv_parentInt = StringHashBJ(lv_parent)
local hashtable lv_h = udg_PlayerAI[lp_playerID]
local integer lv_index = 0
if lv_unitTag != 0 then
set lv_numOrders = LoadIntegerBJ(StringHashBJ("order_" + I2S(lv_unitTag) + "_numList"), lv_parentInt, lv_h)
set lv_index = lv_numOrders + 1
set lv_orderHashString = "order_" + I2S(lv_unitTag) + "_" + I2S(lv_index)
call SaveIntegerBJ(lv_index, StringHashBJ("order_" + I2S(lv_unitTag) + "_numList"), lv_parentInt, lv_h)
//SAVE META-DATA//=======================================================
// meta type is actually saved as the unit tag, allowing for faster reference
//call sAI_hashAddMetaData(I2S(lv_unitTag), lv_orderHashString, lv_parent, lv_h)
//=======================================================================
else
set lv_numOrders = LoadIntegerBJ(StringHashBJ("order_numList"), lv_parentInt, lv_h)
set lv_index = lv_numOrders + 1
set lv_orderHashString = "order_" + I2S(lv_unitTag) + "_" + I2S(lv_index)
call SaveIntegerBJ(lv_index, StringHashBJ("order_" + I2S(lv_unitTag) + "_numList"), lv_parentInt, lv_h)
//SAVE META-DATA//=======================================================
// meta type is actually saved as the unit tag, allowing for faster reference
//call sAI_hashAddMetaData(I2S(lv_unitTag), lv_orderHashString, lv_parent, lv_h)
//=======================================================================
endif
//call SaveStringBJ(StringHashBJ(lv_orderHashString), lv_parentInt, lv_h)
set udg_LastCreatedOrderPath = lv_orderHashString
set udg_LastCreatedOrderParentPath = lv_parent
set udg_LastCreatedOrderHashT = lv_h
set udg_LastCreatedOrderPlayerID = lp_playerID
endfunction
function sAI_createMoveOrder takes integer lp_playerID, unit lp_forUnit, hashtable lp_locationData returns nothing
// Location Data could be added at any point. In fact, it's not location, it's all data. Like destroy hostiles, but not buildings, at places, within time - etc
//It'll probably just all go under "add data to last created order". Data and mData-trees.
//local hashtable lv_locationData = udg_LastCreatedLocationData
local integer lv_index = 0
local string lv_orderType = "move"
local string lv_path = ""
local string lv_parent = ""
local integer lv_parentInt
local hashtable lv_h = null
call sAI_createOrder(lp_playerID, lp_forUnit)
// then get last created order, and add data to it here
set lv_path = udg_LastCreatedOrderPath
set lv_parent = udg_LastCreatedOrderParentPath
set lv_parentInt = StringHashBJ(lv_parent)
set lv_h = udg_LastCreatedOrderHashT
//already have player id
call SaveStringBJ(lv_orderType, StringHashBJ(lv_path + "_orderType"), lv_parentInt, lv_h) // no indexing of order type? I think I've allowed for that
//SAVE META-DATA//=======================================================
//call sAI_hashAddMetaData("orderType", lv_path, lv_parent, lv_h)
//=======================================================================
endfunction
function sAI_addLocDataToLastCreatedOrder takes location lp_loc, string lp_stringModifier returns nothing
local string lv_preString = ""
local string lv_pathString = ""
local string lv_entryString = ""
local integer lv_orderID = 0
local string lv_orderPath = ""
local string lv_metaType = "" // e.g "order" or "move" or "location" or whatever - data entry
local string lv_data = ""
local string lv_stringModifier = lp_stringModifier
call SaveLocationHandleBJ(lp_loc, StringHashBJ(udg_LastCreatedOrderPath + lv_stringModifier + "_location"), StringHashBJ(udg_LastCreatedOrderParentPath) , udg_PlayerAI[udg_LastCreatedOrderPlayerID])
//call sAI_hashAddMetaData("location" , udg_LastCreatedOrderPath , udg_LastCreatedOrderParentPath , udg_PlayerAI[udg_LastCreatedOrderPlayerID])
// create a hashtable for this - so can be transferred etc
endfunction
function sAI_createLocationDataForOrder takes nothing returns nothing
local location lv_tempAreaCentrePoint = null
local real lv_tempRadiusSize = 0
local string lv_orderPath = ""
local integer lv_orderIndex = 0
local string lv_pathString = ""
local string lv_parentString = ""
local hashtable lv_h = null
// saves information to global variable which is then used as a Last Created Location hash data.
// Or puts it directly to wherever.
endfunction
function playerSuggest_sAIAction takes string pString, integer stateValue returns nothing
//state value determines if the suggestion is critical/permanent, needs to be fulfilled only once, etc
//example dictionary suggestion is = "take a small group of men and harrass the enemy at last ping"
// these are suggestions the computer will interpret and read and execute
endfunction
function playerSuggest_clearSuggestions takes nothing returns nothing
endfunction
// A long form of player suggestion
// basically custom script but in ze sAI lingo, hopefully more efficient and direct
function sAI_unitPathFindingUpdate takes integer lp_playerID, unit lp_unit, lp_orderString returns nothing // Order String is optional, just for efficiency in right context
// An Order could be constructed simply to tree together other orders, so one root path is always the only thing needed
local location lv_pickedLoc = null
local integer lv_mapSquareX = 0
local integer lv_mapSquareY = 0
local string lv_orderPathString = lp_orderString
local integer lv_currentSquareX = 0
local integer lv_currentSquareY = 0
local string lv_unitPathFindingPath = ""
local string lv_unitPathFindingParent = ""
local hashtable lv_unitPathFindingHash = InitHashtable()
local string lv_pathRootString = ""
local string lv_parent = ""
local hashtable lv_h = udg_PlayerAI[lp_playerID]
local integer lv_unitPathFind_NumList = 0
local integer i = 0
//========================
local integer lv_recordedTimesUnitEnteredPickedSquare = 0
local integer lv_recordedTimesUnitEnteredPickedSquare = 0
local integer lv_numberOfEntriesSinceOrderIssued = 0
local integer lv_recordedTimesUnitEnteredPickedSquareSincePathInt = 0 //You can tell it to search back to the first path, or the beginning of a seq,
// or just an arbitrary number
local string lv_unitIDString = StringHashBJ(GetHandleId(lp_unit))
local string lv_unitTypeString = ""
local string lv_pickedString = ""
local integer lv_enumNumList = 0
local boolean lv_unitWasAbleToProgress = false
local boolean lv_unitMovedToPointAsExpected = false
local boolean lv_isThisFailure = false
local string lv_potentialReasonsForFailure = ""
local integer lv_eventNumList = 0
local integer lv_timesUnitEnteredSquare = 0
local boolean lv_squareObstructed = false
local string lv_rootPathObstructions = ""
local real lv_recordedTime = 0
local string lv_path = ""
local integer i2 = 0
local integer lv_recordedTimeNumList = 0
//===================================================================================================================
set lv_pickedString = lv_unitIDString + "_timesEntered"
set lv_path = lv_pathRootString + "_" + lv_pickedString
set lv_eventNumList = LoadIntegerBJ(StringHashBJ(lv_path + "_numList"), StringHashBJ(lv_parent), lv_h)
//===================================================================================================================
// GET CURRENT SQUARE
//===================================================================================================================
set lv_unitPos = GetUnitLoc(lp_unit)
set lv_currentSquareX = R2I(Abs(GetLocationX(lv_unitPos )))
set lv_currentSquareY = R2I(Abs(GetLocationY(lv_unitPos )))
set lv_pathRootString = lv_unitIDString
set lv_tempSquareString = "X_" + I2S(lv_currentSquareX) + "_Y_" + I2S(lv_currentSquareX)
//===================================================================================================================
// SAVE INSTANCE OF PATH INFORMATION (CURRENT TIME) (NO LOOP NEEDED)
//===================================================================================================================
set lv_path = lv_pathRootString + "_" + lv_tempSquareString
set lv_timesUnitEnteredSquare = LoadIntegerBJ(StringHashBJ(lv_enumUnitIDString + "_" + lv_enumSquareLocString + "_numEnteredSquare"), lv_enumUnitIDString, lv_h
set i = LoadIntegerBJ(StringHashBJ(lv_path + "_timeRecorded_numList", StringHashBJ(lv_parent), lv_h)
set lv_currentSquareLocString = "X_" + I2S(lv_currentSquareX) + "_Y_" + I2S(lv_currentSquareX)
// iterate current square + 1
call SaveIntegerBJ(lv_timesUnitEnteredSquare + 1, StringHashBJ(lv_enumUnitIDString + "_" + lv_enumSquareLocString + "_numEnteredSquare"), lv_enumUnitIDString, lv_h)
// this iteration of no. entered current square only has to happen once in this function
// also need to save the precise time iteration
call SaveIntegerBJ(lv_timesUnitEnteredSquare + 1, StringHashBJ(R2S(lv_time) + "_unitEnteredSquare" ), StringHashBJ(lv_parent), lv_h) // or sum
call SaveRealBJ(lv_recordedTime, StringHashBJ(lv_path + "_" + I2S(i) + "_timeRecorded_" + I2S(i2)), StringHashBJ(lv_parent), lv_h)
// Tidy this up (fix the last two lines to make sense, specific event data, not short-cut
//===================================================================================================================
// IS MAKING PROGRESS
//===================================================================================================================
set lv_orderTargetLoc = LoadRealBJ(StringHashBJ("order_" + I2S(lv_orderInt) + "_targetLoc"), StringHashBJ("orders"), lv_h)
set lv_distToTarget = DistanceBetweenPoints(GetUnitLoc(lv_enumUnit), lv_orderTargetLoc) // to see if it's making progress
//if it is learned that air transport or something is required in an area
//a marker is placed (or saved) so the AI remembers - also linked to an Order, or Orders
// take into account if it's stopped by external factors, orders, temporary things, like fighting hostiles
// but that should all be logged
// event_50 = "beganfighting" and what-not
set lv_timeOrderIssuedToUnit = LoadRealBJ(StringHashBJ(lv_pathRootString + "_unitOrder_" + I2S(lv_unitOrderInt) + "_timeIssued"), StringHashBJ(lv_enumUnitID), lv_UnitAI[lp_playerID])
set lv_orderInt = LoadRealBJ(StringHashBJ(lv_pathRootString + "_unitOrder_" + I2S(lv_unitOrderInt) + "_orderInt"), StringHashBJ(lv_enumUnitID), lv_UnitAI[lp_playerID])
//===================================================================================================================
// REWIND TIME AND DO THINGS
//===================================================================================================================
set lv_numEnteredSquareFromTime = 0 // leading square
set lv_timeOrderIssuedToUnit = LoadRealBJ(StringHashBJ(lv_pathRootString + "_unitOrder_" + I2S(lv_unitOrderInt) + "_timeIssued"), StringHashBJ(lv_enumUnitID), lv_UnitAI[lp_playerID])
set lv_orderInt = LoadRealBJ(StringHashBJ(lv_pathRootString + "_unitOrder_" + I2S(lv_unitOrderInt) + "_orderInt"), StringHashBJ(lv_enumUnitID), lv_UnitAI[lp_playerID])
set lv_tempReal = lv_realTimeOrderIssued // or just 60 seconds ago, etc
set lv_recordedEventTime = lv_timeOrderIssuedToUnit + 1.0
//==============================================================
set lv_recordedDistToOrderTarget = DistanceBetweenPoints(lv_recordedUnitLoc, lv_orderTargetLoc)
set lv_enumProgressMadeLastMinute = lv_currentDistToOrderTarget - lv_recordedDistToOrderTarget // Really can just grab loc - 60 seconds.
//==============================================================
loop
exitwhen lv_recordedEventTime < lv_tempReal
// so how i do this?
// if this loop occurs every second in the global process, then - 1 second should work fine as an iteration
// since this is exactly what I want, it is faster
// even faster would be if the numbers were already added, such as "number of times entered square" etc, which I can actually do later
set lv_path = "time_" + I2S(lv_time) + _"unitSquareLoc" // eh, something, can change it to whatev
set lv_parent = lv_enumUnitIDString
set lv_h = udg_UnitAI[lp_playerID]
set lv_enumSquareLoc = LoadLocationHandleBJ(lv_path, lv_parent, lv_h) // square that unit existed in in previous iteration
set lv_enumSquareX = R2I(GetLocationX(lv_enumSquareLoc))
set lv_enumSquareY = R2I(GetLocationY(lv_enumSquareLoc))
set lv_enumSquareLocString = "X_" + I2S(lv_enumSquareX) + "_Y_" + I2S(lv_enumSquareX)
set lv_enteredEnumSquareNum = LoadIntegerBJ(StringHashBJ(lv_enumUnitIDString + "_" + lv_enumSquareLocString + "_numEnteredSquare"), lv_enumUnitIDString, lv_h)
//===================================================================
// do things in here
//===================================================================
set lv_time = lv_time - 1.0
set lv_recordedEventTime = lv_time // would work in this instance (remember to get current time, which should be exactly on a second, every second, loop)
endloop
//===================================================================================================================
// FIND OBSTRUCTIONS
//===================================================================================================================
if lv_targetSquareBlocked == true then
//get number of times blocked, if it matters
endif
if lv_squareIsSameAsLast == true then
endif
if lv_unblockedPathAvailable == true then // I mean, you CAN use the normal functions too - this is like, collision useful mostly
endif
//===================================================================================================================
// DETERMINE IF UNIT IS GETTING BLOCKED
//===================================================================================================================
// scan immediate surroundings to get some gist
// analyse squares the unit keeps getting blocked on (prob can just trace to whichever square it repeated previously in an unbroken line or sum)
// or keeps repeating in a suspicious way
// probably it can just see which "lines" it broke free of, if it was momentarily blocked, and thus which one it's stuck on
//===================================================================================================================
// DETERMINE ROUTE
//===================================================================================================================
if lv_tempAngleToGoalTarget < lv_closestAngleToGoalTarget then
endif
//===================================================================================================================
// FIND POTENTIAL BLOCKERS - COMPARE TO DATABASE, STORE DATA POTENTIALS, EVALUATE BEST LOGIC
//===================================================================================================================
set lv_evalLogicPath = ""
endfunction
//probably gotta be a def choice between macro and micro moving units and checking on them etc
// but it could try to generalise that not getting to the next square within one second is shit and fail regardless, and just spam
function sAI_wasUnitPreventedFromSquare takes nothing returns nothing
local real lv_timeLeft = 0 // This is the timer of when unit is expected to be able to reach square. (Could use Time Expire trick)
local string lv_path = "expect_unitLocSquare"
local string lv_parent = "expect"
// I mean, this is a basic idea to explore. Again, start basic. This can also apply to the big order of say, trying to reach a point on another
// island and not reaching it
set lv_targetSquareX = lv_currentSquareX - 1.0
set lv_targetSquareY = lv_currentSquareY - 1.0
loop
exitwhen lv_targetSquareY > lv_currentSquareY + 1.0
set lv_enumNumOfPObstructions = LoadIntegerBJ(StringHashBJ(lv_targetSquareID + "_numObstructions", lv_parent, lv_h) // prob update to using num/meta lists for "potential" obstruction data
if lv_targetSquareX < lv_currentSquareX + 1 then
set lv_targetSquareX = lv_targetSquareX + 1
else // just to make sure it'll pass
set lv_targetSquareY = lv_targetSquareY + 1
endif
endloop
endfunction
function sAI_calcLogistics takes string lp_hashPath returns nothing
local real lv_addedTime = 0
//everything should group together in an order, so, say, an air transport is ordered to a location, a ground unit as well,
// and so the function can easily add up expected times - unit has to wait several seconds, etc
// and "is transported by" or moved by or whatever, the air transport
local real lv_failureLevel = 0 //p/h
endfunction
function sAI_playerAIManageOrder takes integer lp_playerID, string lp_orderRootPath returns nothing
local integer lv_enumWarParty = 0 // in case there's more than one, in theory
local integer lv_enumUnit = 0
local integer lv_enumTownID = 0
local string lv_enumPath = ""
local string lv_enumPathParent = ""
local hashtable lv_enumHash = ""
endfunction
function sAI_playerAIManageAllOrders takes integer lp_playerID returns nothing
local group lv_warPartyGroup = null
local unit lv_enumUnit = null
local integer i = 1
local integer lv_numListofOrders = LoadIntegerBJ(StringHashBJ("order_numList"), StringHashBJ("Orders"), udg_PlayerAI[lp_playerID])
local group lv_tempGroup = null
local integer unit_i = 1
local integer lv_numInGroup = 0
local integer lv_warPartyID = 0
local string lv_orderPath = ""
loop
exitwhen i > lv_numListOfOrders
set lv_orderPath = "order_" + I2S(i)
call sAI_playerAIManageOrder(lp_playerID, lv_orderPath)
set i = i + 1
endloop
//=====================================================================================================
//REMOVE LEAKS
//=====================================================================================================
call GroupClear(lv_warPartyGroup)
call GroupClear(lv_tempGroup)
set lv_enumUnit = null
set i = 0
set lv_numOfParties = 0
set unit_i = 0
set lv_numInGroup = 0
endfunction
function sAI_hashAddStringData takes string lp_s, string lp_pathString, string lp_parentString, hashtable lp_h returns nothing
local integer lv_metaListInt = 0
local integer i = 1
local integer lv_numOfEntries = LoadIntegerBJ( StringHashBJ(lp_pathString + "_numList"), StringHashBJ(lp_parentString), lp_h)
local integer lv_entryInt = 0
local integer lv_stringInt = 1
local integer lv_countOfEntries = 0
local boolean lv_alreadyExists = false
set udg_tempInt = 0
// needs to check for currently existing entry
//===============================================
// CHECK FOR ALREADY EXISTING ENTRY
//===============================================
if udf_hashEntryStringByIteration(lp_s,lp_pathString, lp_parentString, lp_h) == 0 then // dis wurk?
//===============================================
// ENTRY DOESN'T EXIST - CREATE ONE
//===============================================
set lv_entryInt = lv_numOfEntries + 1
call SaveIntegerBJ(lv_metaListInt, StringHashBJ(lp_pathString + "_" + lp_s + "_numList"), StringHashBJ(lp_parentString), lp_h)
//call sAI_hashAddMetaData("unit", StringHashBJ(lp_pathString), StringHashBJ(lp_parentString), lp_h)
// If entry already exists, does it add to a numList of that entry?\
// Maybe I need two functions for that reason
endif
//===============================================
//===============================================
//===============================================
//=============================================================
//REMOVE LEAKS
//=============================================================
set lv_numOfEntries = 0
set lv_stringInt = 0
//=============================================================
endfunction
function sAI_addDataToTownSuggestion takes nothing returns nothing
local real lv_adherenceLevel = 0 // This determines how closely the AI will follow the suggestion. You can softball it.
// At lower levels it will encourage the AI to fulfill the requirements, but the AI can decide other
// things take priority. Such as pulling away defensive units to join it's offensive army in a rush.
//============================================================================
//ADVANCED TOWN INFORMATION
//============================================================================
// just some temp notions to work on
local integer lv_goldValueOfTown = 0
local integer lv_woodValueOfTown = 0
local integer lv_proximityToEnemy = 0
local integer lv_proximityToClosestFriendlyTown = 0
local integer lv_levelOfSupport = 0
local integer lv_levelOfUnderThreat =
local integer lv_riskOfDestruction = 0 //could prob lead into something complex like risk of value gained or lost, and guessing whether it's worth the risk
local integer lv_militaryValueOfTown = 0 // I guess this is a simplification key. But I do want the AI to be able to dig deep.
endfunction
// That's just a template. The actual ADD functions will be specific. Add unit, add gold mine, etc. Add forest. Probably covers it.
// Anything else would probably be like "station your hero and armies here".
function sAI_saveCurrentGoldPMIncomeToTown takes nothing returns nothing
endfunction
function sAI_setDataNameMetaType takes string dataType, string dls, hashtable ht returns nothing
call sAI_saveStringParameter(dataType, "nameMetaType", dls, ht)
endfunction
function sAI_baseRemoveUnit takes integer p, integer b, unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
local string str = ""
local integer dls_i = 0
local string playerIDString = I2S(p)
local string baseIString = I2S(b)
local integer currentB = 0
local integer baseIC = 0
local region baseR = null
local boolean baseFound = false
local group baseGroup = null
local integer count = 0
local string uTS = UnitId2StringBJ(GetUnitTypeId(u))
local string eUTS = "" // enumUTS
local integer subtract = 0
local string sDataType = ""
local integer i = 0
local integer mIC = 0
//MAIN PART
call sAI_deleteDataTree("Units_" + unitIDString + "_baseID", udg_UnitAI) // this will remove it? (to make it clean- although i dunno if it affects the data search when null)
//call SaveIntegerBJ(0, 0, StringHashBJ("Units_" + unitIDString + "_baseID"), udg_UnitAI )
//call FlushChildHashtableBJ( StringHashBJ("Units_" + unitIDString + "_baseID"), udg_UnitAI )
set str = "Player_" + playerIDString + "_base_" + baseIString
set baseGroup = LoadGroupHandleBJ(0, StringHashBJ(str + "_group"), udg_PlayerAI[p])
call GroupRemoveUnit(baseGroup, u)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_workers"), udg_PlayerAI[p]), u)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_workers_idle"), udg_PlayerAI[p]), u)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_army"), udg_PlayerAI[p]), u)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_structures"), udg_PlayerAI[p]), u)
//quick cheese because these are the only types to currently exist
set str = "Player_" + playerIDString + "_base_" + baseIString
set str = str + "_has_" + UnitId2StringBJ(GetUnitTypeId(u)) + "_count"
set count = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
set count = count - 1
call SaveIntegerBJ(count, 0, StringHashBJ(str), udg_PlayerAI[p]) // update to params later
//UPDATE BASE TRAINING
set str = "Units_" + unitIDString + "_training"
set mIC = LoadIntegerBJ(0, StringHashBJ(str + "_metaList_indexCount"), udg_UnitAI)
loop
exitwhen (i > mIC)
set str = "Units_" + unitIDString + "_training"
set eUTS = LoadStringBJ(0, StringHashBJ(str + "_metaList_" + I2S(i)), udg_UnitAI)
if (LoadStringBJ(0, StringHashBJ(str + "_" + eUTS + "_nameMetaType"), udg_UnitAI) == "unitTypeString") then
set subtract = LoadIntegerBJ(0, StringHashBJ(str + "_" + eUTS + "_count"), udg_UnitAI)
call sAI_saveIntegerParameter(0, "count", str + "_training_" + eUTS , udg_PlayerAI[p])
set str = "Player_" + playerIDString + "_base_" + baseIString
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + eUTS + "_count"), udg_UnitAI)
set count = count - subtract
endif
set i = i + 1
endloop
//===============
//PLUG LEAKS
set unitIDString = ""
set str = ""
set dls_i = 0
set playerIDString = ""
set currentB = 0
set baseIString = ""
set baseIC = 0
set baseR = null
set baseFound = false
set baseGroup = null
set count = 0
set uTS = ""
set eUTS = ""
set subtract = 0
set sDataType = ""
set i = 0
set mIC = 0
//params
set p = 0
set b = 0
set u = null
endfunction
function sAI_baseAddUnit takes integer p, integer b, unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
local string str = ""
local integer dls_i = 0
local string playerIDString = I2S(p)
local string baseIString = I2S(b)
local integer currentB = 0
local integer baseIC = 0
local group baseGroup = null
local integer count = 0
//MAIN PART
set str = "Player_" + playerIDString + "_base_" + baseIString
set baseGroup = LoadGroupHandleBJ(0, StringHashBJ(str + "_group"), udg_PlayerAI[p])
set str = "Units_" + unitIDString + "_baseID"
if (HaveSavedValue(0, bj_HASHTABLE_INTEGER, StringHashBJ(str), udg_UnitAI) == false) then
call sAI_saveIntegerParameter(b, "baseID", "Units_" + unitIDString, udg_UnitAI)
call GroupAddUnitSimple(u, baseGroup)
set str = "Player_" + playerIDString + "_base_" + baseIString
call sAI_saveBooleanParameter(true, UnitId2StringBJ(GetUnitTypeId(u)), str + "_has", udg_PlayerAI[p])
set str = str + "_has_" + UnitId2StringBJ(GetUnitTypeId(u))
set count = LoadIntegerBJ(0, StringHashBJ(str + "_count"), udg_PlayerAI[p])
set count = count + 1
call sAI_saveIntegerParameter(count, "count", str, udg_PlayerAI[p])
//call SetUnitColor( u, GetPlayerColor(Player(1)) ) //debug
endif
//ADD TO GROUPS
if (IsUnitType(u, UNIT_TYPE_PEON) == true) then
set str = "Player_" + playerIDString + "_base_" + baseIString
set str = str + "_workers"
call GroupAddUnit(LoadGroupHandleBJ(0, StringHashBJ(str), udg_UnitAI), u)
set str = "Player_" + playerIDString + "_base_" + baseIString
set str = str + "_workers_idle"
call GroupAddUnit(LoadGroupHandleBJ(0, StringHashBJ(str), udg_UnitAI), u)
endif
if (IsUnitType(u, UNIT_TYPE_STRUCTURE) == true) then
set str = "Player_" + playerIDString + "_base_" + baseIString
set str = str + "_structures"
call GroupAddUnit(LoadGroupHandleBJ(0, StringHashBJ(str), udg_UnitAI), u)
endif
if ((IsUnitType(u, UNIT_TYPE_PEON) == false) and (IsUnitType(u, UNIT_TYPE_STRUCTURE) == false)) then
set str = "Player_" + playerIDString + "_base_" + baseIString
set str = str + "_army"
call GroupAddUnit(LoadGroupHandleBJ(0, StringHashBJ(str), udg_UnitAI), u)
endif
//===============
//PLUG LEAKS
set unitIDString = ""
set str = ""
set dls_i = 0
set playerIDString = ""
set currentB = 0
set baseIString = ""
set baseIC = 0
set baseGroup = null
set count = 0
//params
set p = 0
set b = 0
set u = null
endfunction
function sAI_assignBaseToUnit takes integer p, integer b, unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
local string str = ""
local integer dls_i = 0
local string playerIDString = I2S(p)
local string baseIString = I2S(b)
local integer currentB = 0
local integer baseIC = 0
local region baseR = null
local boolean baseFound = false
local group baseGroup = null
local integer count = 0
//MAIN PART
//===============
//REMOVE FROM CURRENT BASE
set str = "Units_" + unitIDString + "_baseID"
set currentB = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
set baseIString = I2S(currentB)
if (HaveSavedValue(0, bj_HASHTABLE_INTEGER, StringHashBJ(str), udg_UnitAI) == true) then
call sAI_baseRemoveUnit(p,b,u)
endif
//ADD TO NEW BASE
set str = "Units_" + unitIDString + "_baseID"
set currentB = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
set baseIString = I2S(currentB)
call sAI_baseAddUnit(p,b,u)
//===============
//PLUG LEAKS
set unitIDString = ""
set str = ""
set dls_i = 0
set playerIDString = ""
set currentB = 0
set baseIString = ""
set baseIC = 0
set baseR = null
set baseFound = false
set baseGroup = null
set count = 0
//params
set p = 0
set b = 0
set u = null
endfunction
function sAI_assignNearbyBaseToUnit takes integer p, unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
local string str = ""
local integer dls_i = 0
local string playerIDString = I2S(p)
local integer baseI = 0
local string baseIString = ""
local integer baseIC = 0
local region baseR = null
local boolean baseFound = false
local group baseGroup = null
//MAIN PART
set str = "Player_" + playerIDString + "_base_indexCount"
set baseIC = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
//REMOVE FROM CURRENT BASE IF ANY
set str = "Units_" + unitIDString + "_baseID"
set baseI = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
if (HaveSavedValue(0, bj_HASHTABLE_INTEGER, StringHashBJ(str), udg_UnitAI) == true) then
call sAI_baseRemoveUnit(p, baseI, u)
endif
//========================================
set baseI = 1
loop
exitwhen ((baseI > baseIC) or (baseFound == true))
set baseIString = I2S(baseI)
set str = "Player_" + playerIDString + "_base_" + baseIString
set baseR = LoadRegionHandleBJ(0, StringHashBJ(str + "_region"), udg_PlayerAI[p])
if (IsUnitInRegion(baseR, u) == true) then
set baseFound = true
call sAI_baseAddUnit(p, baseI, u)
//call SetUnitColor( u, GetPlayerColor(Player(1)) ) //debug
endif
set baseI = baseI + 1
endloop
if (baseFound == false) then
//call sAI_baseAddUnit(p, 0, u) //if a base is not found nearby, assigns them to 0 "base" which basically means no base
endif
//PLUG LEAKS
set unitIDString = ""
set str = ""
set dls_i = 0
set playerIDString = ""
set baseI = 0
set baseIString = ""
set baseIC = 0
set baseR = null
set baseFound = false
set baseGroup = null
//params
set p = 0
set u = null
endfunction
function sAI_addBase takes integer p, unit townhall returns nothing
local integer dls_i = 0
local string playerIDString = I2S(p)
local integer indexCount = 0
local string str = ""
local string pS = I2S(p)
local integer index = 0
local string iS = ""
local integer numNeeded = 0
local integer currentlyBuildingCount = 0
local string prefix = ""
local group sortGroup = CreateGroup()
local group sortGroup2 = CreateGroup()
local group alreadySorted = CreateGroup()
local group saveGroup = CreateGroup()
local string baseType = ""
local real range = 1000
local unit enumUnit = null
local region baseR = CreateRegion()
local rect baseRect = null
local string baseIString = ""
local location unitLoc = null
local integer base = 0
local integer bIC = 0
//new
local boolean alreadyAssigned = false
local location townHallLoc = null
//MAIN PART
//Create new base
set str = "Player_" + I2S(p)
call sAI_addBooleanParameter( true, "base", str, udg_PlayerAI[p])
//GET BASE ID
set str = "Player_" + playerIDString + "_base"
set bIC = LoadIntegerBJ(0, StringHashBJ(str +"_indexCount"), udg_PlayerAI[p])
//set bIC = 1 //debug
set base = bIC
set udg_sAI_lastCreatedBaseID = bIC
set baseIString = I2S(base)
//PREEMPTIVELY CREATE/SAVE GROUP
set str = "Player_" + playerIDString + "_base_" + baseIString
call sAI_saveGroupParameter( saveGroup, "group", str, udg_PlayerAI[p])
// GET GROUP
// doing a chain jump adding structures to given base data structure
set unitLoc = GetUnitLoc(townhall)
call GroupAddGroup( GetUnitsInRangeOfLocAll(range, unitLoc), sortGroup )
set enumUnit = FirstOfGroup(sortGroup)
call RemoveLocation(unitLoc)
//======================
loop
exitwhen (enumUnit == null)
if (HaveSavedValue(0, bj_HASHTABLE_INTEGER, StringHashBJ("Units_" + I2S(GetHandleIdBJ(enumUnit)) + "_baseID"), udg_UnitAI) == false) then
if ( (GetConvertedPlayerId(GetOwningPlayer(enumUnit)) == p ) and (IsUnitIdType(GetUnitTypeId(enumUnit), UNIT_TYPE_STRUCTURE) == true )) then // i think units are added somewhere else also i don't think it matters
//call SetUnitColor( enumUnit, GetPlayerColor(Player(2)) ) //debug
if (IsUnitInGroup(enumUnit, alreadySorted) == true) then
//Do nothing, it'll be eliminated. I think the exponent growth should be fine.
else
call GroupAddGroup( GetUnitsInRangeOfLocAll(range, GetUnitLoc(enumUnit)), sortGroup )
call GroupAddUnitSimple(enumUnit, saveGroup)
call sAI_assignBaseToUnit(p,base,enumUnit)
call RemoveLocation(unitLoc)
set unitLoc = GetUnitLoc(enumUnit)
set baseRect = RectFromCenterSizeBJ(unitLoc, range, range)
call RegionAddRect(baseR, baseRect)
call RemoveRect(baseRect)
call RemoveLocation(unitLoc)
endif
endif
endif
call GroupRemoveUnit(sortGroup, enumUnit)
call GroupAddUnitSimple(enumUnit, alreadySorted)
set enumUnit = FirstOfGroup(sortGroup)
endloop
//SAVE GROUP TO BASE
set baseIString = I2S(bIC)
set str = "Player_" + playerIDString + "_base_" + baseIString
//call sAI_saveGroupParameter( saveGroup, "group", str, udg_PlayerAI[p]) //shouldn't need this
call sAI_saveRegionParameter( baseR, "region", str, udg_PlayerAI[p])
call sAI_saveRectParameter( RectFromCenterSizeBJ(GetUnitLoc(townhall), range, range), "rect", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "workers", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "workers_idle", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "army", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "builders", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "harvesters", str, udg_PlayerAI[p])
call sAI_saveGroupParameter( CreateGroup() , "isBuilding", str, udg_PlayerAI[p])
//This should be an entirely new base, so this should be clean.
//PLUG LEAKS
call RemoveRect(baseRect)
call RemoveLocation(unitLoc)
call DestroyGroup(sortGroup)
call DestroyGroup(sortGroup2)
call DestroyGroup(alreadySorted)
set dls_i = 0
set playerIDString = ""
set indexCount = 0
set str = ""
set pS = ""
set index = 0
set iS = ""
set numNeeded = 0
set currentlyBuildingCount = 0
set prefix = ""
set sortGroup = null
set sortGroup2 = null
set alreadySorted = null
set saveGroup = null
set baseType = ""
set range = 0
set enumUnit = null
set baseR = null
set baseRect = null
set baseIString = ""
set unitLoc = null
set base = 0
set bIC = 0
endfunction
function sAI_base_addWant_unit takes integer p, integer baseI, string uTS, integer count returns nothing
local integer dls_i = 0
local integer indexCount = 0
local string str = ""
local integer index = 0
local string iS = ""
local integer numNeeded = 0
local integer currentlyBuildingCount = 0
local string prefix = ""
local group sortGroup = CreateGroup()
local string meta_DLS = ""
local integer mDLSI = 0
local integer currentNumWanted = 0
local integer mL_indexCount = 0
local string newMIS = ""
//MAIN PART
set str = "Player_" + I2S(p) + "_base_" + I2S(baseI)
set str = str + "_wants"
set prefix = str
set str = str + "_" + uTS + "_count"
set dls_i = StringHashBJ(str)
set currentNumWanted = LoadIntegerBJ(0, dls_i, udg_PlayerAI[p])
set currentNumWanted = currentNumWanted + count
call sAI_saveBooleanParameter(true, uTS, prefix, udg_PlayerAI[p])
call sAI_saveIntegerParameter(currentNumWanted, "count", prefix + "_" + uTS, udg_PlayerAI[p])
//PLUG LEAKS
set dls_i = 0
set indexCount = 0
set str = ""
set index = 0
set iS = ""
set numNeeded = 0
set currentlyBuildingCount = 0
set prefix = ""
call DestroyGroup(sortGroup)
set sortGroup = null
set meta_DLS = ""
set mDLSI = 0
set currentNumWanted = 0
set mL_indexCount = 0
set newMIS = ""
//params
set p = 0
set baseI = 0
set uTS = ""
set count = 0
endfunction
//===================================================
function sAI_addUnitTrainingKnowledge takes integer p, string trainerString, string trainedString returns nothing // Are these id strings or unit type strings? prob latter
local string str = ""
local integer dls_i = 0
local integer i = 0
local integer iC = 0
//MAIN PART
// SAVE TERM KNOWLEDGE
//I'm treating Terms much the same as normal data atm, but do want a faster system with less mem use.
set str = trainedString + "_built_by"
call sAI_addBooleanParameter( true, trainerString , str ,udg_Terms[p])
set str = trainerString + "_can_build"
call sAI_addBooleanParameter( true, trainedString , str ,udg_Terms[p]) //This isn't a duplication. It's slightly different from the super-fast access Term use.
//PLUG LEAKS
set str = ""
set dls_i = 0
set i = 0
set iC = 0
//PARAMS
set p = 0
set trainerString = ""
set trainedString = ""
endfunction
//===================================================
//===================================================
function sAI_base_AI takes integer p, integer baseI returns nothing
//it checks it's "wants", trains
// also directs home defense and signals for help
local string uTS = ""
local integer dls_i = 0
local integer indexCount = 0
local string str = ""
local integer index = 0
local string iS = ""
local integer numNeeded = 0
local integer currentlyHave = 0
local integer currentlyBuilding = 0
local group sortGroup = CreateGroup()
local group baseGroup = null
local string str2 = ""
local string prefix = ""
local string prefix2 = ""
local integer count = 0
local integer addCount = 0
local integer i = 0
local integer iEnd = 0
local boolean processFinished = false
local real goldRequired = 0
local real gold = GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_GOLD)
local real woodRequired = 0
local real wood = GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_LUMBER)
local real foodRequired = 0
local real food = (GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_FOOD_CAP) - GetPlayerState(Player(p), PLAYER_STATE_RESOURCE_FOOD_USED))
local integer previousCount = 0
local integer newUnitsQueued = 0
local unit enumUnit = null
local boolean newLoop = false
local integer unitsInGroup = 0
//GetPlayerState(Player(0), PLAYER_STATE_FOOD_CAP_CEILING)
// NEW VARIABLES (REQUIRE LEAKS PLUGGED)
local string reqUTS = "" //requirement for unit, creating a one-off type deal, being needed for a single purpose (creating a unit)
local location l = null
local rect baseRect = null
local region baseR = null
local integer reqI = 0
local integer reqIC = 0
local string reqS = ""
local string prefixBase = ""
local string dataType = ""
local integer mIC = 0
local integer mI = 0
local string cBIS = "" //building id string
//=========================================================================================
//MAIN PART
//=========================================================================================
set str = "Player_" + I2S(p) + "_base_" + I2S(baseI)
set dls_i = StringHashBJ(str + "_group")
set baseGroup = LoadGroupHandleBJ(0, dls_i, udg_PlayerAI[p])
call GroupAddGroup(baseGroup, sortGroup)
set unitsInGroup = CountUnitsInGroup(sortGroup) //this would do nothing, sortGroup is empty at this stage
set str = "Player_" + I2S(p) + "_base_" + I2S(baseI) + "_region"
set baseRect = LoadRectHandleBJ(0, StringHashBJ("Player_" + I2S(p) + "_base_" + I2S(baseI) + "_rect"), udg_PlayerAI[p])
//set baseR = LoadRegionHandleBJ(0, StringHashBJ(str), udg_PlayerAI[p]) //just doesn't work
set l = GetRandomLocInRect(baseRect) // this will need to be changed to just randomly picking a building in group and then offset from it
set str = "Player_" + I2S(p) + "_base_" + I2S(baseI) + "_wants"
set prefix = str
set str = str + "_indexCount"
set dls_i = StringHashBJ(str)
set indexCount = LoadIntegerBJ(0, dls_i, udg_PlayerAI[p]) // this should actually be 0, but fix later
set mIC = LoadIntegerBJ(0, StringHashBJ(prefix + "_metaList_indexCount"), udg_PlayerAI[p]) // this should not get dataName because that shouldn't be in meta, it's inbuilt
set prefix2 = "Player_" + I2S(p) + "_base_" + I2S(baseI) + "_has"
set prefixBase = "Player_" + I2S(p) + "_base_" + I2S(baseI)
/*
if (p == udg_herodinPlayerID) then
call DisplayTextToForce( GetPlayersAll(), "baseAI begun" )
call DisplayTextToForce( GetPlayersAll(), "player: " + I2S(p) )
call DisplayTextToForce( GetPlayersAll(), "base: " + I2S(baseI) )
endif
*/
//=========================================================================================
set index = 1
loop
exitwhen (index > mIC)
if (p == udg_herodinPlayerID) then
//call DisplayTextToForce( GetPlayersAll(), "started loop" )
//call DisplayTextToForce( GetPlayersAll(), "unitsInGroup: " + I2S(unitsInGroup) )
endif
set iS = I2S(index)
set str = prefix + "_metaList_" + iS // it's doing it here
set dls_i = StringHashBJ(str)
set uTS = LoadStringBJ(0, dls_i, udg_PlayerAI[p])
set str = prefix2 + "_" + uTS + "_count"
set currentlyHave = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
set str = prefix2 + "_building_" + uTS + "_count"
set currentlyBuilding = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
set str = prefix + "_" + uTS + "_count"
set count = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p]) // how much wanted
set addCount = count - currentlyHave - currentlyBuilding
if (p == udg_herodinPlayerID) then
/*
call DisplayTextToForce( GetPlayersAll(), "dls: " + prefix2 + "_building_" + uTS + "_count" )
call DisplayTextToForce( GetPlayersAll(), "uTS: " + uTS )
call DisplayTextToForce( GetPlayersAll(), "addCount: " + I2S(addCount) )
call DisplayTextToForce( GetPlayersAll(), "currentlyBuilding: " + I2S(currentlyBuilding) )
call DisplayTextToForce( GetPlayersAll(), "currentlyHave: " + I2S(currentlyHave) )
*/
endif
set i = 1
set iEnd = 250 // just temp blocker atm, I'll plug everything later :3
set enumUnit = FirstOfGroup(sortGroup)
loop
exitwhen ((processFinished == true) or (enumUnit == null))
//add all units that can train unit in here
set previousCount = addCount
set str = prefix2 + "_" + uTS + "_count"
set currentlyHave = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
set str = prefix2 + "_building_" + uTS + "_count"
set currentlyBuilding = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p])
set str = prefix + "_" + uTS + "_count"
set count = LoadIntegerBJ(0, StringHashBJ(str), udg_PlayerAI[p]) // how much wanted
set addCount = count - currentlyHave - currentlyBuilding
//================================
//TRAIN UNIT PART
//================================
if (IsUnitInGroup(enumUnit, LoadGroupHandleBJ(0, StringHashBJ(prefixBase + "_builders"), udg_PlayerAI[p])) == false) then
if (IsUnitIdType(String2UnitIdBJ(uTS), UNIT_TYPE_STRUCTURE) == false ) then
call IssueTrainOrderByIdBJ(enumUnit, String2UnitIdBJ(uTS))
else
call IssueBuildOrderByIdLocBJ( enumUnit, String2UnitIdBJ(uTS), l)
endif
//================================
//REQS
//================================
set str = "UnitType_" + uTS + "_req_indexCount" // data from Terms, what the Player understands (information can be manually set)
set dls_i = StringHashBJ(str)
set reqIC = LoadIntegerBJ(0, dls_i, udg_Terms[p])
set reqI = 1
loop
exitwhen (reqI > reqIC)
set reqS = LoadStringBJ(0, StringHashBJ("UnitType_" + uTS + "_req_" + I2S(reqI)), udg_Terms[p]) // this gives us the req unit type string
// this all needs to be checked, it seems wonky
set str = prefix2 + "_" + reqS + "_count"
set dls_i = StringHashBJ(str)
set currentlyHave = LoadIntegerBJ(0, dls_i, udg_PlayerAI[p])
set str = prefix2 + "_building_" + reqS + "_count"
set dls_i = StringHashBJ(str)
set currentlyBuilding = LoadIntegerBJ(0, dls_i, udg_PlayerAI[p])
set dls_i = StringHashBJ(reqS)
if ((currentlyHave - currentlyBuilding) > 0 ) then // quick cheese, it just needs to make a minimum of one in all cases
if (IsUnitIdType(String2UnitIdBJ(reqS), UNIT_TYPE_STRUCTURE) == false ) then
call IssueTrainOrderByIdBJ(enumUnit, String2UnitIdBJ(uTS))
else
call IssueBuildOrderByIdLocBJ( enumUnit, String2UnitIdBJ(uTS), l) // this is covered by a issued order trigger
endif
//call DisplayTextToForce( GetPlayersAll(), "should have started building req" )
endif
//checking the queue count for the req units too
set reqI = reqI + 1
endloop
endif
//===============================================
set newUnitsQueued = previousCount - addCount // this gets the difference in units wanted between cycles, if it hasn't changed since last then it's stuck
//check this
if (newUnitsQueued <= 0) then
if (newLoop == true) then
set processFinished = true
endif
endif
if (addCount <= 0) then
set processFinished = true
endif
if (i > iEnd) then
set processFinished = true
endif
if(udf_playerCanAffordUnit(String2UnitIdBJ(uTS), p) == false) then
//set processFinished = true
endif
//===============================================
//cycle, remove unit, new unit, group loop, etc
// in its best life just adds a train order one at a time to individual trainers until it's queued up enough
//===============================================
call GroupRemoveUnitSimple(enumUnit,sortGroup)
set enumUnit = FirstOfGroup(sortGroup)
//===============================================
// if sortGroup becomes empty it's time for a new loop
if (newLoop == true) then
set newLoop = false
endif
if (enumUnit == null) then
call GroupAddGroup(baseGroup, sortGroup)
set enumUnit = FirstOfGroup(sortGroup)
set newLoop = true
endif
//===============================================
set i = i + 1
endloop
call GroupAddGroup(baseGroup, sortGroup) // resets group
// just keep rechecking number being trained
// add all units capable of training to the sortGroup, and check when they're all full and can't train anymore
// and also that economic requirements are met
// and add an arbitrary limiter just in case
set index = index + 1
endloop
// Construction will be covered in the train unit parts. Sometimes units are required to be upgraded to as well.
//=========================================================================================
//PLUG LEAKS
//=========================================================================================
set uTS = ""
set dls_i = 0
set indexCount = 0
set str = ""
set index = 0
set iS = ""
set numNeeded = 0
set currentlyHave = 0
set currentlyBuilding = 0
call DestroyGroup(sortGroup)
set sortGroup = null
set baseGroup = null
set str2 = ""
set prefix = ""
set prefix2 = ""
set count = 0
set addCount = 0
set i = 0
set iEnd = 0
set goldRequired = 0
set gold = 0
set woodRequired = 0
set wood = 0
set foodRequired = 0
set food = 0
set previousCount = 0
set newUnitsQueued = 0
set enumUnit = null
set newLoop = false
set processFinished = false
endfunction
function Trig_test_x_gets_ids_of_unit_Actions takes nothing returns nothing
local integer b = 0
local group g = GetUnitsSelectedAll(GetTriggerPlayer())
local unit u = FirstOfGroup(g)
//MAIN PART
set b = LoadIntegerBJ(0, StringHashBJ("Units_" + I2S(GetHandleIdBJ(u)) + "_baseID"), udg_UnitAI)
call DisplayTextToForce( GetPlayersAll(), "unitID: " + I2S(GetHandleIdBJ(u)) )
call DisplayTextToForce( GetPlayersAll(), "playerID: " + I2S(GetConvertedPlayerId(GetOwningPlayer(u))) )
call DisplayTextToForce( GetPlayersAll(), "baseID: " + I2S(b) )
//PLUG LEAKS
call DestroyGroup(g)
set g = null
set u = null
set b = 0
endfunction
//===========================================================================
function InitTrig_test_x_gets_ids_of_unit takes nothing returns nothing
set gg_trg_test_x_gets_ids_of_unit = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_test_x_gets_ids_of_unit, Player(0), "1", true )
call TriggerAddAction( gg_trg_test_x_gets_ids_of_unit, function Trig_test_x_gets_ids_of_unit_Actions )
endfunction
function udf_calculateEricPartyStats takes group lp_g returns nothing
local real lv_partyOriginalHealth = udg_Eric_PartyStartingHealth
local real lv_partyOriginalNumbers = I2R(udg_Eric_PartyStartingNumbers)
local real lv_baseTotalHealth = 0
local real lv_remainingTotalHealth = 0
local group lv_sortGroupAlt = CreateGroup()
local unit lv_enumUnit = null
local integer lv_numRemaining = 0
call GroupAddGroup( udg_Eric_Group, lv_sortGroupAlt)
set lv_numRemaining = CountUnitsInGroup(lv_sortGroupAlt)
set udg_Eric_PartyStartingNumbers = lv_numRemaining
loop
exitwhen (lv_numRemaining <= 0)
set lv_enumUnit = FirstOfGroup(lv_sortGroupAlt)
set lv_remainingTotalHealth = lv_remainingTotalHealth + GetUnitStateSwap(UNIT_STATE_LIFE, lv_enumUnit)
set lv_baseTotalHealth = lv_baseTotalHealth + GetUnitStateSwap(UNIT_STATE_MAX_LIFE, lv_enumUnit)
set lv_numRemaining = lv_numRemaining -1
call GroupRemoveUnitSimple(lv_enumUnit, lv_sortGroupAlt) //i'm assuming this doesn't remove from original unit, and the groups are copies
endloop
set udg_Eric_PartyStartingHealth = lv_baseTotalHealth
if (lv_baseTotalHealth > 0) then
set udg_Eric_PartyHealthQuotient = lv_remainingTotalHealth / lv_baseTotalHealth
endif
set udg_Eric_PartyHealthQuotient = udg_Eric_PartyHealthQuotient * (udg_Eric_PartyStartingNumbers - lv_numRemaining)
//this should work fine
set udg_Eric_PartyRemainingHealth = lv_remainingTotalHealth
//PLUG LEAKS
call DestroyGroup (lv_sortGroupAlt)
set lv_baseTotalHealth = 0
set lv_remainingTotalHealth = 0
set lv_partyOriginalHealth = 0
set lv_partyOriginalNumbers = 0
set lv_enumUnit = null
set lv_numRemaining = 0
//PARAMS
set lp_g = null // i assume this group is actually a udg, so don't destroy it
endfunction
function sAI_addUnitToEricParty takes unit u returns nothing
local integer lv_numRemaining = CountUnitsInGroup(udg_Eric_Group)
local integer p = GetPlayerId(GetOwningPlayer(u))
local integer b = 0
local string unitIDString = I2S(GetHandleIdBJ(u))
//MAIN PART
set b = LoadIntegerBJ(0, StringHashBJ("Units_" + unitIDString + "_baseID"), udg_UnitAI)
set udg_Eric_PartyStartingHealth = udg_Eric_PartyStartingHealth + GetUnitStateSwap(UNIT_STATE_MAX_LIFE, u)
set udg_Eric_PartyRemainingHealth = udg_Eric_PartyRemainingHealth + GetUnitStateSwap(UNIT_STATE_LIFE, u)
set lv_numRemaining = lv_numRemaining + 1
call sAI_baseRemoveUnit(p, b, u) //hopefully no errors occur with this, like unit not being properly added to a returned default 0
call GroupAddUnitSimple(u, udg_Eric_Group)
if (udg_Eric_PartyStartingHealth > 0) then
set udg_Eric_PartyHealthQuotient = udg_Eric_PartyRemainingHealth / udg_Eric_PartyStartingHealth
else
set udg_Herodin_PartyStartingHealth = 0
endif
//PLUG LEAKS
set lv_numRemaining = 0
set p = 0
set b = 0
set unitIDString = ""
//PARAMS
set u = null
endfunction
function sAI_removeUnitFromEricParty takes unit u returns nothing
local integer lv_numRemaining = CountUnitsInGroup(udg_Eric_Group)
//MAIN PART
set udg_Eric_PartyStartingHealth = udg_Eric_PartyStartingHealth - GetUnitStateSwap(UNIT_STATE_MAX_LIFE, u)
set udg_Eric_PartyRemainingHealth = udg_Eric_PartyRemainingHealth - GetUnitStateSwap(UNIT_STATE_LIFE, u)
set udg_Eric_PartyStartingNumbers = udg_Eric_PartyStartingNumbers - 1
call GroupRemoveUnit(udg_Eric_Group, u)
if (udg_Eric_PartyStartingHealth > 0) then
set udg_Eric_PartyHealthQuotient = udg_Eric_PartyRemainingHealth / udg_Eric_PartyStartingHealth
else
set udg_Eric_PartyStartingHealth = 0
endif
//PLUG LEAKS
set lv_numRemaining = 0
//PARAMS
set u = null
endfunction
function sAI_testUnitForTrainAbility takes integer p, unit u returns nothing
//use this later for the ai to generate its own data, learning etc
endfunction
function sAI_cycleUnitAbilitiesAndReturn takes integer p, unit u returns nothing
// a sort of enum function, to help AI test its abilities and what each unit can do
// hopefully there is actually a way to cycle abilities other than manually writing each one down and then testing the entire list
set udg_tempString = ""
endfunction
//==========================================================================
function sAI_playerAI_pregenReqs takes integer p returns nothing
local string prefix = ""
local string str = ""
local string dls = ""
local integer dls_i = 0
local string uTS = ""
local integer reqI = 0
local string reqS = ""
//========================================================================
//HUMAN ALLIANCE
//========================================================================
//HUMAN FOOTMAN
set uTS = UnitId2StringBJ('hfoo')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN VETERAN
set uTS = UnitId2StringBJ('h00N')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN KNIGHT
set reqI = 1
set uTS = UnitId2StringBJ('hkni')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//========
set reqI = reqI + 1
set reqS = UnitId2StringBJ('hbla')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//========
set reqI = reqI + 1
set reqS = UnitId2StringBJ('hcas')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN HUNTER
set reqI = 1
set uTS = UnitId2StringBJ('n006')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN PEASANT
set uTS = UnitId2StringBJ('hpea')
set reqS = UnitId2StringBJ('htow')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN GUARD TOWER
set uTS = UnitId2StringBJ('hgtw') // human guard tower
set reqS = UnitId2StringBJ('hwtw') //normal scout tower which is required for it to upgrade
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//HUMAN CANNON TOWER
set uTS = UnitId2StringBJ('hgtw')
set reqS = UnitId2StringBJ('hwtw')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//ALLIANCE ARCANE TOWER
set uTS = UnitId2StringBJ('hgtw')
set reqS = UnitId2StringBJ('hwtw')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//ALLIANCE BARRACKS
set uTS = UnitId2StringBJ('hbar')
set reqS = UnitId2StringBJ('htow')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//ALLIANCE BLACKSMITH
set uTS = UnitId2StringBJ('hbla')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//ALLIANCE KEEP
set uTS = "hkee"
set reqS = "htow"
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//ALLIANCE CASTLE
set uTS = UnitId2StringBJ('hcas')
set reqS = UnitId2StringBJ('hkee')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//========================================================================
//DWARVES
//========================================================================
//RIFLEMAN
set reqI = 1
set uTS = UnitId2StringBJ('hrif')
set reqS = UnitId2StringBJ('hbar')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//DWARF WORKER
set reqI = 1
set uTS = UnitId2StringBJ('h014')
set reqS = UnitId2StringBJ('h00S')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//========================================================================
//UNDEAD
//========================================================================
//UNDEAD SPIRIT TOWER
set uTS = UnitId2StringBJ('uzg1')
set reqS = UnitId2StringBJ('uzig')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//UNDEAD NERUBIAN TOWER
set uTS = UnitId2StringBJ('uzg2')
set reqS = UnitId2StringBJ('uzig')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
//UNDEAD HAUNTED GOLD MINE
set uTS = UnitId2StringBJ('ugol')
set reqS = UnitId2StringBJ('ngol')
set str = "UnitType_" + uTS + "_req_" + I2S(reqI)
set dls_i = StringHashBJ(str)
call SaveStringBJ(str, 0, dls_i, udg_Terms[p])
endfunction
function sAI_ericPlayerAI_init takes nothing returns nothing
local unit townhall = udg_ericFirstTH
local integer p = udg_ericPlayerID
local integer base = 1
call sAI_addBase(p, townhall)
set base = udg_sAI_lastCreatedBaseID
//Veterans
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h00N'), 3)
//Footmen
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hfoo'), 6)
//Hunters
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('n006'), 4)
//Peasants
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hpea'), 8)
//buildings
//Guard Tower
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hgtw'), 4)
//Town Hall
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hcas'), 1)
//Barracks
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hbar'), 2)
//Lumber Mill
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hlum'), 1)
//Blacksmith
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hbla'), 1)
//Altar of Kings
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('halt'), 1)
//Farms
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hhou'),10)
//PLUG LEAKS
set townhall = null
set p = 0
set base = 0
endfunction
function sAI_undeadGreyPlayerAI_init takes nothing returns nothing
local unit townhall = udg_undeadGreyFirstTH
local integer p = udg_undeadGreyPlayerID
local integer base = 1
call sAI_addBase(p, townhall)
//Ghouls
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('ugol'), 6) // how does this work with duplicated names?
//Child of Gro'dar
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('u001'), 6)
//Crypt Fiends
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('ucry'), 3)
//Carrion Beetles
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('u009'), 4)
//Acolytes
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('uaco'), 5)
//buildings
//Spirit Tower
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('uzg1'), 6)
//Black Citadel
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('unp2'), 1)
//Graveyard
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('ugrv'), 1)
//Crypt
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('usep'), 1)
//Slaughterhouse
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('uslh'), 1)
//PLUG LEAKS
set townhall = null
set p = 0
set base = 0
endfunction
function udf_calculateHerodinPartyStats takes group lp_g returns nothing
local real lv_partyOriginalHealth = udg_Herodin_PartyStartingHealth
local real lv_partyOriginalNumbers = I2R(udg_Herodin_PartyStartingNumbers)
local real lv_baseTotalHealth = 0
local real lv_remainingTotalHealth = 0
local group lv_sortGroupAlt = CreateGroup()
local unit lv_enumUnit = null
local integer lv_numRemaining = 0
call GroupAddGroup( udg_Herodin_Group, lv_sortGroupAlt)
set lv_numRemaining = CountUnitsInGroup(lv_sortGroupAlt)
set udg_Herodin_PartyStartingNumbers = lv_numRemaining
loop
exitwhen (lv_numRemaining <= 0)
set lv_enumUnit = FirstOfGroup(lv_sortGroupAlt)
set lv_remainingTotalHealth = lv_remainingTotalHealth + GetUnitStateSwap(UNIT_STATE_LIFE, lv_enumUnit)
set lv_baseTotalHealth = lv_baseTotalHealth + GetUnitStateSwap(UNIT_STATE_MAX_LIFE, lv_enumUnit)
set lv_numRemaining = lv_numRemaining -1
call GroupRemoveUnitSimple(lv_enumUnit, lv_sortGroupAlt)
endloop
set udg_Herodin_PartyStartingHealth = lv_baseTotalHealth
if (lv_baseTotalHealth > 0) then
set udg_Herodin_PartyHealthQuotient = lv_remainingTotalHealth / lv_baseTotalHealth
endif
set udg_Herodin_PartyHealthQuotient = udg_Herodin_PartyHealthQuotient * (udg_Herodin_PartyStartingNumbers - lv_numRemaining)
//this should work fine
set udg_Herodin_PartyRemainingHealth = lv_remainingTotalHealth
//PLUG LEAKS
call DestroyGroup (lv_sortGroupAlt)
set lv_baseTotalHealth = 0
set lv_remainingTotalHealth = 0
set lv_partyOriginalHealth = 0
set lv_partyOriginalNumbers = 0
set lv_enumUnit = null
set lv_numRemaining = 0
endfunction
function sAI_addUnitToHerodinParty takes unit u returns nothing
local integer lv_numRemaining = CountUnitsInGroup(udg_Herodin_Group)
local integer p = GetPlayerId(GetOwningPlayer(u))
local integer b = 0
local string unitIDString = I2S(GetHandleIdBJ(u))
//MAIN PART
set b = LoadIntegerBJ(0, StringHashBJ("Units_" + unitIDString + "_baseID"), udg_UnitAI)
set udg_Herodin_PartyStartingHealth = udg_Herodin_PartyStartingHealth + GetUnitStateSwap(UNIT_STATE_MAX_LIFE, u)
set udg_Herodin_PartyRemainingHealth = udg_Herodin_PartyRemainingHealth + GetUnitStateSwap(UNIT_STATE_LIFE, u)
set lv_numRemaining = lv_numRemaining + 1
call sAI_baseRemoveUnit(p, b, u) //hopefully no errors occur with this, like unit not being properly added to a returned default 0
call GroupAddUnitSimple(u, udg_Herodin_Group)
if (udg_Herodin_PartyStartingHealth > 0) then
set udg_Herodin_PartyHealthQuotient = udg_Herodin_PartyRemainingHealth / udg_Herodin_PartyStartingHealth
else
set udg_Herodin_PartyStartingHealth = 0
endif
//maybe should make this recalculate cleanly somehow to avoid errors, that shouldn't be an issue
// add all remaining life and incl new unit
// and update numbers, so we know if there's replacement or whatev if need to count dat
//PLUG LEAKS
set lv_numRemaining = 0
set p = 0
set b = 0
set unitIDString = ""
endfunction
function sAI_removeUnitFromHerodinParty takes unit u returns nothing
local integer lv_numRemaining = CountUnitsInGroup(udg_Herodin_Group)
//MAIN PART
set udg_Herodin_PartyStartingHealth = udg_Herodin_PartyStartingHealth - GetUnitStateSwap(UNIT_STATE_MAX_LIFE, u)
set udg_Herodin_PartyRemainingHealth = udg_Herodin_PartyRemainingHealth - GetUnitStateSwap(UNIT_STATE_LIFE, u)
set udg_Herodin_PartyStartingNumbers = udg_Herodin_PartyStartingNumbers - 1
call GroupRemoveUnit(udg_Herodin_Group, u)
if (udg_Herodin_PartyStartingHealth > 0) then
set udg_Herodin_PartyHealthQuotient = udg_Herodin_PartyRemainingHealth / udg_Herodin_PartyStartingHealth
else
set udg_Herodin_PartyStartingHealth = 0
endif
//PLUG LEAKS
set lv_numRemaining = 0
endfunction
function Herodin_createGuardPositions takes nothing returns nothing
endfunction
function loAI_addPatrolLocation takes location lp_loc, string lp_patrolType returns nothing
endfunction
function udf_rootToLastLock takes nothing returns nothing
local hashtable lv_hash = udg_hashTablePathHash
local integer lv_index = 0
local string lv_saveName = udg_lastUsedRootName
local integer lv_parent = StringHashBJ("rootName")
//========================================
set lv_index = LoadIntegerBJ(StringHashBJ("indexCount"), lv_parent, lv_hash)
set lv_index = lv_index + 1
call SaveStringBJ(lv_saveName, StringHashBJ(I2S(lv_index)), lv_parent, lv_hash)
call SaveIntegerBJ(lv_index, StringHashBJ("indexCount"), lv_parent, lv_hash)
set udg_lockedRootName = lv_saveName
set udg_lockedRootNamePathInt = lv_index
endfunction
function udg_rootToLastUnlock takes nothing returns nothing
local hashtable lv_hash = udg_hashTablePathHash
local integer lv_parent = StringHashBJ("rootName")
local integer lv_index = LoadIntegerBJ(StringHashBJ("indexCount"), lv_parent, lv_hash)
local string lv_saveName = LoadStringBJ(StringHashBJ(I2S(lv_index)), lv_parent, lv_hash)
//========================================
call SaveStringBJ(null, StringHashBJ(I2S(lv_index)), lv_parent, lv_hash)
set lv_index = lv_index - 1
call SaveIntegerBJ(lv_index, StringHashBJ("indexCount"), lv_parent, lv_hash)
set udg_lockedRootName = ""
set udg_lockedRootNamePathInt = 0
endfunction
function loAI_addGuardPosition takes location lp_loc, integer lp_unitTypeInt, string lp_patrolRoute returns nothing
local integer lv_pathInt = 0
local integer lv_indexCount = 0
local integer lv_parent = StringHashBJ("guardPosition")
local hashtable lv_hash = udg_herodinGuardForceHash
set udg_tempHash = lv_hash
set udg_tempParent = lv_parent
set udg_tempRootName = ""
//=============================================================
// Add unit data to the hash
//=============================================================
call sAI_addDataToHashLocation_UT(lp_playerInt, lp_location)
call sAI_addDataToHashString_UT(lp_playerInt,"unit", "") // creates an empty for a unit - auto added to last, waiting for fill
call udf_rootToLastLock() // locks the temp root name, cannot be changed, so next addDatas will be set to this root name
call sAI_addDataToHashInteger_UT(lp_playerInt, lp_unitTypeInt)
call sAI_addDataToHashString_UT(lp_playerInt,"behavior", "guard") // need a field state add?
call udf_rootToLastUnlock()
//=============================================================
//=============================================================
endfunction
function loAI_setGuardsPeriodicCheck takes nothing returns nothing
local integer lv_herodinAIInt = udg_herodinAIInt
//these strings need to be proper unit type ids
if udg_HDxNumOfRiflemen < udg_HDxNumOfRiflemenNeeded[udg_bridgeDefenderLevel] then
udf_createHerodinDefenders("riflemen", udg_HDxNumOfRiflemenNeeded[udg_bridgeDefenderLevel] - udg_HDxNumOfRiflemen)
endif
if udg_HDxNumOfMortarTeams < udg_HDxNumOfMortarTeamsNeeded[udg_bridgeDefenderLevel] then
udf_createHerodinDefenders("mortarteam", udg_HDxNumOfMortarTeamsNeeded[udg_bridgeDefenderLevel] - udg_HDxNumOfMortarTeams)
endif
if udg_HDxNumOfWorkers < udg_HDxNumOfWorkersNeeded[udg_bridgeDefenderLevel] then
udf_createHerodinDefenders("dwarvenworker", udg_HDxNumOfWorkersNeeded[udg_bridgeDefenderLevel] - udg_HDxNumOfWorkers)
endif
// if positions are filled up, then the reinforcement just picks a unit to go stand by
// loops guard position and also sees if assigned unit is there, if unit is alive but not there, attack move to
// new unit just stands close by, unassigned until a slot opens up
if then
elseif then
else
endif
endfunction
function sAI_herodinSpells takes nothing returns nothing
local unit u = udg_Herodin
local integer closeEnemyCount = 0
local group sortGroup = CreateGroup()
local boolean processFinished = false
local unit enumUnit = null
//MAIN PART
set sortGroup = GetUnitsInRangeOfLocAll(200.00, GetUnitLoc(u))
set enumUnit = FirstOfGroup(sortGroup)
loop
exitwhen (enumUnit == null)
if (IsPlayerEnemy(GetOwningPlayer(enumUnit), (GetOwningPlayer(u))) == true) then
if (IsUnitType(enumUnit, UNIT_TYPE_STRUCTURE) == false ) then
set closeEnemyCount = closeEnemyCount + 1
endif
endif
call GroupRemoveUnitSimple(enumUnit, sortGroup)
set enumUnit = FirstOfGroup(sortGroup)
endloop
if (closeEnemyCount >= 3) then
call IssueImmediateOrderBJ( u, "thunderclap" )
endif
//PLUG LEAKS
set u = null
set closeEnemyCount = 0
call DestroyGroup(sortGroup)
set sortGroup = null
set processFinished = false
set enumUnit = null
endfunction
function sAI_herodinPlayerAI_init takes nothing returns nothing
local unit townhall = udg_herodinFirstTH
local integer p = udg_herodinPlayerID
local integer base = 1
//MAIN PART
call sAI_addBase(p, townhall)
set base = udg_sAI_lastCreatedBaseID
//Rifleman
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h019'), 9)
//Skybarge prob
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('n00q'), 2)
//Dwarven Worker
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h00K'), 6)
//buildings
//Dwarven Rifleman Tower (bottom piece - fix later)
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h018'), 1)
//Dwarven AA Tower
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h017'), 1)
//Dwarven Town Hall
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h00S'), 1)
//Barracks
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h00F'), 1)
//D Smithy
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('h00E'), 1)
//Altar of Kings
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('halt'), 1)
//Farm
call sAI_base_addWant_unit(p, base, UnitId2StringBJ('hhou'),8)
//PLUG LEAKS
set townhall = null
set p = 0
set base = 0
endfunction
function sAI_hunterDog takes unit u returns nothing
local integer unitID = GetHandleIdBJ(u)
local string unitIDString = I2S(unitID)
local unit hunter = LoadUnitHandleBJ(0, StringHashBJ("Units_" + unitIDString + "_hunter"), udg_UnitAI)
local string hunterIDString = I2S(GetHandleIdBJ(hunter))
local unit hunterTarget = LoadUnitHandleBJ(0, StringHashBJ("Units_" + hunterIDString + "_currentTarget"), udg_UnitAI) // this requires some attack input
local location dogAttackPoint = GetUnitLoc(hunterTarget)
local location randPoint = PolarProjectionBJ(GetUnitLoc(hunter), 256, GetRandomDirectionDeg())
//local timer dogDecisionWait = null
if (hunterTarget != null) then
call IssueTargetOrderBJ( u, "attack", hunterTarget )
else
call IssuePointOrderLocBJ( u, "attack", dogAttackPoint )
endif
//PLUG LEAKS
set unitID = 0
set unitIDString = ""
set hunter = null
set hunterIDString = ""
set hunterTarget = null
call RemoveLocation(dogAttackPoint)
set dogAttackPoint = null
call RemoveLocation(randPoint)
set randPoint = null
endfunction
function Trig_Hunter_Dies_Conditions takes nothing returns boolean
if ( not ( GetUnitTypeId(GetDyingUnit()) == 'n006' ) ) then
return false
endif
return true
endfunction
function Trig_Hunter_Dies_Actions takes nothing returns nothing
local string hunterIDString = I2S(GetHandleIdBJ(GetDyingUnit()))
local integer dls_i = StringHashBJ("Units_" + hunterIDString + "_hunter")
local unit pet = LoadUnitHandleBJ(0, dls_i, udg_UnitAI)
//==============================================
//MAIN PART
//==============================================
call KillUnit(pet)
//==============================================
//PLUG LEAKS
//==============================================
set hunterIDString = ""
set dls_i = 0
set pet = null
endfunction
//===========================================================================
function InitTrig_Hunter_Dies takes nothing returns nothing
set gg_trg_Hunter_Dies = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Hunter_Dies, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Hunter_Dies, Condition( function Trig_Hunter_Dies_Conditions ) )
call TriggerAddAction( gg_trg_Hunter_Dies, function Trig_Hunter_Dies_Actions )
endfunction
function Trig_Unit_Acquires_Target_x_General_Actions takes nothing returns nothing
local unit u = GetOrderedUnit()
local string unitIDString = I2S(GetHandleIdBJ(u))
local integer dls_i = StringHashBJ("Units_" + unitIDString + "_currentTarget")
//MAIN PART
call SaveUnitHandleBJ(GetOrderTargetUnit(), 0, dls_i, udg_UnitAI)
//PLUG LEAKS
set u = null
set unitIDString = ""
set dls_i = 0
endfunction
//===========================================================================
function InitTrig_Unit_Acquires_Target_x_General takes nothing returns nothing
set gg_trg_Unit_Acquires_Target_x_General = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Acquires_Target_x_General, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddAction( gg_trg_Unit_Acquires_Target_x_General, function Trig_Unit_Acquires_Target_x_General_Actions )
endfunction
function Trig_Unit_Unacquires_Target_x_General_Actions takes nothing returns nothing
local unit u = GetOrderedUnit()
local string unitIDString = I2S(GetHandleIdBJ(u))
local integer dls_i = StringHashBJ("Units_" + unitIDString + "_currentTarget")
//MAIN PART
call SaveUnitHandleBJ(null, 0, dls_i, udg_UnitAI)
//PLUG LEAKS
set u = null
set unitIDString = ""
set dls_i = 0
endfunction
//===========================================================================
function InitTrig_Unit_Unacquires_Target_x_General takes nothing returns nothing
set gg_trg_Unit_Unacquires_Target_x_General = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Unacquires_Target_x_General, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Unacquires_Target_x_General, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddAction( gg_trg_Unit_Unacquires_Target_x_General, function Trig_Unit_Unacquires_Target_x_General_Actions )
endfunction
function sAI_saveUnitToHash takes unit u returns nothing
local string uIS = I2S(GetHandleIdBJ(u))
//MAIN PART
call sAI_saveUnitParameter(u, "unit", "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set uIS = ""
endfunction
function sAI_unitStopBuilding takes unit u returns nothing
local unit trainer = u
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
local string cBIS = ""
local unit cB = null // currently building
local string cBTS = ""
local string bOrdString = null
//MAIN PART
//GET ID VARIABLES
set baseIDString = I2S(LoadIntegerBJ(0, StringHashBJ("Units_" + trainerIDString + "_baseID"), udg_UnitAI))
set cB = LoadUnitHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_unit"), udg_UnitAI)
set cBTS = LoadStringBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_unitType"), udg_UnitAI) // maybe update to "unitTypeString"
//call IssueImmediateOrderBJ(u, "stop")
call sAI_saveUnitParameter(null, "currentlyBuilding_unit", "Units_" + trainerIDString, udg_UnitAI)
call sAI_saveLocationParameter(null, "currentlyBuilding_location", "Units_" + trainerIDString, udg_UnitAI)
call sAI_saveStringParameter("", "currentlyBuilding_unitType", "Units_" + trainerIDString, udg_UnitAI)
set str = "Player_" + playerIDString + "_base_" + baseIDString
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_builders"), udg_PlayerAI[p]), trainer)
call GroupAddUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_workers_idle"), udg_PlayerAI[p]), trainer)
set str = "Player_" + playerIDString + "_base_" + baseIDString
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + cBTS + "_count"), udg_PlayerAI[p])
set count = count - 1
call SaveIntegerBJ(count, 0, StringHashBJ(str + "_has_building_" + cBTS + "_count"), udg_PlayerAI[p])
//"has building" applies even to a structure that has begun construction, they are not considered "has" until complete
//PLUG LEAKS
set trainer = null
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
set cBIS = ""
set cB = null
set cBTS = ""
set bOrdString = null
endfunction
function sAI_cancelConstruction takes unit u returns nothing
call IssueImmediateOrderById(u, 851976)
endfunction
function sAI_startException takes unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
//MAIN PART
call sAI_saveBooleanParameter(true, "loopException", "Units_" + unitIDString, udg_UnitAI)
//PLUG LEAKS
set unitIDString = ""
endfunction
function sAI_endException takes unit u returns nothing
local string unitIDString = I2S(GetHandleIdBJ(u))
//MAIN PART
call sAI_saveBooleanParameter(false, "loopException", "Units_" + unitIDString, udg_UnitAI)
//PLUG LEAKS
set unitIDString = ""
endfunction
function Trig_PlayerAI_x_Base_Attacked_Actions takes nothing returns nothing
local string unitIDString = I2S(GetHandleId(GetAttackedUnitBJ()))
local integer p = GetConvertedPlayerId(GetOwningPlayer(GetAttackedUnitBJ()))
local string playerIDString = I2S(p)
local string bIS = I2S(LoadIntegerBJ(0, StringHashBJ("Units_" + unitIDString + "_baseID"), udg_UnitAI))
local group g = CreateGroup()
local unit enumUnit = null
local location loc = GetUnitLoc(GetAttackedUnitBJ())
//======================================================
if (IsUnitType(GetAttackedUnitBJ(), UNIT_TYPE_STRUCTURE) == true) then
set udg_tempGroup = LoadGroupHandleBJ(0, StringHashBJ("Player_" + playerIDString + "_base_" + bIS + "_army"), udg_PlayerAI[p])
call sAI_saveUnitParameter(GetAttackedUnitBJ(), "lastAttackedBuilding", "Player_" + playerIDString + "_base_" + bIS, udg_PlayerAI[p])
call GroupAddGroup(udg_tempGroup, g)
set enumUnit = FirstOfGroup(g)
loop
exitwhen (enumUnit == null)
call IssuePointOrderLoc(enumUnit, "attack", loc)
call GroupRemoveUnit(g, enumUnit)
set enumUnit = FirstOfGroup(g)
endloop
endif
// //======================================================
call DestroyGroup(g)
call RemoveLocation(loc)
set g = null
set unitIDString = ""
set p = 0
set playerIDString = ""
set bIS = ""
set enumUnit = null
set loc = null
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Base_Attacked takes nothing returns nothing
set gg_trg_PlayerAI_x_Base_Attacked = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Base_Attacked, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddAction( gg_trg_PlayerAI_x_Base_Attacked, function Trig_PlayerAI_x_Base_Attacked_Actions )
endfunction
function Trig_PlayerAI_x_Construction_Finishes_Actions takes nothing returns nothing
local unit trainer = GetTriggerUnit() //invalid i tink
local unit u = GetConstructedStructure()
local string unitIDString = I2S(GetHandleIdBJ(u))
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer))
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train indec string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local group baseArmy = null
local integer count = 0
local string uTS = UnitId2StringBJ(GetUnitTypeId(u))
//new
local group sortGroup = CreateGroup()
//MAIN PART
//call AddSpecialEffectLocBJ( GetUnitLoc(trainer), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
//call DestroyEffectBJ( GetLastCreatedEffectBJ() )
call sAI_saveUnitParameter(null, "currentlyBuilding_unit", "Units_" + trainerIDString, udg_UnitAI)
call sAI_saveLocationParameter(null, "currentlyBuilding_location", "Units_" + trainerIDString, udg_UnitAI)
call sAI_saveStringParameter("", "currentlyBuilding_unitType", "Units_" + trainerIDString, udg_UnitAI)
// ASSIGN BASE
call sAI_assignNearbyBaseToUnit(p, u) // Just whatever zone it's actually built in. Otherwise default to 0.
//call sAI_baseAddUnit(p, baseID, u)
// don't need to add terms
//GET BASE ID
set str = "Units_" + unitIDString + "_baseID"
set baseID = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
set baseIDString = I2S(baseID)
//GET BUILDERS
// UPDATE TRAINING COUNT
set str = "Player_" + playerIDString + "_base_" + baseIDString
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_builders"), udg_PlayerAI[p]), trainer)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_isBuilding"), udg_UnitAI), u)
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + uTS + "_count"), udg_PlayerAI[p])
set count = count - 1
call SaveIntegerBJ(count, 0, StringHashBJ(str + "_has_building_" + uTS + "_count"), udg_PlayerAI[p])
//PLUG LEAKS
set trainer = null
set u = null
set unitIDString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set baseArmy = null
set count = 0
set uTS = ""
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Construction_Finishes takes nothing returns nothing
set gg_trg_PlayerAI_x_Construction_Finishes = CreateTrigger( )
call DisableTrigger( gg_trg_PlayerAI_x_Construction_Finishes )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Construction_Finishes, EVENT_PLAYER_UNIT_CONSTRUCT_FINISH )
call TriggerAddAction( gg_trg_PlayerAI_x_Construction_Finishes, function Trig_PlayerAI_x_Construction_Finishes_Actions )
endfunction
function Trig_PlayerAI_x_Construction_Queued_2_Conditions takes nothing returns boolean
if ( not ( IsUnitIdType(String2UnitIdBJ(OrderId2StringBJ(GetIssuedOrderIdBJ())), UNIT_TYPE_STRUCTURE) == true ) ) then
return false
endif
if ( not ( String2UnitIdBJ(OrderId2StringBJ(GetIssuedOrderIdBJ())) != 0 ) ) then
return false
endif
return true
endfunction
function Trig_PlayerAI_x_Construction_Queued_2_Actions takes nothing returns nothing
local integer ord = GetIssuedOrderIdBJ()
//
local unit trainer = GetOrderedUnit()
local string orderString = OrderId2StringBJ(GetIssuedOrderIdBJ())
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
//new
local location orderLoc = GetOrderPointLoc()
local timer newTimer = LoadTimerHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_timer"), udg_UnitAI)
//MAIN PART
//call AddSpecialEffectLocBJ( GetUnitLoc(trainer), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
//call DestroyEffectBJ( GetLastCreatedEffectBJ() )
//call DisplayTextToForce( GetPlayersAll(), "queued" )
set trainerIDString = I2S(GetHandleIdBJ(trainer))
//Get Base Id
set str = "Units_" + trainerIDString + "_baseID"
set dls_i = StringHashBJ(str)
set baseID = LoadIntegerBJ(0, dls_i, udg_UnitAI)
set baseIDString = I2S(baseID)
//Save Unit Type Being Constructed
call sAI_saveStringParameter(orderString, "currentlyBuilding_unitType", "Units_" + trainerIDString, udg_UnitAI)
call sAI_saveLocationParameter(orderLoc, "currentlyBuilding_location", "Units_" + trainerIDString, udg_UnitAI)
if (newTimer == null) then
set newTimer = CreateTimer()
endif
call sAI_saveTimerParameter(newTimer, "currentlyBuilding_timer", "Units_" + trainerIDString, udg_UnitAI)
if (TimerGetRemaining(newTimer) <= 0.0) then
call StartTimerBJ(newTimer, false, 20)
endif
set str = "Player_" + playerIDString + "_base_" + baseIDString
call GroupAddUnitSimple(trainer, LoadGroupHandleBJ(0, StringHashBJ(str + "_builders"), udg_PlayerAI[p]))
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_harvesters"), udg_PlayerAI[p]), trainer)
// the following adds Terms
//call sAI_addUnitTrainingKnowledge(GetConvertedPlayerId(GetOwningPlayer(trainer)), UnitId2StringBJ(GetUnitTypeId(trainer)), orderString)
// update training count
call sAI_saveBooleanParameter(true, orderString, str + "_has_building", udg_PlayerAI[p])
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + orderString + "_count"), udg_PlayerAI[p])
set count = count + 1
call sAI_saveIntegerParameter(count, "count", str + "_has_building_" + orderString, udg_PlayerAI[p])
//PLUG LEAKS
set ord = 0
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
set orderLoc = null //it's being saved to data
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Construction_Queued_2 takes nothing returns nothing
set gg_trg_PlayerAI_x_Construction_Queued_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Construction_Queued_2, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Construction_Queued_2, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( gg_trg_PlayerAI_x_Construction_Queued_2, Condition( function Trig_PlayerAI_x_Construction_Queued_2_Conditions ) )
call TriggerAddAction( gg_trg_PlayerAI_x_Construction_Queued_2, function Trig_PlayerAI_x_Construction_Queued_2_Actions )
endfunction
function Trig_PlayerAI_x_Construction_Starts_Conditions takes nothing returns boolean
return true
endfunction
function Trig_PlayerAI_x_Construction_Starts_Actions takes nothing returns nothing
local integer ord = GetIssuedOrderIdBJ()
//
local unit trainer = GetTriggerUnit()
local unit u = GetConstructingStructure()
local string orderString = OrderId2StringBJ(GetIssuedOrderIdBJ())
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
//new
local location orderLoc = GetOrderPointLoc()
local string cBIS = ""
local unit cB = null // currently building
//MAIN PART
//call AddSpecialEffectLocBJ( GetUnitLoc(trainer), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
//call DestroyEffectBJ( GetLastCreatedEffectBJ() )
call sAI_saveUnitToHash(u)
call sAI_saveUnitParameter(u, "currentlyBuilding_unit", "Units_" + trainerIDString, udg_UnitAI)
call GroupAddUnitSimple(u, LoadGroupHandleBJ(0, StringHashBJ("Player_" + playerIDString + "_base_" + baseIDString + "_isBuilding"), udg_UnitAI))
call GroupAddUnitSimple(u, LoadGroupHandleBJ(0, StringHashBJ("Player_" + playerIDString + "_base_" + baseIDString + "_group"), udg_UnitAI))
//PLUG LEAKS
set ord = 0
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
set orderLoc = null //it's being save to data
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Construction_Starts takes nothing returns nothing
set gg_trg_PlayerAI_x_Construction_Starts = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Construction_Starts, EVENT_PLAYER_UNIT_CONSTRUCT_START )
call TriggerAddCondition( gg_trg_PlayerAI_x_Construction_Starts, Condition( function Trig_PlayerAI_x_Construction_Starts_Conditions ) )
call TriggerAddAction( gg_trg_PlayerAI_x_Construction_Starts, function Trig_PlayerAI_x_Construction_Starts_Actions )
endfunction
function Trig_Player_x_Construction_Unqueued_Conditions takes nothing returns boolean
if ( ( String2UnitIdBJ(OrderId2StringBJ(GetIssuedOrderIdBJ())) != 0 ) ) then
return false
endif
return true
endfunction
function Trig_Player_x_Construction_Unqueued_Actions takes nothing returns nothing
local integer ord = GetIssuedOrderIdBJ()
//
local unit trainer = GetOrderedUnit()
local string orderString = OrderId2StringBJ(GetIssuedOrderIdBJ())
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
//new
local location orderLoc = GetOrderPointLoc()
local string cBIS = ""
local unit cB = null // currently building
local string cBTS = ""
local string bOrdString = null
local location loc = null
local timer t = LoadTimerHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_timer"), udg_UnitAI)
local unit transport = LoadUnitHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_timer"), udg_UnitAI)
local boolean unitIsBuilding = false
local boolean loopException = false
local unit targetUnit = GetOrderTargetUnit()
//MAIN PART
if (orderString == "repair" ) then
call sAI_saveUnitParameter(targetUnit, "currentlyBuilding_unit", "Units_" + trainerIDString, udg_UnitAI)
//integrate this with next part so building will remove it from its b group if this is a new building it's instructed to build
endif
//GET ID VARIABLES
set baseIDString = I2S(LoadIntegerBJ(0, StringHashBJ("Units_" + trainerIDString + "_baseID"), udg_UnitAI))
set cB = LoadUnitHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_unit"), udg_UnitAI)
set cBTS = LoadStringBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_unitType"), udg_UnitAI) // maybe update to "unitTypeString"
set loc = LoadLocationHandleBJ(0, StringHashBJ("Units_" + trainerIDString + "_currentlyBuilding_location"), udg_UnitAI)
set loopException = LoadBooleanBJ(0, StringHashBJ("Units_" + trainerIDString + "_loopException"), udg_UnitAI)
set str = "Player_" + playerIDString + "_base_" + baseIDString
if ((IsUnitInGroup(trainer, LoadGroupHandleBJ(0, StringHashBJ(str + "_builders"), udg_PlayerAI[p])) == true) and (loopException == false)) then
if (TimerGetRemaining(t) <= 0.0) then
if (cB != null) then
//call StartTimerBJ(t, false, 20.0)
//call IssuePointOrderLocBJ( trainer, "move", loc) // avoid infinite murozond loop, might need another timer
//call sAI_cancelConstruction(cB)
else
call sAI_unitStopBuilding(trainer)
endif
else
if (cBTS != "") then
if (cB != null) then
//call IssueTargetOrder(trainer, "smart", cB) // actually need it to repair, not build new unit, maybe this smart commands it?
call sAI_startException(trainer)
//call IssueTargetOrder(trainer, "repair", cB) // test // does this create infinite loop? i think it does
call sAI_endException(trainer)
//call sAI_cancelConstruction(cB)
//call DisplayTextToForce( GetPlayersAll(), "requeue" )
else
set str = "Player_" + playerIDString + "_base_" + baseIDString
//set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + cBTS + "_count"), udg_PlayerAI[p])
//set count = count - 1
//call SaveIntegerBJ(count, 0, StringHashBJ(str + "_has_building_" + cBTS + "_count"), udg_PlayerAI[p])
//because it reissues and +counts
// test
call sAI_startException(trainer)
//call IssuePointOrderLocBJ( trainer, cBTS, loc)
call sAI_endException(trainer)
//call DisplayTextToForce( GetPlayersAll(), "requeue" )
endif
endif
endif
endif // Of Unit Is Builder
//PLUG LEAKS
set ord = 0
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
set orderLoc = null //it's being saved to data
endfunction
//===========================================================================
function InitTrig_Player_x_Construction_Unqueued takes nothing returns nothing
set gg_trg_Player_x_Construction_Unqueued = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_x_Construction_Unqueued, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_x_Construction_Unqueued, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_x_Construction_Unqueued, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddCondition( gg_trg_Player_x_Construction_Unqueued, Condition( function Trig_Player_x_Construction_Unqueued_Conditions ) )
call TriggerAddAction( gg_trg_Player_x_Construction_Unqueued, function Trig_Player_x_Construction_Unqueued_Actions )
endfunction
function Trig_PlayerAI_x_Construction_Cancelled_2_Actions takes nothing returns nothing
local unit trainer = GetTriggerUnit()
local string orderString = UnitId2StringBJ(GetUnitTypeId(GetCancelledStructure()))
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
local unit u = GetCancelledStructure()
local string unitIDString = I2S(GetHandleIdBJ(u))
local group builderGroup = LoadGroupHandleBJ(0, StringHashBJ("Units_" + unitIDString + "_builderGroup"), udg_UnitAI)
local group sortGroup = CreateGroup()
local unit enumUnit = null
//MAIN PART
call sAI_saveUnitParameter(null, "currentlyBuilding_unit", "Units_" + trainerIDString, udg_UnitAI)
//Get Base Id
set str = "Units_" + trainerIDString + "_baseID"
set dls_i = StringHashBJ(str)
set baseID = LoadIntegerBJ(0, dls_i, udg_UnitAI)
set baseIDString = I2S(baseID)
//STOP ALL WORKERS
call GroupAddGroup(builderGroup, sortGroup)
set enumUnit = FirstOfGroup(sortGroup)
loop
exitwhen (enumUnit == null)
//call sAI_unitStopBuilding // removes all its building data
call GroupRemoveUnit(sortGroup, enumUnit)
set enumUnit = FirstOfGroup(sortGroup)
endloop
//I think builder group gets automatically cleared by delete data func, at least it SHOULD
//REMOVE CANCELLED BUILDING FROM GROUP (Redundant?)
call GroupRemoveUnit(LoadGroupHandleBJ(0, StringHashBJ(str + "_isBuilding"), udg_PlayerAI[p]), u)
// UPDATE BUILDING COUNT
set str = "Player_" + playerIDString + "_base_" + baseIDString
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + orderString + "_count"), udg_PlayerAI[p])
set count = count - 1
call SaveIntegerBJ(count, 0, StringHashBJ(str + "_has_building_" + orderString + "_count"), udg_PlayerAI[p])
//PLUG LEAKS
call DestroyGroup(sortGroup)
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
set u = null
set unitIDString = ""
set builderGroup = null
set sortGroup = null
set enumUnit = null
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Construction_Cancelled_2 takes nothing returns nothing
set gg_trg_PlayerAI_x_Construction_Cancelled_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Construction_Cancelled_2, EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL )
call TriggerAddAction( gg_trg_PlayerAI_x_Construction_Cancelled_2, function Trig_PlayerAI_x_Construction_Cancelled_2_Actions )
endfunction
function Trig_PlayerAI_x_Building_Queues_Training_Conditions takes nothing returns boolean
if ( String2UnitIdBJ(OrderId2StringBJ(GetIssuedOrderIdBJ())) != 0 ) then
return true
endif
return false
endfunction
//==============================================================================================
function Trig_PlayerAI_x_Building_Queues_Training_Actions takes nothing returns nothing
local unit trainer = GetOrderedUnit()
local string orderString = OrderId2StringBJ(GetIssuedOrderIdBJ())
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer))
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(p)
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
//MAIN PART
if (p == udg_herodinPlayerID) then
//call DisplayTextToForce( GetPlayersAll(), "training queue order: " + orderString )
endif
//debug
// call AddSpecialEffectLocBJ( GetUnitLoc(trainer), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
// call DestroyEffectBJ( GetLastCreatedEffectBJ() )
//Get Base Id
set str = "Units_" + trainerIDString + "_baseID"
set baseID = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
//set baseID = 1 //debug
set baseIDString = I2S(baseID)
set str = "Player_" + playerIDString + "_base_" + baseIDString
// the following adds Terms
//call sAI_addUnitTrainingKnowledge(GetConvertedPlayerId(GetOwningPlayer(trainer)), UnitId2StringBJ(GetUnitTypeId(trainer)), orderString)
// update training count
call sAI_saveBooleanParameter(true, orderString, str + "_has_building", udg_PlayerAI[p])
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + orderString + "_count"), udg_PlayerAI[p])
set count = count + 1
call sAI_saveIntegerParameter(count, "count", str + "_has_building_" + orderString, udg_PlayerAI[p])
if (p == udg_herodinPlayerID) then
//call DisplayTextToForce( GetPlayersAll(), "training queue count: " + I2S(count) )
//call DisplayTextToForce( GetPlayersAll(), "queued unit: " + orderString )
//call DisplayTextToForce( GetPlayersAll(), "dls: " + str + "_has_building_" + orderString + "_count" )
endif
//UPDATE TRAINER INFO
set str = "Units_" + trainerIDString
call sAI_saveBooleanParameter(true, "isTrainer", str, udg_PlayerAI[p])
call sAI_saveBooleanParameter(true, "training", str, udg_PlayerAI[p])
call sAI_saveBooleanParameter(true, orderString, str + "_training", udg_PlayerAI[p])
call sAI_setDataNameMetaType("unitTypeString", udg_lastPLS, udg_PlayerAI[p])
set count = LoadIntegerBJ(0, StringHashBJ(str + "_training_" + orderString + "_count"), udg_PlayerAI[p])
set count = count + 1
call sAI_saveIntegerParameter(count, "count", str + "_training_" + orderString, udg_PlayerAI[p])
//PLUG LEAKS
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
endfunction
//===========================================================================
//TRIGGER INIT
//===========================================================================
function InitTrig_PlayerAI_x_Building_Queues_Training takes nothing returns nothing
set gg_trg_PlayerAI_x_Building_Queues_Training = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Building_Queues_Training, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( gg_trg_PlayerAI_x_Building_Queues_Training, Condition( function Trig_PlayerAI_x_Building_Queues_Training_Conditions ) )
call TriggerAddAction( gg_trg_PlayerAI_x_Building_Queues_Training, function Trig_PlayerAI_x_Building_Queues_Training_Actions )
endfunction
function Trig_PlayerAI_x_Building_Finishes_Training_2_Actions takes nothing returns nothing
local unit trainer = GetTriggerUnit()
local unit u = GetTrainedUnit()
local string unitIDString = I2S(GetHandleIdBJ(u))
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer))
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train indec string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(GetConvertedPlayerId(GetOwningPlayer(trainer)))
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local group baseArmy = null
local integer count = 0
local string uTS = UnitId2StringBJ(GetUnitTypeId(u))
//MAIN PART
//debug
//call AddSpecialEffectLocBJ( GetUnitLoc(trainer), "Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl" )
//call DestroyEffectBJ( GetLastCreatedEffectBJ() )
//SAVE UNIT ID
call sAI_saveUnitToHash(u)
//GET BASE ID
set str = "Units_" + trainerIDString + "_baseID"
set baseID = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
set baseIDString = I2S(baseID)
// ASSIGN BASE
call sAI_assignBaseToUnit(p, baseID, u)
// don't need to add terms
// UPDATE TRAINING COUNT
set str = "Player_" + playerIDString + "_base_" + baseIDString
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + uTS + "_count"), udg_PlayerAI[p])
set count = count - 1
call sAI_saveIntegerParameter(count, "count", str + "_has_building_" + uTS, udg_PlayerAI[p])
//If it's in baseID 0, then training data was still added and needs to be removed.
//UPDATE TRAINER INFO
set str = "Units_" + trainerIDString
call sAI_saveBooleanParameter(true, "training", str, udg_PlayerAI[p])
call sAI_saveBooleanParameter(true, uTS, str + "_training", udg_PlayerAI[p])
set count = LoadIntegerBJ(0, StringHashBJ(str + "_training_" + uTS + "_count"), udg_PlayerAI[p])
set count = count - 1
call sAI_saveIntegerParameter(count, "count", str + "_training_" + uTS, udg_PlayerAI[p])
//PLUG LEAKS
set trainer = null
set u = null
set unitIDString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set baseArmy = null
set count = 0
set uTS = ""
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Building_Finishes_Training_2 takes nothing returns nothing
set gg_trg_PlayerAI_x_Building_Finishes_Training_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Building_Finishes_Training_2, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddAction( gg_trg_PlayerAI_x_Building_Finishes_Training_2, function Trig_PlayerAI_x_Building_Finishes_Training_2_Actions )
endfunction
function Trig_PlayerAI_x_Building_Cancels_Training_2_Actions takes nothing returns nothing
local string unitIDString = ""
local unit trainer = GetTriggerUnit()
local string orderString = UnitId2StringBJ(GetTrainedUnitType())
local string trainerTypeS = UnitId2StringBJ(GetUnitTypeId(trainer)) // As opposed to a handle which doesn't exist cos it's a unit type, not a unit.
local string trainerIDString = I2S(GetHandleIdBJ(trainer))
local string str = ""
local integer dls_i = 0
local string tIS = "" // train index string
local integer trainIndex = 0
local integer tIC = 0
local integer p = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string playerIDString = I2S(GetConvertedPlayerId(GetOwningPlayer(trainer)))
local integer baseID = 0 //get from trainer
local string baseIDString = ""
local integer count = 0
//MAIN PART
//Get Base Id
set str = "Units_" + unitIDString + "_baseID"
set dls_i = StringHashBJ(str)
set baseID = LoadIntegerBJ(0, dls_i, udg_UnitAI)
set baseIDString = I2S(baseID)
set str = "Player_" + playerIDString + "_base_" + baseIDString
//UPDATE BASE TRAINING COUNT
set count = LoadIntegerBJ(0, StringHashBJ(str + "_has_building_" + orderString + "_count"), udg_PlayerAI[p])
set count = count - 1
call sAI_saveIntegerParameter(count, "count", str + "_has_building_" + orderString, udg_PlayerAI[p])
//UPDATE SPECIFIC UNIT TRAINING COUNT
set str = "Units_" + trainerIDString
call sAI_saveBooleanParameter(true, "training", str, udg_PlayerAI[p])
call sAI_saveBooleanParameter(true, orderString, str + "_training", udg_PlayerAI[p])
set count = LoadIntegerBJ(0, StringHashBJ(str + "_training_" + orderString + "_count"), udg_PlayerAI[p])
set count = count - 1
call sAI_saveIntegerParameter(count, "count", str + "_training_" + orderString , udg_PlayerAI[p])
//PLUG LEAKS
set unitIDString = ""
set trainer = null
set orderString = ""
set trainerTypeS = ""
set trainerIDString = ""
set str = ""
set dls_i = 0
set tIS = ""
set trainIndex = 0
set tIC = 0
set p = 0
set playerIDString = ""
set baseID = 0
set baseIDString = ""
set count = 0
endfunction
//===========================================================================
function InitTrig_PlayerAI_x_Building_Cancels_Training_2 takes nothing returns nothing
set gg_trg_PlayerAI_x_Building_Cancels_Training_2 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_PlayerAI_x_Building_Cancels_Training_2, EVENT_PLAYER_UNIT_TRAIN_CANCEL )
call TriggerAddAction( gg_trg_PlayerAI_x_Building_Cancels_Training_2, function Trig_PlayerAI_x_Building_Cancels_Training_2_Actions )
endfunction
function Trig_Unit_Changes_Owner_Actions takes nothing returns nothing
local integer pPlayer = GetConvertedPlayerId(GetChangingUnitPrevOwner())
local integer p = GetConvertedPlayerId(GetTriggerPlayer())
local integer b = 0
local unit u = GetChangingUnit()
local string str = ""
//MAIN PART
set str = "Units_" + I2S(GetHandleIdBJ(u)) + "_baseID"
set b = LoadIntegerBJ(0, StringHashBJ(str), udg_UnitAI)
call sAI_baseRemoveUnit(pPlayer, b, u)
call sAI_assignNearbyBaseToUnit(p, u) // just use this (if something else is needed, I assume the appropriate function will cover it)
//PLUG LEAKS
set pPlayer = 0
set p = 0
set b = 0
set u = null
set str = ""
endfunction
//===========================================================================
function InitTrig_Unit_Changes_Owner takes nothing returns nothing
set gg_trg_Unit_Changes_Owner = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Unit_Changes_Owner, EVENT_PLAYER_UNIT_CHANGE_OWNER )
call TriggerAddAction( gg_trg_Unit_Changes_Owner, function Trig_Unit_Changes_Owner_Actions )
endfunction
function s_isUnitControlled takes unit u returns boolean
local integer i = s_uDI(u, "controlAI_indexCount")
//MAIN PART
if (i > 0) then
set udg_tempBoolean = true
else
set udg_tempBoolean = false
endif
//PLUG LEAKS
set i = 0
//RETURN
return udg_tempBoolean
endfunction
function s_filterUnits_uncontrolled takes group g returns nothing
local integer i = 1
local integer iC = CountUnitsInGroup(g)
local unit eU = null
local group g2 = CreateGroup()
//MAIN PART
call GroupAddGroup(g, g2)
loop
exitwhen (eU == null)
if (s_isUnitControlled(eU) == true) then
call GroupRemoveUnit(g, eU)
endif
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
//PLUG LEAKS
set i = 0
set iC = 0
set eU = null
set g = null
call DestroyGroup(g2)
set g2 = null
endfunction
function s_filterUnits_stormWyrmsNoAI takes group g returns nothing
local integer i = 1
local integer iC = CountUnitsInGroup(g)
local unit eU = null
local group g2 = CreateGroup()
local integer uT = 0
//MAIN PART
call GroupAddGroup(g, g2)
set eU = FirstOfGroup(g2)
loop
exitwhen (eU == null)
set uT = GetUnitTypeId(eU)
if ((s_isUnitControlled(eU) == true) and (( uT == 'nstw' ) or ( uT == 'nthl' ) or ( uT == 'nltl'))) then
call GroupRemoveUnit(g, eU)
endif
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
//PLUG LEAKS
set i = 0
set iC = 0
set eU = null
set g = null
call DestroyGroup(g2)
set g2 = null
set uT = 0
endfunction
function sAI_findEnemyClosestStructure takes integer p, unit u returns unit
endfunction
function sAI_findEnemyRandomStructure takes integer p, unit u returns unit
endfunction
function sAI_cAbility takes nothing returns nothing
// ability added whole sale to unit ai data sheet?
//DATA TO ADD
local string s = ""
//MAIN PART
endfunction
function fx_warningIndicator takes string eS, location l, real time returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local string uIS = I2S(GetHandleId(u))
local group g = null
//MAIN PART
call AddSpecialEffectLoc(eS, l)
call s_destroyEffect_main(bj_lastCreatedEffect, time)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set tIS = ""
set eS = ""
endfunction
function fx_warningIndicator takes string eS, location l, real time returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local string uIS = I2S(GetHandleId(u))
local group g = null
//MAIN PART
call AddSpecialEffectLoc(eS, l)
call s_destroyEffect_main(bj_lastCreatedEffect, time)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set tIS = ""
set eS = ""
endfunction
function s_newUnitAI takes nothing returns nothing
local string iS = ""
//MAIN PART
call CreateNUnitsAtLoc( 1, 'h01Q', Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
set iS = I2S(GetHandleId(bj_lastCreatedUnit))
//create ai here so that it is executed regardless of being "dead"
call sAI_saveStringParameter("", iS, "", udg_UnitAI)
call sAI_saveBooleanParameter(true, "noUnit", iS, udg_UnitAI)
call RemoveUnit(bj_lastCreatedUnit)
//PLUG LEAKS
set iS = ""
endfunction
function sAI_playerCamInRange takes location l, real dist returns boolean
local location l1 = GetCameraTargetPositionLoc()
local real r = DistanceBetweenPoints(l, l1)
if (r <= dist) then
set udg_tempBoolean = true
else
set udg_tempBoolean = false
endif
//PLUG LEAKS
call RemoveLocation(l)
call RemoveLocation(l1)
set l = null
set l1 = null
set r = 0
set dist = 0
//RETURN
return udg_tempBoolean
endfunction
function s_destroyEffect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local effect e = s_tDE(tIS, "effect")
//MAIN PART
call DestroyEffect(e)
call sAI_deleteDataTree(tIS, udg_tempHash) // in theory wipes all leaks
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set e = null
endfunction
function s_destroyEffect_main takes effect e, real time returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call s_tDE_s(e, tIS, "effect")
call TimerStart(t, time, false, function s_destroyEffect)
//PLUG LEAKS
set t = null
set tIS = ""
set e = null
set time = 0
endfunction
function s_projectile_effect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = LoadLocationHandleBJ(0, StringHashBJ(tIS + "_impactLoc"), udg_tempHash)
local group g = GetUnitsInRangeOfLocAll(512, l)
local unit u = s_tDU(tIS, "unit")
local integer pID = s_uDI(u, "owner")
local unit eU = null
local real hp = 0
local real dmg = s_tDR(tIS, "damage")
//MAIN PART
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
if ((BlzIsUnitInvulnerable(eU) == false ) and ( GetConvertedPlayerId(GetOwningPlayer(eU)) != pID )) then // won't hurt caster
call UnitDamageTargetBJ( u, eU, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endif
endloop
call KillUnit(u)
//call DisplayTextToForce( GetPlayersAll(), "boop" )
//call PlaySoundAtPointBJ( gg_snd_ThunderBoltMissileDeath, 100, uL, 0 )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
call DestroyTimer(t)
set t = null
set u = null
set tIS = ""
set pID = 0
set eU = null
set hp = 0
set dmg = 0
endfunction
function fx_delayedEffect_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = s_tDL(tIS, "loc")
local real delay = s_tDR(tIS, "delay")
local string e = s_tDS(tIS, "effect")
//MAIN PART
call AddSpecialEffectLoc(e, l)
call s_tDE_s(bj_lastCreatedEffect, tIS, "effect")
call TimerStart(t, delay, false, function s_destroyEffect)
//Delete hash in expiry.
//call DisplayTextToForce( GetPlayersAll(), "expired effect activated" )
//PLUG LEAKS
set l = null
set t = null
set tIS = ""
set delay = 0
set e = null
endfunction
function fx_delayedEffect takes string eS, location l, real delayEffect, real delayExpire returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
//call AddSpecialEffectLoc(eS, l)
//
call s_tDS_s(eS, tIS, "effect")
call s_tDR_s(delayExpire, tIS, "delay")
call s_tDL_s(l, tIS, "loc")
call TimerStart(t, delayEffect, false, function fx_delayedEffect_expire)
//PLUG LEAKS
set l = null
set t = null
set tIS = ""
set eS = ""
set delayEffect = 0
set delayExpire = 0
endfunction
function s_effect takes string eS, location l, real delayExpire returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call AddSpecialEffectLoc(eS, l)
call s_destroyEffect_main(bj_lastCreatedEffect, delayExpire)
//call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
//call RemoveLocation(l)
set l = null
//call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set tIS = ""
set eS = ""
endfunction
function s_ability_finishCasting_t takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local string abilityString = s_tDS(tIS, "abilityString")
//MAIN PART
call s_uDI_i(-1, u, "stack", "ability_" + abilityString + "_casting" )
if(s_uDI(u, "ability_" + abilityString + "_casting_stack") <=0) then
call s_uDB_s(false, uIS, "ability_" + abilityString + "_casting")
call s_uDB_s(false, uIS, "ability_" + abilityString + "_currentlyExecuting")
endif
// might also check state
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set tIS = ""
endfunction
function s_ability_startCasting takes unit u, string aS returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDI_i(1, u, "stack", "ability_" + aS + "_casting")
call s_uDB_s(true, uIS, "ability_" + aS + "_casting")
call s_uDB_s(true, uIS, "ability_" + aS + "_currentlyExecuting")
//PLUG LEAKS
set u = null
set uIS = ""
set aS = ""
endfunction
function s_g_headMissileXYOffset takes nothing returns location
local unit u = udg_Gustivus
local location l = GetUnitLoc(u)
local real ang = GetUnitFacing(u)
local real dist = 400
//MAIN PART
set udg_tempLoc = PolarProjectionBJ(l, dist, ang) // have to make sure this gets cleaned in all uses
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
set ang = 0
set dist = 0
//RETURN
return udg_tempLoc
endfunction
function s_g_setLightningOffset takes nothing returns location
local unit u = udg_Gustivus
local location l = GetUnitLoc(u)
local real ang = GetUnitFacing(u)
local real dist = 400
local real x = 0
local real y = 0
local real z = 0
//MAIN PART
set udg_tempLoc = PolarProjectionBJ(l, dist, ang) // have to make sure this gets cleaned in all uses
set x = GetLocationX(udg_tempLoc)
set y = GetLocationY(udg_tempLoc)
set z = GetLocationZ(udg_tempLoc)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
set ang = 0
set dist = 0
//RETURN
return udg_tempLoc
endfunction
function s_g_headMissileOffset takes nothing returns location
local unit u = udg_Gustivus
local location l = GetUnitLoc(u)
local real ang = GetUnitFacing(u)
local real dist = 400
local location dLoc = null
//Lightning origin co-ordinates to target
local real lOX = 0
local real lOY = 0
local real lOZ = 0
local real lTX = 0
local real lTY = 0
local real lTZ = 0
//MAIN PART
//set udg_tempLoc = PolarProjectionBJ(l, dist, ang) // have to make sure this gets cleaned in all uses
call AddLightningLoc( "CLPB", GetUnitLoc(GetTriggerUnit()), GetRectCenter(GetPlayableMapRect()) )
call SetLightningColorBJ( GetLastCreatedLightningBJ(), 255.00, 1.00, 1, 1 )
set bj_lastCreatedLightning = AddLightningEx(
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
set ang = 0
set dist = 0
//RETURN
return udg_tempLoc
endfunction
function sAI_scaleEffectOverTime_effect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local effect e = s_tDE(tIS, "effect")
local real inc = s_tDR(tIS, "inc")
local real s = s_tDR(tIS, "scale")
local real tS = s_tDR(tIS, "targetScale")
local string str = ""
//MAIN PART
//timer based loop
if s<tS then
call BlzSetSpecialEffectScale( e, s + inc )
call sAI_saveRealParameter(s + inc, "scale", tIS, udg_tempHash)
call TimerStart(t, udg_gameloop_fx, false, function sAI_scaleEffectOverTime_effect)
//set str = R2S(TimerGetElapsed(udg_time))
//call StartTimerBJ(udg_time, false, 10)
//call DisplayTextToForce(GetPlayersAll(), "scale update")
//call DisplayTextToForce(GetPlayersAll(), str)
else
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
//PLUG LEAKS
set t = null
set tIS = ""
set e = null
set inc = 0
set s = 0
set tS = 0
set str = ""
endfunction
function sAI_scaleEffectOverTime takes effect e, real scale_start, real scale_end, real time returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local real inc = 0
//MAIN PART
call s_tDE_s(e, tIS, "effect")
call s_tDR_s(scale_end, tIS, "targetScale")
if time > 0 then
set inc = ((scale_end - scale_start) / time) * udg_gameloop_fx
else
set inc = scale_end - scale_start
endif
call s_tDR_s(inc, tIS, "inc")
call s_tDR_s(scale_start, tIS, "scale")
call TimerStart(t, 0, false, function sAI_scaleEffectOverTime_effect)
//PLUG LEAKS
set e = null
set scale_end = 0
set scale_start = 0
set time = 0
set t = null
set tIS = ""
set inc = 0
endfunction
function s_removeUnit takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call sAI_deleteDataTree(uIS, udg_UnitAI)
call RemoveUnit(u)
//PLUG LEAKS
set uIS = ""
set u = null
endfunction
function sAI_playerAIUpdate takes integer p returns nothing
local integer numBases = 0
local integer i = 1
local integer iC = 0
local string prefix = ""
local string str = ""
local integer dls_i = 0
//MAIN PART
set prefix = "Player_" + I2S(p) + "_base"
set str = prefix + "_indexCount"
set dls_i = StringHashBJ(str)
set numBases = LoadIntegerBJ(0, dls_i, udg_PlayerAI[p])
loop
exitwhen (i > numBases)
call sAI_base_AI(p, i)
set i = i + 1
endloop
//PLUG LEAKS
set numBases = 0
set i = 0
set iC = 0
set prefix = ""
set str = ""
set dls_i = 0
endfunction
function pF_reportPost takes unit u returns nothing
local player p = GetOwningPlayer(u)
local integer pI = GetConvertedPlayerId(p)
local string s = "gather_troops"
local trigger t = gg_trg_uA_x_Gather_Supply_Units
local location l = null
local boolean terminated = false
//MAIN PART
//GATHER TROOPS
call s_addOrder(u, s, t, l, terminated) // this is it right here
//GOVERN TROOPS
call s_addOrder(u, "govern_troops", gg_trg_uA_x_Govern_Guards, l, terminated)
//PLUG LEAKS
set p = null
set pI = 0
set s = ""
set t = null
set l = null
set terminated = false
endfunction
function pF_trainer takes unit u returns nothing
local player p = GetOwningPlayer(u)
local integer pI = GetConvertedPlayerId(p)
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local string s = "train"
local trigger t = gg_trg_uA_x_Train_Requests
local location l = null
local boolean terminated = false
//MAIN PART
call s_uDB_s(true, uIS, "isTrainer")
//TRAINER
call s_addOrder(u, s, t, l, terminated) // this is it right here
//PLUG LEAKS
set p = null
set pI = 0
set s = ""
set t = null
set l = null
set terminated = false
set uI = 0
set uIS = ""
endfunction
function s_runPrefabs takes nothing returns nothing
local rect rct = GetPlayableMapRect()
local group g = GetUnitsInRectAll(rct)
local unit eU = null
local integer eUI = 0
local string uTS = ""
local string eUTS = ""
local string s = ""
//MAIN PART
set eU = FirstOfGroup(g)
set s = UnitId2String('h01R')
//call DisplayTextToForce(GetPlayersAll(), "running prefab data")
loop
exitwhen eU == null
set eUI = GetUnitTypeId(eU)
set eUTS = UnitId2String(eUI)
if eUTS == s then
call pF_reportPost(eU)
//call DisplayTextToForce(GetPlayersAll(), "rP prefab added")
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//call DisplayTextToForce(GetPlayersAll(), "ran prefab data")
//PLUG LEAKS
call DestroyGroup(g)
set rct = null
set g = null
set eU = null
set eUI = 0
set uTS = ""
set eUTS = ""
endfunction
function sAI_initAI takes nothing returns nothing
local group lv_group = GetUnitsInRectAll(GetPlayableMapRect())
local integer lv_numOfUnits = CountUnitsInGroup(lv_group)
local integer i = 1
local unit lv_evalUnit = null
//======================================
//========================================
//Prefab Player Term Knowledge
//========================================
//call write_sAI_TermsForAll()
//call sAI_addGoldMinesToPlayerKnowledge()
loop
exitwhen i > 28
//call sAI_addPlayerKnowledgeSet1(i)
call sAI_playerAI_pregenReqs(i)
set i = i + 1
endloop
set i = 1
//========================================
// Assign AI to Units
//========================================
loop
exitwhen i > lv_numOfUnits
set lv_evalUnit = FirstOfGroup(lv_group)
call sAI_saveUnitToHash(lv_evalUnit)
call GroupRemoveUnit(lv_group, lv_evalUnit)
set i = i + 1
endloop
//========================================
// Player AI Inits
//========================================
//========================================
// PREFABS
//========================================
call s_runPrefabs()
//PLUG LEAKS
call DestroyGroup(lv_group)
set lv_group = null
set lv_numOfUnits = 0
set i = 0
set lv_evalUnit = null
endfunction
function fx_projectile_update takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = LoadLocationHandleBJ(0, StringHashBJ(tIS + "_impactLoc"), udg_tempHash)
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l1 = LoadLocationHandleBJ(0, StringHashBJ(tIS + "_loc"), udg_tempHash)
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real z = GetUnitFlyHeight(u)
local real tX = s_tDR(tIS, "tX")
local real tY = s_tDR(tIS, "tY")
local real tZ = s_tDR(tIS, "tZ")
local real incX = 0
local real incY = 0
local real incZ = 0
local integer incs = 0
local real speedX = s_tDR(tIS, "speedX")
local real speedY = s_tDR(tIS, "speedY")
local real speedZ = s_tDR(tIS, "speedZ")
local real dX = 0
local real dY = 0
local real dZ = 0
//MAIN PART
set dX = tX - x
set dY = tY - y
set dZ = tZ - z
if (speedX != 0) then
set incX = dX / speedX
else
set incX = 0
endif
if (speedY != 0) then
set incY = dY / speedY
else
set incY = 0
endif
if (speedZ != 0) then
set incZ = dZ / speedZ
else
set incZ = 0
endif
if (z + incZ > 0) then
set speedZ = speedZ - 10
else
set speedZ = 0
endif
//set x = x + incX
//set y = y + incY
//set z = z + incZ
set x = x + speedX
set y = y + speedY
set z = z + speedZ
call s_tDR_s(speedZ, tIS, "speedZ")
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitFlyHeightBJ( u, z, ((z + incZ) * 8) ) // 8 frames ps
if (z <= 0) then
call DestroyTimer(t)
call KillUnit(u)
call RemoveLocation(l)
call RemoveLocation(l1)
else
call TimerStart(t, 0.125, false, function fx_projectile_update)
endif
//PLUG LEAKS
set l = null
set t = null
set l1 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set incX = 0
set incY = 0
set incZ = 0
set incs = 0
set speedX = 0
set speedY = 0
set speedZ = 0
set dX = 0
set dY = 0
set dZ = 0
endfunction
function s_rockProjectileSmall takes unit u, location l, location l2, real v, real vZ returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = ""
local location l1 = null
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real speedX = 0
local real speedY = 0
local real speedZ = 0
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local real angXY = AngleBetweenPoints(l, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(l, l2)
//MAIN PART
//projectile
call CreateNUnitsAtLoc( 1, 'n01G', GetOwningPlayer(udg_EarthKing), l, GetRandomDirectionDeg() )
call KillUnit(GetLastCreatedUnit())
call CreateNUnitsAtLoc( 1, 'n01G', GetOwningPlayer(udg_EarthKing), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), 50, 0)
call SetUnitTimeScalePercent( GetLastCreatedUnit(), GetRandomReal(50, 125 ))
call GroupAddUnit(udg_rocks, bj_lastCreatedUnit)
set speedX = GetRandomReal(-v,v)
set speedY = GetRandomReal(-v,v)
call s_tDL_s(l, tIS, "loc")
call s_tDL_s(l2, tIS, "impactLoc")
call s_tDR_s(speedX, tIS, "speedX")
call s_tDR_s(speedY, tIS, "speedY")
call s_tDR_s(vZ, tIS, "speedZ")
if (u != null) then
call s_tDI_s(GetConvertedPlayerId(GetOwningPlayer(u)), tIS, "owner")
else
call s_tDI_s(0, tIS, "owner")
endif
call TimerStart(t, 0.125, false, function fx_projectile_update)
//PLUG LEAKS
set l = null
set t = null
set l1 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set speedX = 0
set speedY = 0
set speedZ = 0
set dX = 0
set dY = 0
set dZ = 0
set angXY = 0
set angZ = 0
set distXY = 0
endfunction
function s_rockProjectileTarget takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l = s_tDL(tIS, "loc")
local location l2 = s_tDL(tIS, "targetLoc")
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real speedX = 0
local real speedY = 0
local real speedZ = 0
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local location uL = GetUnitLoc(u)
local real angXY = AngleBetweenPoints(uL, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(uL, l2)
local real speedXY = s_tDR(tIS, "speedXY")
local real centerDist = s_tDR(tIS, "centerDist")
local group g = null
local integer pID = s_uDI(u, "owner")
local unit eU = null
local real dmg = s_tDR(tIS, "damage")
local real radius = s_tDR(tIS, "radius")
local location nL = null
//MAIN PART
//set speedXY = 10 // test
//math
//set speedX = Cos(angXY) * speedXY * 0.125
//set speedY = Sin(angXY) * speedXY * 0.125
set nL = PolarProjectionBJ( uL,speedXY * 0.125, angXY)
set z = GetUnitFlyHeight(u)
set z = z + ((distXY - centerDist) / (speedXY * 0.125)) // In theory this creates a clean arc?
//call SetLocZ(nL, z)
//call SetUnitPositionLoc(u, nL)
//call SetUnitPosition(u, GetLocX(nL), GetLocY(nL), GetLocZ(nL))
call SetUnitPosition(u, GetLocationX(nL), GetLocationY(nL))
//set z = z + 5 // test
//call DisplayTextToForce(GetPlayersAll(), R2S(speedX))
//call DisplayTextToForce(GetPlayersAll(), R2S(speedY))
//call PingMinimapLocForForce( GetPlayersAll(), uL, 1 )
//call PingMinimapLocForForce( GetPlayersAll(), l2, 1 )
//projectile
//call SetUnitX(u, x + speedX)
//call SetUnitY(u, y + speedY)
call SetUnitFlyHeight(u, z, 0)
//For huge rocks, add that info.
if z <= 100 and (distXY - centerDist) < 0 then
set g = GetUnitsInRangeOfLocAll(radius, uL)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
if ((BlzIsUnitInvulnerable(eU) == false ) and ( GetConvertedPlayerId(GetOwningPlayer(eU)) != pID )) then // won't hurt caster
call UnitDamageTargetBJ( u, eU, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call KillUnit(u)
call DestroyTimer(t)
call DestroyGroup(g)
call sAI_deleteDataTree(tIS, udg_tempHash)
//call DisplayTextToForce(GetPlayersAll(), "rock boom")
else
call s_tDR_s(speedX, tIS, "speedX")
call s_tDR_s(speedY, tIS, "speedY")
call s_tDR_s(speedZ, tIS, "speedZ")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s(distXY, tIS, "distXY")
call TimerStart(t, 0.125, false, function s_rockProjectileTarget)
//call DisplayTextToForce(GetPlayersAll(), "rock update")
endif
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set speedX = 0
set speedY = 0
set speedZ = 0
set dX = 0
set dY = 0
set dZ = 0
call RemoveLocation(uL)
set uL = null
set eU = null
set angXY = 0
set angZ = 0
set distXY = 0
set speedXY = 0
set centerDist = 0
call DestroyGroup(g)
set g = null
set pID = 0
set dmg = 0
set radius = 0
call RemoveLocation(nL)
set nL = null
endfunction
function s_linearRock_update takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local real rTime = s_tDR(tIS, "time")
local unit u = s_tDU(tIS, "unit")
local real dmg = s_tDR(tIS, "damage")
local unit tUnit = s_tDU(tIS, "targetUnit")
local real speed = s_tDR(tIS, "speed")
local real dist = 0
local real steps = s_tDI(tIS, "steps")
local location l = GetUnitLoc(u)
local location l2 = GetUnitLoc(tUnit)
local real inc = s_tDR(tIS, "inc")
local real a = AngleBetweenPoints(l, l2)
local location l3 = PolarProjectionBJ(l, inc, a)
//MAIN PART
set dist = DistanceBetweenPoints(l, l2)
call SetUnitPositionLoc(u, l3)
if dist < 100 then
call DestroyTimer(t)
call KillUnit(u)
call SetUnitLifeBJ( tUnit, ( GetUnitStateSwap(UNIT_STATE_LIFE, tUnit) - dmg ) )
call sAI_deleteDataTree(tIS, udg_tempHash)
else
call TimerStart(t, udg_gameloop, false, function s_linearRock_update)
endif
//PLUG LEAKS
set t = null
set tIS = ""
set rTime = 0
set u = null
set dmg = 0
set tUnit = null
set speed = 0
set dist = 0
set steps = 0
set l = null
set l2 = null
set l3 = null
set a = 0
set inc = 0
endfunction
function s_linearRock takes location l, location l2, real dmg, real speed, unit tUnit returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local real dist = DistanceBetweenPoints(l, l2)
local integer steps = 0
//MAIN PART
if speed > 0 then
set steps = R2I(dist / (speed * 0.125))
endif
//create rock
call CreateNUnitsAtLoc( 1, 'n01G', GetOwningPlayer(u), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), 100, 0)
call s_tDR_s(dmg, tIS, "damage")
call s_tDI_s(steps, tIS, "steps")
call s_tDU_s(tUnit, tIS, "targetUnit")
call TimerStart(t, 0.125, false, function s_linearRock_update)
//PLUG LEAKS
set t = null
set l = null
set l2 = null
set dmg = 0
set tUnit = null
set speed = 0
set dist = 0
set steps = 0
endfunction
function s_rockProjectileHuge takes unit u, location l, location l2, real speedXY returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = ""
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local real angXY = AngleBetweenPoints(l, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(l, l2)
//MAIN PART
//math
//projectile
call CreateNUnitsAtLoc( 1, 'n01G', GetOwningPlayer(u), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), z, 0)
//just scale huge and increase damage
call s_tDL_s(l, tIS, "loc")
call s_tDL_s(l2, tIS, "targetLoc")
call s_tDR_s(50, tIS, "damage")
call s_tDR_s(400, tIS, "radius")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s((distXY / 2), tIS, "centerDist")
if (u != null) then
call s_tDI_s(GetConvertedPlayerId(GetOwningPlayer(u)), tIS, "owner")
else
call s_tDI_s(0, tIS, "owner")
endif
call TimerStart(t, 0.125, false, function s_rockProjectileTarget)
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set dX = 0
set dY = 0
set dZ = 0
set angXY = 0
set angZ = 0
set distXY = 0
endfunction
function c_pauseTimers takes boolean b returns nothing
local integer i = 1
local string s = "timer_indexCount"
local integer sI = StringHash(s)
local integer iC = LoadIntegerBJ(0, sI, udg_generalHash)
local timer t = null
local string iS = ""
//MAIN PART
loop
exitwhen i > iC
set iS = I2S(i)
set sI = StringHash("timer_" + iS)
set t = LoadTimerHandleBJ(0, sI, udg_generalHash)
call PauseTimerBJ(b, t)
set i = i + 1
endloop
//PLUG LEAKS
set b = false
set i = 0
set s = ""
set iC = 0
set t = null
set sI = 0
set iS = ""
endfunction
function c_add_timer takes timer t returns nothing
call sAI_addTimerParameter(t, "", "timer", udg_generalHash)
endfunction
function cinematic_checkSkip takes nothing returns nothing
call StartTimerBJ(udg_CinematicTransmissionTimer, false, GetLastTransmissionDurationBJ())
loop
exitwhen (TimerGetRemaining(udg_CinematicTransmissionTimer) <= 0 )
if (udg_QuitCinematic == true) then
return
endif
call TriggerSleepAction(0.125)
endloop
return
endfunction
function cinematic_checkWaitSkip takes real r returns nothing
call StartTimerBJ(udg_CinematicTransmissionTimer, false, r)
loop
exitwhen (TimerGetRemaining(udg_CinematicTransmissionTimer) <= 0 )
if (udg_QuitCinematic == true) then
return
endif
call TriggerSleepAction(0.125)
endloop
return
endfunction
function s_bM_contextObject takes nothing returns nothing
local real gH = 0 // ground height
local location l = null
//MAIN PART
// PLUG LEAKS
call RemoveLocation(l)
set l = null
set gH = 0
endfunction
// e.g. destroy rock and create new one to shoot back
// temporarily switch with enemy unit to absorb an attack
//teleport with enemy over water and drown them
//10% to kill, everything else damage
function s_firestorm_loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = s_tDL(tIS, "loc")
local group g = null
local real dist = s_tDR(tIS, "dist")
local real distEnd = 3000 //s_tDR(tIS, "distEnd")
local real ang = s_tDR(tIS, "angle")
local integer pI = GetConvertedPlayerId(GetOwningPlayer(udg_CineKael))
local unit eU = null
local real x = 0
local real y = 0
local location l2 = l
local unit u = s_tDU(tIS, "unit")
local real damage = s_uDR(u, "ability_firestorm_damage")
//MAIN PART
set x = GetLocationX(l)
set y = GetLocationY(l)
call s_effect("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl", Location(x,y), 6)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 2, 1)
//call DisplayTextToForce(GetPlayersAll(), "dist: " + R2S(dist))
//call DisplayTextToForce(GetPlayersAll(), "distEnd: " + R2S(distEnd))
set g = GetUnitsInRangeOfLocAll(1000, l)
set eU = FirstOfGroup(g)
loop
exitwhen eU == null
if IsPlayerEnemy(GetOwningPlayer(eU), GetOwningPlayer(u)) and BlzIsUnitInvulnerable(eU) == false then
call KillUnit(eU)
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//call DisplayTextToForce(GetPlayersAll(), "derp")
call DestroyTimer(t)
call DestroyGroup(g)
call RemoveLocation(l)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set t = null
set tIS = ""
set dist = 0
set distEnd = 0
set ang = 0
set pI = 0
set eU = null
set x = 0
set y = 0
set u = null
endfunction
//=================================================
//=================================================
//=================================================
//=================================================
function s_firestorm takes unit u, location l, integer count, real ang, real angOffset returns nothing
local timer t = null
local string tIS = ""
local integer i = 1
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real dist = 200
local location l2 = null
local real time = 0.25
//MAIN PART
call s_effect("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl", Location(x,y), 6)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 2, 1)
loop
exitwhen (i>count)
loop
exitwhen dist > 3000
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_tDR_s(2000, tIS, "distEnd")
set l2 = PolarProjectionBJ(l, dist, ang)
set x = GetLocationX(l2)
set y = GetLocationY(l2)
call s_tDL_s(Location(x,y), tIS, "loc")
call s_tDR_s(ang, tIS, "angle")
call s_tDU_s(u, tIS, "unit")
call TimerStart(t, time, false, function s_firestorm_loop)
set time = time + 0.25
set dist = dist + 200
endloop
set time = 0.25
set ang = ang + angOffset
set dist = 200
set i = i + 1
endloop
//PLUG LEAKS
set u = null
call RemoveLocation(l)
set l = null
set count = 0
set ang = 0
set angOffset = 0
set t = null
set tIS = ""
set i = 0
set l2 = null
set time = 0
set dist = 0
endfunction
function dragons_timeSphereFX takes nothing returns nothing
local real z = 0
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = udg_BronzeDragon
local location uL = GetUnitLoc(u)
local boolean pL = sAI_playerCamInRange(uL, 3000)
//MAIN PART
set z = GetLocationZ(uL)
call AddSpecialEffectLocBJ( uL, "Abilities\\Spells\\Human\\AerialShackles\\AerialShacklesTarget.mdl" )
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 10, 2)
call sAI_saveEffectParameter(bj_lastCreatedEffect, "effect", tIS, udg_tempHash)
call TimerStart(t, 4, false, function s_destroyEffect)
if (pL == true) then
call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUTIN, 2, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100, 100, 100, 0 )
endif
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set z = 0
set t = null
set tIS = ""
set pL = false
endfunction
function dragons_timeSphere takes nothing returns nothing
local unit u = udg_BronzeDragon
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(2000, uL)
local location l = null
local unit eU = FirstOfGroup(g)
//MAIN PART
call dragons_timeSphereFX()
loop
exitwhen (eU == null)
//set l = s_uDL(eU, "abilityEffect_chronomagic_savedPosition") //we're not using this one yet
set l = PolarProjectionBJ(GetRectCenter(gg_rct_KaelTH), 1000, GetRandomDirectionDeg())
call SetUnitPositionLoc(eU, l)
set eU = FirstOfGroup(g)
call RemoveLocation(l)
endloop
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
call DestroyGroup(g)
set g = null
set l = null
set u = null
set eU = null
endfunction
function dragons_chronoSave takes nothing returns nothing
local group g = GetUnitsInRectAll(GetPlayableMapRect())
local unit u = udg_BronzeDragon
local string uIS = I2S(GetHandleId(u))
local unit eU = FirstOfGroup(g)
local string eUIS = ""
local location eUL = null
//MAIN PART
call sAI_deleteDataTree(uIS + "_effect_chronomagic", udg_UnitAI)
loop
exitwhen (eU == null)
set eUL = GetUnitLoc(eU)
set eUIS = I2S(GetHandleId(eU))
call s_uDL_s(eUL, uIS, "effect_chronomagic_" + eUIS + "_savedPosition")
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
call RemoveLocation(eUL)
endloop
//PLUG LEAKS
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set eU = null
set eUIS = ""
set eUL = null
endfunction
function bd_update takes nothing returns nothing
local real dist = 0
local location uL = GetUnitLoc(udg_BronzeDragon)
local location l = null
local rect r = GetPlayableMapRect()
local group g = null
local unit eU = null
local location eUL = null
local boolean b = false
local real a = 0
local location l2 = null
local integer i = 1
local integer iC = 10
//MAIN PART
loop
exitwhen i > iC or b == true
set l2 = GetRectCenter(gg_rct_KaelTH)
set udg_tempReal = GetRandomDirectionDeg()
set l = PolarProjectionBJ(uL, 2100, udg_tempReal)
set dist = DistanceBetweenPoints(l, l2)
call DestroyGroup(g)
set g = GetUnitsInRangeOfLocAll(2000, l)
set eU = FirstOfGroup(g)
loop
exitwhen eU == null or b == true
if eU == udg_Gustivus or eU == udg_GaleWinterFreeze or eU == udg_EarthKing or eU == udg_ChildOfAir or eU == udg_FireOgre or dist < 2000 then
else
set b = true
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
set i = i + 1
endloop
if b == true then
call GroupPointOrderLocBJ(udg_BronzeDragons, "move", l)
else
call GroupImmediateOrderBJ(udg_BronzeDragons, "stop")
endif
//PLUG LEAKS
set dist = 0
call RemoveLocation(uL)
set uL = null
call RemoveLocation(l)
set l = null
set r = null
call DestroyGroup(g)
set g = null
set eU = null
call RemoveLocation(eUL)
set eUL = null
set b = false
set a = 0
call RemoveLocation(l2)
set l2 = null
set i = 0
set iC = 0
endfunction
function dragons_detect takes nothing returns nothing
local unit u = udg_BronzeDragon
local string uIS = I2S(GetHandleId(u))
local string aIS = s_uDS(u, "ai")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(2000, uL)
local unit eU = FirstOfGroup(g)
local boolean found = false
//MAIN PART
loop
exitwhen eU == null or found == true
if IsPlayerEnemy(GetOwningPlayer(u), GetOwningPlayer(eU)) == true and TimerGetRemaining(udg_Timer_Dragons_Timesphere) <= 0 then
call s_uDS_s("timesphere", uIS, "ai")
call s_uDU_s(eU, uIS, "targetUnit")
call StartTimerBJ(udg_Timer_Dragons_Timesphere, false, 30)
set found = true
endif
call GroupRemoveUnit(g,eU)
set eU = FirstOfGroup(g)
endloop
//call DisplayTextToForce( GetPlayersAll(), "dragons detect" )
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set aIS = ""
set uIS = ""
call DestroyGroup(g)
set g = null
set eU = null
set found = false
endfunction
function s_cOA_tornadoTeleport_effect takes unit u, location l returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call SetUnitPositionLoc(u, l)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
set uIS = ""
endfunction
function s_cOA_tornado_check takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l = GetUnitLoc(u)
local group g = s_uDG(u, "group")
//
local group eG = CreateGroup()
local unit eU = null
local real cT = 0
local real time = s_tDR(tIS, "time")
local group tG = GetUnitsInRangeOfLocAll(300, l)
local string eUIS = ""
local location rC = GetRectCenter(gg_rct_KaelTH)
local location home = PolarProjectionBJ(rC, GetRandomReal(200, 1000), GetRandomDirectionDeg())
//MAIN PART
set time = time - 0.125
call s_tDR_s(time, tIS, "time")
call GroupAddGroup(eG, g)
set eU = FirstOfGroup(eG)
loop
exitwhen (eU == null)
set eUIS = I2S(GetHandleId(eU))
if IsUnitInGroup(eU, tG) == false then
call s_uDR_s(0, eUIS, "state_ability_cOATornado_time")
call GroupRemoveUnit(g, eU)
endif
set cT = s_uDR(eU, "state_ability_cOATornado_time")
if(cT >= 5.0) then
call s_cOA_tornadoTeleport_effect(eU, home)
call s_uDR_s(0, eUIS, "state_ability_cOATornado_time")
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
else
call s_uDR_s(cT + 0.125, I2S(GetHandleId(eU)), "state_ability_cOATornado_time")
endif
set eU = FirstOfGroup(eG)
endloop
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
set t = null
set u = null
set uIS = ""
set tIS = ""
endfunction
function s_stormEffect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = s_tDL(tIS, "loc")
local real radius = s_tDR(tIS, "radius")
local group g = GetUnitsInRangeOfLocAll( radius, l)
local unit eU = null
local real time = s_tDR(tIS, "time")
local location uL = null
//MAIN PART
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
set eU = FirstOfGroup(g)
//call DisplayTextToForce( GetPlayersAll(), "zap" )
loop
exitwhen (eU == null)
set uL = GetUnitLoc(eU)
call s_stun(eU, time)
call SetUnitLifeBJ( eU, GetUnitStateSwap(UNIT_STATE_LIFE, eU) - 50 )
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
set t = null
set tIS = ""
set l = null
set radius = 0
set g = null
set eU = null
set time = 0
set uL = null
endfunction
function s_cOA_skystorm takes nothing returns nothing
local timer t = null
local integer tI = 0
local string tIS = ""
local unit u = udg_ChildOfAir
local string uIS = I2S(GetHandleId(u))
local location l = null
local group g = null
local real time = 2
local real r = 125
local real dmg = 125
//
local real delay = 2
local real time2 = 2
local real delay2 = 2
local integer iCount = s_uDI(u, "ability_skystorm_lightning_count")
local integer i = 1
local integer iC = 12
local timer t2 = CreateTimer()
local string tIS2 = I2S(GetHandleId(t2))
//MAIN PART
call s_ability_startCasting(u, "skystorm")
set l = GetRectCenter(gg_rct_CoA_x_Summon_AE_01)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call RemoveLocation(l)
set l = GetRectCenter(gg_rct_CoA_x_Summon_AE_02)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call RemoveLocation(l)
set l = GetRectCenter(gg_rct_CoA_x_Summon_AE_03)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call RemoveLocation(l)
set l = GetRectCenter(gg_rct_CoA_x_Summon_AE_04)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call RemoveLocation(l)
set l = GetRectCenter(gg_rct_CoA_x_Summon_AE_05)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call RemoveLocation(l)
//"the spirits"
loop
exitwhen i > iC
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
set l = GetRandomLocInRect(gg_rct_Region_074)
call s_tDL_s(l, tIS, "loc")
call s_tDR_s(r, tIS, "radius")
call s_tDR_s(dmg, tIS, "damage")
call s_tDR_s(2, tIS, "time")
call TimerStart(t, time2, false, function s_stormEffect)
//call DisplayTextToForce( GetPlayersAll(), "cast lightning" )
set time2 = time2 + 1
set i = i + 1
endloop
call s_tDU_s(u, tIS2, "unit")
call s_tDS_s("skystorm", tIS2, "abilityString")
call TimerStart(t2, time2, false, function s_ability_finishCasting_t)
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set t = null
set u = null
set uIS = ""
set tIS = ""
set time = 0
set r = 0
set dmg = 0
set iCount = 0
set delay = 0
set time2 = 0
set delay2 = 0
set iCount = 0
set i = 0
set iC = 0
set t2 = null
set tIS2 = ""
endfunction
function cOA_endlessWind takes nothing returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = udg_ChildOfAir
local string uIS = I2S(GetHandleId(u))
local group g = null
local location uL = GetUnitLoc(u)
local real ang = GetRandomDirectionDeg()
local location l = null
local integer i = 1
local location l2 = null
local integer num = 0
local timer t2 = CreateTimer()
local string tIS2 = I2S(GetHandleId(t2))
//MAIN PART
call s_ability_startCasting(u, "endlesswinds")
loop
exitwhen i > num
set udg_tempReal = GetRandomReal(250.00, 1400.00)
set udg_tempReal2 = GetRandomDirectionDeg()
set l = PolarProjectionBJ(GetRectCenter(gg_rct_CoA_Final_Form), udg_tempReal, udg_tempReal2)
call CreateNUnitsAtLoc( 1, 'n01D', GetOwningPlayer(u), l, bj_UNIT_FACING )
set uL = GetUnitLoc(bj_lastCreatedUnit)
call s_tDU_s(bj_lastCreatedUnit, tIS, "unit")
call s_tDL_s(l2, tIS, "loc")
call s_tDR_s(15, tIS, "time")
set ang = ang + 180
call RemoveLocation(l)
set l = PolarProjectionBJ(uL, 1000, ang)
call IssuePointOrderLoc(bj_lastCreatedUnit, "move", l2)
call TimerStart(t, 0, false, function s_cOA_tornado_check)
call RemoveLocation(uL)
call RemoveLocation(l)
set i = i + 1
endloop
call s_tDU_s(u, tIS2, "unit")
call s_tDS_s("skystorm", tIS2, "abilityString")
call TimerStart(t2, 30, false, function s_ability_finishCasting_t)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
set t = null
set u = null
set uIS = ""
set tIS = ""
call RemoveLocation(l)
set l = null
call RemoveLocation(uL)
set uL = null
set ang = 0
set l2 = null
set num = 0
set t2 = null
set tIS2 = ""
endfunction
function cOA_detect takes nothing returns nothing
local unit u = udg_ChildOfAir
local string uIS = I2S(GetHandleId(u))
local string aIS = s_uDS(u, "ai")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(2000, uL)
local unit eU = FirstOfGroup(g)
local boolean found = false
//MAIN PART
if s_uDB(u, "ability_skystorm_currentlyExecuting") == false and s_uDB(u, "ability_endlesswinds_currentlyExecuting") == false and s_uDS(u, "ai") == "attacking" then
call PauseTimerBJ(true, udg_Timer_CoA_EndlessWinds_Cycle)
call PauseTimerBJ(false, udg_Timer_CoA_Skystorm_Cycle)
call StartTimerBJ(udg_Timer_CoA_Skystorm, false, 30)
call s_cOA_skystorm()
call s_uDB_s(true, uIS, "ability_skystorm_currentlyExecuting")
//call DisplayTextToForce( GetPlayersAll(), "start skystorm" )
endif
loop
exitwhen eU == null or found == true
if IsPlayerEnemy(GetOwningPlayer(u), GetOwningPlayer(eU)) == true then
call s_uDS_s("attacking", uIS, "ai")
call s_uDU_s(eU, uIS, "targetUnit")
set found = true
endif
call GroupRemoveUnit(g,eU)
set eU = FirstOfGroup(g)
endloop
//call DisplayTextToForce( GetPlayersAll(), "coa detect" )
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set aIS = ""
set uIS = ""
call DestroyGroup(g)
set g = null
set eU = null
set found = false
endfunction
function s_cOA_aiInit takes nothing returns nothing
local unit u = udg_ChildOfAir
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDI_s(3, uIS, "ability_skystorm_count")
call s_uDR_s(2, uIS, "ability_skystorm_period")
call s_uDI_s(9, uIS, "ability_skystorm_lightning_count")
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function s_blizzardStrike takes location l returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call fx_delayedEffect( "Abilities\\Spells\\Human\\Blizzard\\BlizzardTarget.mdl", l, 0, 6 )
//PLUG LEAKS
// destroy timer in expireEffect
set l = null
set t = null
set tIS = ""
endfunction
function s_freezeEffect takes location l, real time returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local group g = GetUnitsInRangeOfLocAll( 200, l)
local unit eU = null
local location uL = null
//MAIN PART
//call fx_delayedEffect( "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl", l, 0, time)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
set uL = GetUnitLoc(eU)
call AddSpecialEffectLocBJ( uL, "Abilities\\Spells\\Undead\\FrostNova\\FrostNovaTarget.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, time)
call s_stun(eU, time)
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//PLUG LEAKS
call DestroyTimer(t)
set t = null
call DestroyGroup(g)
set g = null
set eU = null
set l = null
set tIS = ""
call RemoveLocation(uL)
set uL = null
set time = 0
endfunction
function s_Gale_freezeBlast_effect takes nothing returns nothing // creates Impale style lines of freezing novas
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l = s_tDL(tIS, "loc")
local real ang = s_tDR(tIS, "angle")
local real dist = s_tDR(tIS, "distance")
local real distEnd = s_tDR(tIS, "distanceMax")
local real period = s_tDR(tIS, "period")
local real radius = s_tDR(tIS, "radius")
local unit eU = null
local group g = GetUnitsInRangeOfLocAll(radius, l)
//MAIN PART
set l = PolarProjectionBJ(l, 175, ang)
set dist = dist + 175
call s_tDR_s(dist, tIS, "dist")
call s_tDL_s(l, tIS, "loc")
call s_freezeEffect(l, 10)
if (dist > distEnd) then
call DestroyTimer(t)
call RemoveLocation(l)
else
call TimerStart(t, period, false, function s_Gale_freezeBlast_effect)
endif
//call DisplayTextToForce(GetPlayersAll(), "freezeblast effect")
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set t = null
set u = null
set uIS = ""
set tIS = ""
set ang = 0
set dist = 0
set distEnd = 0
set period = 0
set radius = 0
set eU = null
call DestroyGroup(g)
set g = null
endfunction
function s_Gale_freezeBlast takes nothing returns nothing // creates Impale style lines of freezing novas
local timer t = CreateTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = udg_GaleWinterFreeze
local string uIS = I2S(GetHandleId(u))
local location l = GetUnitLoc(u)
local group g = null
local unit tUnit = s_uDU(u, "targetUnit")
local location l2 = GetUnitLoc(tUnit)
local real ang = AngleBetweenPoints(l, l2)
local real dist = 0
local real distEnd = 2000
local real period = 0.25
local real radius = 125
//MAIN PART
call s_tDR_s(ang, tIS, "angle")
call s_tDR_s(dist, tIS, "distance")
call s_tDR_s(distEnd, tIS, "distanceMax")
call s_tDR_s(period, tIS, "period")
call s_tDR_s(radius, tIS, "radius")
call s_tDL_s(l, tIS, "loc")
call TimerStart(t, 0, false, function s_Gale_freezeBlast_effect)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(ang - 33, tIS, "angle")
call s_tDR_s(dist, tIS, "distance")
call s_tDR_s(distEnd, tIS, "distanceMax")
call s_tDR_s(period, tIS, "period")
call s_tDR_s(radius, tIS, "radius")
call s_tDL_s(l, tIS, "loc")
call TimerStart(t, 0, false, function s_Gale_freezeBlast_effect)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(ang + 33, tIS, "angle")
call s_tDR_s(dist, tIS, "distance")
call s_tDR_s(distEnd, tIS, "distanceMax")
call s_tDR_s(period, tIS, "period")
call s_tDR_s(radius, tIS, "radius")
call s_tDL_s(l, tIS, "loc")
call TimerStart(t, 0, false, function s_Gale_freezeBlast_effect)
//PLUG LEAKS
call RemoveLocation(l2)
set l = null
call DestroyGroup(g)
set g = null
set t = null
set u = null
set uIS = ""
set tIS = ""
endfunction
function s_Gale_winterVengeance takes nothing returns nothing
local unit u = udg_GaleWinterFreeze
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local unit eU = null
local group g = GetUnitsInRectAll(GetPlayableMapRect())
local location l = null
//MAIN PART
set eU = FirstOfGroup(g)
loop
exitwhen eU == null
set l = GetUnitLoc(eU)
if s_uDS(eU, "gender") == "male" then
call s_freezeEffect(l, 15)
//call DisplayTextToForce( GetPlayersAll(), "froze unit" )
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
call RemoveLocation(l)
endloop
//call DisplayTextToForce( GetPlayersAll(), "WINTER HAS COME" )
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set eU = null
set t = null
endfunction
function gale_detect takes nothing returns nothing
local unit u = udg_GaleWinterFreeze
local string uIS = I2S(GetHandleId(u))
local string aIS = s_uDS(u, "ai")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(1200, uL)
local unit eU = FirstOfGroup(g)
local boolean found = false
local boolean casting = s_uDB(u, "casting")
//MAIN PART
loop
exitwhen eU == null or found == true
if IsPlayerEnemy(GetOwningPlayer(u), GetOwningPlayer(eU)) == true and casting == false then
call StartTimerBJ(udg_Timer_Gale_FreezingBlast, true, 70)
call PauseTimerBJ( true, udg_Timer_Gale_WinterFreeze )
call s_uDB_s(true, uIS, "casting")
//call DisplayTextToForce(GetPlayersAll(), "freeze blast!")
call s_uDS_s("attacking", uIS, "ai")
call s_uDU_s(eU, uIS, "targetUnit")
call s_Gale_freezeBlast()
set found = true
endif
call GroupRemoveUnit(g,eU)
set eU = FirstOfGroup(g)
endloop
if found == false and casting == false then
if aIS != "winterfreeze" then
call StartTimerBJ(udg_Timer_Gale_WinterFreeze, true, 70)
call PauseTimerBJ( true, udg_Timer_Gale_FreezingBlast )
endif
call s_uDS_s("winterfreeze", uIS, "ai")
endif
//call DisplayTextToForce( GetPlayersAll(), "gale detect" )
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set aIS = ""
set uIS = ""
call DestroyGroup(g)
set g = null
set eU = null
set found = false
endfunction
function fireOgre_detect takes nothing returns nothing
local unit u = udg_FireOgre
local string uIS = I2S(GetHandleId(u))
local string aIS = s_uDS(u, "ai")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(2000, uL)
local unit eU = FirstOfGroup(g)
local boolean found = false
//MAIN PART
if s_uDB(u, "ability_rockThrow_casting") == false and s_uDS(u, "ai") != "attacking" then
call PauseTimerBJ(false, udg_Timer_FireOgre_RockThrow)
call EnableTrigger(gg_trg_Fire_Ogre_Chucks_Rocks)
endif
call s_uDS_s("", uIS, "ai")
loop
exitwhen eU == null or found == true
if IsPlayerEnemy(GetOwningPlayer(u), GetOwningPlayer(eU)) == true then
call s_uDS_s("attacking", uIS, "ai")
call s_uDU_s(eU, uIS, "targetUnit")
call PauseTimerBJ(true, udg_Timer_FireOgre_RockThrow)
set found = true
endif
call GroupRemoveUnit(g,eU)
set eU = FirstOfGroup(g)
endloop
call ConditionalTriggerExecute( gg_trg_FireOgre_Pick_Taunt )
//call DisplayTextToForce( GetPlayersAll(), "donkey detect" )
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set aIS = ""
set uIS = ""
call DestroyGroup(g)
set g = null
set eU = null
set found = false
endfunction
function fireOgre_rockThrow takes nothing returns nothing
local unit u = udg_FireOgre
local location tL = null
local real x = 0
local real y = 0
local real z = 0
// throws and learns from impact
endfunction
function fireOgre_monitorAttacks takes nothing returns nothing
local unit u = udg_FireOgre
local string uIS = I2S(GetHandleId(u))
local unit mU = s_uDU(u, "attackProjectile")
local location mUL = GetUnitLoc(mU)
local real x = GetLocationX(mUL)
local real y = GetLocationY(mUL)
local real z = GetUnitFlyHeight(mU)
local real targetX = GetLocationX(s_uDL(u, "attackProjectile_targetLoc"))
local real targetY = GetLocationY(s_uDL(u, "attackProjectile_targetLoc"))
local real targetZ = GetLocationZ(s_uDL(u, "attackProjectile_targetLoc"))
local real diffV = 0
local real dist = 0
local real bestDist = 0
local real bestX = s_uDR(u, "attackProjectile_bestX")
local real bestY = s_uDR(u, "attackProjectile_bestY")
local real bestZ = s_uDR(u, "attackProjectile_bestZ")
local real aimX = s_uDR(u, "attackProjectile_aimX")
local real aimY = s_uDR(u, "attackProjectile_aimY")
local real aimZ = s_uDR(u, "attackProjectile_aimZ")
local real bestAimX = s_uDR(u, "attackProjectile_bestAimX")
local real bestAimY = s_uDR(u, "attackProjectile_bestAimY")
local real bestAimZ = s_uDR(u, "attackProjectile_bestAimZ")
//MAIN PART
set diffV = RAbsBJ(targetX - x)
if diffV < bestX then
set bestX = diffV
call s_uDR_s(bestX, uIS, "attackProjectile_bestX")
call s_uDR_s(aimX, uIS, "attackProjectile_bestAimX")
endif
set diffV = RAbsBJ(targetY - y)
if diffV < bestY then
set bestY = diffV
call s_uDR_s(bestY, uIS, "attackProjectile_bestY")
call s_uDR_s(aimY, uIS, "attackProjectile_bestAimY")
endif
set diffV = RAbsBJ(targetZ - z)
if diffV < bestZ then
set bestZ = diffV
call s_uDR_s(bestZ, uIS, "attackProjectile_bestZ")
call s_uDR_s(aimZ, uIS, "attackProjectile_bestAimZ")
endif
//PLUG LEAKS
set u = null
set uIS = ""
set mU = null
call RemoveLocation(mUL)
set mUL = null
set x = 0
set y = 0
set z = 0
set targetX = 0
set targetY = 0
set targetZ = 0
set diffV = 0
set dist = 0
set bestDist = 0
set bestX = 0
set bestY = 0
set bestZ = 0
set aimX = 0
set aimY = 0
set aimZ = 0
set bestAimX = 0
set bestAimY = 0
set bestAimZ = 0
endfunction
function s_eK_updateArcPath takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l = s_tDL(tIS, "centerPoint")
local location uL = GetUnitLoc(u)
local real a = AngleBetweenPoints(l, uL)
local real dist = DistanceBetweenPoints(l, uL)
local real arcDone = s_tDR(tIS, "arcDone")
local real arcTarget = s_tDR(tIS, "arcTarget")
//MAIN PART
set a = a + 5
set arcDone = arcDone + 5
call s_tDR_s(arcDone, tIS, "arcDone")
set l = PolarProjectionBJ(l, dist, a)
call IssuePointOrderLocBJ(u, "move", l)
if ((arcDone < arcTarget) and (IsUnitAliveBJ(u) == true)) then
call TimerStart(t, 0.125, false, function s_eK_updateArcPath)
elseif (IsUnitAliveBJ(u) == true) then
call RemoveLocation(l)
call DestroyTimer(t)
call s_uDB_s(false, uIS, "ability_wallRun_using")
endif
//PLUG LEAKS
set l = null
set t = null
set u = null
set uIS = ""
set tIS = ""
set a = 0
set dist = 0
endfunction
function s_eK_circleRun takes unit u, location l, real arc returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = I2S(GetHandleId(u))
// arc is total amount the unit runs around, uses this after hitting wall and shoots rocks at you
//MAIN PART
call s_sTimer(t, tIS)
call s_tDU_s(u, tIS, "unit")
call s_tDR_s(arc, tIS, "arcTarget")
call s_uDB_s(false, uIS, "ability_wallRun_ready")
call s_uDB_s(true, uIS, "ability_wallRun_using")
//PLUG LEAKS
set l = null
set t = null
set u = null
set uIS = ""
set tIS = ""
endfunction
function s_eK_turnFinished takes nothing returns nothing
local timer t = GetExpiredTimer()
local string uIS = I2S(GetHandleId(udg_EarthKing))
//MAIN PART
call s_uDB_s(false, uIS, "turning")
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set uIS = ""
endfunction
function s_eK_turnToward takes location l, real r returns nothing // remember to destroy loc in capture function
local string uIS = I2S(GetHandleId(udg_EarthKing))
//MAIN PART
call SetUnitFacingToFaceLocTimed( udg_EarthKing, l, r )
call s_uDB_s(true, uIS, "turning")
call TimerStart(CreateTimer(), r, false, function s_eK_turnFinished)
//PLUG LEAKS
set uIS = ""
set l = null
set r = 0
endfunction
function s_eK_finishCharge takes nothing returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = I2S(GetHandleId(udg_EarthKing))
//MAIN PART
call s_uDB_s(false, uIS, "ability_charge_using")
//PLUG LEAKS
set t = null
set uIS = ""
set tIS = ""
endfunction
function s_eK_pickChargePath takes nothing returns nothing
local unit u = udg_EarthKing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = I2S(GetHandleId(u))
local real arc = GetRandomReal(0, 360)
//MAIN PART
call s_tDU_s(u, tIS, "unit")
call s_tDR_s(arc, tIS, "arcTarget")
call s_uDB_s(true, uIS, "ability_charge_using")
//PLUG LEAKS
set t = null
set u = null
set uIS = ""
set tIS = ""
set arc = 0
endfunction
function s_eK_finishCharge takes nothing returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = I2S(GetHandleId(udg_EarthKing))
//MAIN PART
call s_uDB_s(false, uIS, "ability_charge_using")
//PLUG LEAKS
set t = null
set uIS = ""
set tIS = ""
endfunction
function s_eK_pickChargePath takes nothing returns nothing
local unit u = udg_EarthKing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = I2S(GetHandleId(u))
local real arc = GetRandomReal(0, 360)
//MAIN PART
call s_sTimer(t, tIS)
call s_tDU_s(u, tIS, "unit")
call s_tDR_s(arc, tIS, "arcTarget")
call s_uDB_s(true, uIS, "ability_charge_using")
//PLUG LEAKS
set t = null
set u = null
set uIS = ""
set tIS = ""
set arc = 0
endfunction
function s_eK_aiInit takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
//exits
set udg_tempLoc = GetRectCenter(gg_rct_The_Blip)
call sAI_saveLocationParameter(udg_tempLoc, "exit1", "Units_" + uIS, udg_UnitAI)
set udg_tempLoc = GetRectCenter(gg_rct_EarthKing_x_Exit_02)
call sAI_saveLocationParameter(udg_tempLoc, "exit2", "Units_" + uIS, udg_UnitAI)
set udg_tempLoc = GetRectCenter(gg_rct_EarthKing_x_Exit_03)
call sAI_saveLocationParameter(udg_tempLoc, "exit3", "Units_" + uIS, udg_UnitAI)
//
call s_uDI_s(8, uIS, "rockCount")
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function s_eK_flingRocks takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location l = null
local location uL = GetUnitLoc(u)
local location l2 = null
local real oS = 0
local real oSR = 0
local integer rocks = s_uDI(u, "rockCount")
local integer i = 1
local real uF = GetUnitFacing(u)
//MAIN PART
set oS = uF
set oSR = -40
if s_uDI(u, "state_stun") <= 0 then
loop
exitwhen (i > 8)
set oS = oS + oSR
set l = PolarProjectionBJ(uL, 100, oS)
call s_rockProjectileSmall(u, l, l2, 30, GetRandomReal(0,50) )
if (i >= 4) then
set oSR = 40
set oS = uF
endif
set i = i + 1
endloop
endif
//PLUG LEAKS
set l = null
set l2 = null
set u = null
set uIS = ""
call RemoveLocation(uL)
set uL = null
set oS = 0
set oSR = 0
set rocks = 0
set i = 0
set uF = 0
endfunction
function s_eK_flingRocksSmall takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location l = null
local location uL = GetUnitLoc(u)
local location l2 = null
local real oS = 0
local real oSR = 0
local integer rocks = s_uDI(u, "rockCount")
local integer i = 1
local real uF = GetUnitFacing(u)
//MAIN PART
set oS = uF
set oSR = -40
if s_uDI(u, "state_stun") <= 0 then
loop
exitwhen (i > 8)
set oS = oS + oSR
set l = PolarProjectionBJ(uL, 100, oS)
call s_rockProjectileSmall(u, l, l2, 10, GetRandomReal(0,25) )
if (i >= 4) then
set oSR = 40
set oS = uF
endif
set i = i + 1
endloop
endif
//PLUG LEAKS
set l = null
set l2 = null
set u = null
set uIS = ""
call RemoveLocation(uL)
set uL = null
set oS = 0
set oSR = 0
set rocks = 0
set i = 0
set uF = 0
endfunction
function eK_scanTerrain takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local real uA = GetUnitFacing(u)
local location uL = GetUnitLoc(u)
local integer tI = s_uDI(u, "cliff_level")
local integer cTI = 0
local location nL = null
local integer nTI = 0
local boolean impacted = false
local string cOS = s_uDS(u, "current_order")
//
local location oL = s_uDL(u, "current_order_loc")
local real oLA = AngleBetweenPoints(uL, oL)
local integer sTI = s_uDI(u, "cliff_level_start")
//MAIN PART
set uA = AngleBetweenPoints(uL, oL)
set nL = PolarProjectionBJ(uL, 250, uA)
set cTI = GetTerrainCliffLevelBJ(uL)
set nTI = GetTerrainCliffLevelBJ(nL)
if tI == 0 then
set tI = cTI
endif
if nTI != sTI then
set impacted = true
endif
if s_uDS(u, "ai") != "retreat" and cOS == "move" and s_uDI(u, "state_stun") == 0 and impacted == true then
call s_stun(u, 15)
call s_eK_flingRocks()
call SetUnitVertexColorBJ( udg_EarthKing, 20, 100.00, 20.00, 0 )
endif
call s_uDI_s(cTI, uIS, "cliff_level")
//PLUG LEAKS
set u = null
set uIS = ""
set uA = 0
set uL = null
set tI = 0
set cTI = 0
set nL = null
set nTI = 0
set impacted = false
set cOS = ""
endfunction
function fx_eK_feetStampede_effect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location uL = GetUnitLoc(udg_EarthKing)
local integer fI = LoadIntegerBJ(0, StringHashBJ(tIS + "_footIndex"), udg_tempHash) // get offset information from tIS and calculate it right now
local boolean lastFoot = LoadBooleanBJ(0, StringHashBJ(tIS + "_isLastFoot"), udg_tempHash)
local integer i = 1
local location l = null
local real uF = GetUnitFacing(udg_EarthKing)
//MAIN PART
if (fI == i) then
set l = PolarProjectionBJ(uL, 256, uF -60)
endif
set i = i + 1
if (fI == i) then
set l = PolarProjectionBJ(uL, 256, uF + 60)
endif
set i = i + 1
if (fI == i) then
set l = PolarProjectionBJ(uL, 256, uF -300)
endif
set i = i + 1
if (fI == i) then
set l = PolarProjectionBJ(uL, 256, uF + 300)
endif
set i = i + 1
call AddSpecialEffectLocBJ( l, "Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, 5) // dunno if need or not
call sAI_deleteDataTree(tIS, udg_tempHash) // all use individual timers
//PLUG LEAKS
call DestroyTimer(t)
set t = null
call RemoveLocation(l)
call RemoveLocation(uL)
set l = null
set uL = null
set fI = 0
set lastFoot = false
set uF = 0
set i = 0
set tIS = ""
endfunction
function fx_eK_feetStampede takes nothing returns nothing
local unit u = udg_EarthKing
local location uL = GetUnitLoc(u)
local location f1 = null
local location f2 = null
local location f3 = null
local location f4 = null //these are actually offsets, not the final location
local timer t = GetExpiredTimer()
local string tIS = ""
local timer fXT = null
local string fXTIS = ""
local real delay = 0
local boolean stampeding = s_uDB(u, "stampeding")
//MAIN PART
call DestroyTimer(t)
if (stampeding == true) then
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_sTimer(t, tIS)
call sAI_saveIntegerParameter(1, "footIndex", tIS, udg_tempHash)
call TimerStart(t, 0, false, function fx_eK_feetStampede_effect)
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_sTimer(t, tIS)
call sAI_saveIntegerParameter(2, "footIndex", tIS, udg_tempHash)
call TimerStart(t, 0.25, false, function fx_eK_feetStampede_effect)
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_sTimer(t, tIS)
call sAI_saveIntegerParameter(3, "footIndex", tIS, udg_tempHash)
call TimerStart(t, 0.5, false, function fx_eK_feetStampede_effect)
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_sTimer(t, tIS)
call sAI_saveIntegerParameter(4, "footIndex", tIS, udg_tempHash)
call sAI_saveBooleanParameter(true, "isLastFoot", tIS, udg_tempHash)
call TimerStart(t, 0.75, false, function fx_eK_feetStampede_effect)
call TimerStart(CreateTimer(), 2, false, function fx_eK_feetStampede)
endif
//PLUG LEAKS
call RemoveLocation(f1)
call RemoveLocation(f2)
call RemoveLocation(f3)
call RemoveLocation(f4)
call RemoveLocation(uL)
set f1 = null
set f2 = null
set f3 = null
set f4 = null
set uL = null
set u = null
set t = null
set tIS = ""
set fXT = null
set fXTIS = ""
set delay = 0
set stampeding = false
endfunction
function fx_feetQuake takes unit u returns nothing
local location uL = GetUnitLoc(u)
//MAIN PART
//call s_effect( "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl", uL, 3 ) //for some reason s_effect is failing
//call s_destroyEffect_main(bj_lastCreatedEffect, 5)
call AddSpecialEffectLocBJ( uL, "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, 5)
//PLUG LEAKS
set u = null
call RemoveLocation(uL)
set uL = null
endfunction
function s_eK_stampedeCrush takes nothing returns nothing
local unit u = udg_EarthKing
local location uL = GetUnitLoc(u)
local real uF = GetUnitFacing(u)
local location l = null
local rect r = null
local group g = null
local unit eU = null
local boolean stampeding = s_uDB(u, "stampeding")
//MAIN PART
set l = PolarProjectionBJ(uL, 250, uF)
set r = RectFromCenterSizeBJ(l, 200.00, 200.00)
set g = GetUnitsInRectAll(r)
call GroupRemoveUnit(g, u)
set eU = FirstOfGroup(g)
if s_uDS(u, "current_order") == "move" then
loop
exitwhen (eU == null)
call KillUnit(eU)
call GroupRemoveUnit(g,eU)
set eU = FirstOfGroup(g)
endloop
endif
//PLUG LEAKS
call DestroyGroup(g)
set g = null
call RemoveLocation(uL)
call RemoveLocation(l)
set uL = null
set l = null
call RemoveRect(r)
set r = null
set eU = null
set u = null
set uF = 0
set stampeding = false
endfunction
function eK_stampede takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location uL = GetUnitLoc(u)
local real rA = GetRandomDirectionDeg()
local location cL = GetRectCenter(gg_rct_EK_Battlezone)
local location l = PolarProjectionBJ(cL, 2000, rA)
//MAIN PART
call s_uDS_s("charging", uIS, "ai")
call IssuePointOrderLoc(udg_EarthKing, "move", l)
call s_uDS_s("move", uIS, "current_order")
call s_uDS_s("point", uIS, "current_order_type")
call RemoveLocation(s_uDL(u, "current_order_loc"))
call s_uDL_s(l, uIS, "current_order_loc")
call EnableTrigger(gg_trg_EarthKing_x_Rock_Fling)
call EnableTrigger(gg_trg_EarthKing_x_Crushing_Feet)
//call DisplayTextToForce( GetPlayersAll(), "stampede" )
//PLUG LEAKS
set u = null
set uIS = ""
call RemoveLocation(uL)
set uL = null
set rA = 0
set l = null
call RemoveLocation(cL)
set cL = null
endfunction
function eK_attack takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location cL = GetRectCenter(gg_rct_EK_Battlezone)
local location uL = GetUnitLoc(u)
local real rA = GetRandomDirectionDeg()
local location l = PolarProjectionBJ(uL, 2000, rA)
//MAIN PART
call s_uDS_s("attacking", uIS, "ai")
call IssuePointOrderLoc(udg_EarthKing, "attack", l)
call s_uDS_s("attack", uIS, "current_order")
call s_uDS_s("point", uIS, "current_order_type")
call RemoveLocation(s_uDL(u, "current_order_loc"))
call s_uDL_s(l, uIS, "current_order_loc")
//call DisplayTextToForce( GetPlayersAll(), "attack" )
//PLUG LEAKS
set u = null
set uIS = ""
call RemoveLocation(uL)
set uL = null
set rA = 0
set l = null
call RemoveLocation(cL)
set cL = null
endfunction
function eK_runsToBlip takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location l = s_uDL(u, "retreatDest")
//MAIN PART
call IssuePointOrderLoc(udg_EarthKing, "move", l)
call s_uDS_s("move", uIS, "current_order")
call s_uDS_s("point", uIS, "current_order_type")
call s_uDL_s(l, uIS, "current_order_loc")
// PLUG LEAKS
set u = null
set uIS = ""
set l = null
endfunction
function eK_pickRetreat takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local integer i = GetRandomInt(1, 3)
local location l = null
//MAIN PART
call RemoveLocation(s_uDL(u, "current_order_loc"))
call RemoveLocation(s_uDL(u, "retreatDest"))
if (i == 1) then
set l = GetRectCenter(gg_rct_The_Blip)
endif
if (i == 2) then
set l = GetRectCenter(gg_rct_EarthKing_x_Exit_02)
endif
if (i == 3) then
set l = GetRectCenter(gg_rct_EarthKing_x_Exit_03)
endif
call s_uDL_s(l, uIS, "retreatDest")
//PLUG LEAKS
set l = null
set i = 0
set u = null
set uIS = ""
endfunction
function eK_retreat takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDS_s("retreating", uIS, "ai")
call eK_pickRetreat()
call eK_runsToBlip()
//call DisplayTextToForce( GetPlayersAll(), "retreat" )
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function eK_blips takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location l = s_uDL(u, "retreatDest")
//MAIN PART
call ShowUnitHide( udg_EarthKing )
call SetUnitInvulnerable( udg_EarthKing, true )
call StartTimerBJ(udg_Timer_EK_Blipped, false, 10)
call IssueImmediateOrder(udg_EarthKing, "stop")
call s_uDS_s("stop", uIS, "current_order")
call s_uDS_s("none", uIS, "current_order_type")
//call DisplayTextToForce( GetPlayersAll(), "blip" )
// PLUG LEAKS
set u = null
set uIS = ""
set l = null
endfunction
function eK_return takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location l = GetRectCenter(gg_rct_EK_Idle)
//MAIN PART
call ShowUnitShow( udg_EarthKing )
call SetUnitInvulnerable( udg_EarthKing, false )
call s_uDS_s("returning", uIS, "ai")
call IssuePointOrderLoc(udg_EarthKing, "move", l)
call s_uDS_s("move", uIS, "current_order")
call s_uDS_s("point", uIS, "current_order_type")
call RemoveLocation(s_uDL(u, "current_order_loc"))
call s_uDL_s(l, uIS, "current_order_loc")
//call DisplayTextToForce( GetPlayersAll(), "return" )
//PLUG LEAKS
set u = null
set uIS = ""
set l = null
endfunction
function eK_reset takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call s_uDS_s("idle", uIS, "ai")
call IssueImmediateOrder(udg_EarthKing, "stop")
call s_uDS_s("stop", uIS, "current_order")
call s_uDS_s("none", uIS, "current_order_type")
//call DisplayTextToForce( GetPlayersAll(), "reset" )
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function eK_detect takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(2000, uL)
local unit eU = null
local string aiS = s_uDS(u, "ai")
local boolean found = false
//MAIN PART
set eU = FirstOfGroup(g)
loop
exitwhen eU == null or found == true
if IsPlayerEnemy(GetOwningPlayer(u), GetOwningPlayer(eU)) == true and (aiS == "idle" or aiS == "") then
call eK_stampede()
call StartTimerBJ( udg_Timer_EK_Stampede, false, 20 )
call StartTimerBJ( udg_Timer_EK_Stampeding, true, 5 )
set found = true
call s_uDU_s(eU, uIS, "target_unit")
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
if s_uDS(u, "ai") == "charging" and s_uDI(u, "state_stun") <= 0 then
call SetUnitVertexColorBJ( udg_EarthKing, 100.00, 0.00, 0.00, 0 )
elseif s_uDI(u, "state_stun") > 0 then
call SetUnitVertexColorBJ( udg_EarthKing, 0.00, 100.00, 0.00, 0 )
else
call SetUnitVertexColorBJ( udg_EarthKing, 100.00, 100.00, 100.00, 0 )
endif
//PLUG LEAKS
set u = null
set uIS = ""
call RemoveLocation(uL)
set uL = null
call DestroyGroup(g)
set g = null
set eU = null
set aiS = ""
set found = false
endfunction
function eK_changeOrder takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local string oS = s_uDS(u, "current_order")
local string oType = s_uDS(u, "current_order_type")
local location l = s_uDL(u, "current_order_loc")
local unit u2 = s_uDU(u, "current_order_unit")
//MAIN PART
//PLUG LEAKS
set u = null
set uIS = ""
set oS = ""
set oType = ""
set l = null
set u2 = null
endfunction
function eK_order takes nothing returns nothing
local unit u = udg_EarthKing
local string uIS = I2S(GetHandleId(u))
local string oS = s_uDS(u, "current_order")
local string oType = s_uDS(u, "current_order_type")
local location l = s_uDL(u, "current_order_loc")
local unit u2 = s_uDU(u, "current_order_unit")
//MAIN PART
if oType == "point" then
call IssuePointOrderLocBJ( u, oS, l )
elseif oType == "unit" then
call IssueTargetOrderBJ( u, oS, u2 )
else
call IssueImmediateOrderBJ( u, oS )
endif
//PLUG LEAKS
set u = null
set uIS = ""
set oS = ""
set oType = ""
set l = null
set u2 = null
endfunction
function hero_unpause takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
//MAIN PART
if udg_CinematicModeOn == false then
call PauseUnitBJ(false, u)
call DestroyTimer(t)
endif
//PLUG LEAKS
set t = null
set tIS = ""
set u = null
endfunction
function hero_pause takes unit u, real r returns nothing
local timer t = CreateTimer()
local string tIS = ""
//MAIN PART
call s_tDU_s(u, tIS, "unit")
call TimerStart(t, r, false, function hero_unpause)
//PLUG LEAKS
set t = null
set tIS = ""
set u = null
set r = 0
endfunction
function hero_rockAttack takes unit u, integer num, rect rct returns nothing
local location l = null
local real rand = 0
local integer i = 1
local location uL = GetUnitLoc(u)
local location tL = GetUnitLoc(udg_EarthKing)
//
local real speed = 1000
local integer steps = 0
local real dist = 0
local timer t = null
local integer tI = 0
local string tIS = ""
local unit rock = null
//MAIN PART
loop
exitwhen i > num
set l = GetRandomLocInRect(rct)
set rand = GetRandomReal(0, 150)
call CreateNUnitsAtLoc( 1, 'n01G', Player(5), l, GetRandomDirectionDeg() )
call SetUnitFlyHeight(bj_lastCreatedUnit, rand, 1)
set rock = bj_lastCreatedUnit
set dist = DistanceBetweenPoints(uL, tL)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(50, tIS, "damage")
call s_tDU_s(rock, tIS, "unit")
call s_tDU_s(udg_EarthKing, tIS, "targetUnit")
call s_tDL_s(l, tIS, "loc")
call s_tDR_s(speed * udg_gameloop, tIS, "inc")
call s_tDR_s(speed, tIS, "speed")
call TimerStart(t, 1, false, function s_linearRock_update) //adding 1 second to account for the rock's lift period
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set rand = 0
set i = 0
set uL = null
set tL = null
endfunction
function fx_chargeMissile2_scale takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local real time = s_tDR(tIS, "time")
local real scale = s_tDR(tIS, "scale")
local effect e = s_tDE(tIS, "effect")
//MAIN PART
call sAI_scaleEffectOverTime(e, scale, time)
call s_tDE_s(null, tIS, "effect")
call sAI_deleteDataTree(tIS, udg_tempHash) //so that the effect isn't destroyed because we're still using it
call DestroyTimer(t)
//PLUG LEAKS
set u = null
set uIS = ""
set t = null
set tIS = ""
set time = 0
set scale = 0
set e = null
endfunction
function fx_chargeMissile2 takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local real time = s_tDR(tIS, "time")
local real chargeTime = s_tDR(tIS, "charge_time")
local effect e = s_tDE(tIS, "effect")
local location uL = s_tDL(tIS, "loc")
local location tL = null
local real a = 0
local location l = null
local real scale = s_tDR(tIS, "scale")
local timer t2 = CreateTimer()
local real scaling = s_tDR(tIS, "scaling")
local real scale_start = s_tDR(tIS, "scale_start")
local real scale_end = s_tDR(tIS, "scale_end")
local boolean initPassed = s_tDB(tIS, "init_passed")
local real height = s_tDR(tIS, "height")
local real inc = s_tDR(tIS, "inc")
//MAIN PART
if uL == null then
set uL = GetUnitLoc(u)
endif
set tL = GetRectCenter(gg_rct_Dragonbreath)
set a = AngleBetweenPoints(uL, tL)
set l = PolarProjectionBJ(uL, 200, a)
if t == null then
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
set scaling = 1
set scale = 1
endif
if scale_start == 0 then
set scale_start = 8
set scale_end = 0.1
call s_tDR_s(scale_start, tIS, "scale_start")
call s_tDR_s(scale_end, tIS, "scale_end")
endif
if chargeTime <= 0 then
set chargeTime = 6
call s_tDR_s(chargeTime, tIS, "charge_time")
endif
if initPassed == false and time <= 0 then
set time = chargeTime
call s_tDR_s(time, tIS, "time")
endif
if e == null then
call AddSpecialEffectLocBJ( l, "Abilities\\Weapons\\WitchDoctorMissile\\WitchDoctorMissile.mdl" )
set e = GetLastCreatedEffectBJ()
call s_tDE_s(e, tIS, "effect")
call BlzSetSpecialEffectZ( e, 300 + height )
call BlzSetSpecialEffectColor( e, 0, 255, 0 )
call BlzSetSpecialEffectScale( e, scale_start )
endif
if initPassed == false and inc == 0 then
set inc = ((scale_end - scale_start) / chargeTime)
call s_tDR_s(inc, tIS, "inc")
set scale = scale_start
call s_tDR_s(scale, tIS, "scale")
endif
if initPassed == false then
call s_tDB_s(true, tIS, "init_passed")
endif
//==================================================================================
set scaling = time / chargeTime
set time = time - (1 * scaling)
call s_tDR_s(time, tIS, "time")
if time < 0.0625 then
set time = 0
else
set scale = scale + (inc * scaling)
call s_tDR_s(scale, tIS, "scale")
//call DisplayTextToForce(GetPlayersAll(), "inc: " + R2S(inc))
//call DisplayTextToForce(GetPlayersAll(), "scale: " + R2S(scale))
call s_tDR_s(scaling, tIS, "scaling")
set tI = GetHandleId(t2)
set tIS = I2S(tI)
call s_tDR_s(scale * 0.1, tIS, "scale")
call s_tDR_s(0.5 * scaling, tIS, "time")
call s_tDE_s(e, tIS, "effect")
call TimerStart(t2, 0, false, function fx_chargeMissile2_scale)
set t2 = CreateTimer()
set tI = GetHandleId(t2)
set tIS = I2S(tI)
call s_tDR_s(scale, tIS, "scale")
call s_tDR_s(0.5 * scaling, tIS, "time")
call s_tDE_s(e, tIS, "effect")
call TimerStart(t2, 0.5 * scaling, false, function fx_chargeMissile2_scale)
endif
if time <= 0 then
call s_destroyEffect_main(e, 0)
call DestroyTimer(t)
call RemoveLocation(uL)
else
set time = 1 * scaling
if time < udg_gameloop_fx then
set time = udg_gameloop_fx
endif
call TimerStart(t, 1 * scaling, false, function fx_chargeMissile2)
endif
//PLUG LEAKS
set u = null
set uIS = ""
set t = null
set tIS = ""
set time = 0
set e = null
call RemoveLocation(tL)
call RemoveLocation(l)
set uL = null
set tL = null
set a = 0
set l = null
set scale = 0
set t2 = null
set scaling = 0
set scale_start = 0
set scale_end = 0
set initPassed = false
set height = 0
set inc = 0
endfunction
function s_g_fireElementals_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = LoadUnitHandleBJ(0, StringHashBJ(tIS + "_unit"), udg_tempHash)
//MAIN PART
call UnitRemoveAbilityBJ( 'A02F', u )
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
//params
set u = null
endfunction
function s_g_fireElementals takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local real uF = GetUnitFacing(u)
local real ang = GetRandomReal(-60, 60)
local location l = PolarProjectionBJ(uL, 1500, uF + ang)
local location l1 = PolarProjectionBJ(uL, 450, uF)
//MAIN PART
call CreateNUnitsAtLoc( 1, 'h01P', GetOwningPlayer(udg_Gustivus), l1, GetRandomDirectionDeg() )
call IssuePointOrderLoc(GetLastCreatedUnit(), "move", l)
call UnitAddAbilityBJ( 'A02F', u )
call sAI_saveUnitParameter(GetLastCreatedUnit(), "unit", tIS, udg_tempHash)
call TimerStart(t, 10, false, function s_g_fireElementals_expire)
//PLUG LEAKS
call RemoveLocation(uL)
call RemoveLocation(l)
call RemoveLocation(l1)
set uL = null
set l = null
set l1 = null
set t = null
set tIS = ""
set uF = 0
set ang = 0
endfunction
function s_g_fireElementals_main takes location l returns nothing
local timer t = null
local real time = 0
local real delay = 0.5
local integer casts = 12
local integer i = 1
//MAIN PART
loop
exitwhen (i > casts)
set t = CreateTimer()
call TimerStart(t, time, false, function s_g_fireElementals)
set i = i + 1
endloop
//PLUG LEAKS
set t = null
set time = 0
set delay = 0
set casts = 0
set i = 0
//params
call RemoveLocation(l)
set l = null
endfunction
function s_g_sLavaSpawn_expires takes unit u returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call KillUnit(u)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
//params
set u = null
endfunction
function s_g_targetHero takes nothing returns nothing
local unit tU = GroupPickRandomUnit(udg_GFight_Heroes)
local string uIS = I2S(GetHandleId(udg_Gustivus))
//MAIN PART
call sAI_saveUnitParameter(tU, "targetHero", "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
set tU = null
set uIS = ""
endfunction
function s_g_alterAttackAngle_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local integer count = LoadIntegerBJ(0, StringHashBJ(tIS + "_count"), udg_tempHash)
local real attackAngle = s_uDR(udg_Gustivus, "attackAngle")
local real inc = LoadRealBJ(0, StringHashBJ(tIS + "_inc"), udg_tempHash)
local string uIS = I2S(GetHandleId(udg_Gustivus))
//MAIN PART
set attackAngle = attackAngle + inc
call sAI_saveRealParameter(attackAngle, "attackAngle", "Units_" + uIS, udg_UnitAI)
if (count <= 0) then
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
else
set count = count -1
call sAI_saveIntegerParameter(count, "count", tIS, udg_tempHash)
endif
//PLUG LEAKS
set t = null
set tIS = ""
set count = 0
set attackAngle = 0
set inc = 0
set uIS = ""
endfunction
function s_g_alterAttackAngle takes real ang, real time returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local integer count = 0
local real inc = 0
//MAIN PART
//call sAI_saveRealParameter(tU, "targetHero", "Units_" + uIS, udg_UnitAI)
if (time > 0) then
set inc = ang / time
set count = R2I(ang /inc) // a bit inexact doe
else
set inc = ang
set count = 1
endif
call sAI_saveIntegerParameter(count, "count", tIS, udg_tempHash)
call sAI_saveRealParameter(inc, "inc", tIS, udg_tempHash)
//PLUG LEAKS
set u = null
set uIS = ""
set t = null
set tIS = ""
set count = 0
set inc = 0
endfunction
//===========================================================
function s_unitExpire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local hashtable ht = udg_UnitAI
local unit u = LoadUnitHandleBJ(0, StringHashBJ(tIS + "_unit"), udg_tempHash)
//MAIN PART
call DestroyTimer(t)
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
set t= null
set tIS = ""
set ht = null
set u = null
endfunction
//===========================================================
function s_unit_timedExpire_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = LoadUnitHandleBJ(0, StringHashBJ(tIS + "_unit"), udg_tempHash)
//MAIN PART
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
//params
set u = null
endfunction
function s_unit_timedExpire takes unit u, real time returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call sAI_saveUnitParameter(u, "unit", tIS, udg_tempHash)
call TimerStart(t, time, false, function s_unit_timedExpire_expires)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
//params
set u = null
set time = 0
endfunction
function s_abilFinished takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local string dLS = LoadStringBJ(0, StringHashBJ(tIS + "_abilityDLS"), udg_tempHash)
local hashtable ht = udg_UnitAI
//MAIN PART
call DestroyTimer(t)
call sAI_saveBooleanParameter(false, "abilityBeingCast", dLS, udg_UnitAI)
call sAI_deleteDataTree(tIS, udg_tempHash) // if this doesn't work properly it's going to leak to hell and create the minecraft underworld
//PLUG LEAKS
set t= null
set tIS = ""
set dLS = ""
set ht = null
endfunction
function fx_heightBlend_loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real time = s_tDR(tIS, "time")
local real inc = s_tDR(tIS, "inc")
local real height = s_tDR(tIS, "height")
local effect e = s_tDE(tIS, "effect")
//MAIN PART
if time > 0 then
set height = height + inc
call BlzSetSpecialEffectZ( e, height )
set time = time - udg_gameloop_fx
call s_tDR_s(time, tIS, "time")
call s_tDR_s(height, tIS, "height")
call TimerStart(t, udg_gameloop_fx, false, function fx_heightBlend_loop)
else
call DestroyTimer(t)
call DestroyEffect(e)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
//PLUG LEAKS
set t = null
set tI = 0
set tIS = ""
set time = 0
set height = 0
set e = null
endfunction
function fx_heightBlend takes effect e, real height, real time returns nothing
local timer t = CreateTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real inc = 0
local real h2 = BlzGetLocalSpecialEffectZ(e)
//MAIN PART
set inc = (height - h2) * (udg_gameloop_fx * time)
call s_tDE_s(e, tIS, "effect")
call s_tDR_s(h2, tIS, "height")
call s_tDR_s(time, tIS, "time")
call s_tDR_s(inc, tIS, "inc")
call TimerStart(t, 0, false, function fx_heightBlend_loop)
//PLUG LEAKS
set height = 0
set time = 0
set t = null
set tI = 0
set tIS = ""
set inc = 0
set h2 = 0
endfunction
function fx_warningIndicator takes string eS, location l, real time returns nothing
//MAIN PART
call AddSpecialEffectLoc(eS, l)
call s_destroyEffect_main(bj_lastCreatedEffect, time)
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set eS = ""
set time = 0
endfunction
function fx_stopCamShake takes nothing returns nothing
//MAIN PART
call DestroyTimer(GetExpiredTimer())
call CameraClearNoiseForPlayer( Player(0) )
//PLUG LEAKS
endfunction
function g_destroyFText takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call DestroyTextTagBJ( udg_G_FText )
endfunction
function g_finalWords takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call DestroyTextTagBJ( udg_G_FText )
call CreateTextTagUnitBJ( "|cffff00ffT|r|cffe603e6h|r|cffcd06cde|r|cffb409b4 |r|cff9b0d9be|r|cff831083n|r|cff691369d|r|cff501750.|r|cff381a38.|r|cff1e1d1e.|r", udg_Gustivus, 0.00, 10, 100, 100, 100, 0 )
set udg_G_FText = GetLastCreatedTextTag()
call TimerStart(CreateTimer(), 10, false, function g_destroyFText)
endfunction
function g_darktides takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call DestroyTextTagBJ( udg_G_FText )
call CreateTextTagUnitBJ( "|cffffffffT|r|cfffff3ffh|r|cffffe6ffe|r|cffffd9ff |r|cffffccfft|r|cffffc0ffi|r|cffffb3ffd|r|cffffa6ffe|r|cffff99ffs|r|cffff8dff |r|cffff80ffc|r|cffff73ffo|r|cffff66ffm|r|cffff5affe|r|cffff4dff |r|cffff40fft|r|cffff33ffo|r|cffff27ff |r|cffff1affm|r|cffff0dffe|r|cffff00ff!|r", udg_Gustivus, 0.00, 10, 100, 100, 100, 0 )
set udg_G_FText = GetLastCreatedTextTag()
call TimerStart(CreateTimer(), 10, false, function g_destroyFText)
endfunction
function s_lightningXYZ_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local lightning lE = LoadLightningHandleBJ(0, StringHashBJ(tIS + "_lightning"), udg_tempHash)
//MAIN PART
call DestroyLightningBJ( lE )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set lE = null
endfunction
function s_lightningXYZ takes real x, real y, real z, real tX, real tY, real tZ, real time, real r, real g, real b returns nothing
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local location l = null
local real ang = GetUnitFacing(u)
local real dist = 600
local location dLoc = null
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local integer count = s_uDI(u, "lightning_remainingCount")
local real delay = 0.5
local integer rI = GetRandomInt(1,4)
//MAIN PART
set l = PolarProjectionBJ(uL, 300, ang)
if rI == 1 then
set bj_lastCreatedLightning = AddLightningEx("CHIM", true, x, y, z, tX, tY, tZ)
endif
if rI == 2 then
set bj_lastCreatedLightning = AddLightningEx("HWPB", true, x, y, z, tX, tY, tZ)
endif
if rI == 3 then
set bj_lastCreatedLightning = AddLightningEx("AFOD", true, x, y, z, tX, tY, tZ)
endif
if rI == 4 then
set bj_lastCreatedLightning = AddLightningEx("CLPB", true, x, y, z, tX, tY, tZ)
endif
call SetLightningColorBJ( bj_lastCreatedLightning, r, g, b, 0 )
call sAI_saveLightningParameter(bj_lastCreatedLightning, "lightning", tIS, udg_tempHash) // does the placeholding DLS string create memory leak? prob not
call TimerStart(t, time, false, function s_lightningXYZ_expires)
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
call RemoveLocation(l)
set l = null
set u = null
set ang = 0
set dist = 0
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set r = 0
set g = 0
set b = 0
set t = null
set tIS = ""
set count = 0
set delay = 0
set time = 0
set rI = 0
endfunction
function s_lightningXYZ_main takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local location uL = GetUnitLoc(u)
local real dist = 600
local real ang1 = GetUnitFacing(u)
local real ang2 = GetRandomReal(-60,60)
local real x = GetLocationX(uL)
local real y = GetLocationY(uL)
local real z = GetLocationZ(uL) + 200
local real tX = 0
local real tY = 0
local real tZ = 0
local real r = GetRandomReal(0, 255) // can change this to select stronger for reds greens etc
local real g = GetRandomReal(0, 255)
local real b = GetRandomReal(0, 255)
local integer count = s_uDI(u, "lightning_count")
local integer remainingCount = s_uDI(u, "lightning_remainingCount")
local real delay = 0.0625
local real time = 0.5
local timer t = null
//MAIN PART
if (remainingCount == 0) then
call sAI_saveIntegerParameter(count, "lightning_remainingCount", "Units_" + uIS, udg_UnitAI)
call sAI_saveBooleanParameter(false, "lightning_casting", "Units_" + uIS, udg_UnitAI)
else
call sAI_saveBooleanParameter(true, "lightning_casting", "Units_" + uIS, udg_UnitAI)
set t = CreateTimer()
//gets origin
call s_g_setLightningOffset()
//target
set udg_tempLoc = PolarProjectionBJ(uL, dist, (ang1 + ang2)) // have to make sure this gets cleaned in all uses
set tX = GetLocationX(udg_tempLoc)
set tY = GetLocationY(udg_tempLoc)
set tZ = GetLocationZ(udg_tempLoc) + GetRandomReal(0, 800)
//effect
call s_lightningXYZ(x,y,z, tX,tY,tZ, time, r,g,b)
//update
call sAI_saveIntegerParameter(remainingCount - 1, "lightning_remainingCount", "Units_" + uIS, udg_UnitAI)
//loop
call TimerStart(t, delay, false, function s_lightningXYZ_main)
endif
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
set uIS = ""
set dist = 0
set ang1 = 0
set ang2 = 0
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set r = 0
set g = 0
set b = 0
set t = null
set count = 0
set remainingCount = 0
set delay = 0
set time = 0
endfunction
function s_g_fireHeadFX_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local effect fx = s_uDE(u, "fx_fireheadFX")
//MAIN PART
call DestroyEffect(fx)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set fx = null
endfunction
function s_g_fireHeadFX takes real time returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer()
//MAIN PART
call AddSpecialEffectTargetUnitBJ( "head", u, "Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl" )
call BlzSetSpecialEffectScale( GetLastCreatedEffectBJ(), 2.00 )
call sAI_saveEffectParameter(GetLastCreatedEffectBJ(), "fx_fireheadFX", "Units_" + uIS, udg_UnitAI)
call TimerStart(t, time, false, function s_g_fireHeadFX_expires)
//PLUG LEAKS
set t = null
set u = null
set uIS = ""
set time = 0
endfunction
function s_g_chargeMissileFX_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local effect fx = s_uDE(u, "fx_chargeMissileFX")
//MAIN PART
call DestroyEffect(fx)
call sAI_saveEffectParameter(null, "fx_chargeMissileFX", "Units_" + uIS, udg_UnitAI)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set u = null
set uIS = ""
set fx = null
endfunction
function s_g_chargeMissileFX takes real time returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call AddSpecialEffectLocBJ( udg_tempLoc, "Abilities\\Spells\\Human\\AerialShackles\\AerialShacklesTarget.mdl" )
call sAI_saveEffectParameter(GetLastCreatedEffectBJ(), "fx_chargeMissileFX", "Units_" + uIS, udg_UnitAI)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 0.5, 0)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 2, 2)
// can create a "vibrating" power up effect
call sAI_saveEffectParameter(bj_lastCreatedEffect, "effect", tIS, udg_tempHash)
call TimerStart(t, time, false, function s_g_chargeMissileFX_expires)
//PLUG LEAKS
set t = null
set u = null
set uIS = ""
set time = 0
endfunction
function fx_chargeMissile2_scale takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local real time = s_tDR(tIS, "time")
local real scale_start = s_tDR(tIS, "scale_start")
local real scale_end = s_tDR(tIS, "scale_end")
local effect e = s_tDE(tIS, "effect")
//MAIN PART
call sAI_scaleEffectOverTime(e, scale_start, scale_end, time)
call s_tDE_s(null, tIS, "effect")
call sAI_deleteDataTree(tIS, udg_tempHash) //so that the effect isn't destroyed because we're still using it
call DestroyTimer(t)
//PLUG LEAKS
set u = null
set uIS = ""
set t = null
set tIS = ""
set time = 0
set scale_start = 0
set scale_end = 0
set e = null
endfunction
function fx_chargeMissile2 takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local real time = s_tDR(tIS, "time")
local real chargeTime = s_tDR(tIS, "charge_time")
local effect e = s_tDE(tIS, "effect")
local location uL = s_tDL(tIS, "loc")
local location tL = null
local real a = 0
local location l = null
local real scale = s_tDR(tIS, "scale")
local timer t2 = CreateTimer()
local real scaling = s_tDR(tIS, "scaling")
local real scale_start = s_tDR(tIS, "scale_start")
local real scale_end = s_tDR(tIS, "scale_end")
local boolean initPassed = s_tDB(tIS, "init_passed")
local real height = s_tDR(tIS, "height")
local real inc = s_tDR(tIS, "inc")
local real dist = s_tDR(tIS, "dist")
local string eS = s_tDS(tIS, "effectType_string")
local real pulse_min = s_tDR(tIS, "pulse_min")
//MAIN PART
if uL == null then
set uL = GetUnitLoc(u)
call s_tDL_s(uL, tIS, "loc")
endif
set tL = GetRectCenter(gg_rct_Dragonbreath)
set a = AngleBetweenPoints(uL, tL)
set l = PolarProjectionBJ(uL, 200 + dist, a)
if t == null then
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
set scaling = 1
set scale = 1
endif
if scale_start == 0 then
set scale_start = 8
set scale_end = 0.1
call s_tDR_s(scale_start, tIS, "scale_start")
call s_tDR_s(scale_end, tIS, "scale_end")
endif
if chargeTime <= 0 then
set chargeTime = 6
call s_tDR_s(chargeTime, tIS, "charge_time")
endif
if initPassed == false and time <= 0 then
set time = chargeTime
call s_tDR_s(time, tIS, "time")
endif
if e == null then
if eS == "" then
set eS = "Abilities\\Weapons\\WitchDoctorMissile\\WitchDoctorMissile.mdl"
endif
call AddSpecialEffectLocBJ( l, eS )
set e = GetLastCreatedEffectBJ()
call s_tDE_s(e, tIS, "effect")
call BlzSetSpecialEffectZ( e, 300 + height )
call BlzSetSpecialEffectColor( e, 0, 255, 0 )
call BlzSetSpecialEffectScale( e, scale_start )
endif
if initPassed == false and inc == 0 then
set inc = ((scale_end - scale_start) / chargeTime)
call s_tDR_s(inc, tIS, "inc")
set scale = scale_start
call s_tDR_s(scale, tIS, "scale")
endif
if initPassed == false then
call s_tDB_s(true, tIS, "init_passed")
endif
//==================================================================================
set scaling = time / chargeTime
set time = time - (1 * scaling)
call s_tDR_s(time, tIS, "time")
if time < 0.0625 or scaling < 0.0625 then
set time = 0
else
if pulse_min == 0 then
set pulse_min = 0.0125
endif
set scale = scale + (inc * scaling)
call s_tDR_s(scale, tIS, "scale")
//call DisplayTextToForce(GetPlayersAll(), "inc: " + R2S(inc))
//call DisplayTextToForce(GetPlayersAll(), "scale: " + R2S(scale))
call s_tDR_s(scaling, tIS, "scaling")
set tI = GetHandleId(t2)
set tIS = I2S(tI)
call s_tDR_s(scale - (inc * scaling), tIS, "scale_start")
call s_tDR_s(scale * pulse_min, tIS, "scale_end")
call s_tDR_s(0.5 * scaling, tIS, "time")
call s_tDE_s(e, tIS, "effect")
call TimerStart(t2, 0, false, function fx_chargeMissile2_scale)
set t2 = CreateTimer()
set tI = GetHandleId(t2)
set tIS = I2S(tI)
call s_tDR_s(scale * pulse_min, tIS, "scale_start")
call s_tDR_s(scale, tIS, "scale_end")
call s_tDR_s(0.5 * scaling, tIS, "time")
call s_tDE_s(e, tIS, "effect")
call TimerStart(t2, 0.5 * scaling, false, function fx_chargeMissile2_scale)
endif
if time <= 0 or (scale < scale_start or scale > scale_end) then
call s_destroyEffect_main(e, 0)
call DestroyTimer(t)
call RemoveLocation(uL)
else
set time = 1 * scaling
if time < udg_gameloop_fx then
set time = udg_gameloop_fx
endif
call TimerStart(t, 1 * scaling, false, function fx_chargeMissile2)
endif
//PLUG LEAKS
set u = null
set uIS = ""
set t = null
set tIS = ""
set time = 0
set e = null
call RemoveLocation(tL)
call RemoveLocation(l)
set uL = null
set tL = null
set a = 0
set l = null
set scale = 0
set t2 = null
set scaling = 0
set scale_start = 0
set scale_end = 0
set initPassed = false
set height = 0
set inc = 0
set dist = 0
set eS = ""
set pulse_min = 0
endfunction
function s_g_lightningHeadFX takes real time returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer()
local real randOffset = GetRandomReal(0, 60)
//MAIN PART
call sAI_saveIntegerParameter(12, "lightning_remainingCount", "Units_" + uIS, udg_UnitAI)
call sAI_saveBooleanParameter(false, "lightning_casting", "Units_" + uIS, udg_UnitAI)
call s_lightningXYZ_main()
//PLUG LEAKS
set t = null
set u = null
set uIS = ""
set time = 0
set randOffset = 0
endfunction
function g_roar takes nothing returns nothing
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local player p = Player(0)
//MAIN PART
call AddSpecialEffectLocBJ( uL, "Abilities\\Spells\\NightElf\\Taunt\\TauntCaster.mdl" ) //"Abilities\\Spells\\NightElf\\BattleRoar\\RoarCasterTarget.mdl"
call s_destroyEffect_main(GetLastCreatedEffectBJ(), 4 )
call CameraSetEQNoiseForPlayer( p, 1.00 )
call TimerStart(CreateTimer(), 3, false, function fx_stopCamShake)
//PLUG LEAKS
set u = null
call RemoveLocation(uL)
set uL = null
set p = null
endfunction
function s_g_timeSphereFX takes nothing returns nothing
local real z = 0
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUTIN, 6.00, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100.00, 100.00, 100.00, 0 )
call s_g_setLightningOffset()
set z = GetLocationZ(udg_tempLoc)
call AddSpecialEffectLocBJ( udg_tempLoc, "Abilities\\Spells\\Human\\AerialShackles\\AerialShacklesTarget.mdl" )
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 45, 3)
call sAI_saveEffectParameter(bj_lastCreatedEffect, "effect", tIS, udg_tempHash)
call TimerStart(t, 3, false, function s_destroyEffect)
//PLUG LEAKS
set z = 0
set t = null
set tIS = ""
endfunction
function g_sTentacle takes nothing returns nothing
local unit u = udg_Gustivus
local location l = s_uDL(u, "ability_sTentacle_loc")
local unit eU = s_uDU(u, "targetHero") // from activating the fight
local location uL1 = GetUnitLoc(eU)
local real ang = GetRandomDirectionDeg()
local real ang1 = s_uDR(u, "ability_sTentacle__ang")
local real dist = GetRandomReal(200, 800)
local string uIS = I2S(GetHandleId(u))
local timer t = CreateTimer() //unique id for cast ability
local string tIS = I2S(GetHandleId(t))
local integer casts = s_uDI(u, "ability_sTentacle_numCasts")
local location l2 = null
//MAIN PART
call sAI_saveBooleanParameter(true, "abilityBeingCast", "Units_" + uIS + "_ability_sTentacle", udg_UnitAI)
//save casts
call sAI_saveIntegerParameter(casts, "remainingCasts", tIS, udg_tempHash)
set l2 = GetUnitLoc(eU)
set l = PolarProjectionBJ(l2, dist, ang)
call CreateNUnitsAtLoc( 1, 'n01O', GetOwningPlayer(udg_Gustivus), l, GetRandomDirectionDeg() ) // SpideryTentacle
call sAI_saveIntegerParameter(s_uDI(u, "remainingCasts") - 1, "remainingCasts", tIS, udg_tempHash)
call DisplayTextToForce(GetPlayersAll(), "spawn tentacles")
// PLUG LEAKS
call RemoveLocation(uL1)
set u = null
set uL1 = null
call RemoveLocation(l)
set l = null
call RemoveLocation(l2)
set l2 = null
set dist = 0
set ang = 0
set ang1 = 0
set uIS = ""
set t = null
set tIS = ""
set casts = 0
endfunction
function g_sTentacle_main takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local integer i = 1
local integer i2 = 6
//MAIN PART
loop
exitwhen i > i2
call g_sTentacle()
set i = i + 1
endloop
//PLUG LEAKS
set u = null
set uIS = ""
set i = 0
set i2 = 0
endfunction
function s_g_darkness_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real time = s_tDR(tIS, "time")
//MAIN PART
call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, time, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 10.00 )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function g_darkness_fadeout takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real time = s_tDR(tIS, "fadeout_time")
//MAIN PART
call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, time, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 100, 100, 100, 10.00 )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function g_darkness takes real time, real delay returns nothing
local timer t = CreateTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
//MAIN PART
//call AddSpecialEffectTargetUnitBJ( "origin", udg_Gustivus, "Abilities\\Spells\\NightElf\\Taunt\\TauntCaster.mdl" )
//call s_destroyEffect_main(bj_lastCreatedEffect, 4)
call s_tDR_s(time * 0.4, tIS, "fadeout_time")
call TimerStart(t, delay, false, function g_darkness_fadeout)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(time * 0.4, tIS, "time")
call TimerStart(t, delay + (time * 0.6), false, function s_g_darkness_expires)
call TimerStart(CreateTimer(), 0, false, function g_darktides)
//PLUG LEAKS
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function s_g_light_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real time = s_tDR(tIS, "time")
//MAIN PART
call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, time, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100, 100, 100, 0.00 )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function g_light_fadeout takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real time = s_tDR(tIS, "fadeout_time")
//MAIN PART
call CinematicFadeBJ( bj_CINEFADETYPE_FADEOUT, time, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100, 100, 100, 0.00 )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function g_light takes real time, real delay returns nothing
local timer t = CreateTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
//MAIN PART
call s_tDR_s(time * 0.4, tIS, "fadeout_time")
call TimerStart(t, delay, false, function g_light_fadeout)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(time * 0.4, tIS, "time")
call TimerStart(t, delay + (time * 0.6), false, function s_g_light_expires)
//PLUG LEAKS
set time = 0
set t = null
set tI = 0
set tIS = ""
endfunction
function g_firebreath_check takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(125, uL)
local unit eU = null
local player p = GetOwningPlayer(u)
local player tP = null
local integer pI = GetConvertedPlayerId(p)
local integer tPI = 0
local location tUL = null
//MAIN PART
if IsUnitAliveBJ(u) == true then
set eU = FirstOfGroup(g)
loop
exitwhen eU == null or IsUnitAliveBJ(u) == false
set tP = GetOwningPlayer(eU)
if IsPlayerEnemy(p, tP) == true and (BlzIsUnitInvulnerable(eU) == false ) then
call UnitDamageTargetBJ( u, eU, 40, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
set tUL = GetUnitLoc(eU)
call AddSpecialEffectLocBJ( tUL, "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" )
call DestroyEffectBJ( GetLastCreatedEffectBJ() )
call RemoveLocation(tUL)
call s_stun(eU, 3)
call KillUnit(u)
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call TimerStart(t, 0.125, false, function g_firebreath_check)
else
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set t = null
set tIS = ""
set u = null
set p = null
set tP = null
set pI = 0
set tPI = 0
set tUL = null
endfunction
function s_g_fireBreath_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
//MAIN PART
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set u = null
endfunction
//===============================================================================
//===============================================================================
function g_firebreath_missile takes nothing returns nothing
local unit u = udg_Gustivus
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local location l = s_tDL(tIS, "loc")
local real ang = s_tDR(tIS, "angle")
local real rA = GetRandomDirectionDeg()
//MAIN PART
call CreateNUnitsAtLoc( 1, 'h01P', GetOwningPlayer(udg_Gustivus), l, ang )
set l = PolarProjectionBJ(l, 1500, ang)
call IssuePointOrderLoc(GetLastCreatedUnit(), "move", l)
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call TimerStart(t, 5, false, function s_g_fireBreath_expire)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDU_s(bj_lastCreatedUnit, tIS, "unit")
call TimerStart(t, 0, false, function g_firebreath_check)
//call DisplayTextToForce(GetPlayersAll(), "cast fb missile")
// PLUG LEAKS
set u = null
set t = null
set tI = 0
set tIS = ""
set l = null
set ang = 0
set rA = 0
endfunction
function s_g_fireBreath takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local real uF = GetUnitFacing(u)
local real ang = s_tDR(tIS, "angle")
local location l = PolarProjectionBJ(uL, 1500, ang)
local location l1 = PolarProjectionBJ(uL, 450, uF)
local real time = 0
local integer balls = s_uDI(u, "ability_firebreath_cast_missiles")
local real period = s_uDR(u, "ability_firebreath_cast_period")
local integer i = 1
//MAIN PART
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
//============================
call RemoveLocation(uL)
//call DisplayTextToForce(GetPlayersAll(), "balls " + I2S(balls))
call SetUnitAnimation( udg_Gustivus, "spell" )
call QueueUnitAnimationBJ( udg_Gustivus, "stand" )
loop
exitwhen i > balls
set uL = GetUnitLoc(u)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(ang, tIS, "angle")
call s_tDL_s(uL, tIS, "loc")
call TimerStart(t, time, false, function g_firebreath_missile)
set time = time + period
set i = i + 1
//call DisplayTextToForce(GetPlayersAll(), I2S(i))
endloop
//PLUG LEAKS
call RemoveLocation(l)
call RemoveLocation(l1)
set uL = null
set l = null
set l1 = null
set t = null
set tI = 0
set tIS = ""
set uF = 0
set ang = 0
set time = 0
set balls = 0
set period = 0
set i = 0
endfunction
//===============================================================================
//===============================================================================
function sfx_fireball takes nothing returns nothing
call DestroyTimer(GetExpiredTimer())
call PlaySoundOnUnitBJ( gg_snd_i_fireball1, 100, udg_Gustivus )
endfunction
//===============================================================================
//===============================================================================
function g_fireBreath_main takes nothing returns nothing
local unit u = udg_Gustivus
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local timer t = GetExpiredTimer()
local real time = 0
local real delay = s_uDR(u, "ability_firebreath_cast_delay")
local integer casts = s_uDI(u, "ability_firebreath_cast_count")
local integer i = 1
local location l = null
local unit tU = s_uDU(u, "targetHero")
local integer rCasts = s_uDI(u, "ability_firebreath_cast_count_remaining")
local location uL = GetUnitLoc(u)
local location tUL = GetUnitLoc(tU)
local location l2 = GetRectCenter(gg_rct_Dragonbreath)
local integer tI = 0
local string tIS = ""
local real rA = GetRandomReal(-45, 45)
local real a = AngleBetweenPoints(uL, l2)
local real castTime = 6
//MAIN PART
call DestroyTimer(t)
//because this function will loop itself, just plugging leaks
if rCasts > 0 then
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(a + rA, tIS, "angle")
call TimerStart(t, castTime, false, function s_g_fireBreath)
endif
if rCasts > 0 then
set t = CreateTimer()
call s_uDI_s(rCasts - 1, uIS + "_ability_firebreath_cast_count", "remaining")
call TimerStart(CreateTimer(), castTime - 1, false, function sfx_fireball)
call TimerStart(t, delay, false, function g_fireBreath_main)
//ANIMATION
call PlaySoundBJ( gg_snd_mixkit_storm_coming_whoosh_2408 )
call g_roar()
call s_g_lightningHeadFX(5)
call fx_chargeMissile2()
call DisplayTextToForce(GetPlayersAll(), "fire breath")
else
call s_uDI_s(casts, uIS + "_ability_firebreath_cast_count", "remaining")
endif
//PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set t = null
set time = 0
set delay = 0
set casts = 0
set i = 0
call RemoveLocation(l)
set l = null
set tU = null
set rCasts = 0
set uL = null
set tUL = null
call RemoveLocation(l2)
set l2 = null
set tI = 0
set tIS = ""
set rA = 0
set a = 0
set castTime = 0
endfunction
function s_laserProjectileTarget takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local string uIS = I2S(GetHandleId(u))
local location l = s_tDL(tIS, "loc")
local location l2 = s_tDL(tIS, "targetLoc")
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real speedX = 0
local real speedY = 0
local real speedZ = 0
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local location uL = GetUnitLoc(u)
local real angXY = AngleBetweenPoints(uL, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(uL, l2)
local real speedXY = s_tDR(tIS, "speedXY")
local real centerDist = s_tDR(tIS, "centerDist")
local group g = null
local integer pID = s_uDI(u, "owner")
local unit eU = null
local real dmg = s_tDR(tIS, "damage")
local real radius = s_tDR(tIS, "radius")
local location nL = null
//MAIN PART
//math
set nL = PolarProjectionBJ( uL,speedXY * udg_gameloop_fx, angXY)
set z = GetUnitFlyHeight(u)
set z = z + ((distXY - centerDist) / (speedXY * udg_gameloop_fx)) // In theory this creates a clean arc?
call SetUnitPosition(u, GetLocationX(nL), GetLocationY(nL))
//projectile
call SetUnitFlyHeight(u, z, 0)
if z <= 100 and (distXY - centerDist) < 0 then
set g = GetUnitsInRangeOfLocAll(radius, uL)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
if ((BlzIsUnitInvulnerable(eU) == false ) and ( GetConvertedPlayerId(GetOwningPlayer(eU)) != pID )) then // won't hurt caster
call UnitDamageTargetBJ( u, eU, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call KillUnit(u)
call DestroyTimer(t)
call DestroyGroup(g)
call sAI_deleteDataTree(tIS, udg_tempHash)
//call DisplayTextToForce(GetPlayersAll(), "rock boom")
else
call s_tDR_s(speedX, tIS, "speedX")
call s_tDR_s(speedY, tIS, "speedY")
call s_tDR_s(speedZ, tIS, "speedZ")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s(distXY, tIS, "distXY")
call TimerStart(t, udg_gameloop_fx, false, function s_laserProjectileTarget)
//call DisplayTextToForce(GetPlayersAll(), "laser update")
endif
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set speedX = 0
set speedY = 0
set speedZ = 0
set dX = 0
set dY = 0
set dZ = 0
call RemoveLocation(uL)
set uL = null
set eU = null
set angXY = 0
set angZ = 0
set distXY = 0
set speedXY = 0
set centerDist = 0
call DestroyGroup(g)
set g = null
set pID = 0
set dmg = 0
set radius = 0
call RemoveLocation(nL)
set nL = null
endfunction
function s_laserProjectile takes unit u, location l, location l2, real speedXY returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = ""
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local real angXY = AngleBetweenPoints(l, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(l, l2)
//MAIN PART
//math
//projectile
call CreateNUnitsAtLoc( 1, 'h025', GetOwningPlayer(u), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), z, 0)
call s_tDL_s(l, tIS, "loc")
call s_tDL_s(l2, tIS, "targetLoc")
call s_tDR_s(400, tIS, "damage")
call s_tDR_s(200, tIS, "radius")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s((distXY / 2), tIS, "centerDist")
call TimerStart(t, udg_gameloop_fx, false, function s_laserProjectileTarget)
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set dX = 0
set dY = 0
set dZ = 0
set angXY = 0
set angZ = 0
set distXY = 0
endfunction
function g_laserToss takes nothing returns nothing
local unit u = udg_Gustivus
local location l = GetUnitLoc(udg_Gustivus)
local location l2 = null
local location l3 = GetRectCenter(gg_rct_Dragonbreath)
local location l4 = null
// //============================================================
//MAIN PART
set udg_tempReal = AngleBetweenPoints(l, l3)
set l4 = PolarProjectionBJ(l, 100, udg_tempReal)
// //============================================================
// //============================================================
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 12
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set udg_tempReal = GetRandomReal(0, 750.00)
set udg_tempReal2 = GetRandomDirectionDeg()
set l2 = PolarProjectionBJ(l3, udg_tempReal, udg_tempReal2)
set udg_tempReal = GetRandomReal(200.00, 600.00)
call s_laserProjectile(u, l4, l2, udg_tempReal)
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
//PLUG LEAKS
call RemoveLocation(l3)
set l = null
set l2 = null
set l3 = null
set l4 = null
endfunction
function g_earthquake takes nothing returns nothing
local unit u = udg_Gustivus
local unit tU = s_uDU(u, "targetHero")
local location tUL = GetUnitLoc(tU)
//MAIN PART
call IssuePointOrderLocBJ( u, "earthquake", tUL )
call DisplayTextToForce(GetPlayersAll(), "earthquake")
//PLUG LEAKS
call RemoveLocation(tUL)
set tUL = null
set u = null
set tU = null
endfunction
function g_epiclaser_check takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local location uL = GetUnitLoc(u)
local group g = GetUnitsInRangeOfLocAll(250, uL)
local unit eU = null
local player p = GetOwningPlayer(u)
local player tP = null
local integer pI = GetConvertedPlayerId(p)
local integer tPI = 0
local location tUL = null
//MAIN PART
if IsUnitAliveBJ(u) == true then
set eU = FirstOfGroup(g)
loop
exitwhen eU == null or IsUnitAliveBJ(u) == false
set tP = GetOwningPlayer(eU)
if IsPlayerEnemy(p, tP) == true and (BlzIsUnitInvulnerable(eU) == false ) then
call UnitDamageTargetBJ( u, eU, 40, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
set tUL = GetUnitLoc(eU)
call AddSpecialEffectLocBJ( tUL, "Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl" ) //"Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl" "Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeTarget.mdl"
call s_destroyEffect_main(bj_lastCreatedEffect, 8)
call RemoveLocation(tUL)
call s_stun(eU, 3)
//call KillUnit(u)
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call TimerStart(t, 0.125, false, function g_epiclaser_check)
else
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set t = null
set tIS = ""
set u = null
set p = null
set tP = null
set pI = 0
set tPI = 0
set tUL = null
endfunction
function g_epiclaser_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
//MAIN PART
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set u = null
endfunction
//===============================================================================
//===============================================================================
function g_epiclaser_missile takes nothing returns nothing
local unit u = udg_Gustivus
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local location l = s_tDL(tIS, "loc")
local real ang = s_tDR(tIS, "angle")
local real rA = GetRandomDirectionDeg()
local real uF = GetUnitFacing(u)
local location uL = GetUnitLoc(u)
local location l2 = PolarProjectionBJ(uL, 300, ang)
local integer uTI = s_tDI(tIS, "unitTypeId") //h025
//MAIN PART
if uTI == 0 then
set uTI = 'h028'
endif
call CreateNUnitsAtLoc( 1, uTI, GetOwningPlayer(udg_Gustivus), l2, ang )
set l = PolarProjectionBJ(l, 1500, ang)
call IssuePointOrderLoc(GetLastCreatedUnit(), "move", l)
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call TimerStart(t, 5, false, function g_epiclaser_expire)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDU_s(bj_lastCreatedUnit, tIS, "unit")
call TimerStart(t, 0, false, function g_epiclaser_check)
//call DisplayTextToForce(GetPlayersAll(), "cast fb missile")
// PLUG LEAKS
set u = null
set t = null
set tI = 0
set tIS = ""
set l = null
set ang = 0
set rA = 0
set uF = 0
call RemoveLocation(uL)
set uL = null
call RemoveLocation(l2)
set l2 = null
set uTI = 0
endfunction
function g_epiclaser_attack takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local real uF = GetUnitFacing(u)
local real ang = s_tDR(tIS, "angle")
local location l = PolarProjectionBJ(uL, 1500, ang)
local location l1 = PolarProjectionBJ(uL, 450, uF)
local real time = 0
local integer balls = s_uDI(u, "ability_epiclaser_cast_missiles")
local real period = s_uDR(u, "ability_epiclaser_cast_period")
local integer i = 1
//MAIN PART
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
//============================
call RemoveLocation(uL)
//call DisplayTextToForce(GetPlayersAll(), "balls " + I2S(balls))
loop
exitwhen i > balls
set uL = GetUnitLoc(u)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(ang, tIS, "angle")
call s_tDL_s(uL, tIS, "loc")
call TimerStart(t, time, false, function g_epiclaser_missile)
set time = time + period
set i = i + 1
//call DisplayTextToForce(GetPlayersAll(), I2S(i))
endloop
call SetUnitAnimation( udg_Gustivus, "spell" )
call QueueUnitAnimationBJ( udg_Gustivus, "stand" )
//PLUG LEAKS
call RemoveLocation(l)
call RemoveLocation(l1)
set uL = null
set l = null
set l1 = null
set t = null
set tI = 0
set tIS = ""
set uF = 0
set ang = 0
set time = 0
set balls = 0
set period = 0
set i = 0
endfunction
//===============================================================================
//===============================================================================
function g_epiclaser takes nothing returns nothing
local unit u = udg_Gustivus
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local timer t = GetExpiredTimer()
local real time = 0
local real delay = s_uDR(u, "ability_epiclaser_cast_delay")
local integer casts = s_uDI(u, "ability_epiclaser_cast_count")
local integer i = 1
local location l = null
local unit tU = s_uDU(u, "targetHero")
local integer rCasts = s_uDI(u, "ability_epiclaser_cast_count_remaining")
local location uL = GetUnitLoc(u)
local location tUL = GetUnitLoc(tU)
local location l2 = GetRectCenter(gg_rct_Dragonbreath)
local integer tI = 0
local string tIS = ""
local real rA = 0
local real a = AngleBetweenPoints(uL, l2)
local real castTime = 4
local timer t2 = null
//MAIN PART
call DestroyTimer(t)
//because this function will loop itself, just plugging leaks
if rCasts > 0 then
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(a, tIS, "angle")
call TimerStart(t, castTime, false, function g_epiclaser_attack)
endif
if rCasts > 0 then
set t = CreateTimer()
call s_uDI_s(rCasts - 1, uIS + "ability_epiclaser_cast_count", "remaining")
call TimerStart(t, delay, false, function g_epiclaser)
else
call s_uDI_s(casts, uIS + "ability_epiclaser_cast_count", "remaining")
endif
//ANIMATION
call g_darkness(4, 0)
call s_g_lightningHeadFX(5)
set t2 = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(12, tIS, "scale_start")
call s_tDR_s(0.1, tIS, "scale_end")
call TimerStart(t2, 0, false, function fx_chargeMissile2)
//call DisplayTextToForce(GetPlayersAll(), "epic laser")
//PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set t = null
set time = 0
set delay = 0
set casts = 0
set i = 0
call RemoveLocation(l)
set l = null
set tU = null
set rCasts = 0
set uL = null
set tUL = null
call RemoveLocation(l2)
set l2 = null
set tI = 0
set tIS = ""
set rA = 0
set a = 0
set castTime = 0
set t2 = null
endfunction
function s_projectileMissile takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit") // gets the original caster
local integer uI = 0
local string uIS = ""
local location l = s_tDL(tIS, "loc")
local location l2 = s_tDL(tIS, "targetLoc")
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real speedX = 0
local real speedY = 0
local real speedZ = 0
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local location uL = GetUnitLoc(u)
local real angXY = AngleBetweenPoints(uL, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(uL, l2)
local real speedXY = s_tDR(tIS, "speedXY")
local real centerDist = s_tDR(tIS, "centerDist")
local group g = null
local integer pID = s_uDI(u, "owner")
local unit eU = null
local real dmg = s_tDR(tIS, "damage")
local real radius = s_tDR(tIS, "radius")
local location nL = null
local integer missileT = s_tDI(tIS, "unitTypeId")
//MAIN PART
//math
if missileT == 0 then
set missileT = 'h025'
endif
call CreateNUnitsAtLoc( 1, missileT, GetOwningPlayer(u), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), z, 0)
set u = GetLastCreatedUnit()
set uI = GetHandleId(u)
set uIS = I2S(uI)
set uL = GetUnitLoc(u)
set angXY = AngleBetweenPoints(l, l2)
set distXY = DistanceBetweenPoints(l, l2)
set nL = PolarProjectionBJ( l,speedXY * udg_gameloop_fx, angXY)
set z = GetUnitFlyHeight(u)
set z = z + ((distXY - centerDist) / (speedXY * udg_gameloop_fx)) // In theory this creates a clean arc?
call SetUnitPosition(u, GetLocationX(nL), GetLocationY(nL))
//projectile
call SetUnitFlyHeight(u, z, 0)
if z <= 100 and (distXY - centerDist) < 0 then
set g = GetUnitsInRangeOfLocAll(radius, uL)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
if ((BlzIsUnitInvulnerable(eU) == false ) and ( GetConvertedPlayerId(GetOwningPlayer(eU)) != pID )) then // won't hurt caster
call UnitDamageTargetBJ( u, eU, dmg, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call KillUnit(u)
call DestroyTimer(t)
call DestroyGroup(g)
call sAI_deleteDataTree(tIS, udg_tempHash)
//call DisplayTextToForce(GetPlayersAll(), "rock boom")
else
call s_tDR_s(speedX, tIS, "speedX")
call s_tDR_s(speedY, tIS, "speedY")
call s_tDR_s(speedZ, tIS, "speedZ")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s(distXY, tIS, "distXY")
call TimerStart(t, udg_gameloop_fx, false, function s_laserProjectileTarget)
//call DisplayTextToForce(GetPlayersAll(), "laser update")
endif
if s_tDB(tIS, "theEnd") == true then
call KillUnit(udg_Kael)
call KillUnit(udg_Saira)
endif
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uI = 0
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set speedX = 0
set speedY = 0
set speedZ = 0
set dX = 0
set dY = 0
set dZ = 0
call RemoveLocation(uL)
set uL = null
set eU = null
set angXY = 0
set angZ = 0
set distXY = 0
set speedXY = 0
set centerDist = 0
call DestroyGroup(g)
set g = null
set pID = 0
set dmg = 0
set radius = 0
call RemoveLocation(nL)
set nL = null
set missileT = 0
endfunction
function s_projectile takes timer t returns nothing
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = s_tDU(tIS, "unit")
local location l = s_tDL(tIS, "loc")
local location l2 = s_tDL(tIS, "targetLoc")
local real speedXY = s_tDR(tIS, "speedXY")
local real delay = s_tDR(tIS, "delay")
//
local string uIS = ""
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local real angXY = AngleBetweenPoints(l, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(l, l2)
local integer uTI = s_tDI(tIS, "unitTypeId")
//MAIN PART
//math
//projectile
call s_tDL_s(l, tIS, "loc")
call s_tDL_s(l2, tIS, "targetLoc")
if s_tDR(tIS, "damage") == 0 then
call s_tDR_s(400, tIS, "damage")
endif
if s_tDR(tIS, "radius") == 0 then
call s_tDR_s(200, tIS, "radius")
endif
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s((distXY / 2), tIS, "centerDist")
if uTI == 0 then
call s_tDI_s('h025', tIS, "unitTypeId")
endif
call TimerStart(t, delay, false, function s_projectileMissile)
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set dX = 0
set dY = 0
set dZ = 0
set angXY = 0
set angZ = 0
set distXY = 0
set uTI = 0
endfunction
function g_spiritbomb takes nothing returns nothing
local unit u = udg_Gustivus
local location l = GetUnitLoc(udg_Gustivus)
local location l2 = null
local location l3 = GetRectCenter(gg_rct_Dragonbreath)
local location l4 = null
local timer t = CreateTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local real chargeTime = 60
local real delay = 0
//MAIN PART
//CHARGE EFFECT
call s_tDR_s(0.1, tIS, "scale_start")
call s_tDR_s(6, tIS, "scale_end")
call s_tDR_s(chargeTime, tIS, "charge_time")
call s_tDR_s(-150, tIS, "dist")
call s_tDR_s(200, tIS, "height")
//call s_tDS_s("Abilities\\Weapons\\FarseerMissile\\FarseerMissile.mdl", tIS, "effectType_string")
call s_tDR_s(1, tIS, "pulse_min")
call s_tDU_s(u, tIS, "unit")
call s_tDL_s(l, tIS, "loc")
call TimerStart(t, delay, false, function fx_chargeMissile2)
// //============================================================
// //============================================================
set udg_tempReal = AngleBetweenPoints(l, l3)
set l4 = PolarProjectionBJ(l, 100, udg_tempReal)
// //============================================================
// //============================================================
//SHOOT GIANT SPIRIT BOMB
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
set udg_tempReal = 150
call s_tDU_s(u, tIS, "unit")
call s_tDL_s(l4, tIS, "loc")
call s_tDL_s(l3, tIS, "targetLoc")
call s_tDR_s(udg_tempReal, tIS, "speedXY")
call s_tDR_s(chargeTime - 1, tIS, "delay")
call s_tDR_s(8, tIS, "scale")
call s_tDI_s('h026', tIS, "unitTypeId")
call s_tDR_s(2000, tIS, "radius")
call s_tDR_s(5000, tIS, "damage")
call s_tDB_s(true, tIS, "theEnd")
call s_projectile(t)
//FINAL WORDS
call TimerStart(CreateTimer(), chargeTime - 1, false, function g_finalWords)
//FINAL LIGHT
call g_light(5, chargeTime + 10)
//PLUG LEAKS
set u = null
set t = null
set tI = 0
set tIS = ""
set l = null
set l2 = null
set l3 = null
set l4 = null
set chargeTime = 0
set delay = 0
endfunction
function sAI_GustivusAI_main takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
//local integer numAbils = s_uDI(u, "ability_metaList_numList") + s_uDI(u, "ability_numList") // update names, also maybe move meta data to Child param
local integer numAbils = 4
local integer i = GetRandomInt(1, numAbils)
local integer i2 = 1
local location l = GetRectCenter(gg_rct_Gustivus_Start)
local boolean casting = false
local real lifeP = GetUnitLifePercent(u)
//MAIN PART
//============================================
//testing
//============================================
//set i = 5
//============================================
call SetUnitPosition(u, GetLocationX(l), GetLocationY(l))
call SetUnitFacingToFaceLocTimed( udg_Gustivus, GetRectCenter(gg_rct_Dragonbreath), 1.00 )
if lifeP < 45 then
call s_uDI_s(6, uIS, "ability_firebreath_cast_count")
call s_uDI_s(9, uIS, "ability_laserball_cast_count")
elseif lifeP < 66 then
call s_uDI_s(4, uIS, "ability_firebreath_cast_count")
call s_uDI_s(6, uIS, "ability_laserball_cast_count")
elseif lifeP < 85 then
call s_uDI_s(2, uIS, "ability_firebreath_cast_count")
endif
if lifeP < 25 then
set i = 5
endif
if s_uDB(u, "currentlyCasting") == false then
if i == i2 then
call g_sTentacle_main()
call s_uDS_s("Spawn Spider Tentacles", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_SpawnTentacles, false, 30)
endif
set i2 = i2 + 1
if i == i2 then
call g_fireBreath_main()
call s_uDS_s("firebreath", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_Firebreath, false, 30)
endif
set i2 = i2 + 1
if i == i2 then
call g_epiclaser()
call s_uDS_s("epiclaser", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_EpicLaser, false, 20)
endif
set i2 = i2 + 1
if i == i2 then
call g_laserToss()
call s_uDS_s("laserballs", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_Laserballs, false, 20)
endif
set i2 = i2 + 1
if i == i2 then
call g_spiritbomb()
call s_uDS_s("spiritbomb", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_Spiritbomb, false, 70)
endif
set i2 = i2 + 1
if i == i2 then
call g_earthquake()
call s_uDS_s("earthquake", uIS, "casting")
call s_uDB_s(true, uIS, "currentlyCasting")
call StartTimerBJ(udg_Timer_Gustivus_Earthquake, false, 30)
endif
set i2 = i2 + 1
endif
//call DisplayTextToForce(GetPlayersAll(), "gustivus ai loop")
//PLUG LEAKS
set u = null
set uIS = ""
set numAbils = 0
set i = 0
call RemoveLocation(l)
set l = null
set casting = false
set lifeP = 0
endfunction
function sAI_GustivusAI_init takes nothing returns nothing
local unit u = udg_Gustivus
local string uIS = I2S(GetHandleId(u))
local location l = GetRectCenter(gg_rct_Dragonbreath)
local integer hI = GetTerrainCliffLevelBJ(l)
//MAIN PART
//ABILITIES
call s_uDS_s("", uIS, "ability") //start root preliminaries (or create function)
call s_uDR_s(300, uIS + "_ability_firestorm", "damage") // for next update
//SUMMON TENTACLES
call s_uDS_s("", uIS + "_ability", "spawn_tentacles")
call s_uDS_s("", uIS + "_ability_spawn_tentacles", "cast")
call s_uDR_s(1, uIS + "_ability_spawn_tentacles", "delay")
call s_uDR_s(0.125, uIS + "_ability_spawn_tentacles", "period")
//=============================
call s_uDI_s(6, uIS + "_ability_spawn_tentacles_cast", "count")
call s_uDI_s(6, uIS + "_ability_spawn_tentacles_cast_count", "remaining")
//=============================
call sAI_saveStringParameter("", "lightning", "Units_" + uIS, udg_UnitAI)
call s_uDI_s(6, uIS, "ability_lightning_cast_count")
//FIREBREATH
call s_uDS_s("", uIS + "_ability", "firebreath")
call s_uDS_s("", uIS + "_ability_firebreath", "cast")
//preliminaries done
call s_uDR_s(0.25, uIS + "_ability_firebreath_cast", "period")
call s_uDR_s(5, uIS + "_ability_firebreath_cast", "delay")
call s_uDI_s(12, uIS + "_ability_firebreath_cast", "missiles")
call s_uDI_s(1, uIS + "_ability_firebreath_cast", "count") // start as test
call s_uDI_s(1, uIS + "_ability_firebreath_cast_count", "remaining")
//EPICLASER
call s_uDS_s("", uIS + "_ability", "epiclaser")
call s_uDS_s("", uIS + "_ability_epiclaser", "cast")
//preliminaries done
call s_uDR_s(0.0625, uIS + "_ability_epiclaser_cast", "period")
call s_uDR_s(10, uIS + "_ability_epiclaser_cast", "delay")
call s_uDI_s(36, uIS + "_ability_epiclaser_cast", "missiles")
call s_uDI_s(1, uIS + "_ability_epiclaser_cast", "count")
call s_uDI_s(1, uIS + "_ability_epiclaser_cast_count", "remaining")
//LASER BALLS
call s_uDS_s("", uIS + "_ability", "laserballs")
call s_uDS_s("", uIS + "_ability_laserballs", "cast")
//preliminaries done
call s_uDR_s(0.5, uIS + "_ability_laserballs_cast", "period")
call s_uDR_s(10, uIS + "_ability_laserballs_cast", "delay")
call s_uDI_s(4, uIS + "_ability_laserballs_cast", "missiles")
call s_uDI_s(2, uIS + "_ability_laserballs_cast", "count")
call s_uDI_s(1, uIS + "_ability_laserballs_cast_count", "remaining")
//SPIRIT BOMB
call s_uDS_s("", uIS + "_ability", "spiritbomb")
call s_uDS_s("", uIS + "_ability_spiritbomb", "cast")
//preliminaries done
call s_uDR_s(0.5, uIS + "_ability_spiritbomb_cast", "period")
call s_uDR_s(10, uIS + "_ability_spiritbomb_cast", "delay")
call s_uDI_s(4, uIS + "_ability_spiritbomb_cast", "missiles")
call s_uDI_s(2, uIS + "_ability_spiritbomb_cast", "count")
call s_uDI_s(1, uIS + "_ability_spiritbomb_cast_count", "remaining")
//EARTHQUAKE
//shakes screen, random boulder tosses from earthquake zones
// or summons or meteors
call s_uDS_s("", uIS + "_ability", "earthquake")
call s_uDS_s("", uIS + "_ability_earthquake", "cast")
//preliminaries done
//call s_uDR_s(0.5, uIS + "_ability_earthquake_cast", "period")
//call s_uDR_s(3, uIS + "_ability_earthquake_cast", "delay")
//=================================================================
//=================================================================
//=================================================================
call IssueImmediateOrderBJ(u, "holdposition")
call EnableTrigger(gg_trg_Gustivus_AI_Loop)
//PLUG LEAKS
set u = null
set uIS = ""
endfunction
function s_projectileAbility takes string s returns nothing
//PLUG LEAKS
set s = ""
endfunction
function s_SpiderQueenCheckDest takes nothing returns nothing
local unit u = udg_SpiderQueen
local location uL = GetUnitLoc(u)
local real dist = DistanceBetweenPoints(udg_SpiderQueen_Dest, uL)
//MAIN PART
if ((dist <= 2.0) or (TimerGetRemaining(udg_SpiderQueen_Impatience) == 0)) then
call RemoveLocation(udg_SpiderQueen_Dest)
set udg_SpiderQueen_Dest = null
else
call IssuePointOrderLoc(udg_SpiderQueen, "move", udg_SpiderQueen_Dest)
endif
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set dist = 0
set u = null
endfunction
function s_sQ_rockFallEffect takes nothing returns nothing
local timer t = GetExpiredTimer()
local string s = I2S(GetHandleId(t)) + "_unit"
local unit u = LoadUnitHandleBJ(0, StringHashBJ(s), udg_tempHash)
local location uL = GetUnitLoc(u)
//MAIN PART
call CameraClearNoiseForPlayer( Player(0) )
call KillUnit(u)
//call DisplayTextToForce( GetPlayersAll(), "boop" )
call PlaySoundAtPointBJ( gg_snd_ThunderBoltMissileDeath, 100, uL, 0 )
call FlushChildHashtableBJ( StringHashBJ(s), udg_tempHash )
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
call DestroyTimer(t)
set s = ""
set t = null
set u = null
endfunction
function s_sQ_rockFall takes nothing returns nothing
local location l = null
local integer i = 1
local integer iC = udg_SpiderQueen_Rocks
local real speed = 200
local real height = 0
local real time = 0
local unit u = null
local timer t = null
local location uL = GetUnitLoc(udg_SpiderQueen)
//mew
local location l1 = GetRectCenter(gg_rct_sQ_move_to)
local location l2 = GetCameraTargetPositionLoc()
local real r = DistanceBetweenPoints(l1, l2)
//MAIN PART
if (r < 1500.00 ) then
call CameraSetEQNoiseForPlayer( Player(0), 2.00 )
endif
call PlaySoundAtPointBJ( gg_snd_ThunderClapCaster, 100, uL, 0 )
loop
exitwhen (i > iC)
set l = GetRandomLocInRect(gg_rct_rocks)
call CreateNUnitsAtLoc( 1, 'n01G', GetOwningPlayer(udg_SpiderQueen), l, GetRandomDirectionDeg() )
set u = GetLastCreatedUnit()
set height = BlzGetLocalUnitZ(u)
call SetUnitFlyHeightBJ( u, -50, speed )
if (speed != 0) then
set t = CreateTimer()
call sAI_saveUnitParameter(u, "unit", I2S(GetHandleId(t)), udg_tempHash)
set time = height / speed
set time = 2
call TimerStart(t, time, false, function s_sQ_rockFallEffect)
endif
call RemoveLocation(l)
set i = i + 1
endloop
call StartTimerBJ(udg_SpiderQueen_RockTimer, false, 20)
// PLUG LEAKS
call RemoveLocation(l)
set l = null
call RemoveLocation(uL)
set uL = null
call RemoveLocation(l1)
set l1 = null
call RemoveLocation(l2)
set l2 = null
set i = 0
set iC = 0
set r = 0
set speed = 0
set height = 0
set time = 0
set u = null
endfunction
function s_sQ_spawnSpiders takes nothing returns nothing
endfunction
function s_sQ_throwHammer takes nothing returns nothing
if (UnitHasItemOfTypeBJ(udg_SpiderQueen, 'I00P') == false) then // replace with throwable hammer
// "i'll get my hammer!"
else
endif
endfunction
function s_sQ_move takes nothing returns nothing
call IssuePointOrderLoc(udg_SpiderQueen, "move", udg_SpiderQueen_Dest)
endfunction
function s_sQ_move takes nothing returns nothing
call IssuePointOrderLoc(udg_SpiderQueen, "move", udg_SpiderQueen_Dest)
endfunction
function s_sQ_move takes nothing returns nothing
call IssuePointOrderLoc(udg_SpiderQueen, "move", udg_SpiderQueen_Dest)
endfunction
function s_sQ_return takes nothing returns nothing
local location l = null
local unit u = udg_SpiderQueen
//MAIN PART
if ( RectContainsUnit(gg_rct_spiderqueenreturn, udg_SpiderQueen) == true ) then
call SetUnitFacingToFaceLocTimed( udg_SpiderQueen, GetRectCenter(gg_rct_spiderqueenface), 0 )
else
call IssuePointOrderLocBJ( udg_SpiderQueen, "move", GetRectCenter(gg_rct_spiderqueenreturn) )
endif
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
endfunction
function s_sQ_emerge takes nothing returns nothing
local location l = null
local integer i = GetRandomInt(1,4)
local integer i2 = 1
local unit u = udg_SpiderQueen
//MAIN PART
if (i == i2) then
set l = GetRectCenter(gg_rct_sQ1)
endif
set i2 = i2 + 1
if (i == i2) then
set l = GetRectCenter(gg_rct_sQ2)
endif
set i2 = i2 + 1
if (i == i2) then
set l = GetRectCenter(gg_rct_sQ3)
endif
set i2 = i2 + 1
if (i == i2) then
set l = GetRectCenter(gg_rct_sQ4)
endif
set i2 = i2 + 1
call SetUnitPositionLoc( u, l )
call ShowUnitShow( u )
call SetUnitInvulnerable( udg_SpiderQueen, false )
call PauseUnitBJ( false, udg_SpiderQueen )
set udg_SpiderQueen_Hidden = false
//set udg_SpiderQueen_Spell = udg_str_move
call RemoveLocation(udg_SpiderQueen_Dest)
set udg_SpiderQueen_Dest = GetRandomLocInRect(gg_rct_sQ_move_to)
call s_sQ_return()
//PLUG LEAKS
set u = null
call RemoveLocation(l)
set l = null
set i = 0
set i2 = 0
endfunction
function s_sQ_hideEffect takes nothing returns nothing
local unit u = udg_SpiderQueen
//MAIN PART
call ShowUnitHide( u )
call SetUnitFlyHeightBJ( u, 0, 9000 )
call DestroyEffectBJ( udg_SpiderQueen_LaunchFX )
//PLUG LEAKS
call DestroyTimer(GetExpiredTimer())
set u = null
endfunction
function s_sQ_hide takes nothing returns nothing // launches directly up
local unit u = udg_SpiderQueen
local location uL = GetUnitLoc(u)
//MAIN PART
call AddSpecialEffectLocBJ( uL, "Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl" )
set udg_SpiderQueen_LaunchFX = GetLastCreatedEffectBJ()
call SetUnitFlyHeightBJ( u, 600, 600 )
call PlaySoundAtPointBJ( gg_snd_ThunderBoltMissileDeath, 100, uL, 0 )
call SetUnitInvulnerable( udg_SpiderQueen, true )
call PauseUnitBJ( true, udg_SpiderQueen )
set udg_SpiderQueen_Hidden = true
call EnableTrigger( gg_trg_SQ_Emerge_Timer )
call StartTimerBJ(udg_SpiderQueen_EmergeTimer, false, 10)
call TimerStart(CreateTimer(), 1, false, function s_sQ_hideEffect)
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
set u = null
endfunction
function s_isUnitEnemy takes nothing returns boolean
return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(udg_SpiderQueen)) == true )
endfunction
function s_spiderQueenUseSpell takes nothing returns nothing
local integer i = GetRandomInt(1,2)
local string s = udg_SpiderQueen_Spell
local group g = GetUnitsInRectMatching(gg_rct_Optic_Queen_Battlezone, Condition(function s_isUnitEnemy))
local unit u = GroupPickRandomUnit(g)
local location uL = GetUnitLoc(u)
//MAIN PART
if (s == udg_str_spawnSpiders) then
call s_sQ_spawnSpiders()
endif
if ((s == udg_str_rockFall)) then
call s_sQ_rockFall()
endif
if (s == udg_str_ensnare) then
call IssueTargetOrderBJ( udg_SpiderQueen, "ensnare", u )
endif
if (s == udg_str_retreat) then
if ((udg_SpiderQueen_Hidden == false) and (TimerGetRemaining(udg_SpiderQueen_EmergeTimer) <= 0) and (TimerGetRemaining(udg_SpiderQueen_RockTimer) <= 0)) then
call s_sQ_hide()
endif
endif
if (s == udg_str_attack) then
call IssueTargetOrderBJ( udg_SpiderQueen, "attack", u )
endif
if (s == udg_str_laser) then
call IssueTargetOrderBJ( udg_SpiderQueen, "shadowstrike", u )
endif
if (s == udg_str_throwHammer) then
call IssueTargetOrderBJ( udg_SpiderQueen, "thunderbolt", u )
endif
if (s == udg_str_move) then
call s_sQ_move()
endif
//PLUG LEAKS
call DestroyGroup(g)
set g = null
call RemoveLocation(uL)
set uL = null
set u = null
set s = ""
set i = 0
endfunction
function s_spiderQueenSelectSpell takes nothing returns nothing
local integer i = GetRandomInt(1,6)
local integer i2 = 1
//MAIN PART
//MAIN
if (udg_SpiderQueen_Spell == udg_str_retreat) then
//=============================
else
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_spawnSpiders
endif
set i2 = i2 + 1
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_ensnare
endif
set i2 = i2 + 1
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_retreat
endif
set i2 = i2 + 1
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_throwHammer
endif
set i2 = i2 + 1
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_laser
endif
set i2 = i2 + 1
if (i == i2) then
set udg_SpiderQueen_Spell = udg_str_attack
endif
set i2 = i2 + 1
endif
//CATCHES
if (udg_SpiderQueen_Hidden == true) and (TimerGetRemaining(udg_SpiderQueen_EmergeTimer) > 0 ) then
set udg_SpiderQueen_Spell = udg_str_rockFall
elseif (udg_SpiderQueen_Hidden == true) and (TimerGetRemaining(udg_SpiderQueen_EmergeTimer) <= 0 ) then
set udg_SpiderQueen_Spell = udg_str_retreat
endif
if ((udg_SpiderQueen_Hidden == false) and (udg_SpiderQueen_Enemies == false)) then
set udg_SpiderQueen_Spell = ""
call s_sQ_return()
endif
//PLUG LEAKS
set i = 0
set i2 = 0
endfunction
function s_spiderQueenAI takes nothing returns nothing
local unit u = udg_SpiderQueen
//MAIN PART
call s_spiderQueenSelectSpell()
call s_spiderQueenUseSpell()
//PLUG LEAKS
set u = null
endfunction
function s_rP_findIdleReplacement takes unit u, string dLS returns nothing
local string uIS = I2S(GetHandleId(u))
local location l = null
local group g = null
//
local unit eU = null
local string uTS = s_uDS(u, dLS + "_uTS") // to avoid confusion with index names, although the root dir will be uTS, it just saves it within index too
local integer pID = GetConvertedPlayerId(GetOwningPlayer(u))
local boolean rPFound = false
local group rPG = null
local group availableGroup = LoadGroupHandleBJ(0, StringHashBJ("Player_" + I2S(pID) + "_army_idle"), udg_PlayerAI[pID])
local integer availableUnits = LoadIntegerBJ(0, StringHashBJ("Player_" + I2S(pID) + "_army_idle_" + uTS + "_indexCount"), udg_PlayerAI[pID])
local group targetGroup = null // where the requested unit is going, the AI records the guard position as where the player orders it, "command level" orders
//MAIN PART
if (availableUnits > 0) then
set eU = FirstOfGroup(availableGroup)
loop
exitwhen (eU == null)
if (UnitId2StringBJ(GetUnitTypeId(eU)) == uTS) then
call s_rP_assignReplaceUnit(u, eU)
endif
set eU = FirstOfGroup(availableGroup)
endloop
else
endif
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call DestroyGroup(g)
set g = null
set u = null
set uIS = ""
set uTS = ""
endfunction
function rP_recallGuard takes unit rP, unit u returns nothing
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local integer rPI = GetHandleId(rP)
local string rPIS = I2S(rPI)
local string oS = s_uDS(u, "issued_order")
local location l = s_uDL(u, "issued_order_loc")
local unit tU = s_uDU(u, "issued_order_unit")
local real dist = 0
local location l1 = GetUnitLoc(rP)
local location l2 = GetUnitLoc(u)
local real gDist = 1500
local location gL = s_uDL(rP, "rebuild_" + uIS + "_loc")
local boolean isHarvester = s_uDB(u, "harvester")
//MAIN PART
set dist = DistanceBetweenPoints(l1, l)
if gL != null and dist > gDist and isHarvester == false then
call IssuePointOrderLocBJ(u, "move", gL)
endif
//PLUG LEAKS
set uI = 0
set uIS = ""
set rPI = 0
set rPIS = ""
set oS = ""
set l = null
set tU = null
set dist = 0
call RemoveLocation(l1)
call RemoveLocation(l2)
set l1 = null
set l2 = null
set gDist = 0
set gL = null
set isHarvester = false
endfunction
function rP_setUnitOrder takes unit rP, integer i returns nothing
local integer rPI = GetHandleId(rP)
local string rPIS = I2S(rPI)
local real dist = 0
local location l1 = GetUnitLoc(rP)
local string iS = I2S(i)
local location gL = s_uDL(rP, "rebuild_" + iS + "_loc")
local unit u = s_uDU(rP, "rebuild_" + iS)
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local location l2 = GetUnitLoc(u)
local location l = s_uDL(u, "issued_order_loc")
local player p = GetOwningPlayer(u)
local integer pI = GetConvertedPlayerId(p)
local boolean selected = IsUnitSelected(u, p) == true
local boolean byPlayer = s_uDB(u, "issued_order_byPlayer")
local string oS = s_uDS(u, "issued_order")
local unit tU = s_uDU(u, "harvest_target_unit")
local destructable tD = s_uDDE(u, "harvest_target_destructible")
local string hType = s_uDS(u, "harvest_target_type")
local boolean iH = s_uDB(u, "harvester")
//MAIN PART
if l != null then
set dist = DistanceBetweenPoints(l1, l)
if (gL == null or byPlayer == true) and dist <= 1500 then
set gL = l
call s_uDL_s(l, rPIS, "rebuild_" + iS + "_loc")
endif
endif
set dist = DistanceBetweenPoints(l1, l2)
if gL == null and dist <= 1500 then
set gL = l
call s_uDL_s(l2, rPIS, "rebuild_" + iS + "_loc")
else
call RemoveLocation(l2)
endif
if selected == false then
if iH == true and oS == "stop" then
if hType == "unit" then
call IssueTargetOrderBJ(u, "harvest", tU)
elseif hType == "destructible" then
call IssueTargetOrderBJ(u, "harvest", tD)
endif
endif
if iH == false and byPlayer == false and oS != "resumeharvesting" then
call IssuePointOrderLocBJ(u, "attack", gL)
endif
endif
//PLUG LEAKS
call RemoveLocation(l1)
set rPI = 0
set rPIS = ""
set dist = 0
set l1 = null
set l2 = null
set iS = ""
set gL = null
set u = null
set uI = 0
set uIS = ""
set p = null
set pI = 0
set selected = false
set oS = ""
set tU = null
set tD = null
set hType = ""
set iH = false
endfunction
function s_reportPost_addUnit takes unit rP, unit u returns nothing
local string rPIS = I2S(GetHandleId(rP))
local string uTS = UnitId2StringBJ(GetUnitTypeId(u))
local string uIS = I2S(GetHandleId(u))
local location l = GetUnitLoc(u)
local string iS = ""
local integer sI = 0
//MAIN PART
call s_uDB_s(true, uIS, "isInReportPostGroup")
call s_uDU_s(rP, uIS, "reportPost")
// save index, because uIS' would be replaced anyway
call sAI_addUnitParameter(u, "rebuild", "Units_" + rPIS, udg_UnitAI)
set udg_tempString = udg_lastPLS
call sAI_saveStringParameter(uTS, "unitType", udg_tempString, udg_UnitAI)
set sI = StringHash(udg_tempString + "_name")
set iS = LoadStringBJ(0, sI, udg_UnitAI)
set sI = S2I(iS)
call rP_setUnitOrder(rP, sI)
// or current order target loc if move etc
//call DisplayTextToForce( GetPlayersAll(), "adding to group of " + rPIS + "_rebuild_group" )
//PLUG LEAKS
set rP = null
set u = null
set rPIS = ""
set l = null
set uTS = ""
set uIS = ""
set iS = ""
set sI = 0
endfunction
function s_reportPost_addUnitGroup takes unit rP, group uG returns nothing
local string rPIS = I2S(GetHandleId(rP))
local group g = s_uDG(rP, "rebuild_group")
//
local group tG = CreateGroup()
local unit eU = null
//MAIN PART
if (g == null) then
set g = CreateGroup()
call s_uDG_s(g, rPIS, "rebuild_group")
endif
call GroupAddGroup(tG, uG)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
call s_reportPost_addUnit(rP, eU)
call GroupRemoveUnit(tG, eU)
set eU = FirstOfGroup(tG)
endloop
//PLUG LEAKS
call DestroyGroup(tG)
set tG = null
set rP = null
set uG = null
set rPIS = ""
set g = null
endfunction
function s_reportPost_addUnit takes unit rP, unit u returns nothing
local string rPIS = I2S(GetHandleId(rP))
local group g = s_uDG(rP, "rebuild_group")
local string uTS = UnitId2StringBJ(GetUnitTypeId(u))
local string uIS = I2S(GetHandleId(u))
//
local location l = GetUnitLoc(u)
//MAIN PART
if (g == null) then
set g = CreateGroup()
call s_uDG_s(g, rPIS, "rebuild_group")
endif
call GroupAddUnit(g, u)
call s_uDB_s(true, uIS, "isInReportPostGroup")
call s_uDU_s(rP, uIS, "reportPost")
call sAI_addUnitParameter(u, "reportPost_unit", rPIS, udg_UnitAI)
set udg_tempString = udg_lastPLS
call s_uDI_s(LoadIntegerBJ(0, StringHash("Units_" + rPIS + "_reportPost_unit_indexCount"), udg_UnitAI), uIS, "reportPostIndex")
call sAI_saveStringParameter(uTS, "unitType", udg_tempString, udg_UnitAI)
call sAI_saveLocationParameter(l, "guardPost", udg_tempString, udg_UnitAI) // or current order target loc if move etc
call DisplayTextToForce( GetPlayersAll(), "adding to group of " + rPIS + "_rebuild_group" )
//PLUG LEAKS
set rP = null
set u = null
set rPIS = ""
set g = null
set uTS = ""
set uIS = ""
endfunction
function s_reportPost_clearGroup takes unit rP returns nothing
local string rPIS = I2S(GetHandleId(rP))
local group g = s_uDG(rP, "rebuild_group")
local unit eU = FirstOfGroup(g)
local string eUIS = ""
//
local string iS = ""
local string lIS = ""
//MAIN PART
//call DisplayTextToForce( GetPlayersAll(), "clearing group of " + rPIS + "_rebuild_group" )
if g != null then
//call DisplayTextToForce( GetPlayersAll(), "group exists" )
else
//call DisplayTextToForce( GetPlayersAll(), "group doesn't exist" )
endif
loop
exitwhen eU == null
set eUIS = I2S(GetHandleId(eU))
call s_uDB_s(false, eUIS, "isInReportPostGroup")
call s_uDU_s(null, eUIS, "reportPost")
call UnitRemoveBuffBJ( 'Bspl', eU )
call s_uDI_s(0, eUIS, "reportPostIndex")
//call DisplayTextToForce( GetPlayersAll(), "cleared unit" )
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call sAI_deleteDataTree("Units_" + rPIS + "_reportPost_unit", udg_UnitAI) //Clearing all units, not rearranging for dead one which just gets replaced, not cleared yet
call GroupClear( g )
//PLUG LEAKS
set rP = null
set rPIS = ""
set g = null
set eU = null
set eUIS = ""
endfunction
function s_playerCanBuild takes integer pI, string tUTS returns boolean
local string pIS = I2S(pI)
local integer count = 0
//MAIN PART
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_indexCount") // check this
set count = LoadIntegerBJ( 0, udg_tempInt, udg_PlayerAI[pI])
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_metaList_indexCount")
set count = count + udg_tempInt
if count != 0 then
set udg_tempBoolean = true
//call DisplayTextToForce( GetPlayersAll(), "player can build " + tUTS )
else
set udg_tempBoolean = false
//call DisplayTextToForce( GetPlayersAll(), "player can NOT build " + tUTS )
endif
//PLUG LEAKS
set pI = 0
set pIS = ""
set tUTS = ""
set count = 0
//RETURNS
return udg_tempBoolean
endfunction
function s_trainingCount takes unit u, string tUTS returns integer
//MAIN PART
set udg_tempInt = s_uDI(u, "training_" + tUTS + "_count")
//PLUG LEAKS
set u = null
set tUTS = ""
//RETURNS
return udg_tempInt
endfunction
function s_unitTrained takes nothing returns nothing
local unit trainer = GetTriggerUnit()
local unit trained = GetTrainedUnit()
local integer pI = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string tRIS = I2S(GetHandleId(trainer))
local string tRIS2 = I2S(GetHandleId(trained))
local string tUTS = UnitId2StringBJ(GetUnitTypeId(trainer))
local string uTS = UnitId2StringBJ(GetUnitTypeId(trained))
local integer i = s_uDI(trainer, "training_" + uTS + "_count")
local integer sI = 0
local group g = null
//MAIN PART
call s_uDI_s(i - 1, tRIS, "training_" + uTS + "_count")
if s_uDI( trainer, "wants_" + uTS + "_count") > 0 then
call s_uDI_s(i - 1, tRIS, "wants_" + uTS + "_count")
endif
if s_uDB(trainer, "autosupply") == true then
call s_uDB_s(true, tRIS2, "autosupplyUnit")
endif
if s_uDG(trainer, "trainedUnits") == null then
call s_uDG_s(CreateGroup(), tRIS, "trainedUnits")
endif
call GroupAddUnit(s_uDG(trainer, "trainedUnits"), trained)
//==========================================
// Add to Player.
set sI = StringHash("Terms_" + uTS + "_group")
set g = LoadGroupHandleBJ(0, sI, udg_PlayerAI[pI])
if g == null then
set g = CreateGroup()
call sAI_saveStringParameter("", uTS, "Terms", udg_PlayerAI[pI])
endif
call GroupAddUnit(g, trained)
call sAI_saveGroupParameter(g, "group", "Terms_" + uTS, udg_PlayerAI[pI])
//=========================================
call sAI_saveBooleanParameter(true, tUTS, "Terms_" + uTS + "_built_by", udg_PlayerAI[pI])
call sAI_saveBooleanParameter(true, uTS, "Terms_" + tUTS + "_builds", udg_PlayerAI[pI])
//call DisplayTextToForce(GetPlayersAll(), "unitTrained: " + "Terms_" + uTS + "_built_by_" + tUTS)
//call sAI_addStringParameter(tUTS, "built_by", "Terms_" + uTS, udg_PlayerAI[pI])
//call sAI_addStringParameter(uTS, "builds", "Terms_" + tUTS, udg_PlayerAI[pI])
//PLUG LEAKS
set trainer = null
set trained = null
set pI = 0
set tRIS = ""
set tRIS2 = ""
set uTS = ""
set tUTS = ""
set i = 0
set sI = 0
set g = null
endfunction
function s_unitQueued takes nothing returns nothing
local unit trainer = GetTriggerUnit()
local integer pI = GetConvertedPlayerId(GetOwningPlayer(trainer))
local string tRIS = I2S(GetHandleId(trainer))
local integer tUTI = GetUnitTypeId(trainer)
local integer uTI = GetTrainedUnitType()
local string tUTS = UnitId2StringBJ(tUTI)
local string uTS = UnitId2StringBJ(uTI)
local integer i = s_uDI(trainer, "training_" + uTS + "_count")
local group g = null
//MAIN PART
call s_uDI_s(i + 1, tRIS, "training_" + uTS + "_count")
//==========================================
// Add to Player.
set i = StringHash("Terms_" + tUTS + "_group")
set g = LoadGroupHandleBJ(0, i, udg_PlayerAI[pI])
if g == null then
set g = CreateGroup()
call sAI_saveStringParameter("", tUTS, "Terms", udg_PlayerAI[pI])
endif
call GroupAddUnit(g, trainer)
//
call sAI_saveGroupParameter(g, "group", "Terms_" + tUTS, udg_PlayerAI[pI])
//==========================================
call sAI_saveBooleanParameter(true, tUTS, "Terms_" + uTS + "_built_by", udg_PlayerAI[pI])
call sAI_saveBooleanParameter(true, uTS, "Terms_" + tUTS + "_builds", udg_PlayerAI[pI])
//call DisplayTextToForce(GetPlayersAll(), "unitQueued: " + "Terms_" + uTS + "_built_by_" + tUTS)
//PLUG LEAKS
set trainer = null
set pI = 0
set tRIS = ""
set tUTI = 0
set uTI = 0
set tUTS = ""
set uTS = ""
set i = 0
set g = null
endfunction
function s_unitCancelled takes nothing returns nothing
local unit trainer = GetTriggerUnit()
local unit trained = GetTrainedUnit()
local string tRIS = I2S(GetHandleId(trainer))
local string tRIS2 = I2S(GetHandleId(trainer))
local string uTS = UnitId2StringBJ(GetUnitTypeId(trained))
local integer i = s_uDI(trainer, "training_" + uTS + "_count")
//MAIN PART
call s_uDI_s(i - 1, tRIS, "training_" + uTS + "_count")
//PLUG LEAKS
set trainer = null
set trained = null
set tRIS = ""
set tRIS2 = ""
set uTS = ""
set i = 0
endfunction
function s_unitCanBuild takes unit u, string uTS returns boolean
local integer pI = GetConvertedPlayerId(GetOwningPlayer(u))
local string pIS = I2S(pI)
local integer count = 0
local integer tUTI = GetUnitTypeId(u)
local string tUTS = UnitId2StringBJ(tUTI)
//MAIN PART
set udg_tempInt = StringHash("Terms_" + uTS + "_built_by_" + tUTS)
if LoadBooleanBJ(0, udg_tempInt, udg_PlayerAI[pI]) ==true then
set udg_tempBoolean = true
//call DisplayTextToForce(GetPlayersAll(), "unitcanbuild: " + "Terms_" + uTS + "_built_by_" + tUTS)
else
set udg_tempBoolean = false
//call DisplayTextToForce(GetPlayersAll(), "unitcanbuild: (NOT): " + "Terms_" + uTS + "_built_by_" + tUTS)
endif
//PLUG LEAKS
set u = null
set uTS = ""
set pI = 0
set pIS = ""
set count = 0
set tUTI = 0
set tUTS = ""
// RETURNS
return udg_tempBoolean
endfunction
function s_unitIssuedOrder takes nothing returns nothing
local unit u = GetOrderedUnit()
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local player p = GetOwningPlayer(u)
local integer pI = GetConvertedPlayerId(p)
local string pIS = I2S(pI)
local integer count = 0
local integer tUTI = GetUnitTypeId(u)
local string tUTS = UnitId2StringBJ(tUTI)
local location l = GetOrderPointLoc()
local unit tU = GetOrderTargetUnit()
local integer ord = GetIssuedOrderIdBJ()
local string ordS = OrderId2StringBJ(ord)
local destructable d = GetOrderTargetDestructable()
local boolean selected = IsUnitSelected(u, p) == true
//MAIN PART
if ordS == "harvest" then
call s_uDB_s(true, uIS, "harvester")
call s_uDB_s(true, uIS, "harvest_target_unit")
if d != null then
call s_uDS_s("destructible", uIS, "harvest_target_type")
call s_uDDE_s(d, uIS, "harvest_target_destructible")
endif
if tU != null then
call s_uDS_s("unit", uIS, "harvest_target_type")
call s_uDU_s(tU, uIS, "harvest_target_unit")
endif
elseif ordS != "resumeharvesting" then
//call DisplayTextToForce(GetPlayersAll(), ordS)
call s_uDB_s(false, uIS, "harvester")
call s_uDB_s(false, uIS, "harvest_target_unit")
call s_uDS_s("", uIS, "harvest_target_type")
call s_uDDE_s(null, uIS, "harvest_target_destructible")
call s_uDU_s(null, uIS, "harvest_target_unit")
endif
//=========================================
//It will constantly update harvest target as needed.
//If this bugs, can save other information.
//=========================================
call s_uDU_s(null, uIS, "issued_order_unit")
call s_uDDE_s(null, uIS, "issued_order_destructible")
call RemoveLocation(s_uDL(u, "issued_order_loc"))
if tU != null then
call s_uDS_s("unit", uIS, "issued_order_type")
call s_uDU_s(tU, uIS, "issued_order_unit")
elseif l != null then
call s_uDS_s("loc", uIS, "issued_order_type")
call s_uDL_s(l, uIS, "issued_order_loc")
elseif d != null then
call s_uDS_s("destructible", uIS, "issued_order_type")
call s_uDDE_s(d, uIS, "issued_order_destructible")
else
call s_uDS_s("immediate", uIS, "issued_order_type")
call s_uDL_s(GetUnitLoc(u), uIS, "issued_order_loc")
endif
if ordS != "returnresources" then
call s_uDS_s(ordS, uIS, "issued_order")
endif
if selected == true then
call s_uDB_s(true, uIS, "issued_order_byPlayer")
else
call s_uDB_s(false, uIS, "issued_order_byPlayer")
endif
//I don't think this will work for queued orders, though.
//PLUG LEAKS
set u = null
set pI = 0
set pIS = ""
set count = 0
set tUTI = 0
set tUTS = ""
set l = null
set tU = null
set ord = 0
set ordS = ""
set d = null
set p = null
set selected = false
// RETURNS
endfunction
function rP_cancelRequest takes unit rP, string uTS, integer i returns nothing
local integer rPI = GetHandleId(rP)
local string rPIS = I2S(rPI)
local unit trainer = s_uDU(rP, "trainer")
local integer tPI = GetHandleId(trainer)
local string tPIS = I2S(tPI)
//MAIN PART
if s_uDI(rP, "wants_" + uTS + "_count") > 0 then
call s_uDI_i(i * -1, rP, "count", "wants_" + uTS)
call s_uDI_i(i * -1, rP, "count", "requested_" + uTS) //if requests are less than wants, it adds more requests, this can happen if the trainer is killed
endif
if s_uDI(rP, "wants_" + uTS + "_count") > 0 then
call s_uDI_i(i * -1, trainer, "count", "wants_" + uTS)
//if using a cancel i'd need to test it to get specific resut
endif
//i believe it also, or instead needs to update "training", rather than "wants" on the trainer
//PLUG LEAKS
set rP = null
set uTS = ""
set rPI = 0
set rPIS = ""
set i = 0
set trainer = null
set tPI = 0
set tPIS = ""
endfunction
function s_qMem takes unit u, string s returns nothing
endfunction
function rP_detachGuard takes unit rP, unit u returns nothing
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local integer rPI = GetHandleId(rP)
local string rPIS = I2S(rPI)
local string oS = s_uDS(u, "issued_order")
local location l = s_uDL(u, "issued_order_loc")
local unit tU = s_uDU(u, "issued_order_unit")
local real dist = 0
local location l1 = GetUnitLoc(rP)
local location l2 = GetUnitLoc(u)
local real gDist = 1500
local location gL = s_uDL(rP, "rebuild_" + uIS + "_loc")
//
local boolean alive = IsUnitAliveBJ(u)
local integer uTI = GetUnitTypeId(u)
local string uTS = UnitId2String(uTI)
//MAIN PART
call s_uDB_s(false, uIS, "autosupplyUnit")
if s_uDI(rP, "wants_" + uTS + "_count") > 0 and alive == false then
call rP_cancelRequest(rP, uTS, 1)
endif
call sAI_deleteDataTree("Units_" + rPIS + "_rebuild_" + uIS, udg_UnitAI)
//PLUG LEAKS
set uI = 0
set uIS = ""
set rPI = 0
set rPIS = ""
set oS = ""
set l = null
set tU = null
set dist = 0
call RemoveLocation(l1)
call RemoveLocation(l2)
set l1 = null
set l2 = null
set gDist = 0
set gL = null
endfunction
function uA_governGuards takes nothing returns nothing
local unit u = udg_uAI_Unit
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local real dist = 0
local unit eU = null
local location l1 = GetUnitLoc(u)
local location l2 = null
local real gDist = 1500
local location gL = s_uDL(u, "rebuild_" + uIS + "_loc")
local boolean alive = IsUnitAliveBJ(u)
local integer uTI = GetUnitTypeId(u)
local string uTS = UnitId2String(uTI)
local integer i = 1
local integer iC = 0
local string iS = ""
local string s = ""
local boolean iH = false
//MAIN PART
set iC = s_uDI(u, "rebuild_indexCount")
//call DisplayTextToForce(GetPlayersAll(), "govern")
loop
exitwhen i > iC
set iS = I2S(i)
set eU = s_uDU(u, "rebuild_" + iS)
set alive = IsUnitAliveBJ(eU)
//call DisplayTextToForce(GetPlayersAll(), "govern 1")
if eU != null and alive == true then
set l2 = GetUnitLoc(eU)
set dist = DistanceBetweenPoints(l1, l2)
//call DisplayTextToForce(GetPlayersAll(), "govern: eu == something")
call rP_setUnitOrder(u, i)
//call DisplayTextToForce(GetPlayersAll(), "set guard loc")
endif
set i = i + 1
endloop
// PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set dist = 0
call RemoveLocation(l1)
call RemoveLocation(l2)
set l1 = null
set l2 = null
set gDist = 0
set gL = null
set alive = false
set uTI = 0
set uTS = ""
set eU = null
set i = 0
set iC = 0
set iS = ""
set s = ""
set iH = false
endfunction
function s_cancel takes unit u returns nothing
// MAIN PART
call IssueImmediateOrderById( u, 851976 )
//PLUG LEAKS
set u = null
endfunction
function s_testTrain takes unit u, string uTS returns boolean
local integer count = s_trainingCount(u, uTS)
//MAIN PART
call IssueImmediateOrderBJ(u, uTS)
if s_unitCanBuild(u, uTS) == true then
call s_cancel(u)
//call DisplayTextToForce(GetPlayersAll(), "found new trainer")
set udg_tempBoolean = true
else
//call DisplayTextToForce(GetPlayersAll(), "you FAILED")
set udg_tempBoolean = false
endif
//PLUG LEAKS
set u = null
set uTS = ""
set count = 0
//RETURNS
return udg_tempBoolean
endfunction
function s_createRequestData takes unit u, unit trainer, string uTS, integer i returns nothing
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local integer tRI = GetHandleId(trainer)
local string tRIS = I2S(tRI)
local integer count = 0
local string s = ""
//MAIN PART
call s_uDS_s("", uIS, "requested")
call s_uDS_s("", uIS + "_requested", uTS)
call s_uDS_s("", uIS + "_requested_" + uTS, "trainer")
set s = uIS + "_requested_" + uTS
set s = s + "_trainer"
call s_uDS_s("", s, tRIS)
set count = s_uDI(u, "requested_" + uTS + "_count")
call s_uDI_s(count + i, uIS + "_requested_" + uTS, "count")
set count = s_uDI(u, "requested_" + uTS + "_trainer_" + tRIS + "_count")
set s = "_requested_" + uTS
set s = s + "_trainer_" + tRIS
call s_uDI_s(count + i, uIS + s, "count")
// remember: requested vs wants
//=======================================
if s_uDG(trainer, "supplied_group") == null then
call s_uDG_s(CreateGroup(), tRIS, "supplied_group")
endif
call GroupAddUnit(s_uDG(trainer, "supplied_group"), u)
call s_uDS_s("", tRIS, "requests")
call s_uDS_s("", tRIS + "_requests", uIS)
call s_uDS_s("", tRIS + "_requests_" + uIS, uTS)
set count = s_uDI(u, "requests_" + uIS + "_" + uTS + "_count")
call s_uDI_s(count + i, "requests_" + uIS + "_" + uTS, "count")
//=============================================
//PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set trainer = null
set uTS = ""
set count = 0
set i = 0
endfunction
function s_cancelRQ takes unit u returns nothing
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local unit supplied = null
local integer sRI = 0
local string sRIS = ""
local integer count = 0
local integer num = 0
local group g = s_uDG(u, "supplied_group")
local unit eU = FirstOfGroup(g)
local integer sI = 0
local string iS = ""
local string s = ""
local string uTS = ""
local integer i = 1
local integer iC = 0
//MAIN PART
set supplied = FirstOfGroup(g)
loop
exitwhen supplied == null
set sRI = GetHandleId(supplied)
set sRIS = I2S(sRI)
set s = "requests_" + sRIS
set s = s + "_" + uTS + "_count"
set num = s_uDI(u, s )
set s = "Units_" + uIS + "_requests_"
set s = s + sRIS + "_metaList_indexCount"
set sI = StringHash(s)
set iC = LoadIntegerBJ(0, sI, udg_UnitAI)
loop
exitwhen i > iC
set iS = I2S(i)
set s = uIS + "_requests_" + sRIS + "_metaList_" + iS
set sI = StringHash(s)
set uTS = LoadStringBJ(0, sI, udg_UnitAI)
//TRAINER UPDATES AMOUNT REQUESTED TOTAL, AND REQUESTED FROM SUPPLIED
set s = "requests_" + uTS + "_count"
set count = s_uDI(u, s)
call s_uDI_s(count - num, uIS + "_requests_" + uTS, "count")
set s = "requests_" + sRIS + "_" + uTS
set s = s + "_count"
set count = s_uDI(u, s)
call s_uDI_s(count - num, uIS, s)
//SUPPLIED UPDATES AMOUNT REQUEST TOTAL, AND AMOUNT REQUESTED FROM TRAINER
set s = "requested_" + uTS
set s = s + "_" + uIS + "_count"
set count = s_uDI(supplied, s)
call s_uDI_s(count - num, sRIS, s)
set s = "requested_" + uTS
set s = s + "_count"
set count = s_uDI(supplied, s)
call s_uDI_s(count - num, sRIS, s)
set i = i + 1
endloop
call GroupRemoveUnit(g, supplied)
set supplied = FirstOfGroup(g)
set i = 1
endloop
//PLUG LEAKS
call DestroyGroup(g)
set num = 0
set g = null
set eU = null
set u = null
set uI = 0
set uIS = ""
set supplied = null
set sRI = 0
set sRIS = ""
set uTS = ""
set count = 0
set i = 0
set iC = 0
set sI = 0
set iS = ""
set s = ""
endfunction
function s_addWant takes unit u, string s, integer i returns nothing
local string uIS = I2S(GetHandleId(u))
//MAIN PART
call sAI_saveBooleanParameter(true, s, "Units_" + uIS + "_wants", udg_UnitAI)
call s_uDI_i(i, u, "count", "wants_" + s)
//PLUG LEAKS
set u = null
set uIS = ""
set s = ""
set i = 0
endfunction
function rP_addRequest takes unit u, string tUTS returns nothing
local string uIS = I2S(GetHandleId(u))
local integer num = s_uDI(u, "training_" + tUTS + "_count")
local integer num2 = num
local integer pI = GetConvertedPlayerId(GetOwningPlayer(u))
local integer wantNum = s_uDI(u, "wants_" + tUTS + "_count")
local boolean pCanBuild = s_playerCanBuild(pI, tUTS)
local group g = CreateGroup()
local unit eU = FirstOfGroup(g)
local integer ePI = 0
local boolean processFinished = false
local integer i = 1
local integer iC = 0
local boolean iMode = true
local string uTS = ""
local real dist = 0
local unit bestUnit = null
local integer mIC = 0
local group g2 = CreateGroup()
local string s = ""
local integer sI = 0
local string iS = ""
local boolean b = false
//MAIN PART
set udg_tempReal = 0
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_indexCount")
set iC = LoadIntegerBJ(0, udg_tempInt, udg_PlayerAI[pI])
loop
exitwhen processFinished == true
if iMode == true then
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_" + I2S(i))
set uTS = LoadStringBJ(0, udg_tempInt, udg_PlayerAI[pI])
else
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_metaList_" + I2S(i)) //Gives name, other gives number like it should.
set uTS = LoadStringBJ(0, udg_tempInt, udg_PlayerAI[pI])
endif
set udg_tempInt = StringHash("Terms_" + uTS + "_group") // simple as
call GroupAddGroup(LoadGroupHandleBJ(0, udg_tempInt, udg_PlayerAI[pI]), g) //Remember this adds group (param1) TO group
//call DisplayTextToForce(GetPlayersAll(), "supplier name " + uTS + ": searched")
if LoadGroupHandleBJ(0, udg_tempInt, udg_PlayerAI[pI]) != null then
//call DisplayTextToForce(GetPlayersAll(), uTS + ": group exists")
//call DisplayTextToForce(GetPlayersAll(), "group contains: " + UnitId2String(GetUnitTypeId(FirstOfGroup(g))))
endif
//========
set i = i + 1
//========
if iMode == true and i > iC then
set iMode = false
set i = 1
set udg_tempInt = StringHash("Terms_" + tUTS + "_built_by_metaList_indexCount")
set iC = LoadIntegerBJ(0, udg_tempInt, udg_PlayerAI[pI])
elseif iMode == false and i > iC then
set processFinished = true
endif
endloop
set processFinished = false
set i = 1
//================
call GroupAddGroup(g, g2)
set eU = FirstOfGroup(g2)
set udg_tempLoc = GetUnitLoc(u)
set dist = 0
set udg_tempReal = 0
//call DisplayTextToForce(GetPlayersAll(), "group 2 contains: " + UnitId2String(GetUnitTypeId(FirstOfGroup(g2))))
loop
exitwhen eU == null or processFinished == true
//just pick every unit, try to train
set udg_tempLoc2 = GetUnitLoc(eU)
set udg_tempReal = DistanceBetweenPoints(udg_tempLoc , udg_tempLoc2)
if (udg_tempReal < dist or dist == 0) and GetConvertedPlayerId(GetOwningPlayer(eU)) == pI and s_uDB(eU, "autosupply") == true then
//call DisplayTextToForce(GetPlayersAll(), "potential supplier found")
set dist = udg_tempReal
set bestUnit = eU
endif
call RemoveLocation(udg_tempLoc2)
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
call DestroyGroup(g2)
set g2 = CreateGroup()
//CREATE REQUEST
// account for unknown trainers (can it train and cancel to learn quick?)
if bestUnit == null then
//call DisplayTextToForce( GetPlayersAll(), "no information found" )
//call DisplayTextToForce( GetPlayersAll(), "find trainer" )
set dist = 0
set udg_tempReal = 0
call GroupAddGroup(GetUnitsInRectAll(GetEntireMapRect()), g2 )
set eU = FirstOfGroup(g2)
loop
exitwhen eU == null
set udg_tempLoc2 = GetUnitLoc(eU)
set udg_tempReal = DistanceBetweenPoints(udg_tempLoc , udg_tempLoc2)
set udg_tempBoolean = s_testTrain(eU, tUTS)
if (udg_tempReal < dist or dist == 0) and GetConvertedPlayerId(GetOwningPlayer(eU)) == pI and s_uDB(eU, "autosupply") == true and udg_tempBoolean == true then
set dist = udg_tempReal
set bestUnit = eU //find these while we're here
endif
call GroupRemoveUnit(g2, eU)
set eU = FirstOfGroup(g2)
endloop
endif
//maybe just adds to training data on RP
if bestUnit != null then
call IssueImmediateOrderBJ(bestUnit, tUTS)
//call DisplayTextToForce( GetPlayersAll(), "builder found" )
set s = "Units_" + uIS + "_isTrainer"
set sI = StringHash(s)
set b = LoadBooleanBJ(0, sI, udg_UnitAI)
if b == false then
call pF_trainer(bestUnit)
endif
call s_createRequestData(u, bestUnit, tUTS, 1)
call s_addWant(bestUnit, tUTS, 1)
//call s_addWant(u, tUTS, 1) //shewwd work
else
//call DisplayTextToForce( GetPlayersAll(), "no builder found" )
endif
//PLUG LEAKS
set u = null
set tUTS = ""
call DestroyGroup(g)
set g = null
set pCanBuild = false
set eU = null
set ePI = 0
set processFinished = false
set i = 0
set iC = 0
set iMode = true
set uTS = ""
set dist = 0
set bestUnit = null
set mIC = 0
call DestroyGroup(g2)
set g2 = null
set s = ""
set sI = 0
set iS = ""
set b = false
//RETURNS
endfunction
function rP_removeRequest takes unit u, string tUTS returns nothing
local string uIS = I2S(GetHandleId(u))
local integer num = s_uDI(u, "training_" + tUTS + "_count")
local integer num2 = num
local integer pI = GetConvertedPlayerId(GetOwningPlayer(u))
local integer wantNum = s_uDI(u, "wants_" + tUTS + "_count")
local boolean pCanBuild = s_playerCanBuild(pI, tUTS)
local group g = CreateGroup()
local unit eU = FirstOfGroup(g)
local integer ePI = 0
local boolean processFinished = false
local integer i = 1
local integer iC = 0
local boolean iMode = true
local string uTS = ""
local real dist = 0
local unit bestUnit = null
local integer mIC = 0
local group g2 = CreateGroup()
local string s = ""
local integer sI = 0
local string iS = ""
local boolean b = false
local string name = ""
local boolean found = false
//MAIN PART
set s = "Units_" + uIS + "_requested_"
set s = s + uTS + "_trainer_indexCount"
set sI = StringHash(s)
set iC = LoadIntegerBJ(0, sI, udg_UnitAI)
loop
exitwhen i > iC or found == true
set iS = I2S(i)
set s = "Units_" + uIS + "_requested_"
set s = s + uTS + "_trainer_metaList_" + iS
set sI = StringHash(s)
set name = LoadStringBJ(0, sI, udg_UnitAI)
set s = "Units_" + name + "_unit"
set sI = StringHash(s)
set bestUnit = LoadUnitHandleBJ(0, sI, udg_UnitAI) //make sure this is saved
//=======================
call s_createRequestData(u, bestUnit, tUTS, -1)
call s_addWant(bestUnit, tUTS, -1)
call s_addWant(u, tUTS, -1)
endloop
//PLUG LEAKS
set u = null
set tUTS = ""
call DestroyGroup(g)
set g = null
set pCanBuild = false
set eU = null
set ePI = 0
set processFinished = false
set i = 0
set iC = 0
set iMode = true
set uTS = ""
set dist = 0
set bestUnit = null
set mIC = 0
call DestroyGroup(g2)
set g2 = null
set s = ""
set sI = 0
set iS = ""
set b = false
set name = ""
set found = false
//RETURNS
endfunction
function rP_unitDies takes nothing returns nothing
local unit u = GetDyingUnit()
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local unit rP = s_uDU(u, "reportPost")
local integer uTI = GetUnitTypeId(u)
local string uTS = UnitId2String(uTI)
//MAIN PART
if s_uDB(u, "isInReportPostGroup") == true then
set udg_tempString = UnitId2String(GetUnitTypeId(u))
call s_addWant(rP, uTS, 1)
call rP_addRequest(rP, udg_tempString)
//call DisplayTextToForce( GetPlayersAll(), "added request for" + udg_tempString )
endif
if (IsUnitType(u, UNIT_TYPE_HERO) == false) then
//call sAI_baseRemoveUnit(p,b,u)
//i think technically delete data tree should cover this, if i add effect in there, which should be a good test
call s_cancelRQ(u)
call sAI_deleteDataTree(("Units_" + uIS), udg_UnitAI)
endif
call DestroyEffect(LoadEffectHandleBJ(0, StringHashBJ("Units_" + uIS + "_saved_specialEffect"), udg_UnitAI))
//PLUG LEAKS
set u = null
set rP = null
set uI = 0
set uIS = ""
endfunction
function uA_resupplyUnit takes nothing returns nothing
local unit u = udg_uAI_Unit
local string uIS = udg_uAI_uIS
local string pIS = I2S(GetConvertedPlayerId(GetOwningPlayer(u)))
local string baseIDS = I2S(s_uDI(u, "baseID"))
local group g = null
local group sortGroup = null
local unit eU = null
local integer i = 1
local integer iC = s_uDI(u, "rebuild_indexCount")
local boolean found = false
local unit trainer = null
local string tRIS = ""
local string uTS = ""
local string rStr = ""
local string iS = ""
local integer eUI = 0
local string eUTS = ""
local string s = ""
local boolean b = false
local location l = null
local unit rU = null
local string eUIS = ""
//MAIN PART
//call DisplayTextToForce(GetPlayersAll(), "gather")
loop
exitwhen i > iC
set iS = I2S(i)
set s = "rebuild_" + iS
set rU = s_uDU(u, s)
set s = "rebuild_" + iS + "_unitType" //just loops group and checks for dead (wants are created in death trigger)
set uTS = s_uDS(u, s) // remember to save unitType
set g = GetUnitsInRectAll(GetEntireMapRect())
set eU = FirstOfGroup(g)
if IsUnitAliveBJ(rU) == true then
set found = true
endif
//call DisplayTextToForce(GetPlayersAll(), "gather 1")
loop
exitwhen eU == null or found == true
//call DisplayTextToForce(GetPlayersAll(), "gather 2")
set eUI = GetUnitTypeId(eU)
set eUTS = UnitId2String(eUI)
set eUI = GetHandleId(eU)
set eUIS = I2S(eUI)
set b = s_uDB(eU, "autosupplyUnit") and s_uDU(eU, "reportPost") == null
if uTS == eUTS and b == true then
set l = s_uDL(u, "rebuild_" + iS + "_loc")
call s_uDU_s(eU, uIS, "rebuild_" + iS)
call s_uDU_s(u, eUIS, "reportPost")
call s_uDB_s(true, eUIS, "isInReportPostGroup")
if s_uDI(u, "wants_" + uTS + "_count") > 0 then
call s_uDI_i(-1, u, "count", "wants_" + uTS) //check which of these needs it (i think i save to unit types not indexes)
endif
call IssuePointOrderLocBJ(eU, "attack", l)
//call DisplayTextToForce(GetPlayersAll(), "unit moving to resupply")
set found = true
//=========
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
set b = false
endloop
set found = false
call DestroyGroup(g)
set i = i + 1
endloop
//call DisplayTextToForce(GetPlayersAll(), "resupply order issued")
// PLUG LEAKS
set u = null
set uIS = ""
set pIS = ""
set baseIDS = ""
set sortGroup = null
call DestroyGroup(g)
set g = null
set eU = null
set i = 0
set iC = 0
set found = false
set trainer = null
set tRIS = ""
set uTS = ""
set rStr = ""
set iS = ""
set eUI = 0
set eUTS = ""
set s = ""
set b = false
set rU = null
set eUIS = ""
endfunction
function uA_performRequests takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
local integer i = 1
local integer iC = 0
local boolean iMode = true
local integer count = 0
local string s = ""
//MAIN PART
set iC = s_uDI(u, "wants_metaList_indexCount")
loop
exitwhen i > iC
set s = I2S(i)
set s = s_uDS(u, "wants_metaList_" + s)
set count = s_uDI(u, "training_" + s + "_count")
if count < s_uDI(u, "wants_" + s + "_count") then
call IssueImmediateOrderBJ(u, s)
endif
set i = i + 1
endloop
//PLUG LEAKS
set u = null
set uIS = ""
set i = 0
set iC = 0
set iMode = false
set count = 0
set s = ""
endfunction
function rP_checkForAddedUnits takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
local location l = s_tDL(tIS, "loc")
local string uIS = I2S(GetHandleId(u))
local real time = s_tDR(tIS, "time") - 1
//=====================================================
local group cG = GetUnitsInRangeOfLocAll(1200, l)
local unit eU = FirstOfGroup(cG)
local string eUIS = ""
//MAIN PART
loop
exitwhen eU == null
set eUIS = I2S(GetHandleId(eU))
if (GetOwningPlayer(u) == GetOwningPlayer(eU)) and (IsUnitType(eU, UNIT_TYPE_STRUCTURE) == false) and (UnitHasBuffBJ(eU, 'Bspl') == true) and (s_uDB(eU, "isInReportPostGroup") != true) then
//call DisplayTextToForce( GetPlayersAll(), "added unit to report post! voila!" )
call s_reportPost_addUnit(u, eU)
endif
call GroupRemoveUnit(cG, eU)
set eU = FirstOfGroup(cG)
endloop
if time <= 0 then
call DestroyTimer(t)
else
call s_tDR_s(time, tIS, "time")
call TimerStart(t, 1, false, function rP_checkForAddedUnits)
endif
//PLUG LEAKS
set u = null
set uIS = ""
set tIS = ""
call RemoveLocation(l)
set l = null
set t = null
set time = 0
call DestroyGroup(cG)
set cG = null
set eU = null
set eUIS = ""
endfunction
function fireOgre_rockThrow takes nothing returns nothing
local unit u = udg_FireOgre
local location tL = null
local real x = 0
local real y = 0
local real z = 0
// throws and learns from impact
endfunction
function fireOgre_monitorAttacks takes nothing returns nothing
local unit u = udg_FireOgre
local string uIS = I2S(GetHandleId(u))
local unit mU = s_uDU(u, "attackProjectile")
local location mUL = GetUnitLoc(mU)
local real x = GetLocationX(mUL)
local real y = GetLocationY(mUL)
local real z = GetUnitFlyHeight(mU)
local real targetX = GetLocationX(s_uDL(u, "attackProjectile_targetLoc"))
local real targetY = GetLocationY(s_uDL(u, "attackProjectile_targetLoc"))
local real targetZ = GetLocationZ(s_uDL(u, "attackProjectile_targetLoc"))
local real diffV = 0
local real dist = 0
local real bestDist = 0
local real bestX = s_uDR(u, "attackProjectile_bestX")
local real bestY = s_uDR(u, "attackProjectile_bestY")
local real bestZ = s_uDR(u, "attackProjectile_bestZ")
local real aimX = s_uDR(u, "attackProjectile_aimX")
local real aimY = s_uDR(u, "attackProjectile_aimY")
local real aimZ = s_uDR(u, "attackProjectile_aimZ")
local real bestAimX = s_uDR(u, "attackProjectile_bestAimX")
local real bestAimY = s_uDR(u, "attackProjectile_bestAimY")
local real bestAimZ = s_uDR(u, "attackProjectile_bestAimZ")
//MAIN PART
set diffV = RAbsBJ(targetX - x)
if diffV < bestX then
set bestX = diffV
call s_uDR_s(bestX, uIS, "attackProjectile_bestX")
call s_uDR_s(aimX, uIS, "attackProjectile_bestAimX")
endif
set diffV = RAbsBJ(targetY - y)
if diffV < bestY then
set bestY = diffV
call s_uDR_s(bestY, uIS, "attackProjectile_bestY")
call s_uDR_s(aimY, uIS, "attackProjectile_bestAimY")
endif
set diffV = RAbsBJ(targetZ - z)
if diffV < bestZ then
set bestZ = diffV
call s_uDR_s(bestZ, uIS, "attackProjectile_bestZ")
call s_uDR_s(aimZ, uIS, "attackProjectile_bestAimZ")
endif
//PLUG LEAKS
set u = null
set uIS = ""
set mU = null
call RemoveLocation(mUL)
set mUL = null
set x = 0
set y = 0
set z = 0
set targetX = 0
set targetY = 0
set targetZ = 0
set diffV = 0
set dist = 0
set bestDist = 0
set bestX = 0
set bestY = 0
set bestZ = 0
set aimX = 0
set aimY = 0
set aimZ = 0
set bestAimX = 0
set bestAimY = 0
set bestAimZ = 0
endfunction
function e_earthWard takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
local group g = s_uDG(u, "ability_earthward_group")
local unit eU = FirstOfGroup(g)
local unit sU = udg_tempUnit
local location l = GetUnitLoc(u)
local location l2 = GetUnitLoc(sU)
//
local location eL = null
//MAIN PART
set udg_tempReal = AngleBetweenPoints(l, l2)
loop
exitwhen eU == null
call KillUnit(eU)
call GroupRemoveUnit(g, eU)
set eL = GetUnitLoc(eU)
call AddSpecialEffectLocBJ( eL, "Objects\\Spawnmodels\\Human\\FragmentationShards\\FragBoomSpawn.mdl" )
call RemoveLocation(eL)
call RemoveUnit(eU)
set eU = FirstOfGroup(g)
endloop
call DestroyGroup(g)
set g = CreateGroup()
call s_uDG_s(g, uIS, "ability_earthward_group")
call GroupAddUnit(g, sU)
set eL = GetUnitLoc(sU)
call AddSpecialEffectLocBJ( eL, "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, 10)
call RemoveLocation(eL)
call CreateNUnitsAtLoc( 1, 'h024', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(GetSummonedUnit()), 256.00, ( udg_tempReal + 90.00 )), GetRandomDirectionDeg() )
call GroupAddUnit(g, bj_lastCreatedUnit)
set eL = GetUnitLoc(bj_lastCreatedUnit)
call AddSpecialEffectLocBJ( eL, "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, 10)
call RemoveLocation(eL)
call CreateNUnitsAtLoc( 1, 'h024', GetOwningPlayer(u), PolarProjectionBJ(GetUnitLoc(GetSummonedUnit()), 256.00, ( udg_tempReal - 90.00 )), GetRandomDirectionDeg() )
call GroupAddUnit(g, bj_lastCreatedUnit)
set eL = GetUnitLoc(bj_lastCreatedUnit)
call AddSpecialEffectLocBJ( eL, "Abilities\\Spells\\Orc\\EarthQuake\\EarthQuakeTarget.mdl" )
call s_destroyEffect_main(bj_lastCreatedEffect, 10)
call RemoveLocation(eL)
//PLUG LEAKS
set u = null
set uIS = ""
set eU = null
set g = null
call RemoveLocation(l)
call RemoveLocation(l2)
set l = null
set l2 = null
set sU = null
endfunction
function e_death takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
local group g = s_uDG(u, "ability_earthward_group")
local unit eU = FirstOfGroup(g)
//MAIN PART
loop
exitwhen eU == null
call KillUnit(eU)
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
call DestroyGroup(g)
call sAI_deleteDataTree(uIS, udg_UnitAI)
//PLUG LEAKS
set u = null
set uIS = ""
set eU = null
call DestroyGroup(g)
set g = null
endfunction
//group handles may be a convenient ai "empty"
function l_groupUpdate takes integer gI returns nothing
local string pathS = ""
local unit u = udg_DarkRangerLilith
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local string gIS = I2S(gI)
local group g = s_uDG(u, "army_" + gIS + "_group")
local integer i = 1
local integer iC = 0
local integer pIC = 0
local group sortGroup = CreateGroup()
local unit eU = null
local real dist = 0
local integer cI = 0
local location eUL = null
local location tP = null
local string iS = ""
local integer eUI = 0
local string eUIS = ""
local boolean go = false
local integer count = s_uDI(u, "army_" + gIS + "_count") //how many reached target zone
local integer gSize = CountUnitsInGroup(g)
local integer tI = R2I(gSize * 0.8)
local timer wT = s_uDT(u, "army_" + gIS + "_timer")
//local string test = ""
//MAIN PART
//everything is actually saved to lilith's uIS
set pathS = "army_" + gIS + "_loc"
set pIC = s_uDI(u, pathS + "_indexCount")
call GroupAddGroup(g, sortGroup)
set eU = FirstOfGroup(sortGroup)
//call DisplayTextToForce(GetPlayersAll(), "pIC: " + I2S(pIC))
//call DisplayTextToForce(GetPlayersAll(), "gSize: " + I2S(gSize))
set count = 0
set cI = s_uDI(u, pathS + "_currentIndex")
loop
exitwhen eU == null
set eUL = GetUnitLoc(eU)
set eUI = GetHandleId(eU)
set eUIS = I2S(eUI)
set iS = I2S(cI)
set tP = s_uDL(u, pathS + "_" + iS)
set dist = DistanceBetweenPoints(eUL, tP)
//call DisplayTextToForce(GetPlayersAll(), "str loc cI 2: " + pathS + "_currentIndex")
//call DisplayTextToForce(GetPlayersAll(), "cI: " + I2S(cI))
//call DisplayTextToForce(GetPlayersAll(), "eu dist: " + R2S(dist))
//set test = s_uDS(u, pathS + "_test")
//call DisplayTextToForce(GetPlayersAll(), "test: " + test)
call IssuePointOrderLoc(eU, "attack", tP)
if dist < 1100 then
set count = count + 1
elseif TimerGetRemaining(wT) == 0 and wT != null then
call KillUnit(u)
endif
// if the right num enter area it starts timing, if other units don't make it in time they die and group moves on
set i = 1
call GroupRemoveUnit(sortGroup, eU)
set eU = FirstOfGroup(sortGroup)
endloop
call s_uDI_s(count, uIS + "_army_" + gIS, "count")
if count >= tI and wT == null then
call StartTimerBJ(CreateTimer(), false, 15)
call s_uDT_s(bj_lastStartedTimer, uIS + "_army_" + gIS, "timer")
endif
if count >= gSize or (TimerGetRemaining(wT) == 0 and wT != null) then
call s_uDI_s(cI + 1, uIS + "_" + pathS, "currentIndex")
call DestroyTimer(wT)
endif
//PLUG LEAKS
set pathS = ""
set u = null
set uI = 0
set uIS = ""
set gIS = ""
set g = null
set i = 0
set iC = 0
set pIC = 0
set sortGroup = null
set eU = null
set dist = 0
set cI = 0
set eUL = null
set tP = null
set iS = ""
set eUI = 0
set eUIS = ""
set go = false
set count = 0
set gSize = 0
set tI = 0
set wT = null
endfunction
function l_moveArmies takes nothing returns nothing
local unit u = udg_DarkRangerLilith
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local group g = null
local integer i = 1
local integer iC = 0
local string iS = ""
//MAIN PART
set iC = s_uDI(u, "army_indexCount")
loop
exitwhen i > iC
call l_groupUpdate(i)
set i = i + 1
endloop
//PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set g = null
set i = 0
set iC = 0
set iS = ""
endfunction
function l_addPath takes group g returns nothing
local location l = null
local unit u = udg_DarkRangerLilith
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local string str = ""
//MAIN PART
//preamble
call sAI_addStringParameter("", "army", "Units_" + uIS, udg_UnitAI)
set str = udg_lastPLS
call sAI_saveGroupParameter(g, "group", str, udg_UnitAI)
//=======================
set l = GetRectCenter(gg_rct_LilithArmy01)
call sAI_addLocationParameter(l, "loc", str, udg_UnitAI)
set l = GetRectCenter(gg_rct_LilithArmy02)
call sAI_addLocationParameter(l, "loc", str, udg_UnitAI)
set l = GetRectCenter(gg_rct_LilithArmy03)
call sAI_addLocationParameter(l, "loc", str, udg_UnitAI)
set l = GetRectCenter(gg_rct_LilithArmy04)
call sAI_addLocationParameter(l, "loc", str, udg_UnitAI)
set l = GetRectCenter(gg_rct_LilithArmy05)
call sAI_addLocationParameter(l, "loc", str, udg_UnitAI)
call sAI_saveIntegerParameter(1, "currentIndex", str + "_loc", udg_UnitAI)
//call DisplayTextToForce(GetPlayersAll(), "str loc cI: " + udg_lastPLS)
call s_uDI_s(0, str, "count")
call sAI_saveIntegerParameter(0, "count", str, udg_UnitAI)
// call s_uDS_s("poop", str + "_loc", "test")
//PLUG LEAKS
set g = null
set l = null
set u = null
set uI = 0
set uIS = ""
set str = ""
endfunction
function l_aiLoop takes nothing returns nothing
call l_moveArmies()
endfunction
function l_initAI takes nothing returns nothing
endfunction
function stormwyrm_addAI takes unit u returns nothing
local string uIS = I2S(GetHandleId(u))
local location l = null
//MAIN PART
set l = GetRectCenter(gg_rct_StormWyrms_Graze_01)
call sAI_addLocationParameter( l , "loc", "Units_" + uIS, udg_UnitAI)
call RemoveLocation(l)
//===================================
set l = GetRectCenter(gg_rct_StormWyrms_Graze_02)
call sAI_addLocationParameter( l , "loc", "Units_" + uIS, udg_UnitAI)
call RemoveLocation(l)
//===================================
set l = GetRectCenter(gg_rct_StormWyrms_Path_01)
call sAI_addLocationParameter( l , "loc", "Units_" + uIS, udg_UnitAI)
call RemoveLocation(l)
//===================================
set l = GetRectCenter(gg_rct_StormWyrms_Graze_02)
call sAI_addLocationParameter( l , "loc", "Units_" + uIS, udg_UnitAI)
call RemoveLocation(l)
//===================================
//PLUG LEAKS
set u = null
set uIS = ""
set l = null
endfunction
function stormwyrms_ai takes nothing returns nothing
local group g = CreateGroup()
local unit eU = null
local string eUIS = ""
local integer i = 1
local integer iC = 0
local integer i2 = 0
local location l = null
local integer ticks = 0
//MAIN PART
call GroupAddGroup(g, udg_StormWyrms)
set eU = FirstOfGroup(g)
loop
exitwhen eU == null
set eUIS = I2S(GetHandleId(eU))
set ticks = s_uDI(eU, "sensory_ticks")
call s_uDI_s(ticks + 1, eUIS, "sensory_ticks") // AI ticks are in seconds, game-time shouldn't be > 2 - 4 billion seconds.
if s_uDI(eU, "loc_currentIndex") == 0 and s_uDI(eU, "loc_indexCount") > 0 then
set iC = s_uDI(eU, "loc_indexCount")
set i2 = GetRandomInt(1, iC)
call s_uDI_s(i2, eUIS, "loc_currentIndex")
else
set udg_tempString = I2S(s_uDI(eU, "loc_currentIndex"))
set l = s_uDL(eU, "loc_" + udg_tempString)
endif
//Location Found
if ticks - s_uDI(eU, "timestamp_tick_lastOrder") > 5 then
endif
call IssuePointOrderLocBJ(eU, "attack", l)
call s_uDI_s(ticks, eUIS, "timestamp_tick_lastOrder")
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//PLUG LEAKS
call DestroyGroup(g)
set g = null
set eU = null
set eUIS = ""
set i = 0
set iC = 0
set i2 = 0
set l = null
set ticks = 0
endfunction
function cTransmission takes unit u, string txt, real t, boolean wait returns nothing
//checks database, if specific unit etc uses that info, and deprecates
// should be a way to make this more efficient tho
endfunction
function zT_changeSpeeds takes nothing returns nothing
local group g = CreateGroup()
local real dist = 0
local unit eU = null
local location l = GetUnitLoc(udg_CineKael)
local location uL = null
local real kaelDist = DistanceBetweenPoints(l, udg_zT_endLoc)
//MAIN PART
call GroupAddGroup(udg_zT_unitGroup, g)
set eU = FirstOfGroup(g)
loop
exitwhen (eU == null)
set uL = GetUnitLoc(eU)
set dist = DistanceBetweenPoints(uL, udg_zT_endLoc)
if (eU == udg_EarthKing) then
if (dist < kaelDist + 800) then
call SetUnitMoveSpeed( eU, udg_zT_speed * 0.7 )
elseif (dist > kaelDist + 1200) then
call SetUnitMoveSpeed( eU, udg_zT_speed * 2 )
else
call SetUnitMoveSpeed( eU, udg_zT_speed)
endif
elseif (eU != udg_CineKael) then
if (dist > kaelDist + 800) then
call SetUnitMoveSpeed( eU, udg_zT_speed * 2 )
else
call SetUnitMoveSpeed( eU, udg_zT_speed)
endif
endif
call RemoveLocation(uL)
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//PLUG LEAKS
call DestroyGroup(g)
set g = null
set uL = null
call RemoveLocation(l)
set l = null
set eU = null
set dist = 0
endfunction
function zT_camShake_expires takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local integer pI = s_tDI(tIS, "playerId")
//MAIN PART
call CameraClearNoiseForPlayer( Player(pI) )
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set pI = 0
endfunction
function zT_camShake takes nothing returns nothing
local player p = Player(0)
local real mag = 3
//MAIN PART
call CameraSetEQNoiseForPlayer( p, mag )
//do i need to reset cam?
//PLUG LEAKS
set p = null
set mag = 0
endfunction
function zT_nextDUnits takes nothing returns nothing
local location l = null
local location l2 = null
local real r = 0
local real r2 = 0
local group g = null
local integer i = 1
local integer i2 = 3
local integer picked = udg_zTxCreateGroup
// MAIN PART
set l = GetRectCenter(gg_rct_zTELoc1x1)
set l2 = GetRectCenter(gg_rct_zTELoc1x2)
set udg_tempReal = DistanceBetweenPoints(l, l2)
call RemoveLocation(l)
call RemoveLocation(l2)
//
set bj_forLoopAIndexEnd = udg_zTxCreateGroup_num
loop
exitwhen udg_zT_on == false or i > i2
set bj_forLoopAIndex = 1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set l = GetRectCenter(gg_rct_zTELoc1x1)
set l2 = GetRectCenter(gg_rct_zTELoc1x2)
set r = AngleBetweenPoints(l, l2)
set r2 = GetRandomDirectionDeg()
set g = udg_zT_environmentG
set udg_tempLoc2 = PolarProjectionBJ(l, GetRandomReal(0, udg_tempReal), r)
set udg_tempLoc = PolarProjectionBJ(udg_tempLoc2, GetRandomReal(0, 200.00), r2)
call RemoveLocation(udg_tempLoc2)
set udg_tempInt = GetRandomInt(1, 11)
set udg_tempInt2 = 1
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01V', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h020', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Y', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Z', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01X', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h009', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01W', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
//call CreateNUnitsAtLoc( 1, 'h023', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h022', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h021', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
call GroupAddUnit( g, bj_lastCreatedUnit )
call IssueImmediateOrderBJ(bj_lastCreatedUnit, "holdposition")
call RemoveLocation(udg_tempLoc)
call RemoveLocation(l)
call RemoveLocation(l2)
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set l2 = null
set r = 0
set r2 = 0
set g = null
set i = 0
set picked = 0
endfunction
function zT_nextDUnits2 takes nothing returns nothing
local location l = null
local location l2 = null
local real r = 0
local real r2 = 0
local group g = null
local integer i = 1
local integer i2 = 3
local integer picked = udg_zTxCreateGroup
// MAIN PART
set l = GetRectCenter(gg_rct_Region_193)
set l2 = GetRectCenter(gg_rct_Region_192)
set udg_tempReal = DistanceBetweenPoints(l, l2)
call RemoveLocation(l)
call RemoveLocation(l2)
//
set bj_forLoopAIndexEnd = 12
set bj_forLoopAIndex = 1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set l = GetRectCenter(gg_rct_Region_193)
set l2 = GetRectCenter(gg_rct_Region_192)
set r = AngleBetweenPoints(l, l2)
set r2 = GetRandomDirectionDeg()
set g = udg_zT_environmentG
set udg_tempLoc2 = PolarProjectionBJ(l, GetRandomReal(0, udg_tempReal), r)
set udg_tempLoc = PolarProjectionBJ(udg_tempLoc2, GetRandomReal(0, 200.00), r2)
call RemoveLocation(udg_tempLoc2)
set udg_tempInt = GetRandomInt(1, 11)
set udg_tempInt2 = 1
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01V', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h020', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Y', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Z', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01X', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h009', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01W', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
//call CreateNUnitsAtLoc( 1, 'h023', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h022', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h021', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
call GroupAddUnit( g, bj_lastCreatedUnit )
call IssueImmediateOrderBJ(bj_lastCreatedUnit, "holdposition")
call RemoveLocation(udg_tempLoc)
call RemoveLocation(l)
call RemoveLocation(l2)
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
set bj_forLoopAIndex = 1
//PLUG LEAKS
set l = null
set l2 = null
set r = 0
set r2 = 0
set g = null
set i = 0
set picked = 0
endfunction
function zT_preTerrain takes nothing returns nothing
local location l = GetRectCenter(gg_rct_introkaelrun)
local integer tI = GetTerrainCliffLevelBJ(l)
local rect rct = gg_rct_intro_hide_doodads //RectFromCenterSizeBJ(l, 500.00, 500.00)
local real dist = 0
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = 30
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
local location l2 = GetRectCenter(gg_rct_introkaelrun)
local integer i2 = 1
local integer iC2 = 4
local rect rct2 = null
//MAIN PART
set l2 = l
loop
exitwhen i2 > iC2
loop
exitwhen i > iC
call RemoveRect(rct2)
call RemoveLocation(l)
set rct2 = RectFromCenterSizeBJ(l2, 500.00, 500.00)
set l = GetRandomLocInRect(rct2)
set dist = DistanceBetweenPoints(l, l2)
set rI = GetRandomInt(1,4)
if rI == 1 then
set tTI = 'Bdrt' //dirt, etc
elseif rI == 2 then
set tTI = 'Bdro'
elseif rI == 3 then
set tTI = 'Bdrg'
elseif rI == 4 then
set tTI = 'Bgrs'
endif
if dist < 6000 then
call SetTerrainTypeBJ( l, tTI, -1, 1, 0 )
set x = GetLocationX(l)
set y = GetLocationY(l)
set xS = R2S(x)
set yS = R2S(y)
call sAI_saveIntegerParameter(tTI, xS + yS, "zT_terrain", udg_tempHash)
call sAI_saveLocationParameter(l, "loc", "zT_terrain_" + xS + yS, udg_tempHash)
endif
set i = i + 1
endloop
set l2 = PolarProjectionBJ(l2, 1000, 45)
set i2 = i2 + 1
endloop
//PLUG LEAKS
set l = null
set tI = 0
set rct = null
set dist = 0
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
call RemoveLocation(l2)
set l2 = null
call RemoveRect(rct2)
set rct2 = null
set i2 = 0
set iC2 = 0
endfunction
function zT_preDUnits takes nothing returns nothing
local location l = null
local location l2 = null
local real r = 0
local real r2 = 0
local group g = null
local integer i = 1
local integer i2 = 3
local integer picked = udg_zTxCreateGroup
// MAIN PART
set l = GetRectCenter(gg_rct_zTELoc1x2)
set l2 = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x01a)
set udg_tempReal = DistanceBetweenPoints(l, l2)
call RemoveLocation(l)
call RemoveLocation(l2)
//
set bj_forLoopAIndexEnd = 36
set bj_forLoopAIndex = 1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set l = GetRectCenter(gg_rct_zTELoc1x2)
set l2 = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x01a)
set r = 45 //AngleBetweenPoints(l, l2)
set r2 = GetRandomDirectionDeg()
set g = udg_zT_environmentG
set udg_tempLoc2 = PolarProjectionBJ(l, GetRandomReal(0, udg_tempReal), r)
set udg_tempLoc = PolarProjectionBJ(udg_tempLoc2, GetRandomReal(0, 200.00), r2)
call RemoveLocation(udg_tempLoc2)
set udg_tempInt = GetRandomInt(1, 11)
set udg_tempInt2 = 1
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01V', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h020', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Y', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Z', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01X', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h009', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01W', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
//call CreateNUnitsAtLoc( 1, 'h023', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h022', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h021', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
call GroupAddUnit( g, GetLastCreatedUnit() )
call IssueImmediateOrderBJ(bj_lastCreatedUnit, "holdposition")
call RemoveLocation(udg_tempLoc)
call RemoveLocation(l)
call RemoveLocation(l2)
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
set bj_forLoopAIndex = 1
//PLUG LEAKS
set l = null
set l2 = null
set r = 0
set r2 = 0
set g = null
set i = 0
set picked = 0
endfunction
function zT_preDUnits2 takes nothing returns nothing
local location l = null
local location l2 = null
local real r = 0
local real r2 = 0
local group g = null
local integer i = 1
local integer i2 = 3
local integer picked = udg_zTxCreateGroup
// MAIN PART
set l = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x02b)
set l2 = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x02a)
set udg_tempReal = DistanceBetweenPoints(l, l2)
call RemoveLocation(l)
call RemoveLocation(l2)
//
set bj_forLoopAIndexEnd = 16
set bj_forLoopAIndex = 1
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set l = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x02b)
set l2 = GetRectCenter(gg_rct_Intro_x_Stampede_Wall_01x02a)
set r = 45 // AngleBetweenPoints(l, l2) //
set r2 = GetRandomDirectionDeg()
set g = udg_zT_environmentG
set udg_tempLoc2 = PolarProjectionBJ(l, GetRandomReal(0, udg_tempReal), r)
set udg_tempLoc = PolarProjectionBJ(udg_tempLoc2, GetRandomReal(0, 200.00), r2)
call RemoveLocation(udg_tempLoc2)
set udg_tempInt = GetRandomInt(1, 11)
set udg_tempInt2 = 1
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01V', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h020', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Y', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01Z', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01X', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h009', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h01W', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
//call CreateNUnitsAtLoc( 1, 'h023', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h022', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
if udg_tempInt == udg_tempInt2 then
call CreateNUnitsAtLoc( 1, 'h021', Player(0), udg_tempLoc, bj_UNIT_FACING )
endif
set udg_tempInt2 = ( udg_tempInt2 + 1 )
call GroupAddUnit( g, GetLastCreatedUnit() )
call IssueImmediateOrderBJ(bj_lastCreatedUnit, "holdposition")
call RemoveLocation(udg_tempLoc)
call RemoveLocation(l)
call RemoveLocation(l2)
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
set bj_forLoopAIndex = 1
//PLUG LEAKS
set l = null
set l2 = null
set r = 0
set r2 = 0
set g = null
set i = 0
set picked = 0
endfunction
function zT_nextTerrain takes nothing returns nothing
local location l = null
local integer tI = 0
local rect rct = gg_rct_intro_hide_doodads
local real dist = 0
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = 30
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
//MAIN PART
loop
exitwhen i > iC
set l = GetRandomLocInRect(rct)
set rI = GetRandomInt(1,4)
if rI == 1 then
set tTI = 'Bdrt' //dirt, etc
elseif rI == 2 then
set tTI = 'Bdro'
elseif rI == 3 then
set tTI = 'Bdrg'
elseif rI == 4 then
set tTI = 'Bgrs'
endif
call SetTerrainTypeBJ( l, tTI, -1, 1, 0 )
set x = GetLocationX(l)
set y = GetLocationY(l)
set xS = R2S(x)
set yS = R2S(y)
call sAI_saveIntegerParameter(tTI, xS + yS, "zT_terrain", udg_tempHash)
call sAI_saveLocationParameter(l, "loc", "zT_terrain_" + xS + yS, udg_tempHash)
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set tI = 0
set rct = null
set dist = 0
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
endfunction
function zT_nextTornadoes takes nothing returns nothing
local location l = null
local integer tI = 0
local rect rct = gg_rct_intro_hide_doodads
local real dist = 0
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = GetRandomInt(0,4)
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
//MAIN PART
loop
exitwhen i > iC
set l = GetRandomLocInRect(rct)
set tTI = 'n022'
call CreateNUnitsAtLoc( 1, tTI, Player(0), l, bj_UNIT_FACING )
call GroupAddUnit(udg_zT_environmentG, bj_lastCreatedUnit)
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set tI = 0
set rct = null
set dist = 0
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
endfunction
function zT_nextLightning takes nothing returns nothing
local location l = GetRectCenter(gg_rct_introkaelrun)
local integer tI = GetTerrainCliffLevelBJ(l)
local rect rct = gg_rct_intro_hide_doodads
local real dist = 0
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = 30
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
//MAIN PART
loop
exitwhen i > iC
set l = GetRandomLocInRect(rct)
set rI = GetRandomInt(1,4)
call AddSpecialEffectLocBJ( l, "Doodads\\Cinematic\\Lightningbolt\\Lightningbolt.mdl" )
set x = GetLocationX(l)
set y = GetLocationY(l)
set xS = R2S(x)
set yS = R2S(y)
call sAI_addEffectParameter(bj_lastCreatedEffect, "zT_lightning", "", udg_tempHash)
call sAI_saveLocationParameter(l, "loc", udg_lastPLS, udg_tempHash)
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set tI = 0
set rct = null
set dist = 0
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
endfunction
function zT_moveTerrain takes nothing returns nothing
local location l = GetRectCenter(gg_rct_introkaelrun)
local integer tI = GetTerrainCliffLevelBJ(l)
local rect rct = gg_rct_intro_hide_doodads
local real dist = udg_zT_dist
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = 0
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
local string iS = ""
local integer sI = 0
local string s = ""
local string name = ""
local location sL = null
local integer sTI = 0
local real ang = udg_zT_ang
//MAIN PART
set s = "zT_terrain_metaList_indexCount"
set sI = StringHash(s)
set iC = LoadIntegerBJ(0, sI, udg_tempHash)
loop
exitwhen i > iC
set iS = I2S(i)
set sI = StringHash("zT_terrain_metaList_" + iS)
set s = LoadStringBJ(0, sI, udg_tempHash)
set name = s
set sI = StringHash("zT_terrain_" + s)
set tTI = LoadIntegerBJ(0, sI, udg_tempHash)
set sTI = tTI
set sI = StringHash("zT_terrain_" + name + "_loc")
//call DisplayTextToForce(GetPlayersAll(), "sti " + I2S(sTI))
//call DisplayTextToForce(GetPlayersAll(), "name " + name)
set l = LoadLocationHandleBJ(0, sI, udg_tempHash)
set sL = l
set l = PolarProjectionBJ(l, dist, ang)
call SetTerrainTypeBJ( l, tTI, -1, 1, 0 )
set x = GetLocationX(l)
set y = GetLocationY(l)
set xS = R2S(x)
set yS = R2S(y)
call sAI_saveIntegerParameter(sTI, xS + yS, "zT_terrain", udg_tempHash)
call sAI_saveLocationParameter(l, "loc", "zT_terrain_" + xS + yS, udg_tempHash)
call sAI_deleteDataTree("zT_terrain_" + name, udg_tempHash)
set i = i + 1
endloop
//PLUG LEAKS
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
set rI = 0
set tI2 = 0
set i = 0
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
set iS = ""
set sI = 0
set s = ""
set name = ""
set sL = null
set sTI = 0
set ang = 0
endfunction
function zT_moveLightning takes nothing returns nothing
local location l = null
local integer tI = 0
local rect rct = gg_rct_intro_hide_doodads
local real dist = udg_zT_dist
local integer tTI = 0
local integer rI = 0
local integer tI2 = 0
local integer i = 1
local integer iC = 0
local real x = 0
local real y = 0
local string xS = ""
local string yS = ""
local string iS = ""
local integer sI = 0
local string s = ""
local string name = ""
local location sL = null
local integer sTI = 0
local real ang = udg_zT_ang
local effect fx = null
local location l2 = GetRectCenter(gg_rct_introkaelrun)
//MAIN PART
set s = "zT_lightning_indexCount"
set sI = StringHash(s)
set iC = LoadIntegerBJ(0, sI, udg_tempHash)
loop
exitwhen i > iC
set iS = I2S(i)
set sI = StringHash("zT_lightning_" + iS + "_loc")
set l = LoadLocationHandleBJ(0, sI, udg_tempHash)
set sL = l
set l = PolarProjectionBJ(l, dist, ang)
set s = "zT_lightning_" + iS
set sI = StringHash(s)
set fx = LoadEffectHandleBJ(0, sI, udg_tempHash)
set x = GetLocationX(l)
set y = GetLocationY(l)
set xS = R2S(x)
set yS = R2S(y)
call BlzSetSpecialEffectPosition( fx, x, y, 0.0 )
call sAI_saveLocationParameter(l, "loc", "zT_lightning_" + iS, udg_tempHash)
//
set dist = DistanceBetweenPoints(l, l2)
if dist > 3000 then
call sAI_deleteDataTree("zT_lightning_" + iS, udg_tempHash)
endif
set i = i + 1
endloop
//PLUG LEAKS
set l = null
set tI = 0
set rct = null
set dist = 0
set tTI = 0
set rI = 0
set tI2 = 0
set i = 1
set iC = 0
set x = 0
set y = 0
set xS = ""
set yS = ""
set iS = ""
set sI = 0
set s = ""
set name = ""
set sL = null
set sTI = 0
set ang = 0
set fx = null
call RemoveLocation(l2)
set l2 = null
endfunction
function zT_moveObjects takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local string uIS = I2S(GetHandleId(u))
local location l = GetCameraTargetPositionLoc()
local group g = CreateGroup()
local group g2 = null
local location uL = null
local location l1 = udg_zT_startLoc
local location l2 = udg_zT_endLoc
local location l3 = null
local location nL = null
local real ang = 0
local real offset = 0
local real x = 0
local real y = 0
local real dist = 0
//MAIN PART
set ang = udg_zT_ang
set offset = udg_zT_dist
call GroupAddGroup(udg_zT_environmentG, g)
call GroupAddGroup(udg_zT_unitGroup, g)
call GroupAddGroup(udg_rocks, g)
set u = FirstOfGroup(g)
call zT_changeSpeeds()
//==================================================
loop
exitwhen (u == null)
set uL = GetUnitLoc(u)
set dist = DistanceBetweenPoints(uL, l2)
set nL = PolarProjectionBJ(uL, offset, ang)
set x = GetLocationX(nL)
set y = GetLocationY(nL)
call SetUnitX(u, x)
call SetUnitY(u, y)
//call SetUnitPositionLoc(u, nL)
if (u == udg_CineKael) then
set l3 = GetRectCenter(gg_rct_introkaelrun)
call IssuePointOrderLocBJ(u, "move", l3)
elseif(u == udg_EarthKing) then
set l3 = GetRectCenter(gg_rct_introsairarun)
call IssuePointOrderLocBJ(u, "move", l3)
elseif(u == udg_CineSaira) then
set l3 = GetRectCenter(gg_rct_introsairarun)
call IssuePointOrderLocBJ(u, "move", l3)
set l3 = GetRectCenter(gg_rct_introericrun)
elseif(u == udg_CineEric) then
call IssuePointOrderLocBJ(u, "move", l3)
else
call IssueImmediateOrderBJ(u, "holdposition")
endif
call RemoveLocation(nL)
call RemoveLocation(uL)
if dist > 5000 then
call KillUnit(u)
call GroupRemoveUnit(udg_zT_unitGroup, u)
call GroupRemoveUnit(udg_zT_environmentG, u)
endif
call GroupRemoveUnit(g, u)
set u = FirstOfGroup(g)
endloop
//PLUG LEAKS
call RemoveLocation(l)
set l = null
call RemoveLocation(l3)
set l3 = null
set l1 = null
set l2 = null
set nL = null
set uL = null
call DestroyGroup(g)
set g = null
set g2 = null
set t = null
set u = null
set uIS = ""
set tIS = ""
set ang = 0
set offset = 0
set x = 0
set y = 0
endfunction
function c_introRocks takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local real duration = s_tDR(tIS, "duration")
local real time = 3.25
//MAIN PART
if (udg_zT_on == true) then
call s_eK_flingRocks()
call TimerStart (t, time, false, function c_introRocks)
else
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
endif
//PLUG LEAKS
set t = null
set tIS = ""
set duration = 0
set time = 0
endfunction
function c_introStampede takes integer pI, real mag, real duration returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
//MAIN PART
call s_tDI_s(pI, tIS, "playerId")
call s_tDR_s(duration, tIS, "duration")
call s_tDR_s(mag, tIS, "magnitude")
call TimerStart (CreateTimer(), 2.5, false, function c_introRocks)
//PLUG LEAKS
set t = null
set tIS = ""
set mag = 0
set duration = 0
endfunction
function zT_cycle takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = null
local string uIS = I2S(GetHandleId(u))
local location l = GetCameraTargetPositionLoc()
local group g = CreateGroup()
local group g2 = null
local location uL = null
local location l1 = udg_zT_startLoc
local location l2 = udg_zT_endLoc
local location nL = null
local real ang = 0
local real offset = 0
local real x = 0
local real y = 0
local timer t2 = CreateTimer()
local timer t3 = CreateTimer()
//MAIN PART
call GroupAddGroup(udg_zT_unitGroup, g)
call GroupAddGroup(udg_rocks, g)
set u = FirstOfGroup(g)
if (udg_zT_on == true) then
set udg_zT_dist = DistanceBetweenPoints(l, l1)
set udg_zT_ang = AngleBetweenPoints(l, l1)
call zT_moveObjects()
call zT_moveTerrain()
call zT_moveLightning()
//===========================================================================
//CREATE ENVIRONMENT HERE
//===========================================================================
call zT_nextDUnits()
call zT_nextDUnits2()
call zT_nextTerrain()
call zT_nextLightning()
call zT_nextTornadoes()
//===========================================================================
//
//===========================================================================
call TimerStart(t, 3.2, false, function zT_cycle) // just slowly widens gap over time i think //(0.03125 * I2R(loopI))
call TimerStart(t2, 2, false, function zT_camShake)
call TimerStart(t3, 4, false, function zT_camShake_expires)
call PanCameraToTimedLocForPlayer( Player(0), udg_zT_startLoc, 0 )
call PanCameraToTimedLocForPlayer( Player(0), udg_zT_endLoc, 10.00 )
endif
if (udg_zT_on2 == false) then
//call DisplayTextToForce(GetPlayersAll(), "loop ended")
call DestroyTimer(t)
call sAI_deleteDataTree("zT_lightning", udg_tempHash)
call sAI_deleteDataTree("zT_terrain", udg_tempHash)
endif
// for some reason this loop is terminating for reasons I cannot specify
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set l1 = null
set l2 = null
set nL = null
set uL = null
call DestroyGroup(g)
set g = null
set g2 = null
set t = null
set u = null
set uIS = ""
set tIS = ""
set ang = 0
set offset = 0
set x = 0
set y = 0
set t2 = null
set t3 = null
endfunction
function gale_rests takes nothing returns nothing
local unit u = udg_GaleWinterFreeze
local string uIS = I2S(GetHandleId(u))
local location l = GetRectCenter(gg_rct_Gale_Rest)
//MAIN PART
call s_removeUnit(u)
call CreateNUnitsAtLoc( 1, 'n01X', Player(PLAYER_NEUTRAL_PASSIVE), GetRectCenter(gg_rct_Gale_Rest), bj_UNIT_FACING )
set u = bj_lastCreatedUnit
call SetUnitPositionLoc(u, l)
call PauseUnit(u, true)
call UnitAddType(u, UNIT_TYPE_SLEEPING)
call s_uDB_s(true, uIS, "state_paused") // Cinematics will check and not unpause this unit.
//PLUG LEAKS
call RemoveLocation(l)
set l = null
set u = null
endfunction
function c_firestorm_loop takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local location l = s_tDL(tIS, "loc")
local group g = null
local real dist = s_tDR(tIS, "dist")
local real distEnd = 3000 //s_tDR(tIS, "distEnd")
local real ang = s_tDR(tIS, "angle")
local integer pI = GetConvertedPlayerId(GetOwningPlayer(udg_CineKael))
local unit eU = null
local real x = 0
local real y = 0
local location l2 = l
//MAIN PART
set x = GetLocationX(l)
set y = GetLocationY(l)
call s_effect("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl", Location(x,y), 6)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 2, 1)
//call DisplayTextToForce(GetPlayersAll(), "dist: " + R2S(dist))
//call DisplayTextToForce(GetPlayersAll(), "distEnd: " + R2S(distEnd))
set g = GetUnitsInRangeOfLocAll(1000, l)
set eU = FirstOfGroup(g)
loop
exitwhen eU == null
if IsPlayerEnemy(GetOwningPlayer(eU), Player(0)) and BlzIsUnitInvulnerable(eU) == false then
call KillUnit(eU)
endif
call GroupRemoveUnit(g, eU)
set eU = FirstOfGroup(g)
endloop
//call DisplayTextToForce(GetPlayersAll(), "derp")
call DestroyTimer(t)
call DestroyGroup(g)
call RemoveLocation(l)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
set l = null
call DestroyGroup(g)
set g = null
set t = null
set tIS = ""
set dist = 0
set distEnd = 0
set ang = 0
set pI = 0
set eU = null
set x = 0
set y = 0
endfunction
//=================================================
//=================================================
//=================================================
//=================================================
function c_firestorm takes location l, integer count, real ang, real angOffset returns nothing
local timer t = null
local string tIS = ""
local integer i = 1
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real dist = 200
local location l2 = null
local real time = 0.25
//MAIN PART
call s_effect("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl", Location(x,y), 6)
call sAI_scaleEffectOverTime(bj_lastCreatedEffect, 1, 2, 1)
loop
exitwhen (i>count)
loop
exitwhen dist > 3000
set t = CreateTimer()
set tIS = I2S(GetHandleId(t))
call s_tDR_s(3000, tIS, "distEnd")
set l2 = PolarProjectionBJ(l, dist, ang)
set x = GetLocationX(l2)
set y = GetLocationY(l2)
call s_tDL_s(Location(x,y), tIS, "loc")
call s_tDR_s(ang, tIS, "angle")
call TimerStart(t, time, false, function c_firestorm_loop)
set time = time + 0.25
set dist = dist + 200
endloop
set time = 0.25
set ang = ang + angOffset
set dist = 200
set i = i + 1
endloop
//PLUG LEAKS
//call RemoveLocation(l)
set l = null
set count = 0
set ang = 0
set angOffset = 0
set t = null
set tIS = ""
set i = 0
set l2 = null
set time = 0
set dist = 0
endfunction
function c_firebolt takes unit u, location l, location l2, real speedXY returns nothing
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local string uIS = ""
local real x = GetLocationX(l)
local real y = GetLocationY(l)
local real z = GetLocationZ(l)
local real tX = GetLocationX(l2)
local real tY = GetLocationY(l2)
local real tZ = GetLocationZ(l2)
local real dX = tX - x
local real dY = tY - y
local real dZ = tZ - z
local real angXY = AngleBetweenPoints(l, l2)
local real angZ = 0
local real distXY = DistanceBetweenPoints(l, l2)
//MAIN PART
//math
//projectile
call CreateNUnitsAtLoc( 1, 'h029', GetOwningPlayer(u), l, GetRandomDirectionDeg() )
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call SetUnitFlyHeight( GetLastCreatedUnit(), z, 0)
call s_tDL_s(l, tIS, "loc")
call s_tDL_s(l2, tIS, "targetLoc")
call s_tDR_s(400, tIS, "damage")
call s_tDR_s(200, tIS, "radius")
call s_tDR_s(speedXY, tIS, "speedXY")
call s_tDR_s((distXY / 2), tIS, "centerDist")
call TimerStart(t, udg_gameloop_fx, false, function s_laserProjectileTarget)
//PLUG LEAKS
set l = null
set t = null
set l2 = null
set u = null
set uIS = ""
set tIS = ""
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set dX = 0
set dY = 0
set dZ = 0
set angXY = 0
set angZ = 0
set distXY = 0
endfunction
function s_fireBreath_expire takes nothing returns nothing
local timer t = GetExpiredTimer()
local string tIS = I2S(GetHandleId(t))
local unit u = s_tDU(tIS, "unit")
//MAIN PART
call KillUnit(u)
call sAI_deleteDataTree(tIS, udg_tempHash)
//PLUG LEAKS
call DestroyTimer(t)
set t = null
set tIS = ""
set u = null
endfunction
//===============================================================================
//===============================================================================
function s_firebreath_missile takes nothing returns nothing
local unit u = udg_Dhjeri
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local location l = s_tDL(tIS, "loc")
local real ang = s_tDR(tIS, "angle")
local real rA = GetRandomDirectionDeg()
//MAIN PART
call CreateNUnitsAtLoc( 1, 'h01P', Player(8), l, ang )
set l = PolarProjectionBJ(l, 1500, ang)
call IssuePointOrderLoc(GetLastCreatedUnit(), "move", l)
call s_tDU_s(GetLastCreatedUnit(), tIS, "unit")
call TimerStart(t, 5, false, function s_g_fireBreath_expire)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDU_s(bj_lastCreatedUnit, tIS, "unit")
call TimerStart(t, 0, false, function g_firebreath_check)
//call DisplayTextToForce(GetPlayersAll(), "cast fb missile")
// PLUG LEAKS
set u = null
set t = null
set tI = 0
set tIS = ""
set l = null
set ang = 0
set rA = 0
endfunction
function s_fireBreath takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = s_tDU(tIS, "unit")
local location uL = GetUnitLoc(u)
local real uF = GetUnitFacing(u)
local real ang = s_tDR(tIS, "angle")
local location l = PolarProjectionBJ(uL, 1500, ang)
local location l1 = PolarProjectionBJ(uL, 450, uF)
local real time = 0
local integer balls = 6
local real period = 0.125
local integer i = 1
//MAIN PART
call DestroyTimer(t)
call sAI_deleteDataTree(tIS, udg_tempHash)
//============================
call RemoveLocation(uL)
//call DisplayTextToForce(GetPlayersAll(), "balls " + I2S(balls))
call SetUnitAnimation( udg_Dhjeri, "spell" )
call QueueUnitAnimationBJ( udg_Dhjeri, "stand" )
loop
exitwhen i > balls
set uL = GetUnitLoc(u)
set t = CreateTimer()
set tI = GetHandleId(t)
set tIS = I2S(tI)
call s_tDR_s(ang, tIS, "angle")
call s_tDL_s(uL, tIS, "loc")
call TimerStart(t, time, false, function s_firebreath_missile)
set time = time + period
set i = i + 1
//call DisplayTextToForce(GetPlayersAll(), I2S(i))
endloop
//PLUG LEAKS
call RemoveLocation(l)
call RemoveLocation(l1)
set uL = null
set l = null
set l1 = null
set t = null
set tI = 0
set tIS = ""
set uF = 0
set ang = 0
set time = 0
set balls = 0
set period = 0
set i = 0
endfunction
function s_fireBreath_main takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer tI = GetHandleId(t)
local string tIS = I2S(tI)
local unit u = s_tDU(tIS, "unit")
local integer uI = GetHandleId(u)
local string uIS = I2S(uI)
local real time = 0
local real delay = s_uDR(u, "ability_firebreath_cast_delay")
local integer casts = 1
local integer i = 1
local location l = null
local unit tU = s_uDU(u, "targetHero")
local integer rCasts = 1
local location uL = GetUnitLoc(u)
local location tUL = GetUnitLoc(tU)
local location l2 = s_tDL(tIS, "targetLoc")
local real rA = 0
local real a = AngleBetweenPoints(uL, l2)
local real castTime = 0
//MAIN PART
call s_tDR_s(a + rA, tIS, "angle")
call TimerStart(t, castTime, false, function s_fireBreath)
//PLUG LEAKS
set u = null
set uI = 0
set uIS = ""
set t = null
set time = 0
set delay = 0
set casts = 0
set i = 0
set l = null
set tU = null
set rCasts = 0
set uL = null
set tUL = null
set l2 = null
set tI = 0
set tIS = ""
set rA = 0
set a = 0
set castTime = 0
endfunction
function c_drainMana takes real x, real y, real z, real tX, real tY, real tZ, real time, real r, real g, real b returns nothing
local unit u = udg_Gustivus
local location uL = GetUnitLoc(u)
local location l = null
local real ang = GetUnitFacing(u)
local real dist = 600
local location dLoc = null
local timer t = CreateTimer()
local string tIS = I2S(GetHandleId(t))
local integer count = s_uDI(u, "lightning_remainingCount")
local real delay = 0.5
local integer rI = 0
//MAIN PART
set l = PolarProjectionBJ(uL, 300, ang)
set bj_lastCreatedLightning = AddLightningEx("DRAM", true, x, y, z, tX, tY, tZ)
call sAI_saveLightningParameter(bj_lastCreatedLightning, "lightning", tIS, udg_tempHash) // does the placeholding DLS string create memory leak? prob not
call TimerStart(t, time, false, function s_lightningXYZ_expires)
//PLUG LEAKS
call RemoveLocation(uL)
set uL = null
call RemoveLocation(l)
set l = null
set u = null
set ang = 0
set dist = 0
set x = 0
set y = 0
set z = 0
set tX = 0
set tY = 0
set tZ = 0
set r = 0
set g = 0
set b = 0
set t = null
set tIS = ""
set count = 0
set delay = 0
set time = 0
set rI = 0
endfunction