Name | Type | is_array | initial_value |
AmbientSounds | sound | Yes | |
Boss | unit | Yes | |
BossGroup | group | No | |
ComputerGoup | force | No | |
ConditionGroup | group | No | |
CooldownGroup_Slow | group | No | |
Heroes | unitcode | Yes | |
HeroLimit | integer | Yes | |
HolyShieldlRemainingTime | real | No | |
HolyShieldTable | hashtable | No | |
Integer | integervar | No | |
INTEGER | integer | No | |
Items | itemcode | Yes | |
ItemsChoose | itemcode | Yes | |
ItemsPrimary | itemcode | Yes | |
Madness | sound | Yes | |
MicosTable | hashtable | No | |
Mutation_List | hashtable | No | |
PlayerGroup | force | No | |
Point | location | Yes | |
POSITION | location | No | |
Random | integer | No | |
RemainingTimeGH | real | No | |
RevealWarning | string | No | |
RevealWarningPlayer | player | No | |
Sacrifice_Table | hashtable | No | |
ShopRandom | integer | No | |
Target | unit | No | |
Timer | timer | Yes | |
Timer_Window | timerdialog | Yes | |
Titans | group | No | |
TownHallCount | integer | Yes | |
Units | unitcode | Yes |
function MeleeGetAllyKeyStructureCountCustom takes player whichPlayer returns integer
local integer playerIndex
local player indexPlayer
local integer keyStructs
// Count the number of buildings controlled by all not-yet-defeated co-allies.
set keyStructs = 0
set playerIndex = 0
loop
set indexPlayer = Player(playerIndex)
if (PlayersAreCoAllied(whichPlayer, indexPlayer)) then
set keyStructs = keyStructs + udg_TownHallCount[playerIndex]
endif
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYERS
endloop
return keyStructs
endfunction
function MeleePlayerIsCrippledCustom takes player whichPlayer returns boolean
local integer allyStructures = MeleeGetAllyStructureCount(whichPlayer)
local integer allyKeyStructures = MeleeGetAllyKeyStructureCountCustom(whichPlayer)
// Dead teams are not considered to be crippled.
return (allyStructures > 0) and (allyKeyStructures <= 0)
endfunction
function MeleeCheckForCrippledPlayersCustom takes nothing returns nothing
local integer playerIndex
local player indexPlayer
local force crippledPlayers = CreateForce()
local boolean isNowCrippled
local race indexRace
// The "finish soon" exposure of all players overrides any "crippled" exposure
if bj_finishSoonAllExposed then
return
endif
// Check each player to see if he or she has been crippled or uncrippled.
set playerIndex = 0
loop
set indexPlayer = Player(playerIndex)
set isNowCrippled = MeleePlayerIsCrippledCustom(indexPlayer)
if (not bj_playerIsCrippled[playerIndex] and isNowCrippled) then
// Player became crippled; start their cripple timer.
set bj_playerIsCrippled[playerIndex] = true
call TimerStart(bj_crippledTimer[playerIndex], bj_MELEE_CRIPPLE_TIMEOUT, false, function MeleeCrippledPlayerTimeout)
set udg_RevealWarningPlayer = indexPlayer
call TriggerExecute(gg_trg_SetRevealWarning)
if (GetLocalPlayer() == indexPlayer) then
// Use only local code (no net traffic) within this block to avoid desyncs.
// Show the timer window.
call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], true)
// Display a warning message.
call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, udg_RevealWarning)
endif
elseif (bj_playerIsCrippled[playerIndex] and not isNowCrippled) then
// Player became uncrippled; stop their cripple timer.
set bj_playerIsCrippled[playerIndex] = false
call PauseTimer(bj_crippledTimer[playerIndex])
if (GetLocalPlayer() == indexPlayer) then
// Use only local code (no net traffic) within this block to avoid desyncs.
// Hide the timer window for this player.
call TimerDialogDisplay(bj_crippledTimerWindows[playerIndex], false)
// Display a confirmation message if the player's team is still alive.
if (MeleeGetAllyStructureCount(indexPlayer) > 0) then
if (bj_playerIsExposed[playerIndex]) then
call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, GetLocalizedString("CRIPPLE_UNREVEALED"))
else
call DisplayTimedTextToPlayer(indexPlayer, 0, 0, bj_MELEE_CRIPPLE_MSG_DURATION, GetLocalizedString("CRIPPLE_UNCRIPPLED"))
endif
endif
endif
// If the player granted shared vision, deny that vision now.
call MeleeExposePlayer(indexPlayer, false)
endif
set playerIndex = playerIndex + 1
exitwhen playerIndex == bj_MAX_PLAYERS
endloop
endfunction
function MeleeCheckLostUnitCustom takes unit lostUnit returns nothing
local player lostUnitOwner = GetOwningPlayer(lostUnit)
local integer index
// We only need to check for mortality if this was the last building.
if (GetPlayerStructureCount(lostUnitOwner, true) <= 0) then
call MeleeCheckForLosersAndVictors()
endif
if( IsUnitType(lostUnit, UNIT_TYPE_TOWNHALL)) then
set index = GetPlayerId(lostUnitOwner)
set udg_TownHallCount[index] = udg_TownHallCount[index] - 1
endif
// Check if the lost unit has crippled or uncrippled the player.
// (A team with 0 units is dead, and thus considered uncrippled.)
call MeleeCheckForCrippledPlayersCustom()
endfunction
function MeleeCheckAddedUnitCustom takes unit addedUnit returns nothing
local player addedUnitOwner = GetOwningPlayer(addedUnit)
local integer index
if( IsUnitType(addedUnit, UNIT_TYPE_TOWNHALL)) then
set index = GetPlayerId(addedUnitOwner)
set udg_TownHallCount[index] = udg_TownHallCount[index] + 1
endif
// If the player was crippled, this unit may have uncrippled him/her.
if (bj_playerIsCrippled[GetPlayerId(addedUnitOwner)]) then
call MeleeCheckForCrippledPlayersCustom()
endif
endfunction
function MeleeTriggerActionUnitDeathCustom takes nothing returns nothing
if (IsUnitType(GetDyingUnit(), UNIT_TYPE_STRUCTURE)) then
call MeleeCheckLostUnitCustom(GetDyingUnit())
endif
endfunction
//actually canceled units also fire the death event, so this is unecessary
function MeleeTriggerActionConstructCancelCustom takes nothing returns nothing
call MeleeCheckLostUnitCustom(GetCancelledStructure())
endfunction
function MeleeTriggerActionUnitConstructionStartCustom takes nothing returns nothing
call MeleeCheckAddedUnitCustom(GetConstructingStructure())
endfunction
function MeleeTriggerActionAllianceChangeCustom takes nothing returns nothing
call MeleeCheckForLosersAndVictors()
call MeleeCheckForCrippledPlayersCustom()
endfunction
function MeleeInitVictoryDefeatCustom takes nothing returns nothing
//this trigger has the same functionality as MeleeInitVictoryDefeat()
//only revealing uses different buildings
local trigger trig
local integer index
local player indexPlayer
// Create a timer window for the "finish soon" timeout period, it has no timer
// because it is driven by real time (outside of the game state to avoid desyncs)
set bj_finishSoonTimerDialog = CreateTimerDialog(null)
// Set a trigger to fire when we receive a "finish soon" game event
set trig = CreateTrigger()
call TriggerRegisterGameEvent(trig, EVENT_GAME_TOURNAMENT_FINISH_SOON)
call TriggerAddAction(trig, function MeleeTriggerTournamentFinishSoon)
// Set a trigger to fire when we receive a "finish now" game event
set trig = CreateTrigger()
call TriggerRegisterGameEvent(trig, EVENT_GAME_TOURNAMENT_FINISH_NOW)
call TriggerAddAction(trig, function MeleeTriggerTournamentFinishNow)
// Set up each player's mortality code.
set index = 0
loop
set indexPlayer = Player(index)
// Make sure this player slot is playing.
if (GetPlayerSlotState(indexPlayer) == PLAYER_SLOT_STATE_PLAYING) then
set bj_meleeDefeated[index] = false
set bj_meleeVictoried[index] = false
// Create a timer and timer window in case the player is crippled.
set bj_playerIsCrippled[index] = false
set bj_playerIsExposed[index] = false
set bj_crippledTimer[index] = CreateTimer()
set bj_crippledTimerWindows[index] = CreateTimerDialog(bj_crippledTimer[index])
call TimerDialogSetTitle(bj_crippledTimerWindows[index], MeleeGetCrippledTimerMessage(indexPlayer))
//actually canceled units also fire the death event, so this is unecessary
// Set a trigger to fire whenever a building is cancelled for this player.
//set trig = CreateTrigger()
//call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL, null)
//call TriggerAddAction(trig, function MeleeTriggerActionConstructCancelCustom)
// Set a trigger to fire whenever a unit dies for this player.
set trig = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_DEATH, null)
call TriggerAddAction(trig, function MeleeTriggerActionUnitDeathCustom)
// Set a trigger to fire whenever a unit begins construction for this player
set trig = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(trig, indexPlayer, EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
call TriggerAddAction(trig, function MeleeTriggerActionUnitConstructionStartCustom)
// Set a trigger to fire whenever this player defeats-out
set trig = CreateTrigger()
call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_DEFEAT)
call TriggerAddAction(trig, function MeleeTriggerActionPlayerDefeated)
// Set a trigger to fire whenever this player leaves
set trig = CreateTrigger()
call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_LEAVE)
call TriggerAddAction(trig, function MeleeTriggerActionPlayerLeft)
// Set a trigger to fire whenever this player changes his/her alliances.
set trig = CreateTrigger()
call TriggerRegisterPlayerAllianceChange(trig, indexPlayer, ALLIANCE_PASSIVE)
call TriggerRegisterPlayerStateEvent(trig, indexPlayer, PLAYER_STATE_ALLIED_VICTORY, EQUAL, 1)
call TriggerAddAction(trig, function MeleeTriggerActionAllianceChangeCustom)
else
set bj_meleeDefeated[index] = true
set bj_meleeVictoried[index] = false
// Handle leave events for observers
if (IsPlayerObserver(indexPlayer)) then
// Set a trigger to fire whenever this player leaves
set trig = CreateTrigger()
call TriggerRegisterPlayerEvent(trig, indexPlayer, EVENT_PLAYER_LEAVE)
call TriggerAddAction(trig, function MeleeTriggerActionPlayerLeft)
endif
endif
set index = index + 1
exitwhen index == bj_MAX_PLAYERS
endloop
set trig = null
set indexPlayer = null
// Test for victory / defeat at startup, in case the user has already won / lost.
// Allow for a short time to pass first, so that the map can finish loading.
call TimerStart(CreateTimer(), 2.0, false, function MeleeTriggerActionAllianceChangeCustom)
endfunction
//===========================================================================
function InitTrig_Custom_Melee_VictoryDefeat takes nothing returns nothing
set gg_trg_Custom_Melee_VictoryDefeat = CreateTrigger( )
call TriggerAddAction( gg_trg_Custom_Melee_VictoryDefeat, function MeleeInitVictoryDefeatCustom )
endfunction