// Cinematic Fade For Player
// Written by Elil
//
// This is a conversion of the cinematic fade triggers in "Blizzard.j" to fade
// the screen only for a single player, even when there are multiple players in the game.
//
// There is no problem executing the fade effect only for a single player using GetLocalPlayer()
// The problem comes from the timers used for cleanly ending the fade
// (and the timer for the middle of "fade out and back in"). If you put the standard fade call
// inside an asynchronous block, the game will desync because of the timers.
//
// The solution here is for every player to know about every timer.
// The timers will be registered and fired for everyone, and only the actual fading will be asynchronous.
//
// I mimic the functions in "Blizzard.j" as closely as possible, CinematicFadeCommonBJ
// is used asynchronously to do the actual fading. If you use both "For Player" fades and standard fades
// at the same time, you will have slight problems, because the fades will not cancel each other properly.
// For example if you do a "fade out and back in" locally, then immediately do a fast global fade,
// the global fade will happen, then the "middle" of the local fade will happen for that player.
//===========================================================================
function CinematicFadeCommonForPlayer takes player fadePlayer, real red, real green, real blue, real duration, string tex, real startTrans, real endTrans returns nothing
if (GetLocalPlayer() == fadePlayer) then
call CinematicFadeCommonBJ(red, green, blue, duration, tex, startTrans, endTrans)
endif
endfunction
//===========================================================================
function FinishCinematicFadeForPlayer takes nothing returns nothing
local integer fadePlayerId = 1
// We don't know which player the expired timer belongs to,
// so we check each player's timer to see if it matches the one that just expired.
loop
exitwhen udg_cineFadeFinishTimer[fadePlayerId] == GetExpiredTimer()
set fadePlayerId = fadePlayerId + 1
endloop
call DestroyTimer(udg_cineFadeFinishTimer[fadePlayerId])
set udg_cineFadeFinishTimer[fadePlayerId] = null
if (GetConvertedPlayerId(GetLocalPlayer()) == fadePlayerId) then
call DisplayCineFilter(false)
call EnableUserUI(true)
endif
endfunction
//===========================================================================
function FinishCinematicFadeAfterForPlayer takes player fadePlayer, real duration returns nothing
local integer fadePlayerId = GetConvertedPlayerId(fadePlayer)
// Create a timer to end the cinematic fade.
set udg_cineFadeFinishTimer[fadePlayerId] = CreateTimer()
call TimerStart(udg_cineFadeFinishTimer[fadePlayerId], duration, false, function FinishCinematicFadeForPlayer)
endfunction
//===========================================================================
function ContinueCinematicFadeForPlayer takes nothing returns nothing
local integer fadePlayerId = 1
// We don't know which player the expired timer belongs to,
// so we check each player's timer to see if it matches the one that just expired.
loop
exitwhen udg_cineFadeContinueTimer[fadePlayerId] == GetExpiredTimer()
set fadePlayerId = fadePlayerId + 1
endloop
call DestroyTimer(udg_cineFadeContinueTimer[fadePlayerId])
set udg_cineFadeContinueTimer[fadePlayerId] = null
call CinematicFadeCommonForPlayer(ConvertedPlayer(fadePlayerId), udg_cineFadeContinueRed, udg_cineFadeContinueGreen, udg_cineFadeContinueBlue, udg_cineFadeContinueDuration, udg_cineFadeContinueTex, udg_cineFadeContinueTrans, 100)
endfunction
//===========================================================================
function ContinueCinematicFadeAfterForPlayer takes player fadePlayer, real duration, real red, real green, real blue, real trans, string tex returns nothing
local integer fadePlayerId = GetConvertedPlayerId(fadePlayer)
if (GetLocalPlayer() == fadePlayer) then
set udg_cineFadeContinueRed = red
set udg_cineFadeContinueGreen = green
set udg_cineFadeContinueBlue = blue
set udg_cineFadeContinueTrans = trans
set udg_cineFadeContinueDuration = duration
set udg_cineFadeContinueTex = tex
endif
// Create a timer to continue the cinematic fade.
set udg_cineFadeContinueTimer[fadePlayerId] = CreateTimer()
call TimerStart(udg_cineFadeContinueTimer[fadePlayerId], duration, false, function ContinueCinematicFadeForPlayer)
endfunction
//===========================================================================
function AbortCinematicFadeForPlayer takes player fadePlayer returns nothing
local integer fadePlayerId = GetConvertedPlayerId(fadePlayer)
if (udg_cineFadeContinueTimer[fadePlayerId] != null) then
call DestroyTimer(udg_cineFadeContinueTimer[fadePlayerId])
endif
if (udg_cineFadeFinishTimer[fadePlayerId] != null) then
call DestroyTimer(udg_cineFadeFinishTimer[fadePlayerId])
endif
endfunction
function CinematicFadeForPlayer takes player fadePlayer, integer fadetype, real duration, string tex, real red, real green, real blue, real trans returns nothing
if (fadetype == bj_CINEFADETYPE_FADEOUT) then
// Fade out to the requested color.
call AbortCinematicFadeForPlayer(fadePlayer)
call CinematicFadeCommonForPlayer(fadePlayer, red, green, blue, duration, tex, 100, trans)
elseif (fadetype == bj_CINEFADETYPE_FADEIN) then
// Fade in from the requested color.
call AbortCinematicFadeForPlayer(fadePlayer)
call CinematicFadeCommonForPlayer(fadePlayer, red, green, blue, duration, tex, trans, 100)
call FinishCinematicFadeAfterForPlayer(fadePlayer, duration)
elseif (fadetype == bj_CINEFADETYPE_FADEOUTIN) then
// Fade out to the requested color, and then fade back in from it.
if (duration > 0) then
call AbortCinematicFadeForPlayer(fadePlayer)
call CinematicFadeCommonForPlayer(fadePlayer, red, green, blue, duration * 0.5, tex, 100, trans)
call ContinueCinematicFadeAfterForPlayer(fadePlayer, duration * 0.5, red, green, blue, trans, tex)
call FinishCinematicFadeAfterForPlayer(fadePlayer, duration)
endif
else
// Unrecognized fadetype - ignore the request.
endif
endfunction
Name | Type | is_array | initial_value |
ActiveRegion | rect | No | |
AprilFools | boolean | No | |
AprilJoke | integer | No | |
AprilLastJoke | integer | No | |
AprilMaxJoke | integer | No | 8 |
armorDefenseStrength | real | No | |
Attack | real | Yes | |
AutoSkip | boolean | Yes | |
BackupGameStartTimer | timer | No | |
BonusItemTypes | itemcode | Yes | |
BotGold | integer | Yes | |
BotThinkTimer | timer | No | |
CameraChaseUnit | unit | Yes | |
CenterPoint | location | No | |
CharacterAbility | abilcode | Yes | |
ChaseCamOn | boolean | No | false |
cineFadeContinueBlue | real | No | |
cineFadeContinueDuration | real | No | |
cineFadeContinueGreen | real | No | |
cineFadeContinueRed | real | No | |
cineFadeContinueTex | string | No | |
cineFadeContinueTimer | timer | Yes | |
cineFadeContinueTrans | real | No | |
cineFadeFinishTimer | timer | Yes | |
Cinematic_CathedralFront | location | No | |
Cinematic_FieldPoints | location | Yes | |
Cinematic_ForestPoints | location | Yes | |
Cinematic_GatePoints | location | Yes | |
Cinematic_KeyItems | item | Yes | |
Cinematic_KeyUnits | unit | Yes | |
Cinematic_Mayor | unit | No | |
Cinematic_StreetPoints | location | Yes | |
CinematicInProgress | boolean | No | |
CinematicPlayers | force | No | |
CinematicRandomInt | integer | No | |
CinematicUnits | group | No | |
COMBAT_ARMOR | integer | No | 2 |
Combat_Attack_Type | integer | No | |
Combat_Attacker | unit | No | |
Combat_Attacker_Number | integer | No | |
COMBAT_HIT | integer | No | 0 |
COMBAT_ILLEGAL | integer | No | -1 |
COMBAT_MISS | integer | No | 1 |
Combat_Outcome | integer | No | |
Combat_Target | unit | No | |
Combat_Target_Number | integer | No | |
CombatAllowed | boolean | No | |
ComputerPlayer | player | No | Player11 |
ControlledByAI | boolean | Yes | |
CountdownStrings | string | Yes | |
CurrentIcon | string | Yes | |
DebugPlayers | force | No | |
EmployeeOfTheMonth | boolean | No | |
Evasion | real | Yes | |
EvilChance | real | Yes | |
EvilPlayers | force | No | |
ExtraUnits | group | No | |
FrozenInsane | group | No | |
GAME_AGE_OF_MYTH | integer | No | |
GAME_GREATER_DEAD | integer | No | |
GAME_LICH | integer | No | |
GAME_MYSTIC | integer | No | |
GAME_NECROMANCER | integer | No | |
GAME_PSYCHO_KILLERS | integer | No | |
GAME_ROBIN | integer | No | |
GAME_SPIRITS | integer | No | |
GAME_VAMPIRE | integer | No | |
GAME_WEREWOLF | integer | No | |
GameActive | boolean | No | |
GameBuffs | buffcode | Yes | |
GameCharacters | unitcode | Yes | |
GameIcons | string | Yes | |
GameLastSelected | integer | No | |
GameLocked | boolean | Yes | |
GameNumberOfEvil | integer | Yes | |
GamePassword | string | Yes | |
GameRegions | location | Yes | |
GameSelected | integer | No | |
GamesStarted | integer | No | |
GamesUnlocked | integer | Yes | |
GameTimeOuts | integer | No | |
GameTimer | timer | No | |
GameTitle | string | Yes | |
GameVillainName | string | Yes | |
HappyKills | integer | Yes | |
HappyvilleMaxPopulation | integer | No | 20 |
HomePoint | location | Yes | |
IneligibleToRise | group | No | |
IsHappy | boolean | Yes | |
IsThralled | boolean | Yes | |
LightningTimer | timer | No | |
LivingHappy | group | No | |
LivingHunters | group | No | |
LivingInsane | group | No | |
LivingThralls | group | No | |
LivingUnhappy | group | No | |
localUnit | unit | No | |
MarketBuilding | unit | No | |
Master | unit | Yes | |
netAttackStrength | real | No | |
netDefenseStrength | real | No | |
Newline | string | No | |
NumberOfGames | integer | No | 2 |
NumberOfGamesUnlocked | integer | No | |
NumberOfTalents | integer | No | |
NumEvil | integer | No | 3 |
Observation | real | Yes | |
ObserverPlayers | force | No | |
OriginalOwner | player | Yes | |
Person | unit | Yes | |
PlayerNames | string | Yes | |
Possessor | unit | Yes | |
ProbabilitySurvived | real | Yes | |
randomColor | real | Yes | |
RemorseEnabled | boolean | No | |
ReservedLoopVar1 | integer | No | |
SecondsBeforeCombatAllowed | integer | No | |
ShadowHandAttackStrings | string | Yes | |
ShadowHandVocabulary | integer | No | |
ShadowHandWanderStrings | string | Yes | |
SkillBoards | leaderboard | Yes | |
SpecialCommandInProgress | boolean | Yes | |
Speed | real | Yes | |
StartBotUpgradesTimer | timer | No | |
StartGameTimer | timer | No | |
StartPopulationTimer | timer | No | |
StartSpecialCharactersTimer | timer | No | |
StatBoard | multiboard | No | |
StatDisplay | boolean | Yes | |
Stealth | real | Yes | |
Successor | unit | Yes | |
TalentAbilities | abilcode | Yes | |
TalentSelectionAbilities | abilcode | Yes | |
TechUnit | unit | Yes | |
tempInt | integer | No | |
tempPlayer | player | No | |
tempPoint | location | No | |
tempPoint2 | location | No | |
tempReal | real | No | |
tempString | string | No | |
tempUnit | unit | No | |
text | texttag | No | |
TimesConsecutiveHappyWon | integer | No | |
TimesConsecutiveUnhappyWon | integer | No | |
TimesEmployee | integer | No | |
TimesGamePlayed | integer | Yes | |
TimesHappyWon | integer | No | |
TimesUnhappyWon | integer | No | |
TotalEvilness | real | No | |
Undead | group | No | |
UnhappyKills | integer | Yes | |
UserPlayers | force | No | |
UsingCaution | boolean | Yes | |
UsingObservation | boolean | Yes | |
UsingStealth | boolean | Yes | |
VisibilityModifiers | fogmodifier | Yes | |
VoteInProgress | boolean | No | |
VoteMaxTally | integer | No | |
VoteTally | integer | Yes | |
VoteText | texttag | Yes | |
VoteTextAux | texttag | No | |
VoteTies | integer | No | |
VoteTimer | timer | No | |
VoteTimerWindow | timerdialog | No | |
VoteUnits | group | No | |
WindFluteDetected | boolean | Yes | |
WindFluteSensitives | group | No | |
ZombieAttackStrings | string | Yes | |
ZombieHappyKills | integer | No | |
Zombies | group | No | |
ZombieUnhappyKills | integer | No | |
ZombieVocabulary | integer | No | |
ZombieWanderStrings | string | Yes |