function DisplayOrderID takes nothing returns nothing
call BJDebugMsg( I2S(GetIssuedOrderIdBJ()) )
endfunction
function ShowMsgToAll takes string message returns nothing
call DisplayTimedTextToForce( GetPlayersAll(), 3, message )
endfunction
function ShowMsgToPlayer takes player pl, string message returns nothing
call DisplayTimedTextToPlayer( pl, 0, 0, 3, message )
endfunction
function GetPlayerIndex takes player pl returns integer
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
if ( Player(nPlayerIndex) == pl ) then
return nPlayerIndex
endif
set nPlayerIndex = nPlayerIndex + 1
endloop
return -1
endfunction
function IsValidPlayer takes player pl returns boolean
return GetPlayerController(pl) == MAP_CONTROL_USER and GetPlayerSlotState(pl) == PLAYER_SLOT_STATE_PLAYING
endfunction
function GetPlayerColorIndex takes integer nPlayerIndex returns integer
local playercolor pc = GetPlayerColor(Player(nPlayerIndex))
if ( pc == PLAYER_COLOR_RED ) then
return 0
elseif ( pc == PLAYER_COLOR_BLUE ) then
return 1
elseif ( pc == PLAYER_COLOR_CYAN ) then
return 2
elseif ( pc == PLAYER_COLOR_PURPLE ) then
return 3
elseif ( pc == PLAYER_COLOR_YELLOW ) then
return 4
elseif ( pc == PLAYER_COLOR_ORANGE ) then
return 5
elseif ( pc == PLAYER_COLOR_GREEN ) then
return 6
elseif ( pc == PLAYER_COLOR_PINK ) then
return 7
elseif ( pc == PLAYER_COLOR_LIGHT_GRAY ) then
return 8
elseif ( pc == PLAYER_COLOR_LIGHT_BLUE ) then
return 9
elseif ( pc == PLAYER_COLOR_AQUA ) then
return 10
elseif ( pc == PLAYER_COLOR_BROWN ) then
return 11
endif
return 0
endfunction
function GetColoredString takes integer nPlayerIndex, string str returns string
return udg_ColorString[GetPlayerColorIndex(nPlayerIndex)] + str + "|r"
endfunction
function GetColoredPlayerName takes integer nPlayerIndex returns string
return GetColoredString( nPlayerIndex, GetPlayerName(Player(nPlayerIndex)) )
endfunction
function InterLineLine takes real x1, real y1, real x2, real y2, real a1, real b1, real a2, real b2, location loc returns boolean
local real p = (x2-x1)*(b2-b1)-(y2-y1)*(a2-a1)
local real x
local real y
if ( p == 0 ) then
return false
endif
set x = ((x2-x1)*(a2-a1)*(y1-b1)+(x2-x1)*(b2-b1)*a1-(y2-y1)*(a2-a1)*x1)/p
set y = -((y2-y1)*(b2-b1)*(x1-a1)+(y2-y1)*(a2-a1)*b1-(x2-x1)*(b2-b1)*y1)/p
call MoveLocation( loc, x, y )
return true
endfunction
function obh_StandardAngle takes real rAngle returns real
loop
if ( rAngle <= -bj_PI ) then
set rAngle = rAngle + 2 * bj_PI
elseif ( rAngle > bj_PI ) then
set rAngle = rAngle - 2 * bj_PI
else
exitwhen true
endif
endloop
return rAngle
endfunction
function obh_AngleBetweenPoints takes real x1, real y1, real x2, real y2 returns real
if ( x1 == x2 ) then
if ( y2 > y1 ) then
return bj_PI/2
else
return -bj_PI/2
endif
elseif ( y1 == y2 ) then
if ( x2 > x1 ) then
return 0
else
return bj_PI
endif
else
return Atan2(y2 - y1, x2 - x1)
endif
endfunction
function obh_DistanceBetweenPoints takes real x1, real y1, real x2, real y2 returns real
return SquareRoot( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) )
endfunction
Name | Type | is_array | initial_value |
AUnitHits | trigger | Yes | |
BonusForFakeChild | integer | No | |
BonusForKill | integer | No | |
CenterFoodGroup | group | No | |
ChildEffect | effect | No | |
ColorBlue | integer | Yes | |
ColorGreen | integer | Yes | |
ColorRed | integer | Yes | |
ColorString | string | Yes | |
CravingEffect | effect | Yes | |
CravingFood | unit | Yes | |
CRAVINGFOOD_MAXNUM | integer | No | 20 |
CravingFoodLightning | lightning | Yes | |
CravingFoodNum | integer | Yes | |
CravingStage | integer | Yes | -1 |
CRAVINGSTAGE_MAX | integer | No | 18 |
CravingTimer | timer | Yes | |
CreateWormHeadPlayerIndex | integer | No | -1 |
CurrentAngle | real | Yes | |
CurrentTargetLoc | location | Yes | |
FoodSpawnExt | timer | No | |
FoodTypes | unitcode | Yes | |
FoodTypesNum | integer | No | |
GameOver | boolean | No | |
HOSTILE | player | No | PlayerNA |
KILLSTYLE_BORDER | integer | No | 2 |
KILLSTYLE_NORMAL | integer | No | |
KILLSTYLE_SCORPION | integer | No | 3 |
KILLSTYLE_SELF | integer | No | 1 |
KillWormByLightning | boolean | Yes | |
KillWormSeg | integer | Yes | -1 |
KillWormTimer | timer | Yes | |
LightningKillEffect | lightning | Yes | |
MultiSquishStart | boolean | Yes | |
MultiSquishTimer | timer | Yes | |
nAddAddLength | integer | No | |
NPC | player | No | PlayerNP |
nPlayerIndexAddLength | integer | No | |
NumberToWin | integer | No | |
NumCenterFood | integer | No | |
NumExtFood | integer | No | |
NumFood | integer | No | |
NumSuperFood | integer | No | |
NvrStopTimer | timer | No | |
PLAYERNUM | integer | No | 12 |
PosGoo | unit | No | |
PositionOfFakeChild | unit | No | |
POSNUM_PERSEG | integer | No | 1 |
Powerup | unit | Yes | |
PowerupAbilities | abilcode | Yes | |
PowerupChances | integer | Yes | |
PowerupNames | string | Yes | |
PowerupPickTrg | trigger | Yes | |
PowerupSpawnTimer | timer | No | |
PowerupTypesNum | integer | No | |
RespawnTime | real | No | |
Reversing | boolean | Yes | |
Scoreboard | leaderboard | No | |
ScorpionEaterEffect | effect | Yes | |
ScorpionEaterId | integer | Yes | -1 |
ScorpionEatingRewards | integer | No | 5 |
ScorpionHits | trigger | Yes | |
ScorpionMoveTimer | timer | No | |
ScorpionNum | integer | No | 3 |
Scorpions | unit | Yes | |
SpawnNum | integer | No | |
SpawnPowerupIndex | integer | No | -1 |
SquishingPlayer | player | No | |
StickyGooCaster | player | No | |
StickyGooPowerup | item | No | |
STR_DEFEAT | string | No | |
STR_EATSCORPION | string | No | |
STR_GOOBOMB | string | No | |
STR_MORESHEEP | string | No | |
STR_MULTISQUISH | string | No | |
STR_MULTISQUISH_FLOATTEXT | string | No | |
STR_OUTOFBORDER | string | No | |
STR_PLAYERLEFT | string | No | |
STR_POWERUP_PICKUP | string | No | |
STR_SCORPIONSQUISH | string | No | |
STR_SEGMENTBOMB1 | string | No | |
STR_SEGMENTBOMB2 | string | No | |
STR_SELFSQUISH | string | No | |
STR_SQUISH1 | string | No | |
STR_SQUISH2 | string | No | |
STR_SQUISH_FLOATTEXT | string | No | |
STR_WARNING_10SEG1 | string | No | |
STR_WARNING_10SEG2 | string | No | |
STR_WORMMASTER | string | No | |
strLeadAddLength | string | No | |
TempPlayerGroup | force | No | |
TimeUntilEnd | real | No | |
UT_ItemHolder | unitcode | No | e002 |
UT_Pig | unitcode | No | n001 |
UT_Powerup | unitcode | No | U001 |
UT_Scorpion | unitcode | No | n00A |
UT_Sheep | unitcode | No | n009 |
UT_WormHead | unitcode | No | U000 |
UT_WormSegment | unitcode | No | e000 |
WormHead | unit | Yes | |
WormLength | integer | Yes | |
WormRespawn | boolean | Yes | |
WormSegments | unit | Yes | |
WormSlowed | boolean | Yes | |
WormSlowedId | integer | Yes | -1 |
function IsWormAlive takes integer nPlayerIndex returns boolean
return udg_WormHead[nPlayerIndex] != null and IsUnitAliveBJ( udg_WormHead[nPlayerIndex] )
endfunction
function IsWormDead takes integer nPlayerIndex returns boolean
return not IsWormAlive( nPlayerIndex )
endfunction
function RemoveWorm takes integer nPlayerIndex returns nothing
local integer nIndex = 0
local integer nIndexEnd
if ( udg_CurrentTargetLoc[nPlayerIndex] != null ) then
call RemoveLocation( udg_CurrentTargetLoc[nPlayerIndex] )
set udg_CurrentTargetLoc[nPlayerIndex] = null
endif
call RemoveUnit( udg_WormHead[nPlayerIndex] )
set udg_WormHead[nPlayerIndex] = null
set nIndex = udg_NumberToWin * nPlayerIndex
set nIndexEnd = nIndex + udg_WormLength[nPlayerIndex]
loop
exitwhen nIndex >= nIndexEnd
call RemoveUnit( udg_WormSegments[nIndex] )
set nIndex = nIndex + 1
endloop
set udg_WormLength[nPlayerIndex] = 0
endfunction
function WormLightningDeath takes integer nPlayerIndex returns nothing
local integer nIndex
local real x = GetUnitX(udg_WormHead[nPlayerIndex])
local real y = GetUnitY(udg_WormHead[nPlayerIndex])
if ( udg_KillWormSeg[nPlayerIndex] >= 0 ) then
return
endif
set udg_LightningKillEffect[nPlayerIndex] = AddLightning( "CLPB", true, x - 100, y + 600, x, y )
call AddSpecialEffectTarget( "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", udg_WormHead[nPlayerIndex], "chest" )
call KillUnit( udg_WormHead[nPlayerIndex] )
if ( udg_WormLength[nPlayerIndex] <= 0 ) then
call DestroyLightning( udg_LightningKillEffect[nPlayerIndex] )
set udg_LightningKillEffect[nPlayerIndex] = null
return
endif
set udg_KillWormSeg[nPlayerIndex] = 0
set udg_KillWormByLightning[nPlayerIndex] = true
call TimerStart( udg_KillWormTimer[nPlayerIndex], 0.07, true, null )
loop
call TriggerSleepAction( 0.1 )
exitwhen udg_KillWormSeg[nPlayerIndex] < 0
endloop
if ( udg_LightningKillEffect[nPlayerIndex] != null ) then
call DestroyLightning( udg_LightningKillEffect[nPlayerIndex] )
set udg_LightningKillEffect[nPlayerIndex] = null
endif
endfunction
function WormExplodeDeath takes integer nPlayerIndex, integer nPlayerIndexKiller returns nothing
local integer nIndex
local real x = GetUnitX(udg_WormHead[nPlayerIndex])
local real y = GetUnitY(udg_WormHead[nPlayerIndex])
if ( udg_KillWormSeg[nPlayerIndex] >= 0 ) then
return
endif
call AddSpecialEffectTarget( "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl", udg_WormHead[nPlayerIndex], "origin" )
if ( nPlayerIndexKiller != nPlayerIndex ) then
call SetUnitInvulnerable( udg_WormHead[nPlayerIndex], false )
call UnitDamageTargetBJ( udg_WormHead[nPlayerIndexKiller], udg_WormHead[nPlayerIndex], 2000, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
else
call KillUnit( udg_WormHead[nPlayerIndex] )
endif
if ( udg_WormLength[nPlayerIndex] <= 0 ) then
return
endif
set udg_KillWormSeg[nPlayerIndex] = 0
set udg_KillWormByLightning[nPlayerIndex] = false
call TimerStart( udg_KillWormTimer[nPlayerIndex], 0.07, true, null )
loop
call TriggerSleepAction( 0.1 )
exitwhen udg_KillWormSeg[nPlayerIndex] < 0
endloop
endfunction
function BlowUpHead takes integer nPlayerIndex, integer nPlayerIndexKiller, boolean bLightning returns nothing
local integer nIndex
local integer nIndexEnd
local effect eff = null
local integer nPowerupTypeIndex
set nPowerupTypeIndex = 0
loop
exitwhen nPowerupTypeIndex >= udg_PowerupTypesNum
if ( GetUnitAbilityLevel(udg_WormHead[nPlayerIndex], udg_PowerupAbilities[nPowerupTypeIndex]) > 0 ) then
call UnitRemoveAbility( udg_WormHead[nPlayerIndex], udg_PowerupAbilities[nPowerupTypeIndex] )
endif
set nPowerupTypeIndex = nPowerupTypeIndex + 1
endloop
if ( udg_CurrentTargetLoc[nPlayerIndex] != null ) then
call RemoveLocation( udg_CurrentTargetLoc[nPlayerIndex] )
set udg_CurrentTargetLoc[nPlayerIndex] = null
endif
call LeaderboardSetPlayerItemValueBJ( Player(nPlayerIndex), udg_Scoreboard, 0 )
if ( bLightning ) then
call WormLightningDeath( nPlayerIndex )
else
call WormExplodeDeath( nPlayerIndex, nPlayerIndexKiller )
endif
set udg_WormLength[nPlayerIndex] = 0
endfunction
function LightningKillWormAction takes integer nPlayerIndex returns nothing
local integer nIndex
local real x1
local real y1
local real x2
local real y2
if ( udg_LightningKillEffect[nPlayerIndex] != null ) then
call DestroyLightning( udg_LightningKillEffect[nPlayerIndex] )
set udg_LightningKillEffect[nPlayerIndex] = null
endif
if ( udg_KillWormSeg[nPlayerIndex] < 0 ) then
return
elseif ( udg_KillWormSeg[nPlayerIndex] >= udg_WormLength[nPlayerIndex] ) then
set udg_KillWormSeg[nPlayerIndex] = -1
call PauseTimer( udg_KillWormTimer[nPlayerIndex] )
return
endif
set nIndex = udg_NumberToWin * nPlayerIndex + udg_KillWormSeg[nPlayerIndex]
if ( udg_KillWormSeg[nPlayerIndex] == 0 ) then
set x1 = GetUnitX(udg_WormHead[nPlayerIndex])
set y1 = GetUnitY(udg_WormHead[nPlayerIndex])
else
set x1 = GetUnitX(udg_WormSegments[nIndex - 1])
set y1 = GetUnitY(udg_WormSegments[nIndex - 1])
endif
set x2 = GetUnitX(udg_WormSegments[nIndex])
set y2 = GetUnitY(udg_WormSegments[nIndex])
set udg_LightningKillEffect[nPlayerIndex] = AddLightning( "CLPB", true, x1, y1, x2, y2 )
call AddSpecialEffectTarget( "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", udg_WormSegments[nIndex], "chest" )
call KillUnit(udg_WormSegments[nIndex])
set udg_KillWormSeg[nPlayerIndex] = udg_KillWormSeg[nPlayerIndex] + 1
endfunction
function ExplodeKillSegment takes integer nPlayerIndex, integer nSegIndex returns nothing
local integer nIndex
set nIndex = udg_NumberToWin * nPlayerIndex + nSegIndex
call AddSpecialEffectTarget( "Objects\\Spawnmodels\\Demon\\DemonLargeDeathExplode\\DemonLargeDeathExplode.mdl", udg_WormSegments[nIndex], "origin" )
call KillUnit(udg_WormSegments[nIndex])
endfunction
function ExplodeKillWormAction takes integer nPlayerIndex returns nothing
if ( udg_KillWormSeg[nPlayerIndex] < 0 ) then
return
elseif ( udg_KillWormSeg[nPlayerIndex] >= udg_WormLength[nPlayerIndex] ) then
set udg_KillWormSeg[nPlayerIndex] = -1
call PauseTimer( udg_KillWormTimer[nPlayerIndex] )
return
endif
call ExplodeKillSegment( nPlayerIndex, udg_KillWormSeg[nPlayerIndex] )
set udg_KillWormSeg[nPlayerIndex] = udg_KillWormSeg[nPlayerIndex] + 1
endfunction
function KillWormTimerAction takes timer t returns nothing
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
exitwhen t == udg_KillWormTimer[nPlayerIndex]
set nPlayerIndex = nPlayerIndex + 1
endloop
if ( nPlayerIndex >= udg_PLAYERNUM ) then
return
endif
if ( udg_KillWormByLightning[nPlayerIndex] ) then
call LightningKillWormAction( nPlayerIndex )
else
call ExplodeKillWormAction( nPlayerIndex )
endif
endfunction
//===========================================================================
function InitTrig_Kill_Worm_Functions takes nothing returns nothing
endfunction
function InitColor takes nothing returns nothing
local integer nIndex = 0
set udg_ColorRed[nIndex] = 255
set udg_ColorGreen[nIndex] = 0
set udg_ColorBlue[nIndex] = 0
set udg_ColorString[nIndex] = "|cffff0000" //red
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 0
set udg_ColorGreen[nIndex] = 0
set udg_ColorBlue[nIndex] = 255
set udg_ColorString[nIndex] = "|cff0000ff" //blue
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 0
set udg_ColorGreen[nIndex] = 245
set udg_ColorBlue[nIndex] = 255
set udg_ColorString[nIndex] = "|cff00f5ff" //Teal
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 85
set udg_ColorGreen[nIndex] = 26
set udg_ColorBlue[nIndex] = 139
set udg_ColorString[nIndex] = "|cff551A8B" //Purple
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 255
set udg_ColorGreen[nIndex] = 255
set udg_ColorBlue[nIndex] = 0
set udg_ColorString[nIndex] = "|cffffff00" //Yellow
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 248
set udg_ColorGreen[nIndex] = 154
set udg_ColorBlue[nIndex] = 0
set udg_ColorString[nIndex] = "|cffEE9A00" //Orange
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 0
set udg_ColorGreen[nIndex] = 255
set udg_ColorBlue[nIndex] = 0
set udg_ColorString[nIndex] = "|cff00CD00" //Green
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 255
set udg_ColorGreen[nIndex] = 105
set udg_ColorBlue[nIndex] = 180
set udg_ColorString[nIndex] = "|cffFF69B4" //Pink
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 192
set udg_ColorGreen[nIndex] = 192
set udg_ColorBlue[nIndex] = 192
set udg_ColorString[nIndex] = "|cffC0C0C0" //Gray
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 176
set udg_ColorGreen[nIndex] = 226
set udg_ColorBlue[nIndex] = 255
set udg_ColorString[nIndex] = "|cffB0E2FF" //Light Blue
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 0
set udg_ColorGreen[nIndex] = 100
set udg_ColorBlue[nIndex] = 0
set udg_ColorString[nIndex] = "|cff006400" //Dark Green
set nIndex = nIndex + 1
set udg_ColorRed[nIndex] = 139
set udg_ColorGreen[nIndex] = 69
set udg_ColorBlue[nIndex] = 19
set udg_ColorString[nIndex] = "|cff8B4513" //Brown
endfunction
function ResetPlayerNameColor takes boolean bColored returns nothing
local integer nIndex = 0
loop
exitwhen nIndex >= udg_PLAYERNUM
if ( bColored ) then
call SetPlayerName( Player(nIndex), GetColoredPlayerName( nIndex) )
else
call SetPlayerName( Player(nIndex), GetPlayerName(Player(nIndex)) )
endif
set nIndex = nIndex + 1
endloop
endfunction
function CreateWorms takes nothing returns nothing
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
if ( IsValidPlayer( Player(nPlayerIndex) ) ) then
set udg_CreateWormHeadPlayerIndex = nPlayerIndex
call TriggerExecute( gg_trg_Create_Worm_Head )
endif
set nPlayerIndex = nPlayerIndex + 1
endloop
endfunction
function SpawnStartFood takes nothing returns nothing
local integer nIndex
local location loc
local integer nType
local unit u
set nIndex = 0
loop
exitwhen nIndex >= udg_NumFood
set loc = GetRandomLocInRect(gg_rct_Food)
set nType = GetRandomInt( 0, udg_FoodTypesNum - 1 )
call CreateUnitAtLoc( udg_NPC, udg_FoodTypes[nType], loc, bj_UNIT_FACING )
call RemoveLocation( loc )
set nIndex = nIndex + 1
endloop
set nIndex = 0
loop
exitwhen nIndex >= udg_NumSuperFood
set loc = GetRandomLocInRect(gg_rct_Food)
call CreateUnitAtLoc( udg_NPC, 'n001', loc, bj_UNIT_FACING )
call RemoveLocation( loc )
set nIndex = nIndex + 1
endloop
set nIndex = 0
loop
exitwhen nIndex >= udg_NumCenterFood
set loc = GetRandomLocInRect(gg_rct_ArenaCenter)
set nType = GetRandomInt( 0, udg_FoodTypesNum - 1 )
set u = CreateUnitAtLoc( udg_NPC, udg_FoodTypes[nType], loc, bj_UNIT_FACING )
call RemoveLocation( loc )
call GroupAddUnit( udg_CenterFoodGroup, u )
set nIndex = nIndex + 1
endloop
endfunction
function SpawnExtFood takes nothing returns nothing
local integer nIndex
local location loc
local integer nType
local unit u
set nIndex = 0
loop
exitwhen nIndex >= udg_NumExtFood
set loc = GetRandomLocInRect(gg_rct_Food)
set nType = GetRandomInt( 0, udg_FoodTypesNum - 1 )
call CreateUnitAtLoc( udg_NPC, udg_FoodTypes[nType], loc, bj_UNIT_FACING )
call RemoveLocation( loc )
set nIndex = nIndex + 1
endloop
//call ShowMsgToAll( I2S(udg_NumExtFood) + udg_STR_MORESHEEP )
endfunction
function SpawnScorpions takes nothing returns nothing
call TriggerExecute( gg_trg_Spawn_Scorpions )
endfunction
//===========================================================================
function InitTrig_Initialization_Functions takes nothing returns nothing
endfunction
function Victory_Cin takes integer nPlayerIndexWin returns nothing
local integer nPlayerIndex
local location loc
local location loc1
local real rFacing
call CinematicModeBJ( true, GetPlayersAll() )
call StopMusicBJ( true )
call PlaySoundBJ( gg_snd_DarkVictory )
call SetUnitAnimationByIndex( udg_WormHead[nPlayerIndexWin], 6 )
set loc = GetUnitLoc( udg_WormHead[nPlayerIndexWin] )
set rFacing = GetUnitFacing( udg_WormHead[nPlayerIndexWin] ) + 150
set loc1 = PolarProjectionBJ( loc, 50, rFacing )
call RemoveLocation( loc )
set nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
call PanCameraToTimedLocForPlayer( Player(nPlayerIndex), loc1, 3.00 )
call SetCameraFieldForPlayer( Player(nPlayerIndex), CAMERA_FIELD_TARGET_DISTANCE, 2000.00, 3.00 )
set nPlayerIndex = nPlayerIndex + 1
endloop
call RemoveLocation( loc1 )
call PolledWait( 3.00 )
set nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
call SetCameraFieldForPlayer( Player(nPlayerIndex), CAMERA_FIELD_ROTATION, rFacing, 3.00 )
call SetCameraFieldForPlayer( Player(nPlayerIndex), CAMERA_FIELD_TARGET_DISTANCE, 800.00, 3.00 )
set nPlayerIndex = nPlayerIndex + 1
endloop
call PolledWait( 3.00 )
call PlaySoundBJ( gg_snd_WinnerPiss )
call SetUnitAnimation( udg_WormHead[nPlayerIndexWin], "spell throw" )
call QueueUnitAnimationBJ( udg_WormHead[nPlayerIndexWin], "spell channel" )
call PolledWait( 4.00 )
endfunction
function Victory takes integer nPlayerIndexWin returns nothing
local integer nPlayerIndex
local integer nIndex = 0
local integer nIndexEnd = 0
set udg_GameOver = true
call PauseAllUnitsBJ( true )
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndexWin) + udg_STR_WORMMASTER )
call PlaySoundBJ( gg_snd_Wormtastic )
call Victory_Cin( nPlayerIndexWin )
call CustomVictoryBJ( Player(nPlayerIndexWin), true, true )
set nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
if ( IsValidPlayer(Player(nPlayerIndex)) and nPlayerIndex != nPlayerIndexWin ) then
call CustomDefeatBJ( Player(nPlayerIndex), udg_STR_DEFEAT )
endif
set nPlayerIndex = nPlayerIndex + 1
endloop
endfunction
//===========================================================================
function InitTrig_Victory_and_Defeat takes nothing returns nothing
endfunction
function Warning10Remaining takes integer nPlayerIndex returns nothing
local location loc
call PlaySoundBJ( gg_snd_Warning )
call ShowMsgToAll( udg_STR_WARNING_10SEG1 + GetColoredPlayerName(nPlayerIndex) + udg_STR_WARNING_10SEG2 )
set loc = GetUnitLoc( udg_WormHead[nPlayerIndex] )
call PingMinimapLocForForceEx( GetPlayersAll(), loc, 5.00, bj_MINIMAPPINGSTYLE_SIMPLE, udg_ColorRed[nPlayerIndex] / 2.55, udg_ColorGreen[nPlayerIndex] / 2.55, udg_ColorBlue[nPlayerIndex] / 2.55 )
call RemoveLocation( loc )
endfunction
function WormResetSpeed takes integer nPlayerIndex returns nothing
local integer nSegIndex
local integer nIndex
local real rSpeed = GetUnitDefaultMoveSpeed(udg_WormHead[nPlayerIndex])
if ( udg_WormSlowed[nPlayerIndex] ) then
set rSpeed = rSpeed * .3
else
set rSpeed = rSpeed * ( 100 - udg_WormLength[nPlayerIndex] * 0.3 ) / 100
endif
call SetUnitMoveSpeed( udg_WormHead[nPlayerIndex], rSpeed )
set nSegIndex = 0
set nIndex = udg_NumberToWin * nPlayerIndex
loop
exitwhen nSegIndex >= udg_WormLength[nPlayerIndex]
call SetUnitMoveSpeed( udg_WormSegments[nIndex], rSpeed )
set nSegIndex = nSegIndex + 1
set nIndex = nIndex + 1
endloop
endfunction
function WormAddLength takes integer nPlayerIndex returns nothing
local location loc = null
local location loc1 = null
local integer nIndexStart
local unit uLast = null
local unit u = null
local integer nIndex = 0
local real rDir = 0
if ( IsWormDead( nPlayerIndex ) ) then
return
endif
if ( udg_WormLength[nPlayerIndex] >= udg_NumberToWin ) then
return
endif
set nIndexStart = udg_NumberToWin * nPlayerIndex
if ( udg_WormLength[nPlayerIndex] <= 0 ) then
set uLast = udg_WormHead[nPlayerIndex]
else
set uLast = udg_WormSegments[nIndexStart + udg_WormLength[nPlayerIndex] - 1]
endif
set loc1 = GetUnitLoc( uLast )
set loc = PolarProjectionBJ( loc1, 120.00, GetUnitFacing(uLast) + 180.00 )
call RemoveLocation( loc1 )
set rDir = GetUnitFacing(uLast)
set u = CreateUnitAtLoc( Player(nPlayerIndex), 'e000', loc, rDir )
call SetUnitInvulnerable( u, true )
call SetUnitPathing( u, false )
set nIndex = nIndexStart + udg_WormLength[nPlayerIndex]
call IssueTargetOrder( u, "move", uLast )
set udg_WormSegments[nIndex] = u
set udg_WormLength[nPlayerIndex] = udg_WormLength[nPlayerIndex] + 1
call AddSpecialEffectTarget( "Abilities\\Spells\\Orc\\SpikeBarrier\\SpikeBarrier.mdl", u, "origin" )
//call AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\ThornyShield\\ThornyShieldTargetChestLeft.mdl", u, "chest" )
call RemoveLocation( loc )
call WormResetSpeed( nPlayerIndex )
call LeaderboardSetPlayerItemValueBJ( Player(nPlayerIndex), udg_Scoreboard, udg_WormLength[nPlayerIndex] )
call LeaderboardSortItemsBJ( udg_Scoreboard, bj_SORTTYPE_SORTBYVALUE, false )
if ( udg_WormLength[nPlayerIndex] == udg_NumberToWin - 10 ) then
call Warning10Remaining( nPlayerIndex )
return
elseif ( udg_WormLength[nPlayerIndex] == udg_NumberToWin ) then
call Victory(nPlayerIndex)
return
endif
endfunction
function WormAddLengthFloatText takes integer nPlayerIndex, integer nAdd, string strLead returns nothing
local texttag tt
local integer nColorIndex
set tt = CreateTextTag()
call SetTextTagText( tt, strLead + "+" + I2S(nAdd), TextTagSize2Height(10) )
call SetTextTagPosUnit( tt, udg_WormHead[nPlayerIndex], 0 )
set nColorIndex = GetPlayerColorIndex( nPlayerIndex )
call SetTextTagColor( tt, udg_ColorRed[nColorIndex], udg_ColorGreen[nColorIndex], udg_ColorBlue[nColorIndex], 255 )
//call SetTextTagColor( tt, 255, 255, 255, 255 )
call SetTextTagVelocityBJ( tt, 64.00, 90 )
call PolledWait(1)
call DestroyTextTag( tt )
endfunction
function WormAddLengthEx takes integer nPlayerIndex, integer nAdd, string strLead returns nothing
if ( nAdd <= 0 ) then
return
endif
set udg_nPlayerIndexAddLength = nPlayerIndex
set udg_nAddAddLength = nAdd
set udg_strLeadAddLength = strLead
call ConditionalTriggerExecute( gg_trg_Worm_Add_Length_Float_Text )
loop
exitwhen nAdd == 0 or udg_GameOver
call WormAddLength( nPlayerIndex )
call PolledWait( 0.3 )
set nAdd = nAdd - 1
endloop
endfunction
function SpawnWormConditions takes nothing returns boolean
local integer nType = GetUnitTypeId( GetFilterUnit() )
return nType == udg_UT_WormHead or nType == udg_UT_WormSegment or nType == udg_UT_Scorpion
endfunction
function RespawnWorm takes integer nPlayerIndex returns nothing
local location locCenter = GetRectCenter( gg_rct_Arena )
local real rAngle
local location loc
local group g
local integer nTimes
local player pl = Player(nPlayerIndex)
//Try to avoid spawn player near dangerous thing
set g = CreateGroup()
set nTimes = 0
loop
set rAngle = GetRandomInt( 0, 359 )
set loc = PolarProjectionBJ( locCenter, 3500, rAngle )
exitwhen nTimes >= 50
call GroupEnumUnitsInRangeOfLoc( g, loc, 600, Condition(function SpawnWormConditions) )
exitwhen FirstOfGroup(g) == null
call GroupClear(g)
call RemoveLocation(loc)
set nTimes = nTimes + 1
endloop
call DestroyGroup(g)
set udg_WormRespawn[nPlayerIndex] = true
call PanCameraToTimedLocForPlayer( pl, loc, 1.00 )
call ReviveHeroLoc( udg_WormHead[nPlayerIndex], loc, true )
call SetUnitPathing( udg_WormHead[nPlayerIndex], false )
call SuspendHeroXP( udg_WormHead[nPlayerIndex], true )
call SetUnitInvulnerable( udg_WormHead[nPlayerIndex], true )
call SelectUnitForPlayerSingle( udg_WormHead[nPlayerIndex], pl )
call LeaderboardSortItemsBJ( udg_Scoreboard, bj_SORTTYPE_SORTBYVALUE, false )
call RemoveLocation( locCenter )
call RemoveLocation( loc )
set udg_WormSlowed[nPlayerIndex] = false
call WormResetSpeed( nPlayerIndex )
call PolledWait(1)
set udg_WormRespawn[nPlayerIndex] = false
endfunction
function KillWorm takes integer nPlayerIndex, integer nPlayerIndexKiller, integer nKillingStyle returns nothing
if ( nKillingStyle == udg_KILLSTYLE_SELF ) then
call PlaySoundBJ( gg_snd_Humiliation )
call BlowUpHead( nPlayerIndex, nPlayerIndex, false )
elseif ( nKillingStyle == udg_KILLSTYLE_SCORPION ) then
call PlaySoundBJ( gg_snd_woopsie_final )
call BlowUpHead( nPlayerIndex, nPlayerIndex, false )
elseif ( nKillingStyle == udg_KILLSTYLE_BORDER ) then
call PlaySoundBJ( gg_snd_Noob )
call BlowUpHead( nPlayerIndex, nPlayerIndex, true )
else
call BlowUpHead( nPlayerIndex, nPlayerIndexKiller, false )
endif
call PolledWait( udg_RespawnTime )
if ( not udg_GameOver ) then
call RespawnWorm( nPlayerIndex )
endif
endfunction
function AUnitHitsConditions takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer nType = GetUnitTypeId(u)
return not udg_GameOver and IsUnitAliveBJ(u) and ( nType == udg_UT_WormSegment or nType == udg_UT_WormHead )
endfunction
function HeadVsHead takes integer nPlayerIndex, integer nPlayerIndexDied returns boolean
local location locInter = null
local real x
local real y
local real x1
local real y1
local real x2
local real y2
local real a1
local real b1
local real a2
local real b2
local real rDir1
local real rDir2
local real rDir
local real rDis
local real rDirDied1
local real rDirDied2
local real rDirDied
local real rDisDied
//local unit u
set x2 = GetUnitX( udg_WormHead[nPlayerIndex] )
set y2 = GetUnitY( udg_WormHead[nPlayerIndex] )
set rDir1 = GetUnitFacing(udg_WormHead[nPlayerIndex]) * bj_DEGTORAD
set x1 = x2 + 500 * Cos(rDir1+bj_PI)
set y1 = y2 + 500 * Sin(rDir1+bj_PI)
set a2 = GetUnitX( udg_WormHead[nPlayerIndexDied] )
set b2 = GetUnitY( udg_WormHead[nPlayerIndexDied] )
set rDirDied1 = GetUnitFacing(udg_WormHead[nPlayerIndexDied]) * bj_DEGTORAD
set a1 = a2 + 500 * Cos(rDirDied1+bj_PI)
set b1 = b2 + 500 * Sin(rDirDied1+bj_PI)
set locInter = Location(0, 0)
if ( not InterLineLine(x1, y1, x2, y2, a1, b1, a2, b2, locInter) ) then
call RemoveLocation( locInter )
set rDir = obh_AngleBetweenPoints( a2, b2, x2, y2 )
set rDir = obh_StandardAngle( rDir - rDir1 )
return rDir <= ( bj_PI/2+0.1 ) and rDir >= ( -bj_PI/2-0.1 )
endif
set x = GetLocationX( locInter )
set y = GetLocationY( locInter )
call RemoveLocation( locInter )
set rDir2 = obh_AngleBetweenPoints( x2, y2, x, y )
set rDis = obh_DistanceBetweenPoints( x2, y2, x, y )
set rDir = obh_StandardAngle( rDir2 - rDir1 )
if ( rDir > bj_PI/2 or rDir < -bj_PI/2 ) then
set rDis = -rDis
endif
set rDirDied2 = obh_AngleBetweenPoints( a2, b2, x, y )
set rDisDied = obh_DistanceBetweenPoints( a2, b2, x, y )
set rDirDied = obh_StandardAngle( rDirDied2 - rDirDied1 )
if ( rDirDied > bj_PI/2 or rDirDied < -bj_PI/2 ) then
set rDisDied = -rDisDied
endif
//set u = CreateUnit( udg_NPC, 'hfoo', x1, y1, 0 )
//call SetUnitPathing( u, false )
//call CreateUnit( udg_NPC, 'hfoo', x2, y2, 0 )
//call SetUnitPathing( u, false )
//call CreateUnit( udg_NPC, 'hfoo', a1, b1, 0 )
//call SetUnitPathing( u, false )
//call CreateUnit( udg_NPC, 'hfoo', a2, b2, 0 )
//call SetUnitPathing( u, false )
//call CreateUnit( udg_NPC, 'hfoo', x, y, 0 )
//call SetUnitPathing( u, false )
//call BJDebugMsg( "x1 = " + R2S(x1) + " y1 = " + R2S(y1) )
//call BJDebugMsg( "a1 = " + R2S(a1) + " b1 = " + R2S(b1) )
//call BJDebugMsg( "x2 = " + R2S(x2) + " y2 = " + R2S(y2) )
//call BJDebugMsg( "a2 = " + R2S(a2) + " b2 = " + R2S(b2) )
//call BJDebugMsg( "x = " + R2S(x) + " y = " + R2S(y) )
//call BJDebugMsg( "nPlayerIndex = " + I2S(nPlayerIndex) + " dis = " + R2S(rDis) )
//call BJDebugMsg( "nPlayerIndexDied = " + I2S(nPlayerIndexDied) + " disDied = " + R2S(rDisDied) )
return (rDisDied - rDis) >= -10
endfunction
function AUnitHitsActions takes nothing returns nothing
local integer nIndex = 0
local integer nIndexEnd = 0
local integer nPlayerIndexDied = 0
local unit u = GetTriggerUnit()
local integer nPlayerIndex = GetPlayerIndex( GetOwningPlayer(u) )
local trigger trg = GetTriggeringTrigger()
local integer nLenBonus
local string strSquish
if ( nPlayerIndex < 0 ) then
return
endif
set nPlayerIndexDied = 0
loop
exitwhen nPlayerIndexDied >= udg_PLAYERNUM
exitwhen trg == udg_AUnitHits[nPlayerIndexDied]
set nPlayerIndexDied = nPlayerIndexDied + 1
endloop
if ( nPlayerIndexDied >= udg_PLAYERNUM ) then
return
endif
if ( IsWormDead( nPlayerIndexDied ) ) then
return
endif
if ( udg_WormRespawn[nPlayerIndexDied] ) then
return
endif
if ( udg_Reversing[nPlayerIndexDied] ) then
return
endif
if ( nPlayerIndex == nPlayerIndexDied ) then
set nIndex = nPlayerIndexDied * udg_NumberToWin
set nIndexEnd = nIndex + 5
loop
exitwhen nIndex >= nIndexEnd
if ( u == udg_WormSegments[nIndex] ) then
return
endif
set nIndex = nIndex + 1
endloop
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndex) + udg_STR_SELFSQUISH )
call KillWorm( nPlayerIndexDied, nPlayerIndexDied, udg_KILLSTYLE_SELF )
else
if ( GetUnitTypeId(u) == udg_UT_WormHead ) then
if ( not HeadVsHead( nPlayerIndex, nPlayerIndexDied ) ) then
return
endif
endif
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndexDied) + udg_STR_SQUISH1 + GetColoredPlayerName(nPlayerIndex) + udg_STR_SQUISH2 )
//Multi Squish
if ( udg_MultiSquishStart[nPlayerIndex] ) then
set udg_MultiSquishStart[nPlayerIndex] = false
call PauseTimer( udg_MultiSquishTimer[nPlayerIndex] )
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndex) + udg_STR_MULTISQUISH )
call PlaySoundBJ( gg_snd_MultiSquishLoud )
set udg_strLeadAddLength = udg_STR_MULTISQUISH_FLOATTEXT
else
set udg_MultiSquishStart[nPlayerIndex] = true
call TimerStart( udg_MultiSquishTimer[nPlayerIndex], 3, false, null )
set udg_strLeadAddLength = udg_STR_SQUISH_FLOATTEXT
if ( udg_WormLength[nPlayerIndexDied] >= udg_NumberToWin - 10 ) then
call PlaySoundBJ( gg_snd_Denied01 )
else
call PlaySoundBJ( gg_snd_Squished1 )
endif
endif
set nLenBonus = ( udg_WormLength[nPlayerIndexDied] + 19 ) / 20
if ( nLenBonus > 0 ) then
set udg_nPlayerIndexAddLength = nPlayerIndex
set udg_nAddAddLength = nLenBonus
call ConditionalTriggerExecute( gg_trg_Worm_Add_Length )
endif
call KillWorm( nPlayerIndexDied, nPlayerIndex, udg_KILLSTYLE_NORMAL )
endif
endfunction
function NewTrgAUnitHits takes integer nPlayerIndex returns nothing
if ( udg_AUnitHits[nPlayerIndex] != null ) then
return
endif
set udg_AUnitHits[nPlayerIndex] = CreateTrigger()
call TriggerRegisterUnitInRangeSimple( udg_AUnitHits[nPlayerIndex], 100, udg_WormHead[nPlayerIndex] )
call TriggerAddCondition( udg_AUnitHits[nPlayerIndex], Condition( function AUnitHitsConditions ) )
call TriggerAddAction( udg_AUnitHits[nPlayerIndex], function AUnitHitsActions )
endfunction
function CreateWormHead takes integer nPlayerIndex returns nothing
local location locCenter = GetRectCenter( gg_rct_Arena )
local real rAngle = 360. * nPlayerIndex / udg_PLAYERNUM
local location loc = PolarProjectionBJ( locCenter, 3500, rAngle )
local player pl = Player(nPlayerIndex)
local integer nIndex = 0
set udg_WormRespawn[nPlayerIndex] = true
set udg_WormHead[nPlayerIndex] = CreateUnitAtLoc( pl, udg_UT_WormHead, loc, rAngle + 180 )
call SetUnitPathing( udg_WormHead[nPlayerIndex], false )
call SuspendHeroXP( udg_WormHead[nPlayerIndex], true )
call SetUnitInvulnerable( udg_WormHead[nPlayerIndex], true )
call NewTrgAUnitHits(nPlayerIndex)
call ClearSelectionForPlayer( pl )
call SelectUnitForPlayerSingle( udg_WormHead[nPlayerIndex], pl )
call SetCameraPositionLocForPlayer( pl, loc )
call RemoveLocation( locCenter )
call RemoveLocation( loc )
set udg_WormSlowed[nPlayerIndex] = false
call WormResetSpeed( nPlayerIndex )
call PolledWait(1)
set udg_WormRespawn[nPlayerIndex] = false
endfunction
function WormRunOutOfBorder takes integer nPlayerIndex returns nothing
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndex) + udg_STR_OUTOFBORDER )
call KillWorm( nPlayerIndex, nPlayerIndex, udg_KILLSTYLE_BORDER )
endfunction
//===========================================================================
function InitTrig_Worm_Functions takes nothing returns nothing
endfunction
function IsWormAbleToEatScorpion takes integer nPlayerIndex returns boolean
return udg_ScorpionEaterEffect[nPlayerIndex] != null
endfunction
function LightningKillFood takes unit uFood returns nothing
local real x
local real y
local lightning lightningEff
if ( IsUnitDeadBJ(uFood) ) then
return
endif
set x = GetUnitX(uFood)
set y = GetUnitY(uFood)
set lightningEff = AddLightning( "CLPB", true, x - 100, y + 600, x, y )
call AddSpecialEffectTarget( "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", uFood, "chest" )
call KillUnit( uFood )
call PolledWait(0.2)
call DestroyLightning( lightningEff )
endfunction
function RespawnFood takes unit uFood returns nothing
local unit u
local location loc
local integer nType
set nType = GetRandomInt( 0, udg_FoodTypesNum - 1 )
if ( IsUnitInGroup( uFood, udg_CenterFoodGroup ) ) then
call GroupRemoveUnit( udg_CenterFoodGroup, uFood )
set loc = GetRandomLocInRect(gg_rct_ArenaCenter)
set u = CreateUnitAtLoc( udg_NPC, udg_FoodTypes[nType], loc, bj_UNIT_FACING )
call RemoveLocation( loc )
call GroupAddUnit( udg_CenterFoodGroup, u )
else
set loc = GetRandomLocInRect( gg_rct_Food )
call CreateUnitAtLoc( udg_NPC, udg_FoodTypes[nType], loc, bj_UNIT_FACING )
call RemoveLocation( loc )
endif
endfunction
function RespawnSuperFood takes unit uSuperFood returns nothing
local location loc = GetRandomLocInRect(gg_rct_Food)
call CreateUnitAtLoc( udg_NPC, 'n001', loc, bj_UNIT_FACING )
call RemoveLocation( loc )
endfunction
function KillScorpion takes integer nScorpionIndex returns nothing
call DestroyTrigger( udg_ScorpionHits[nScorpionIndex] )
set udg_ScorpionHits[nScorpionIndex] = null
call KillUnit( udg_Scorpions[nScorpionIndex] )
endfunction
function ScorpionHitsConditions takes nothing returns boolean
local integer nType
if ( udg_GameOver ) then
return false
endif
set nType = GetUnitTypeId(GetTriggerUnit())
return nType == udg_UT_WormHead or nType == udg_UT_WormSegment
endfunction
function ScorpionHitsActions takes nothing returns nothing
local integer nScorpionIndex = 0
local trigger trg = GetTriggeringTrigger()
local unit uHit = GetTriggerUnit()
local integer nPlayerIndex = 0
set nScorpionIndex = 0
loop
exitwhen nScorpionIndex >= udg_ScorpionNum
exitwhen trg == udg_ScorpionHits[nScorpionIndex]
set nScorpionIndex = nScorpionIndex + 1
endloop
if ( nScorpionIndex >= udg_ScorpionNum ) then
return
endif
if ( GetUnitTypeId( uHit ) == udg_UT_WormSegment ) then
call KillScorpion( nScorpionIndex )
elseif ( GetUnitTypeId( uHit ) == udg_UT_WormHead ) then
set nPlayerIndex = GetPlayerIndex( GetOwningPlayer(uHit) )
if ( IsWormAbleToEatScorpion(nPlayerIndex) ) then
call KillScorpion( nScorpionIndex )
call WormAddLengthEx( nPlayerIndex, udg_ScorpionEatingRewards, "" )
call ShowMsgToPlayer( Player(nPlayerIndex), "You" + udg_STR_EATSCORPION )
elseif ( not udg_WormRespawn[nPlayerIndex] ) then
call ShowMsgToAll( GetColoredPlayerName(nPlayerIndex) + udg_STR_SCORPIONSQUISH )
call KillWorm( nPlayerIndex, nPlayerIndex, udg_KILLSTYLE_SCORPION )
endif
endif
endfunction
function NewTrgScorpionHits takes integer nIndex returns nothing
if ( udg_ScorpionHits[nIndex] != null ) then
call DestroyTrigger( udg_ScorpionHits[nIndex] )
endif
set udg_ScorpionHits[nIndex] = CreateTrigger()
call TriggerRegisterUnitInRangeSimple( udg_ScorpionHits[nIndex], 80, udg_Scorpions[nIndex] )
call TriggerAddCondition( udg_ScorpionHits[nIndex], Condition( function ScorpionHitsConditions ) )
call TriggerAddAction( udg_ScorpionHits[nIndex], function ScorpionHitsActions )
endfunction
function SpawnScorpionConditions takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == udg_UT_WormHead
endfunction
function SpawnScorpion takes integer nIndex returns nothing
local location loc
local group g
//Try to avoid spawn scorpion near a player
set g = CreateGroup()
loop
set loc = GetRandomLocInRect( gg_rct_ArenaCenter )
call GroupEnumUnitsInRangeOfLoc( g, loc, 600, Condition(function SpawnScorpionConditions) )
exitwhen FirstOfGroup(g) == null
call GroupClear(g)
call RemoveLocation(loc)
endloop
call DestroyGroup(g)
set udg_Scorpions[nIndex] = CreateUnitAtLoc( udg_HOSTILE, udg_UT_Scorpion, loc, bj_UNIT_FACING )
call RemoveLocation( loc )
call SetUnitPathing( udg_Scorpions[nIndex], false )
call NewTrgScorpionHits( nIndex )
endfunction
function RespawnScorpion takes unit u returns nothing
local integer nIndex = 0
loop
exitwhen nIndex >= udg_ScorpionNum
exitwhen udg_Scorpions[nIndex] == u
set nIndex = nIndex + 1
endloop
if ( nIndex >= udg_ScorpionNum ) then
return
endif
call SpawnScorpion( nIndex )
endfunction
function MoveScorpions takes nothing returns nothing
local integer nIndex = 0
local location locCur = null
local location locNext = null
local real rAngle = 0
local integer nAngleIndex
loop
exitwhen nIndex >= udg_ScorpionNum
if ( udg_Scorpions[nIndex] != null and IsUnitAliveBJ(udg_Scorpions[nIndex]) ) then
set locCur = GetUnitLoc( udg_Scorpions[nIndex] )
set rAngle = I2R(GetRandomInt(0, 359))
set nAngleIndex = 0
loop
exitwhen nAngleIndex >= 4
set locNext = PolarProjectionBJ( locCur, 1000, rAngle )
exitwhen RectContainsLoc( gg_rct_Arena, locNext )
call RemoveLocation( locNext )
set locNext = null
set rAngle = rAngle + 90.
set nAngleIndex = nAngleIndex + 1
endloop
if ( locNext == null ) then
set locNext = GetRectCenter( gg_rct_Arena )
endif
call IssuePointOrderLoc( udg_Scorpions[nIndex], "move", locNext )
call RemoveLocation( locCur )
set locCur = null
call RemoveLocation( locNext )
set locNext = null
endif
set nIndex = nIndex + 1
endloop
endfunction
//===========================================================================
function InitTrig_Food_Functions takes nothing returns nothing
endfunction
function CalcTargetPoint takes location locSrc, real rAngle, location locTarget returns nothing
local real rDis = 600
call MoveLocation( locTarget, GetLocationX(locSrc) + rDis * Cos(rAngle * bj_DEGTORAD), GetLocationY(locSrc) + rDis * Sin(rAngle * bj_DEGTORAD) )
endfunction
function ResetCamera takes nothing returns nothing
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
if (GetLocalPlayer() == Player(nPlayerIndex) ) then
if ( GetCameraField(CAMERA_FIELD_TARGET_DISTANCE) != 2500 ) then
call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, 2500, 0 )
endif
endif
set nPlayerIndex = nPlayerIndex + 1
endloop
endfunction
function NewTargetPoint takes player pl, location locTarget returns nothing
local integer nPlayerIndex = GetPlayerId(pl)
local location loc = null
if ( udg_CurrentTargetLoc[nPlayerIndex] != null ) then
if ( GetLocationX(udg_CurrentTargetLoc[nPlayerIndex]) == GetLocationX( locTarget ) and GetLocationY(udg_CurrentTargetLoc[nPlayerIndex]) == GetLocationY( locTarget ) ) then
return
endif
endif
set loc = GetUnitLoc( udg_WormHead[nPlayerIndex] )
set udg_CurrentAngle[nPlayerIndex] = AngleBetweenPoints( loc, locTarget )
if ( udg_CurrentTargetLoc[nPlayerIndex] == null ) then
set udg_CurrentTargetLoc[nPlayerIndex] = Location( 0, 0 )
endif
call CalcTargetPoint( loc, udg_CurrentAngle[nPlayerIndex], udg_CurrentTargetLoc[nPlayerIndex] )
call RemoveLocation( loc )
call IssuePointOrderLoc( udg_WormHead[nPlayerIndex], "move", udg_CurrentTargetLoc[nPlayerIndex] )
endfunction
function NeverStop takes player pl returns nothing
local integer nPlayerIndex = GetPlayerId(pl)
if ( udg_CurrentTargetLoc[nPlayerIndex] == null ) then
return
endif
call IssuePointOrderLoc( udg_WormHead[nPlayerIndex], "move", udg_CurrentTargetLoc[nPlayerIndex] )
endfunction
function MoveWormHead takes integer nPlayerIndex returns nothing
local location loc = null
local real rDis
if ( IsWormDead( nPlayerIndex ) or udg_CurrentTargetLoc[nPlayerIndex] == null ) then
return
endif
set loc = GetUnitLoc( udg_WormHead[nPlayerIndex] )
set rDis = DistanceBetweenPoints( loc, udg_CurrentTargetLoc[nPlayerIndex] )
if ( rDis > 120 ) then
call RemoveLocation( loc )
return
endif
call CalcTargetPoint( loc, udg_CurrentAngle[nPlayerIndex], udg_CurrentTargetLoc[nPlayerIndex] )
call RemoveLocation( loc )
call IssuePointOrderLoc( udg_WormHead[nPlayerIndex], "move", udg_CurrentTargetLoc[nPlayerIndex] )
endfunction
function NvrStopTimerExpires takes nothing returns nothing
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
if ( IsValidPlayer( Player(nPlayerIndex) ) ) then
call MoveWormHead( nPlayerIndex )
endif
set nPlayerIndex = nPlayerIndex + 1
endloop
endfunction
function ReMoveSegment takes unit uSeg returns nothing
local integer nSegIndex = 0
local integer nIndex = 0
local unit uTarget
local integer nPlayerIndex = GetPlayerIndex( GetOwningPlayer(uSeg) )
if ( nPlayerIndex < 0 ) then
return
endif
set nIndex = udg_NumberToWin * nPlayerIndex
set nSegIndex = 0
loop
exitwhen nSegIndex >= udg_WormLength[nPlayerIndex]
exitwhen udg_WormSegments[nIndex + nSegIndex] == uSeg
set nSegIndex = nSegIndex + 1
endloop
if ( nSegIndex >= udg_WormLength[nPlayerIndex] ) then
return
endif
if ( nSegIndex == 0 ) then
set uTarget = udg_WormHead[nPlayerIndex]
else
set uTarget = udg_WormSegments[nIndex + nSegIndex - 1]
endif
call IssueTargetOrder( uSeg, "move", uTarget )
endfunction
function OrderedTargetSegment takes unit uSeg, integer nOrderId, widget target returns nothing
local integer nSegIndex = 0
local integer nIndex = 0
local unit uTarget
local integer nPlayerIndex
set nPlayerIndex = GetPlayerIndex( GetOwningPlayer(uSeg) )
if ( nPlayerIndex < 0 ) then
return
endif
if ( nOrderId != 851986 ) then
call ReMoveSegment(uSeg)
return
endif
set nIndex = udg_NumberToWin * nPlayerIndex
set nSegIndex = 0
loop
exitwhen nSegIndex >= udg_WormLength[nPlayerIndex]
exitwhen udg_WormSegments[nIndex + nSegIndex] == uSeg
set nSegIndex = nSegIndex + 1
endloop
if ( nSegIndex >= udg_WormLength[nPlayerIndex] ) then
return
endif
if ( nSegIndex == 0 ) then
set uTarget = udg_WormHead[nPlayerIndex]
else
set uTarget = udg_WormSegments[nIndex + nSegIndex - 1]
endif
if ( uTarget != target ) then
call IssueTargetOrder( uSeg, "move", uTarget )
endif
endfunction
//===========================================================================
function InitTrig_NvrStopFunctions takes nothing returns nothing
endfunction
function GooBomb takes integer nPlayerIndex returns nothing
local integer nIndex
local effect array effs
local real rSpeed = 400
local integer array nSlowedId
call StartSound( gg_snd_EntanglingRootsTarget1 )
set nIndex = 0
loop
exitwhen nIndex >= udg_PLAYERNUM
if ( nIndex != nPlayerIndex and IsWormAlive(nIndex) ) then
call ShowMsgToPlayer( Player(nIndex), udg_STR_GOOBOMB + GetColoredPlayerName(nPlayerIndex) )
set effs[nIndex] = AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\DeathCoil\\DeathCoilSpecialArt.mdl", udg_WormHead[nIndex], "chest" )
set udg_WormSlowedId[nIndex] = udg_WormSlowedId[nIndex] + 1
set nSlowedId[nIndex] = udg_WormSlowedId[nIndex]
set udg_WormSlowed[nIndex] = true
call WormResetSpeed( nIndex )
else
set nSlowedId[nIndex] = -1
endif
set nIndex = nIndex + 1
endloop
call PolledWait( 4.00 )
set nIndex = 0
loop
exitwhen nIndex >= udg_PLAYERNUM
if ( nSlowedId[nIndex] >= 0 ) then
call DestroyEffect( effs[nIndex] )
if ( nSlowedId[nIndex] == udg_WormSlowedId[nIndex] ) then
set udg_WormSlowed[nIndex] = false
call WormResetSpeed( nIndex )
set udg_WormSlowedId[nIndex] = -1
endif
endif
set nIndex = nIndex + 1
endloop
endfunction
function SegmentBomb takes integer nPlayerIndex returns nothing
local integer nIndex
local integer nSegIndex
local integer nLose = 0
local integer nLoseLeft = 0
call StartSound( gg_snd_SoulBurn1 )
set nIndex = 0
loop
exitwhen nIndex >= udg_PLAYERNUM
if ( nIndex != nPlayerIndex and IsWormAlive( nIndex ) ) then
set nLose = R2I( (udg_WormLength[nIndex] + 9) * .1 )
if ( nLose > 0 ) then
set udg_WormLength[nIndex] = udg_WormLength[nIndex] - nLose
set nSegIndex = 0
loop
exitwhen nSegIndex >= nLose
call ExplodeKillSegment( nIndex, udg_WormLength[nIndex] + nSegIndex )
set nSegIndex = nSegIndex + 1
endloop
call WormResetSpeed( nIndex )
endif
call ShowMsgToPlayer( Player(nIndex), GetColoredPlayerName(nPlayerIndex) + udg_STR_SEGMENTBOMB1 + I2S(nLose) + udg_STR_SEGMENTBOMB2 )
call LeaderboardSetPlayerItemValueBJ( Player(nIndex), udg_Scoreboard, udg_WormLength[nIndex] )
call LeaderboardSortItemsBJ( udg_Scoreboard, bj_SORTTYPE_SORTBYVALUE, false )
endif
set nIndex = nIndex + 1
endloop
endfunction
function ScorpionEater takes integer nPlayerIndex returns nothing
local integer nScorpionEaterIdBak
if ( GetLocalPlayer() == Player(nPlayerIndex) ) then
call StartSound( gg_snd_ElementKiller )
endif
set udg_ScorpionEaterId[nPlayerIndex] = udg_ScorpionEaterId[nPlayerIndex] + 1
set nScorpionEaterIdBak = udg_ScorpionEaterId[nPlayerIndex]
if ( udg_ScorpionEaterEffect[nPlayerIndex] != null ) then
call DestroyEffect( udg_ScorpionEaterEffect[nPlayerIndex] )
endif
set udg_ScorpionEaterEffect[nPlayerIndex] = AddSpecialEffectTarget( "Abilities\\Spells\\Other\\SoulBurn\\SoulBurnbuff.mdl", udg_WormHead[nPlayerIndex], "overhead" )
call PolledWait( 10 )
if ( udg_ScorpionEaterId[nPlayerIndex] == nScorpionEaterIdBak ) then
if ( udg_ScorpionEaterEffect[nPlayerIndex] != null ) then
call DestroyEffect( udg_ScorpionEaterEffect[nPlayerIndex] )
set udg_ScorpionEaterEffect[nPlayerIndex] = null
endif
endif
endfunction
function CryptCravingFilter takes nothing returns boolean
local unit u = GetFilterUnit()
local integer nType = GetUnitTypeId(u)
if ( IsUnitDeadBJ(u) ) then
return false
endif
if ( nType == udg_UT_Sheep ) then //Sheep
return true
endif
if ( nType == udg_UT_Pig ) then //Pig
return true
endif
return false
endfunction
function CryptCraving takes integer nPlayerIndex returns nothing
local group g = null
local unit u
local integer nIndex = 0
local integer nFoodIndex = 0
local real xWorm = GetUnitX( udg_WormHead[nPlayerIndex] )
local real yWorm = GetUnitY( udg_WormHead[nPlayerIndex] )
local real x
local real y
if ( udg_CravingStage[nPlayerIndex] >= 0 ) then
return
endif
call PlaySoundOnUnitBJ( gg_snd_Craving, 100, udg_WormHead[nPlayerIndex] )
set udg_CravingEffect[nPlayerIndex] = AddSpecialEffectTarget( "Abilities\\Spells\\Other\\Drain\\DrainTarget.mdl", udg_WormHead[nPlayerIndex], "overhead" )
set g = CreateGroup()
call GroupEnumUnitsInRange( g, xWorm, yWorm, 1000, Condition(function CryptCravingFilter) )
set udg_CravingFoodNum[nPlayerIndex] = 0
set nFoodIndex = nPlayerIndex * udg_CRAVINGFOOD_MAXNUM
loop
set udg_CravingFood[nFoodIndex] = FirstOfGroup( g )
exitwhen udg_CravingFood[nFoodIndex] == null or udg_CravingFoodNum[nPlayerIndex] >= udg_CRAVINGFOOD_MAXNUM
call IssueImmediateOrder( udg_CravingFood[nFoodIndex], "stop" )
call SetUnitInvulnerable( udg_CravingFood[nFoodIndex], true )
set x = GetUnitX(udg_CravingFood[nFoodIndex])
set y = GetUnitY(udg_CravingFood[nFoodIndex])
set udg_CravingFoodLightning[nFoodIndex] = AddLightning( "DRAB", true, x, y, xWorm, yWorm )
call GroupRemoveUnit( g, udg_CravingFood[nFoodIndex] )
set udg_CravingFoodNum[nPlayerIndex] = udg_CravingFoodNum[nPlayerIndex] + 1
set nFoodIndex = nFoodIndex + 1
endloop
call DestroyGroup( g )
if ( udg_CravingFoodNum[nPlayerIndex] == 0 ) then
call DestroyEffect( udg_CravingEffect[nPlayerIndex] )
set udg_CravingEffect[nPlayerIndex] = null
return
endif
set udg_CravingStage[nPlayerIndex] = 0
call TimerStart( udg_CravingTimer[nPlayerIndex], 0.05, true, null )
endfunction
function CravingTimerAction takes timer t returns nothing
local real xWorm
local real yWorm
local real x
local real y
local integer nIndex
local integer nFoodIndex
local integer nTypeId
local integer nLen
local integer nPlayerIndex = 0
loop
exitwhen nPlayerIndex >= udg_PLAYERNUM
exitwhen udg_CravingTimer[nPlayerIndex] == t
set nPlayerIndex = nPlayerIndex + 1
endloop
if ( nPlayerIndex >= udg_PLAYERNUM ) then
return
endif
if ( not IsWormAlive( nPlayerIndex ) ) then
call PauseTimer( t )
set nIndex = 0
set nFoodIndex = nPlayerIndex * udg_CRAVINGFOOD_MAXNUM
loop
exitwhen nIndex >= udg_CravingFoodNum[nPlayerIndex]
call DestroyLightning( udg_CravingFoodLightning[nFoodIndex] )
set nIndex = nIndex + 1
set nFoodIndex = nFoodIndex + 1
endloop
if ( udg_CravingEffect[nPlayerIndex] != null ) then
call DestroyEffect( udg_CravingEffect[nPlayerIndex] )
set udg_CravingEffect[nPlayerIndex] = null
endif
set udg_CravingStage[nPlayerIndex] = -1
return
endif
if ( udg_CravingStage[nPlayerIndex] == udg_CRAVINGSTAGE_MAX ) then
call PauseTimer( t )
set nLen = 0
set nIndex = 0
set nFoodIndex = nPlayerIndex * udg_CRAVINGFOOD_MAXNUM
loop
exitwhen nIndex >= udg_CravingFoodNum[nPlayerIndex]
if ( udg_CravingFood[nFoodIndex] != null and IsUnitDeadBJ(udg_CravingFood[nFoodIndex]) ) then
set udg_CravingFood[nFoodIndex] = null
call DestroyLightning( udg_CravingFoodLightning[nFoodIndex] )
endif
if ( udg_CravingFood[nFoodIndex] != null ) then
set nTypeId = GetUnitTypeId( udg_CravingFood[nFoodIndex] )
if ( nTypeId == udg_UT_Sheep ) then
set nLen = nLen + 1
elseif ( nTypeId == udg_UT_Pig ) then
set nLen = nLen + 2
endif
call KillUnit( udg_CravingFood[nFoodIndex] )
call DestroyLightning( udg_CravingFoodLightning[nFoodIndex] )
endif
set nIndex = nIndex + 1
set nFoodIndex = nFoodIndex + 1
endloop
call WormAddLengthEx( nPlayerIndex, nLen, "" )
if ( udg_CravingEffect[nPlayerIndex] != null ) then
call DestroyEffect( udg_CravingEffect[nPlayerIndex] )
set udg_CravingEffect[nPlayerIndex] = null
endif
set udg_CravingStage[nPlayerIndex] = -1
return
endif
set xWorm = GetUnitX( udg_WormHead[nPlayerIndex] )
set yWorm = GetUnitY( udg_WormHead[nPlayerIndex] )
set nIndex = 0
set nFoodIndex = nPlayerIndex * udg_CRAVINGFOOD_MAXNUM
loop
exitwhen nIndex >= udg_CravingFoodNum[nPlayerIndex]
if ( udg_CravingFood[nFoodIndex] != null and IsUnitDeadBJ(udg_CravingFood[nFoodIndex]) ) then
set udg_CravingFood[nFoodIndex] = null
call DestroyLightning( udg_CravingFoodLightning[nFoodIndex] )
set udg_CravingFoodLightning[nFoodIndex] = null
endif
if ( udg_CravingFood[nFoodIndex] != null ) then
set x = GetUnitX(udg_CravingFood[nFoodIndex])
set y = GetUnitY(udg_CravingFood[nFoodIndex])
set x = x + ( xWorm - x ) / (20 - udg_CravingStage[nPlayerIndex])
set y = y + ( yWorm - y ) / (20 - udg_CravingStage[nPlayerIndex])
call SetUnitPosition( udg_CravingFood[nFoodIndex], x, y )
call MoveLightning( udg_CravingFoodLightning[nFoodIndex], false, x, y, xWorm, yWorm )
endif
set nIndex = nIndex + 1
set nFoodIndex = nFoodIndex + 1
endloop
set udg_CravingStage[nPlayerIndex] = udg_CravingStage[nPlayerIndex] + 1
endfunction
function Reverse takes integer nPlayerIndex returns nothing
local integer nSegIndex1 = nPlayerIndex * udg_NumberToWin
local integer nSegIndex2 = nSegIndex1 + udg_WormLength[nPlayerIndex] - 1
local integer nSegIndex = 0
local location locLast
local real dirLast
local location locNext
local integer nIndex1 = 0
local integer nIndex2 = 0
local location locTemp
local unit uTemp
local real rTemp
set udg_Reversing[nPlayerIndex] = true
call PlaySoundOnUnitBJ( gg_snd_Reverse, 100, udg_WormHead[nPlayerIndex] )
if ( udg_WormLength[nPlayerIndex] == 0 ) then
set locTemp = GetUnitLoc( udg_WormHead[nPlayerIndex] )
set dirLast = GetUnitFacing( udg_WormHead[nPlayerIndex] ) + 180
else
set locTemp = GetUnitLoc( udg_WormSegments[nSegIndex2] )
set dirLast = GetUnitFacing( udg_WormSegments[nSegIndex2] ) + 180
endif
set locLast = PolarProjectionBJ( locTemp, 120, dirLast )
call RemoveLocation( locTemp )
//flip the segments
set nIndex1 = nSegIndex1
set nIndex2 = nSegIndex2
loop
exitwhen nIndex1 >= nIndex2
set uTemp = udg_WormSegments[nIndex1]
set udg_WormSegments[nIndex1] = udg_WormSegments[nIndex2]
set udg_WormSegments[nIndex2] = uTemp
set nIndex1 = nIndex1 + 1
set nIndex2 = nIndex2 - 1
endloop
//Turn the head back
call SetUnitPositionLoc( udg_WormHead[nPlayerIndex], locLast )
call SetUnitFacing( udg_WormHead[nPlayerIndex], dirLast )
//Turn all segments back
set nSegIndex = nSegIndex1
loop
exitwhen nSegIndex > nSegIndex2
call SetUnitFacing( udg_WormSegments[nSegIndex], GetUnitFacing(udg_WormSegments[nSegIndex]) + 180 )
if ( nSegIndex == nSegIndex1 ) then
set uTemp = udg_WormHead[nPlayerIndex]
else
set uTemp = udg_WormSegments[nSegIndex - 1]
endif
call IssueTargetOrder( udg_WormSegments[nSegIndex], "move", uTemp )
set nSegIndex = nSegIndex + 1
endloop
call SetCameraPositionLocForPlayer( Player(nPlayerIndex), locLast )
//Never stop
set locNext = PolarProjectionBJ( locLast, 100, dirLast )
call RemoveLocation( locLast )
call NewTargetPoint( Player(nPlayerIndex), locNext )
call RemoveLocation( locNext )
call PolledWait(0.1)
set udg_Reversing[nPlayerIndex] = false
endfunction
function WormCastSpell takes unit uWorm, integer nSpellId returns nothing
local integer nPlayerIndex = GetPlayerIndex( GetOwningPlayer(uWorm) )
if ( nPlayerIndex < 0 ) then
return
endif
call UnitRemoveAbility( udg_WormHead[nPlayerIndex], nSpellId )
call NeverStop( Player(nPlayerIndex) )
if ( nSpellId == 'A009' ) then //Goo bomb
call GooBomb( nPlayerIndex )
elseif ( nSpellId == 'A00B' ) then //Segment bomb
call SegmentBomb( nPlayerIndex )
elseif ( nSpellId == 'A00A' ) then //Element Killer
call ScorpionEater( nPlayerIndex )
elseif ( nSpellId == 'A006' ) then //Crypt Craving
call CryptCraving( nPlayerIndex )
elseif ( nSpellId == 'A007' ) then //Reverse
call Reverse( nPlayerIndex )
endif
endfunction
function PickPowerupConditions takes nothing returns boolean
return not udg_GameOver and GetUnitTypeId(GetTriggerUnit()) == udg_UT_WormHead
endfunction
function DoesWormHavePowerup takes integer nPlayerIndex returns boolean
local integer nPowerupTypeIndex = 0
loop
exitwhen nPowerupTypeIndex >= udg_PowerupTypesNum
if ( GetUnitAbilityLevel(udg_WormHead[nPlayerIndex], udg_PowerupAbilities[nPowerupTypeIndex]) > 0 ) then
return true
endif
set nPowerupTypeIndex = nPowerupTypeIndex + 1
endloop
return false
endfunction
function PowerupDice takes nothing returns integer
local integer nIndex = 0
local integer nTotal = 0
local integer nDice = 0
set nIndex = 0
set nTotal = 0
loop
exitwhen nIndex >= udg_PowerupTypesNum
set nTotal = nTotal + udg_PowerupChances[nIndex]
set nIndex = nIndex + 1
endloop
set nDice = GetRandomInt( 1, nTotal )
set nIndex = 0
set nTotal = 0
loop
exitwhen nIndex >= udg_PowerupTypesNum
set nTotal = nTotal + udg_PowerupChances[nIndex]
if ( udg_PowerupChances[nIndex] > 0 and nDice <= nTotal ) then
return nIndex
endif
set nIndex = nIndex + 1
endloop
return -1
endfunction
//Everytime player pick up a powerup, add 1 to player's item score
function ItemHolderBonus takes integer nPlayerIndex returns nothing
local unit u = CreateUnit( Player(nPlayerIndex), udg_UT_ItemHolder, GetRectCenterX(gg_rct_ItemHolder), GetRectCenterY(gg_rct_ItemHolder), 0 )
//rde1 can be any item
local item itemTemp = CreateItem( 'rde1', GetRectCenterX(gg_rct_ItemHolder), GetRectCenterY(gg_rct_ItemHolder) )
call UnitAddItem( u, itemTemp)
call RemoveUnit(u)
endfunction
function PickPowerupActions takes nothing returns nothing
local integer nPlayerIndex = 0
local integer nPowerupIndex = 0
local trigger trg = GetTriggeringTrigger()
local integer nPowerupTypeIndex
local effect effPicking = null
local location loc = null
set nPlayerIndex = GetPlayerIndex( GetOwningPlayer( GetTriggerUnit() ) )
if ( nPlayerIndex < 0 ) then
return
endif
if ( DoesWormHavePowerup(nPlayerIndex) ) then
return
endif
set nPowerupIndex = 0
loop
exitwhen nPowerupIndex >= 3
exitwhen trg == udg_PowerupPickTrg[nPowerupIndex]
set nPowerupIndex = nPowerupIndex + 1
endloop
if ( nPowerupIndex >= 3 ) then
return
endif
set nPowerupTypeIndex = PowerupDice()
set loc = GetUnitLoc( udg_Powerup[nPowerupIndex] )
call RemoveUnit( udg_Powerup[nPowerupIndex] )
set udg_Powerup[nPowerupIndex] = null
call DestroyTrigger( udg_PowerupPickTrg[nPowerupIndex] )
set udg_PowerupPickTrg[nPowerupIndex] = null
set udg_SpawnPowerupIndex = nPowerupIndex
call ConditionalTriggerExecute( gg_trg_Spawn_Powerup )
set effPicking = AddSpecialEffectLoc( "Objects\\Spawnmodels\\Other\\ToonBoom\\ToonBoom.mdl", loc)
call RemoveLocation( loc )
call DestroyEffect( effPicking )
call UnitAddAbility( udg_WormHead[nPlayerIndex], udg_PowerupAbilities[nPowerupTypeIndex] )
call ShowMsgToPlayer( Player(nPlayerIndex), udg_STR_POWERUP_PICKUP + udg_PowerupNames[nPowerupTypeIndex] )
call ItemHolderBonus( nPlayerIndex )
endfunction
function SpawnPowerupConditions takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == udg_UT_WormHead
endfunction
function SpawnPowerup takes integer nPowerupIndex returns nothing
local location loc = null
local rect rct = null
local integer nIndex = 0
local group g
if ( udg_Powerup[nPowerupIndex] != null ) then
return
endif
if ( udg_PowerupPickTrg[nPowerupIndex] != null ) then
call DestroyTrigger( udg_PowerupPickTrg[nPowerupIndex] )
set udg_PowerupPickTrg[nPowerupIndex] = null
endif
call PolledWait( 5 )
//Try to avoid spawn powerup near a player
set g = CreateGroup()
set rct = Rect( GetRectMinX(gg_rct_Arena) + 100, GetRectMinY(gg_rct_Arena) + 100, GetRectMaxX(gg_rct_Arena) - 100, GetRectMaxY(gg_rct_Arena) - 100 )
loop
set loc = GetRandomLocInRect( rct )
call GroupEnumUnitsInRangeOfLoc( g, loc, 600, Condition(function SpawnPowerupConditions) )
exitwhen FirstOfGroup(g) == null
call GroupClear(g)
call RemoveLocation(loc)
endloop
call RemoveRect(rct)
call DestroyGroup(g)
set udg_Powerup[nPowerupIndex] = CreateUnitAtLoc( udg_NPC, udg_UT_Powerup, loc, I2R(GetRandomInt(0, 359)) )
set udg_PowerupPickTrg[nPowerupIndex] = CreateTrigger()
call TriggerRegisterUnitInRangeSimple( udg_PowerupPickTrg[nPowerupIndex], 100, udg_Powerup[nPowerupIndex] )
call TriggerAddCondition( udg_PowerupPickTrg[nPowerupIndex], Condition( function PickPowerupConditions ) )
call TriggerAddAction( udg_PowerupPickTrg[nPowerupIndex], function PickPowerupActions )
call RemoveLocation( loc )
endfunction
function PingPowerup takes nothing returns nothing
local location loc
local integer nPowerupIndex = 0
loop
exitwhen nPowerupIndex >= 3
if ( udg_Powerup[nPowerupIndex] != null ) then
set loc = GetUnitLoc( udg_Powerup[nPowerupIndex] )
call PingMinimapLocForForce( GetPlayersAll(), loc, 5.00 )
call RemoveLocation( loc )
endif
set nPowerupIndex = nPowerupIndex + 1
endloop
endfunction
function PowerupSpawnTimerAction takes nothing returns nothing
local integer nPowerupIndex = 0
loop
exitwhen nPowerupIndex >= 3
call SpawnPowerup(nPowerupIndex)
set nPowerupIndex = nPowerupIndex + 1
call PolledWait(20)
endloop
endfunction
//===========================================================================
function InitTrig_Powerup_Functions takes nothing returns nothing
endfunction