//TESH.scrollpos=198
//TESH.alwaysfold=0
library NewEndgame uses HelperFunctions, Awards
globals
boolean array wraithWait
private trigger array wraithInterrupt
private boolean array isWraithInterrupt
private triggeraction array trigact
private dialog endgame_dialog = DialogCreate()
private button endgame_button1
private button endgame_button2
endglobals
function ShareCredit takes nothing returns nothing
local player p = GetEnumPlayer()
call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)+bj_forLoopAIndexEnd)
if GetPlayerController(p) == MAP_CONTROL_USER then
call DisplayTextToPlayer(p, 0,0, "|cff32cd32You have received "+I2S(bj_forLoopAIndexEnd)+" gold from your defeated ally |r"+bj_lastPlayedMusic)
endif
set p = null
endfunction
function ShareCreditOfDefeatedPlayer takes player p returns nothing
local force f = CreateForce()
if GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) > 50 then
call ForceEnumAllies(f, p, Filter(function IsInPlayers))
set bj_forLoopAIndexEnd = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) / CountPlayersInForceBJ(f)
set bj_lastPlayedMusic = "|c" + GetPlayerColorString(p) + GetPlayerName(p) + "|r"
call ForForce(f, function ShareCredit)
endif
call DestroyForce(f)
set f = null
endfunction
private function WraithExpire takes integer playerId returns nothing
set wraithWait[playerId] = false
if (isWraithInterrupt[playerId] == false) then
call CreateUnit(Player(playerId), wraith_1, GetLocationX(building_loc[24 + playerId]), GetLocationY(building_loc[24 + playerId]), 0.00)
call DisplayTimedTextToPlayer(Player(playerId), 0, 0, 5.00, "|cffc5dbffReinforcements have arrived!")
call PingMinimapEx(GetLocationX(building_loc[24 + playerId]), GetLocationY(building_loc[24 + playerId]), 5.0, 0 , 255, 0, true)
endif
call DestroyTrigger(wraithInterrupt[playerId])
call TriggerRemoveAction(wraithInterrupt[playerId], trigact[playerId])
endfunction
private function WraithInterrupt takes nothing returns nothing
local integer index = 0
loop
exitwhen (index == 9)
if (GetTriggeringTrigger() == wraithInterrupt[index]) then
exitwhen true
endif
set index = index + 1
endloop
if (GetUnitTypeId(GetTrainedUnit()) == wraith_1) or (GetUnitTypeId(GetTrainedUnit()) == wraith_2) or (GetUnitTypeId(GetTrainedUnit()) == wraith_3) then
set isWraithInterrupt[index] = true
call WraithExpire(index)
endif
endfunction
function MultiboardAddTimer takes multiboard mb, integer column, integer row, integer playerId returns nothing
local multiboarditem mbi = MultiboardGetItem(mb, row, column)
local integer index = 30
loop
call TriggerSleepAction(1.00)
exitwhen (index == 0) or (isWraithInterrupt[playerId] == true) or (wraithWait[playerId] == false)
call MultiboardSetItemValue(mbi, "|CFFDD1C240|R"+" - "+I2S(index)+"sec")
set index = index - 1
endloop
call MultiboardSetItemValue(mbi, "|CFFDD1C240|R")
call MultiboardReleaseItem(mbi)
set mbi = null
if (isWraithInterrupt[playerId] == false) then
call WraithExpire(playerId)
endif
endfunction
function ShowCinematic takes nothing returns nothing
local location loc = GetRectCenter(bj_mapInitialPlayableArea)
local integer index = 0
local string s = "We have an incoming message from Terran headquarters! This cinematic is under construction."
call CinematicFadeBJ(1, 1.00, "ReplaceableTextures\\CameraMasks\\Black_mask.blp", 0, 0, 0, 0)
call PolledWait(1.00)
call TransmissionFromUnitTypeWithNameBJ(bj_FORCE_ALL_PLAYERS, Player(8), 'e000', "Lieutenant Doomhammer", loc, null, s, 0, 5.00, true)
loop
exitwhen (index == 8)
call CustomDefeatBJ(Player(index), "Thank you for playing!")
set index = index + 1
endloop
call RemoveLocation(loc)
set loc = null
endfunction
function ClickEndGameDialog takes nothing returns nothing
if (GetClickedButton() == endgame_button1) then
if GetLocalPlayer() == GetTriggerPlayer() then
call ClearTextMessages()
endif
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0.00, 0.00, 5.00, "You chose to watch the cinematic!")
call DialogDisplay(GetTriggerPlayer(), endgame_dialog, false)
else
call CustomDefeatBJ(GetTriggerPlayer(), "Thank you for playing!")
call DialogDisplay(GetTriggerPlayer(), endgame_dialog, false)
endif
endfunction
function ShowEndGameDialog takes nothing returns nothing
local integer index = 0
call DialogSetMessage(endgame_dialog, "|cffc5dbffWhat next?|R")
set endgame_button1 = DialogAddButton(endgame_dialog, "|cffc5dbffWatch the cinematic|R", 0)
set endgame_button2 = DialogAddButton(endgame_dialog, "|cffc5dbffQuit the game|R", 0)
loop
exitwhen (index == 8)
if IsPlayerInForce(Player(index), humans) then
call DialogDisplay(Player(index), endgame_dialog, true)
endif
set index = index + 1
endloop
call TriggerSleepAction(8.00)
call DialogClear(endgame_dialog)
set index = 0
loop
exitwhen (index == 8)
call DialogDisplay(Player(index), endgame_dialog, false)
set index = index + 1
endloop
call DialogDestroy(endgame_dialog)
call ShowCinematic()
endfunction
function RemovePlayerUnitsAction takes nothing returns nothing
if (GetUnitTypeId(GetEnumUnit()) != 'h006') then
call SetUnitExploded(GetEnumUnit(), true)
call KillUnit(GetEnumUnit())
endif
endfunction
private function Defeat takes integer playerId, integer teamId returns nothing
local integer index = 0
local integer index2
local boolean win = true
local group g = CreateGroup()
if teamId != 0 then
//Team Defeat
call ForceRemovePlayer(players, Player(2 * teamId - 2))
call ForceRemovePlayer(players, Player(2 * teamId - 1))
if IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.00, 0.00, 5.00, "Team "+I2S(teamId)+" has been defeated!")
endif
call SetForceAllianceStateBJ(bj_FORCE_PLAYER[2 * teamId - 2], bj_FORCE_ALL_PLAYERS, bj_ALLIANCE_UNALLIED_VISION)
call SetForceAllianceStateBJ(bj_FORCE_PLAYER[2 * teamId - 1], bj_FORCE_ALL_PLAYERS, bj_ALLIANCE_UNALLIED_VISION)
set bj_lastCreatedFogModifier = CreateFogModifierRect(Player(2 * teamId - 2), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
call FogModifierStart(bj_lastCreatedFogModifier)
set bj_lastCreatedFogModifier = CreateFogModifierRect(Player(2 * teamId - 1), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
call FogModifierStart(bj_lastCreatedFogModifier)
call GroupEnumUnitsOfPlayer(g, Player(2 * teamId - 2), null)
call ForGroup(g, function RemovePlayerUnitsAction)
call GroupClear(g)
call GroupEnumUnitsOfPlayer(g, Player(2 * teamId - 1), null)
call ForGroup(g, function RemovePlayerUnitsAction)
call CreateUnit(Player(2 * teamId - 2), 'H00C', GetLocationX(building_loc[24 + (2 * teamId - 2)]), GetLocationX(building_loc[24 + (2 * teamId - 2)]), 0.00)
call CreateUnit(Player(2 * teamId - 1), 'H00C', GetLocationX(building_loc[24 + (2 * teamId - 1)]), GetLocationX(building_loc[24 + (2 * teamId - 1)]), 0.00)
else
//Player Defeat
call ForceRemovePlayer(players, Player(playerId))
if IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.00, 0.00, 5.00, "Player "+I2S(playerId)+" has been defeated!")
endif
call SetForceAllianceStateBJ(bj_FORCE_PLAYER[playerId], bj_FORCE_ALL_PLAYERS, bj_ALLIANCE_UNALLIED_VISION)
set bj_lastCreatedFogModifier = CreateFogModifierRect(Player(playerId), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false)
call FogModifierStart(bj_lastCreatedFogModifier)
call GroupEnumUnitsOfPlayer(g, Player(playerId), null)
call ForGroup(g, function RemovePlayerUnitsAction)
endif
call DestroyGroup(g)
set g = null
//Check if anyone won the game
loop
exitwhen (index == 8)
set index2 = 0
loop
exitwhen (index2 == 8)
if IsPlayerEnemy(Player(index), Player(index2)) and IsPlayerInForce(Player(index2), players) then
set win = false
exitwhen true
endif
set index2 = index2 + 1
endloop
set index = index + 1
endloop
//If someone won, then..
if (win == true) then
set index = 0
loop
exitwhen (index == 8)
if IsPlayerInForce(Player(index), players) then
//Found a winning team or player
call BJDebugMsg("Game Won!")
if (game_mode < 2) then
//Normal/Simple game win actions
if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.00, 0.00, 5.00, "Team "+I2S(GetPlayerId(Player(index)) / 2 + 1)+" has won the game!
")
if (game_mode == 1) then
call BJDebugMsg("Team #"+I2S(GetPlayerId(Player(index)) / 2 + 1)+" has won the game in normal!")
call PanCameraToTimedForPlayer(GetLocalPlayer(), GetLocationX(lastBunker), GetLocationY(lastBunker), 0.00)
call SetCameraRotateMode(GetLocationX(lastBunker), GetLocationY(lastBunker), bj_DEGTORAD * 360.00, 20.00)
else
call BJDebugMsg("Team #"+I2S(GetPlayerId(Player(index)) / 2 + 1)+" has won the game in normal!")
call PanCameraToTimedForPlayer(GetLocalPlayer(), GetLocationX(building_loc[31 + GetPlayerId(Player(index)) / 2 + 1]), GetLocationY(building_loc[31 + GetPlayerId(Player(index)) / 2 + 1]), 0.00)
call SetCameraRotateMode(GetLocationX(building_loc[31 + GetPlayerId(Player(index)) / 2 + 1]), GetLocationY(building_loc[31 + GetPlayerId(Player(index)) / 2 + 1]), bj_DEGTORAD * 360.00, 20.00)
endif
endif
else
//FFA game win actions
if (IsPlayerInForce(GetLocalPlayer(), bj_FORCE_ALL_PLAYERS)) then
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0.00, 0.00, 5.00, "Player "+I2S(GetPlayerId(Player(index)))+" has won the game!
")
call BJDebugMsg("Player #"+I2S(GetPlayerId(Player(index)))+" has won the game in normal!")
call PanCameraToTimedForPlayer(GetLocalPlayer(), GetLocationX(building_loc[24 + GetPlayerId(Player(index)) / 2 + 1]), GetLocationY(building_loc[24 + GetPlayerId(Player(index)) / 2 + 1]), 0.00)
call SetCameraRotateMode(GetLocationX(building_loc[24 + GetPlayerId(Player(index)) / 2 + 1]), GetLocationY(building_loc[24 + GetPlayerId(Player(index)) / 2 + 1]), bj_DEGTORAD * 360.00, 20.00)
endif
endif
call ShowAwards(null)
call TriggerSleepAction(20.00)
return
endif
set index = index + 1
endloop
endif
endfunction
private function DefeatTeam takes integer k returns nothing
if (wraithWait[2 * k - 2] == true) then
set isWraithInterrupt[2 * k - 2] = true
endif
if (wraithWait[2 * k - 1] == true) then
set isWraithInterrupt[2 * k - 1] = true
endif
call Defeat(0, k)
endfunction
function DefeatCheck takes integer k, unit u returns nothing
//Check defeat for FFA
if game_mode == 2 and player_zones[k] <= 0 then
call Defeat(k, 0)
return
endif
//Check defeat for Simple
if game_mode == 1 and player_zones[k] <= 0 then
call ShareCreditOfDefeatedPlayer(Player(k))
if (Player(k) != Player(2 * (k / 2 + 1) - 2)) and (IsPlayerInForce(Player(2 * (k / 2 + 1) - 2), players)) then
call Defeat(k, 0)
return
elseif (Player(k) != Player(2 * (k / 2 + 1) - 1)) and (IsPlayerInForce(Player(2 * (k / 2 + 1) - 1), players)) then
call Defeat(k, 0)
return
endif
call Defeat(0, k / 2 + 1)
return
endif
//Check defeat for Normal
if game_mode == 0 and GetUnitTypeId(u) == 'h006' then
call DefeatTeam(k / 2 + 1)
return
endif
//This just starts the timer for new dropship
if game_mode == 0 and player_zones[k] <= 0 and CountLivingPlayerUnitsOfTypeId(wraith_1, Player(k)) == 0 then
set wraithInterrupt[k] = CreateTrigger()
set trigact[k] = TriggerAddAction(wraithInterrupt[k], function WraithInterrupt)
call TriggerRegisterPlayerUnitEvent(wraithInterrupt[k], Player(k), EVENT_PLAYER_UNIT_TRAIN_FINISH, null)
call MultiboardAddTimer.execute(mboard, 1, mboard_spots[k] - 1, k)
set wraithWait[k] = true
set isWraithInterrupt[k] = false
endif
endfunction
function InitTrig_New_Endgame takes nothing returns nothing
endfunction
endlibrary