Skip to content

Commit

Permalink
Fix desyncs #266 #224
Browse files Browse the repository at this point in the history
Various spots were variables were being saved for only a single player which is a desync culprit.
  • Loading branch information
SMUnlimited committed Mar 2, 2024
1 parent 71fed75 commit 48e5b9f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 45 deletions.
49 changes: 26 additions & 23 deletions Blizzard.eai
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
trigger ZoomSetx = null
trigger AdjustZoomUp = null
trigger AdjustZoomDown = null
real current_zoom = 1650
real array current_zoom

dialog game_start_dialog = null
trigger game_start_trigger = null
Expand Down Expand Up @@ -563,56 +563,58 @@ endfunction
//===========================================================================
function ZoomSet takes nothing returns nothing
local real Zoom = 0
if SubStringBJ(GetEventPlayerChatString(), 6, 6) != " " then
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 6, 10))
else
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 7, 11))
endif
if (GetTriggerPlayer() == GetLocalPlayer()) then
if SubStringBJ(GetEventPlayerChatString(), 6, 6) != " " then
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 6, 10))
else
set Zoom = S2R(SubStringBJ(GetEventPlayerChatString(), 7, 11))
endif

if Zoom < 1650 then
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, 1650, 0 )
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "zoom min:|cff00ff001650|r" )
set current_zoom = 1650
elseif Zoom > 3000 then
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, 3000, 0 )
call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 7, "zoom max:|cff00ff003000|r" )
set current_zoom = 3000
else
call SetCameraFieldForPlayer( GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, Zoom, 0 )
set current_zoom = Zoom
endif
endif
// Fix desync, variables must be same across players
if Zoom < 1650 then
set current_zoom[GetPlayerId(GetTriggerPlayer())] = 1650
elseif Zoom > 3000 then
set current_zoom[GetPlayerId(GetTriggerPlayer())] = 3000
else
set current_zoom[GetPlayerId(GetTriggerPlayer())] = Zoom
endif
endfunction

function ZoomDown takes nothing returns nothing
if current_zoom > 1650 and GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom - 50 ), 0 )
set current_zoom = current_zoom - 50
if current_zoom[GetPlayerId(GetTriggerPlayer())] > 1650 then
if GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom[GetPlayerId(GetTriggerPlayer())] - 50 ), 0 )
endif
set current_zoom[GetPlayerId(GetTriggerPlayer())] = current_zoom[GetPlayerId(GetTriggerPlayer())] - 50
endif
endfunction

function ZoomUp takes nothing returns nothing
if current_zoom < 3000 and GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom + 50 ), 0 )
set current_zoom = current_zoom + 50
if current_zoom[GetPlayerId(GetTriggerPlayer())] < 3000 then
if GetTriggerPlayer() == GetLocalPlayer() then
call SetCameraFieldForPlayer(GetTriggerPlayer(), CAMERA_FIELD_TARGET_DISTANCE, ( current_zoom[GetPlayerId(GetTriggerPlayer())] + 50 ), 0 )
endif
set current_zoom[GetPlayerId(GetTriggerPlayer())] = current_zoom[GetPlayerId(GetTriggerPlayer())] + 50
endif
endfunction

function InitZoom takes nothing returns nothing
local integer i = 0
local camerasetup theCam = null
set ZoomSetx = CreateTrigger()
set AdjustZoomUp = CreateTrigger()
set AdjustZoomDown = CreateTrigger()
call TriggerAddAction(ZoomSetx, function ZoomSet)
call TriggerAddAction(AdjustZoomUp , function ZoomUp)
call TriggerAddAction(AdjustZoomDown , function ZoomDown)
if (legacyCamera) then
set theCam = GetCurrentCameraSetup()
set current_zoom = CameraSetupGetFieldSwap(CAMERA_FIELD_TARGET_DISTANCE, theCam)
set theCam = null
endif
loop
exitwhen i >= GetBJMaxPlayers()
if (GetPlayerController(Player(i)) != MAP_CONTROL_COMPUTER) then
Expand All @@ -621,9 +623,10 @@ function InitZoom takes nothing returns nothing
if (legacyCamera) then // Only required for legacy versions as no camera support built into the game
call TriggerRegisterPlayerKeyEventBJ( AdjustZoomUp, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
call TriggerRegisterPlayerKeyEventBJ( AdjustZoomDown, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
set current_zoom[i] = 1650 // Default expected in legacy systems
if IsPlayerObserver(Player(i)) then
call SetCameraFieldForPlayer(Player(i), CAMERA_FIELD_TARGET_DISTANCE, 1950, 0)
set current_zoom = 1950
set current_zoom[i] = 1950
endif
endif
endif
Expand Down
4 changes: 3 additions & 1 deletion Jobs/CHAT_QUEUE.eai
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function FireChat takes nothing returns nothing
elseif lockplayer == GetAiPlayer() then
set i_locked_chat = true
if chat_strategy != null then
call DisplayToPlayer(chat_strategy, GetLocalPlayer(), true)
if IsPlayerAlly(ai_player,GetLocalPlayer()) or IsPlayerObserver(GetLocalPlayer()) then
call DisplayToPlayer(chat_strategy, GetLocalPlayer(), true)
endif
set chat_strategy = null
else
call DisplayToPlayer(chat_queue[0] , chat_queue_player[0], chat_queue_importance[0])
Expand Down
38 changes: 18 additions & 20 deletions common.eai
Original file line number Diff line number Diff line change
Expand Up @@ -3091,23 +3091,21 @@ endfunction
//============================================================================
function QueueChat takes string text, player p, boolean important returns nothing
local integer i = 0
if (p == GetLocalPlayer()) then
set chat_queue_size = chat_queue_size + 1
set chat_queue[chat_queue_size] = text
set chat_queue_player[chat_queue_size] = p
set chat_queue_importance[chat_queue_size] = important
if (chat_queue_size > 5) then
// Remove oldest message
set i = 0
loop
exitwhen i >= chat_queue_size
set chat_queue[i] = chat_queue[i+1]
set chat_queue_player[i] = chat_queue_player[i+1]
set chat_queue_importance[i] = chat_queue_importance[i+1]
set i = i + 1
endloop
set chat_queue_size = chat_queue_size - 1
endif
set chat_queue_size = chat_queue_size + 1
set chat_queue[chat_queue_size] = text
set chat_queue_player[chat_queue_size] = p
set chat_queue_importance[chat_queue_size] = important
if (chat_queue_size > (5 * c_ai_total)) then
// Remove oldest message
set i = 0
loop
exitwhen i >= chat_queue_size
set chat_queue[i] = chat_queue[i+1]
set chat_queue_player[i] = chat_queue_player[i+1]
set chat_queue_importance[i] = chat_queue_importance[i+1]
set i = i + 1
endloop
set chat_queue_size = chat_queue_size - 1
endif
endfunction

Expand All @@ -3132,7 +3130,7 @@ function DisplayChat takes integer chat, boolean ally, boolean enemy, boolean ob
set rand = GetRandomInt(0, chat_list_length - 1)
endloop
call SetChatVarsPlayer(p)
// Only send at most 8 greetings to a single player
// Only send a limited number of greetings to a single player
if chat == C_Greet then
if (HaveStoredInteger(amaiCache, Int2Str(GREETINGS_NUM), Int2Str(i))) then
set chat_greet_count = GetStoredInteger(amaiCache, Int2Str(GREETINGS_NUM), Int2Str(i))
Expand Down Expand Up @@ -3167,9 +3165,9 @@ function Chat takes integer c returns nothing
endif

if c == C_STRATEGY then
if IsPlayerAlly(ai_player,GetLocalPlayer()) or IsPlayerObserver(GetLocalPlayer()) and chatting then
if chatting then
call QueueStrategy(GetCurrentStrategyReport() + GetCurrentDynamicReport())
endif
endif
//call DisplayToAlliesImportant( GetCurrentStrategyReport() + GetCurrentDynamicReport() )
//call DisplayToObserversImportant( GetCurrentStrategyReport() + GetCurrentDynamicReport() )
else
Expand Down
2 changes: 1 addition & 1 deletion races.eai
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ function build_sequence_all takes nothing returns nothing

if reportStrategy then
set reportStrategy = false
if (IsPlayerObserver(GetLocalPlayer()) or IsPlayerAlly(GetLocalPlayer(), ai_player)) and chatting then
if chatting then
call QueueStrategy(GetCurrentStrategyReport() + GetCurrentDynamicReport())
endif
//call DisplayToAlliesImportant( GetCurrentStrategyReport() + GetCurrentDynamicReport())
Expand Down

0 comments on commit 48e5b9f

Please sign in to comment.