‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
hostmigration_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\hud_shared;
4 #using scripts\shared\hud_util_shared;
5 #using scripts\shared\util_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 #namespace hostmigration;
10 
12 {
13 }
14 
16 {
17  shouldBeStopped = isdefined( level.hostMigrationTimer );
18 
19  if ( !level.timerStopped && shouldBeStopped )
20  {
21  level.timerStopped = true;
22  level.playableTimerStopped = true;
23  level.timerPauseTime = gettime();
24  }
25  else if ( level.timerStopped && !shouldBeStopped )
26  {
27  level.timerStopped = false;
28  level.playableTimerStopped = false;
29  level.discardTime += gettime() - level.timerPauseTime;
30  }
31 }
32 
33 function ‪pauseTimer()
34 {
35  level.migrationTimerPauseTime = gettime();
36 }
37 
38 
39 function ‪resumeTimer()
40 {
41  level.discardTime += gettime() - level.migrationTimerPauseTime;
42 }
43 
44 function ‪lockTimer()
45 {
46  level endon( "host_migration_begin" );
47  level endon( "host_migration_end" );
48 
49  for( ;; )
50  {
51  currTime = gettime();
53  if ( !level.timerStopped && isdefined(level.discardTime) )
54  {
55  level.discardTime += gettime() - currTime;
56  }
57  }
58 }
59 
61 {
62  waittillframeend; // wait till cleanup of previous start timer if multiple happen at once
63 
64  level endon( "match_start_timer_beginning" );
65  while ( countTime > 0 && !level.gameEnded )
66  {
67  ‪matchStartTimer thread ‪hud::font_pulse( level );
68  wait ( ‪matchStartTimer.inFrames * 0.05 );
69  ‪matchStartTimer setValue( countTime );
70  if ( countTime == 2 )
71  {
72  visionSetNaked( GetDvarString( "mapname" ), 3.0 );
73  }
74  countTime--;
75  wait ( 1 - (‪matchStartTimer.inFrames * 0.05) );
76  }
77 }
78 
79 function ‪matchStartTimerConsole( type, duration )
80 {
81  level notify( "match_start_timer_beginning" );
83 
84  matchStartText = ‪hud::createServerFontString( "objective", 1.5 );
85  matchStartText ‪hud::setPoint( "CENTER", "CENTER", 0, -40 );
86  matchStartText.sort = 1001;
87  matchStartText setText( game["strings"]["waiting_for_teams"] );
88  matchStartText.foreground = false;
89  matchStartText.hidewheninmenu = true;
90 
91 // globallogic::waitForPlayers();
92  matchStartText setText( game["strings"][type] ); // "match begins in:"
93 
95  ‪matchStartTimer ‪hud::setPoint( "CENTER", "CENTER", 0, 0 );
96  ‪matchStartTimer.sort = 1001;
97  ‪matchStartTimer.color = (1,1,0);
98  ‪matchStartTimer.foreground = false;
99  ‪matchStartTimer.hidewheninmenu = true;
100 
102 
103  countTime = int( duration );
104 
105  if ( IsDefined( level.host_migration_activate_visionset_func ) )
106  {
107  level thread [[level.host_migration_activate_visionset_func]]();
108  }
109 
110  if ( countTime >= 2 )
111  {
113  }
114 
115  if ( IsDefined( level.host_migration_deactivate_visionset_func ) )
116  {
117  level thread [[level.host_migration_deactivate_visionset_func]]();
118  }
119 
121  matchStartText ‪hud::destroyElem();
122 }
123 
125 {
126  level endon( "game_ended" );
127 
128  // start with a 20 second wait.
129  // once we get enough players, or the first 15 seconds pass, switch to a 5 second timer.
130 
131  // Handle the case of the notify firing before we're even checking for it.
132  if ( level.hostMigrationReturnedPlayerCount < level.players.size * 2 / 3 )
133  {
134  thread ‪matchStartTimerConsole( "waiting_for_teams", 20.0 );
136  }
137 
138  level notify( "host_migration_countdown_begin" );
139  thread ‪matchStartTimerConsole( "match_starting_in", 5.0 );
140  wait 5;
141 }
142 
144 {
145  level endon( "host_migration_end" );
146 
147  if ( !isDefined( level.hostMigrationTimer ) )
148  {
149  return;
150  }
151 
152  level waittill( "host_migration_countdown_begin" );
153 }
154 
155 
157 {
158  level endon( "hostmigration_enoughplayers" );
159  wait 15;
160 }
161 
163 {
164  level endon( "host_migration_begin" );
165  level endon( "host_migration_end" );
166 
167  self.hostMigrationControlsFrozen = false;
168 
169  while ( !isAlive( self ) )
170  {
171  self waittill( "spawned" );
172  }
173 
174  self.hostMigrationControlsFrozen = true;
175  self freezeControls( true );
176 
177  level waittill( "host_migration_end" );
178 }
179 
181 {
182  self endon( "disconnect" );
183  level endon( "host_migration_begin" );
184 
186 
187  if ( self.hostMigrationControlsFrozen )
188  {
189  self freezeControls( false );
190  }
191 }
192 
194 {
195  if ( !isdefined( level.hostMigrationTimer ) )
196  {
197  return 0;
198  }
199 
200  starttime = gettime();
201  level waittill( "host_migration_end" );
202  return gettime() - starttime;
203 }
204 
205 function ‪waitTillHostMigrationStarts( duration )
206 {
207  if ( isdefined( level.hostMigrationTimer ) )
208  {
209  return;
210  }
211 
212  level endon( "host_migration_begin" );
213  wait duration;
214 }
215 
217 {
218  if ( duration == 0 )
219  {
220  return;
221  }
222  assert( duration > 0 );
223 
224  starttime = gettime();
225 
226  endtime = gettime() + duration * 1000;
227 
228  while ( gettime() < endtime )
229  {
230  ‪waitTillHostMigrationStarts( (endtime - gettime()) / 1000 );
231 
232  if ( isdefined( level.hostMigrationTimer ) )
233  {
234  timePassed = ‪waitTillHostMigrationDone();
235  endtime += timePassed;
236  }
237  }
238 
239 /#
240  if( gettime() != endtime )
241  {
242  println("SCRIPT WARNING: gettime() = " + gettime() + " NOT EQUAL TO endtime = " + endtime);
243  }
244 #/
246 
247  return gettime() - starttime;
248 }
249 
250 
252 {
253  if ( duration == 0 )
254  {
255  return;
256  }
257  assert( duration > 0 );
258 
259  starttime = gettime();
260 
261  empendtime = gettime() + duration * 1000;
262  level.empendtime = empendtime;
263 
264  while ( gettime() < empendtime )
265  {
266  ‪waitTillHostMigrationStarts( (empendtime - gettime()) / 1000 );
267 
268  if ( isdefined( level.hostMigrationTimer ) )
269  {
270  timePassed = ‪waitTillHostMigrationDone();
271  if ( isdefined ( empendtime ) )
272  {
273  empendtime += timePassed;
274  }
275  }
276  }
277 
278 /#
279  if( gettime() != empendtime )
280  {
281  println("SCRIPT WARNING: gettime() = " + gettime() + " NOT EQUAL TO empendtime = " + empendtime);
282  }
283 #/
284 
286 
287  level.empendtime = undefined;
288  return gettime() - starttime;
289 }
290 
291 
293 {
294  if ( duration == 0 )
295  {
296  return;
297  }
298  assert( duration > 0 );
299 
300  starttime = gettime();
301 
302  endtime = gettime() + duration * 1000;
303 
304  while ( gettime() < endtime )
305  {
306  ‪waitTillHostMigrationStarts( (endtime - gettime()) / 1000 );
307 
308  while ( isdefined( level.hostMigrationTimer ) )
309  {
310  endTime += 1000;
311  setGameEndTime( int( endTime ) );
312  wait 1;
313  }
314  }
315 
316 /#
317  if( gettime() != endtime )
318  {
319  println("SCRIPT WARNING: gettime() = " + gettime() + " NOT EQUAL TO endtime = " + endtime);
320  }
321 #/
322 
323  while ( isdefined( level.hostMigrationTimer ) )
324  {
325  endTime += 1000;
326  setGameEndTime( int( endTime ) );
327  wait 1;
328  }
329 
330  return gettime() - starttime;
331 }
332 
333 function ‪MigrationAwareWait( durationMs )
334 {
336 
337  endTime = gettime() + durationMs;
338  timeRemaining = durationMs;
339 
340  while( true )
341  {
342  event = level ‪util::waittill_level_any_timeout( timeRemaining / 1000, self, "game_ended", "host_migration_begin" );
343 
344  if ( !isdefined( event ) )
345  {
346  return;
347  }
348 
349  if( event != "host_migration_begin" )
350  {
351  return;
352  }
353 
354  timeRemaining = endTime - gettime();
355  if( timeRemaining <= 0 )
356  {
357  return;
358  }
359 
360  endTime = gettime() + durationMs;
362  }
363 }
‪waitTillHostMigrationDone
‪function waitTillHostMigrationDone()
Definition: hostmigration_shared.gsc:193
‪waittillHostMigrationCountDown
‪function waittillHostMigrationCountDown()
Definition: hostmigration_shared.gsc:143
‪pauseTimer
‪function pauseTimer()
Definition: hostmigration_shared.gsc:33
‪setPoint
‪function setPoint(point, relativePoint, xOffset, yOffset, moveTime)
Definition: hud_util_shared.gsc:53
‪waitLongDurationWithHostMigrationPauseEMP
‪function waitLongDurationWithHostMigrationPauseEMP(duration)
Definition: hostmigration_shared.gsc:251
‪waittill_level_any_timeout
‪function waittill_level_any_timeout(n_timeout, otherEnt, string1, string2, string3, string4, string5)
Definition: util_shared.gsc:680
‪waitLongDurationWithHostMigrationPause
‪function waitLongDurationWithHostMigrationPause(duration)
Definition: hostmigration_shared.gsc:216
‪destroyElem
‪function destroyElem()
Definition: hud_util_shared.gsc:755
‪debug_script_structs
‪function debug_script_structs()
Definition: hostmigration_shared.gsc:11
‪UpdateTimerPausedness
‪function UpdateTimerPausedness()
Definition: hostmigration_shared.gsc:15
‪waitTillHostMigrationStarts
‪function waitTillHostMigrationStarts(duration)
Definition: hostmigration_shared.gsc:205
‪hostMigrationTimerThink
‪function hostMigrationTimerThink()
Definition: hostmigration_shared.gsc:180
‪font_pulse_init
‪function font_pulse_init()
Definition: hud_shared.gsc:187
‪font_pulse
‪function font_pulse(player)
Definition: hud_shared.gsc:196
‪lockTimer
‪function lockTimer()
Definition: hostmigration_shared.gsc:44
‪matchStartTimerConsole_Internal
‪function matchStartTimerConsole_Internal(countTime, matchStartTimer)
Definition: hostmigration_shared.gsc:60
‪createServerFontString
‪function createServerFontString(font, fontScale, team)
Definition: hud_util_shared.gsc:353
‪waitLongDurationWithGameEndTimeUpdate
‪function waitLongDurationWithGameEndTimeUpdate(duration)
Definition: hostmigration_shared.gsc:292
‪hostMigrationWait
‪function hostMigrationWait()
Definition: hostmigration_shared.gsc:124
‪matchStartTimerConsole
‪function matchStartTimerConsole(type, duration)
Definition: hostmigration_shared.gsc:79
‪hostMigrationTimerThink_Internal
‪function hostMigrationTimerThink_Internal()
Definition: hostmigration_shared.gsc:162
‪hostMigrationWaitForPlayers
‪function hostMigrationWaitForPlayers()
Definition: hostmigration_shared.gsc:156
‪MigrationAwareWait
‪function MigrationAwareWait(durationMs)
Definition: hostmigration_shared.gsc:333
‪matchStartTimer
‪function matchStartTimer()
Definition: _globallogic.gsc:1015
‪resumeTimer
‪function resumeTimer()
Definition: hostmigration_shared.gsc:39
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265