-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfn_initPhaseManager.sqf
More file actions
161 lines (134 loc) · 5.32 KB
/
fn_initPhaseManager.sqf
File metadata and controls
161 lines (134 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Function: FLO_fnc_initPhaseManager
* Author: Frontline Operations Development Group
* Description:
* Central initialization phase manager. Controls the entire mission startup
* sequence with proper dependency tracking and error handling.
*
* ALL initialization runs on the server. Clients just wait for completion.
*
* Phases:
* 0: Save Detection - Check for saved game, load config if present
* 1: Mission Config - Wait for faction dialog OR use saved config
* 2: Factions - Load faction scripts based on config
* 3: Objectives - Index objectives OR restore from save
* 4: Virtualization - Setup virtualization OR restore from save
* 5: Mission Systems - Start AI commander, startup systems
*
* Global Variables Set:
* FLO_InitPhase - Current phase number (0-5, 99=complete, -1=error)
* FLO_InitError - Error message if initialization failed
* FLO_MissionReady - Final ready flag for clients to check
* FLO_IsLoadedSave - True if loading from saved game
* FLO_SavedGameData - Raw save data (if loading from save)
*
* Arguments: None
* Returns: Boolean - True if initialization completed successfully
*
* Example:
* [] call FLO_fnc_initPhaseManager;
*/
if (!isServer) exitWith {
diag_log "[FLO_INIT] Phase manager called on non-server - ignoring";
false
};
// Initialize phase tracking
FLO_InitPhase = 0;
FLO_InitError = "";
FLO_MissionReady = false;
FLO_IsLoadedSave = false;
publicVariable "FLO_InitPhase";
publicVariable "FLO_InitError";
publicVariable "FLO_MissionReady";
publicVariable "FLO_IsLoadedSave";
diag_log "[FLO_INIT] ========================================";
diag_log "[FLO_INIT] Phase Manager Starting";
diag_log "[FLO_INIT] ========================================";
// ============================================================================
// PHASE 0: SAVE DETECTION
// ============================================================================
diag_log "[FLO_INIT] === PHASE 0: Save Detection ===";
private _saveResult = [] call FLO_fnc_detectSavedGame;
_saveResult params ["_hasSave", "_savedConfig"];
if (_hasSave) then {
FLO_IsLoadedSave = true;
publicVariable "FLO_IsLoadedSave";
// Set the mission config from save so Phase 1 can use it
FLO_MissionConfig = _savedConfig;
publicVariable "FLO_MissionConfig";
diag_log "[FLO_INIT] Loading from saved game - skipping faction dialog";
} else {
// Explicitly re-publish false to ensure clients get the value
FLO_IsLoadedSave = false;
publicVariable "FLO_IsLoadedSave";
diag_log "[FLO_INIT] Fresh start - will wait for faction dialog";
};
sleep 0.5;
// Helper function to run a phase with error handling
private _fnc_runPhase = {
params ["_phaseNum", "_phaseName", "_phaseFunc"];
FLO_InitPhase = _phaseNum;
publicVariable "FLO_InitPhase";
diag_log format ["[FLO_INIT] === PHASE %1: %2 ===", _phaseNum, _phaseName];
private _startTime = diag_tickTime;
private _success = false;
try {
_success = [] call _phaseFunc;
} catch {
FLO_InitError = format ["Phase %1 (%2) exception: %3", _phaseNum, _phaseName, _exception];
diag_log format ["[FLO_INIT] ERROR: %1", FLO_InitError];
publicVariable "FLO_InitError";
_success = false;
};
private _duration = diag_tickTime - _startTime;
if (_success) then {
diag_log format ["[FLO_INIT] Phase %1 completed in %2 seconds", _phaseNum, _duration toFixed 2];
} else {
if (FLO_InitError isEqualTo "") then {
FLO_InitError = format ["Phase %1 (%2) returned false", _phaseNum, _phaseName];
publicVariable "FLO_InitError";
};
diag_log format ["[FLO_INIT] Phase %1 FAILED after %2 seconds: %3", _phaseNum, _duration toFixed 2, FLO_InitError];
};
_success
};
// Phase definitions
private _phases = [
[1, "Mission Config", FLO_fnc_initPhase1_MissionConfig],
[2, "Factions", FLO_fnc_initPhase2_Factions],
[3, "Objectives", FLO_fnc_initPhase3_Objectives],
[4, "Virtualization", FLO_fnc_initPhase4_Virtualization],
[5, "Mission Systems", FLO_fnc_initPhase5_MissionSystems]
];
// Run all phases in sequence
private _allSuccess = true;
{
_x params ["_num", "_name", "_func"];
if (_allSuccess) then {
_allSuccess = [_num, _name, _func] call _fnc_runPhase;
if (!_allSuccess) then {
diag_log format ["[FLO_INIT] Initialization stopped at phase %1", _num];
FLO_InitPhase = -1;
publicVariable "FLO_InitPhase";
};
};
} forEach _phases;
// Finalization
if (_allSuccess) then {
FLO_InitPhase = 99;
FLO_MissionReady = true;
publicVariable "FLO_InitPhase";
publicVariable "FLO_MissionReady";
diag_log "[FLO_INIT] ========================================";
diag_log "[FLO_INIT] ALL PHASES COMPLETE - MISSION READY";
diag_log "[FLO_INIT] ========================================";
// Notify all players
["FLO_INIT_COMPLETE", []] remoteExec ["FLO_fnc_initClientFinalize", 0];
} else {
diag_log "[FLO_INIT] ========================================";
diag_log format ["[FLO_INIT] INITIALIZATION FAILED: %1", FLO_InitError];
diag_log "[FLO_INIT] ========================================";
// Notify all players of failure
[FLO_InitError] remoteExec ["hint", 0];
};
_allSuccess