‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_hostmigration.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\array_shared;
4 #using scripts\shared\callbacks_shared;
5 #using scripts\shared\flag_shared;
6 #using scripts\shared\hud_shared;
7 #using scripts\shared\hud_util_shared;
8 
9 #insert scripts\shared\shared.gsh;
10 
11 #using scripts\zm\_zm;
12 #using scripts\zm\_zm_utility;
13 
14 #namespace hostmigration;
15 
16 
18 {
19  shouldBeStopped = isdefined( level.hostMigrationTimer );
20 
21  if ( !level.timerStopped && shouldBeStopped )
22  {
23  level.timerStopped = true;
24  level.timerPauseTime = gettime();
25  }
26  else if ( level.timerStopped && !shouldBeStopped )
27  {
28  level.timerStopped = false;
29  level.discardTime += gettime() - level.timerPauseTime;
30  }
31 }
32 
34 {
35 }
36 
38 {
40 
41  if ( ‪IS_TRUE( level._hm_should_pause_spawning ) )
42  {
43  level ‪flag::set( "spawn_zombies" ); // If we're migrating during a migration, this will allow the next migration to correctly start and stop the spawns.
44  }
45 
46  for(i = 0; i < level.players.size; i++)
47  {
48  level.players[i] EnableInvulnerability();
49  level.players[i] setDStat( "AfterActionReportStats", "lobbyPopup", "summary" );
50  }
51 }
52 
53 function ‪pauseTimer()
54 {
55  level.migrationTimerPauseTime = gettime();
56 }
57 
58 function ‪resumeTimer()
59 {
60  level.discardTime += gettime() - level.migrationTimerPauseTime;
61 }
62 
63 function ‪lockTimer()
64 {
65  level endon( "host_migration_begin" );
66  level endon( "host_migration_end" );
67 
68  for( ;; )
69  {
70  currTime = gettime();
72  if ( !level.timerStopped && isdefined(level.discardTime) )
73  level.discardTime += gettime() - currTime;
74  }
75 }
76 
78 {
79 
81 
82  setSlowMotion( 1, 1, 0 );
83  //makeDvarServerInfo( "ui_guncycle", 0 );
84 
85  //make sure we upload any dirty counters from the current round
87 
88  level.hostMigrationReturnedPlayerCount = 0;
89 
90  if ( level.gameEnded )
91  {
92 
93  return;
94  }
95 
96  sethostmigrationstatus(true);
97 
98  level notify( "host_migration_begin" );
99 
100  for(i = 0; i < level.players.size; i++)
101  {
102  if(isdefined(level.hostmigration_link_entity_callback))
103  {
104  if(!isdefined(level.players[i]._host_migration_link_entity))
105  {
106  level.players[i]._host_migration_link_entity = level.players[i] [[level.hostmigration_link_entity_callback]]();
107  }
108  }
109 
110  level.players[i] thread ‪hostMigrationTimerThink();
111  }
112 
113  if(isdefined(level.hostmigration_ai_link_entity_callback))
114  {
115  zombies = GetAiTeamArray( level.zombie_team );
116  if(IsDefined(zombies) && zombies.size > 0)
117  {
118  foreach(zombie in zombies)
119  {
120  if(!isdefined(zombie._host_migration_link_entity))
121  {
122  zombie._host_migration_link_entity = zombie [[level.hostmigration_ai_link_entity_callback]]();
123  }
124  }
125  }
126  }
127  else
128  {
129  zombies = GetAiTeamArray( level.zombie_team );
130  if(IsDefined(zombies) && zombies.size > 0)
131  {
132  foreach(zombie in zombies)
133  {
134  zombie.no_powerups = true;
135  zombie.marked_for_recycle = 1;
136  zombie.has_been_damaged_by_player = false;
137  zombie DoDamage( zombie.health + 1000, zombie.origin, zombie );
138  }
139  }
140  }
141 
142  if (level.inPrematchPeriod)
143  level waittill("prematch_over");
144 
145 
146 
147  level.hostMigrationTimer = true;
148 
149 
150  thread ‪lockTimer();
151 
152  if ( ‪IS_TRUE( level.b_host_migration_force_player_respawn ) )
153  {
154  foreach(player in level.players)
155  {
156  if ( ‪zm_utility::is_player_valid( player, false, false ) )
157  {
158  player ‪host_migration_respawn();
159  }
160  }
161  }
162 
163  zombies = GetAiTeamArray( level.zombie_team );
164  if(IsDefined(zombies) && zombies.size > 0)
165  {
166  foreach(zombie in zombies)
167  {
168  if(isdefined(zombie._host_migration_link_entity))
169  {
170 
171  ent = ‪spawn("script_origin", zombie.origin);
172  ent.angles = zombie.angles;
173  zombie LinkTo(ent);
174 
175  ent LinkTo(zombie._host_migration_link_entity, "tag_origin", zombie._host_migration_link_entity WorldToLocalCoords(ent.origin), ent.angles + zombie._host_migration_link_entity.angles);
176  zombie._host_migration_link_helper = ent;
177  zombie LinkTo(zombie._host_migration_link_helper);
178  }
179  }
180  }
181 
182  level endon( "host_migration_begin" );
183 
184  //pause the spawning if it was active
185  should_pause_spawning = level ‪flag::get("spawn_zombies");
186 
187  if(should_pause_spawning )
188  {
189  level ‪flag::clear("spawn_zombies");
190  }
191 
193 
194  //make the players invulnerable for 3 seconds or so
195  foreach(player in level.players)
196  {
197  player thread ‪post_migration_invulnerability();
198  }
199 
200  zombies = GetAiTeamArray( level.zombie_team );
201  if(IsDefined(zombies) && zombies.size > 0)
202  {
203  foreach(zombie in zombies)
204  {
205  if(isdefined(zombie._host_migration_link_entity))
206  {
207  zombie Unlink();
208  zombie._host_migration_link_helper delete();
209  zombie._host_migration_link_helper = undefined;
210  zombie._host_migration_link_entity = undefined;
211  }
212  }
213  }
214 
215  if(should_pause_spawning )
216  {
217  level ‪flag::set("spawn_zombies");
218  }
219 
220  level.hostMigrationTimer = undefined;
221  level._hm_should_pause_spawning = undefined;
222  sethostmigrationstatus(false);
223 
224 
225  level notify( "host_migration_end" );
226 }
227 
229 {
230  self endon("disconnect");
231 
232 }
233 
235 {
236  self endon("disconnect");
237 
238  was_inv = self EnableInvulnerability();
239  wait(3);
240  self DisableInvulnerability();
241 }
242 
243 // This is a stripped down version of _zm::spectator_respawn()
245 {
246 
247 
248  new_origin = undefined;
249 
250  if ( isdefined( level.check_valid_spawn_override ) )
251  {
252  new_origin = [[ level.check_valid_spawn_override ]]( self );
253  }
254 
255  if ( !isdefined( new_origin ) )
256  {
257  new_origin = ‪zm::check_for_valid_spawn_near_team( self, true );
258  }
259 
260 
261  if( IsDefined( new_origin ) )
262  {
263  if(!isDefined(new_origin.angles))
264  {
265  angles = (0, 0, 0);
266  }
267  else
268  {
269  angles = new_origin.angles;
270  }
271  self DontInterpolate();
272  self SetOrigin( new_origin.origin );
273  self SetPlayerAngles( angles );
274  }
275 
276  return true;
277 }
278 
279 
280 
282 {
283  waittillframeend; // wait till cleanup of previous start timer if multiple happen at once
284 
285  level endon( "match_start_timer_beginning" );
286  while ( countTime > 0 && !level.gameEnded )
287  {
288  ‪matchStartTimer thread ‪hud::font_pulse( level );
289  wait ( ‪matchStartTimer.inFrames * 0.05 );
290  ‪matchStartTimer setValue( countTime );
291 /* if ( countTime == 2 )
292  visionSetNaked( GetDvarString( "mapname" ), 3.0 ); */
293  countTime--;
294  wait ( 1 - (‪matchStartTimer.inFrames * 0.05) );
295  }
296 }
297 
298 function ‪matchStartTimerConsole( type, duration )
299 {
300  thread ‪matchStartBlacscreen( duration );
301  level notify( "match_start_timer_beginning" );
303 
304  matchStartText = ‪hud::createServerFontString( "objective", 1.5 );
305  matchStartText ‪hud::setPoint( "CENTER", "CENTER", 0, -40 );
306  matchStartText.sort = 1001;
307  matchStartText setText( game["strings"]["waiting_for_teams"] );
308  matchStartText.foreground = false;
309  matchStartText.hidewheninmenu = true;
310 
311 // globallogic::waitForPlayers();
312  matchStartText setText( game["strings"][type] ); // "match begins in:"
313 
315  ‪matchStartTimer ‪hud::setPoint( "CENTER", "CENTER", 0, 0 );
316  ‪matchStartTimer.sort = 1001;
317  ‪matchStartTimer.color = (1,1,0);
318  ‪matchStartTimer.foreground = false;
319  ‪matchStartTimer.hidewheninmenu = true;
320 
322 
323  countTime = int( duration );
324 
325  if ( countTime >= 2 )
326  {
328  //visionSetNaked( GetDvarString( "mapname" ), 3.0 );
329  }
330  else
331  {
332  //visionSetNaked( GetDvarString( "mapname" ), 1.0 );
333  }
334 
336  matchStartText ‪hud::destroyElem();
337 }
338 
339 function ‪matchStartBlacscreen( duration )
340 {
341  array::thread_all(GetPlayers(), &‪zm::initialBlack);
342 
343  fade_time = 4.0;
344 
345  n_black_screen = duration - fade_time;
346  level thread ‪zm::fade_out_intro_screen_zm( n_black_screen, fade_time, true );
347  wait fade_time;
348 }
349 
350 
352 {
353  level endon( "game_ended" );
354 
355  // start with a 20 second wait.
356  // once we get enough players, or the first 15 seconds pass, switch to a 5 second timer.
357 
358  // Handle the case of the notify firing before we're even checking for it.
359  if ( level.hostMigrationReturnedPlayerCount < level.players.size * 2 / 3 )
360  {
361  thread ‪matchStartTimerConsole( "waiting_for_teams", 20.0 );
363  }
364 
365  thread ‪matchStartTimerConsole( "match_starting_in", 9.0 );
366  wait 5;
367 }
368 
369 
371 {
372  level endon( "hostmigration_enoughplayers" );
373  wait 15;
374 }
375 
377 {
378  level endon( "host_migration_begin" );
379  level endon( "host_migration_end" );
380 
381  self.hostMigrationControlsFrozen = false;
382 
383  while ( !isAlive( self ) )
384  {
385  self waittill( "spawned" );
386  }
387 
388  if(isdefined(self._host_migration_link_entity))
389  {
390  ent = ‪spawn("script_origin", self.origin);
391  ent.angles = self.angles;
392  self LinkTo(ent);
393 
394  ent LinkTo(self._host_migration_link_entity, "tag_origin", self._host_migration_link_entity WorldToLocalCoords(ent.origin), ent.angles + self._host_migration_link_entity.angles);
395  self._host_migration_link_helper = ent;
396 
397  }
398 
399  self.hostMigrationControlsFrozen = true;
400  self freezeControls( true );
401 
402  level waittill( "host_migration_end" );
403 }
404 
406 {
407  self endon( "disconnect" );
408  level endon( "host_migration_begin" );
409 
411 
412  if ( self.hostMigrationControlsFrozen )
413  {
414  self freezeControls( false );
415  self.hostMigrationControlsFrozen = false;
416 
417 
418  }
419 
420  if(isdefined(self._host_migration_link_entity))
421  {
422  self Unlink();
423  self._host_migration_link_helper delete();
424  self._host_migration_link_helper = undefined;
425 
426  if(isdefined(self._host_migration_link_entity._post_host_migration_thread))
427  {
428  self thread [[self._host_migration_link_entity._post_host_migration_thread]](self._host_migration_link_entity);
429  }
430 
431  self._host_migration_link_entity = undefined;
432  }
433 }
434 
436 {
437  if ( !isdefined( level.hostMigrationTimer ) )
438  return 0;
439 
440  starttime = gettime();
441  level waittill( "host_migration_end" );
442  return gettime() - starttime;
443 }
444 
445 function ‪waitTillHostMigrationStarts( duration )
446 {
447  if ( isdefined( level.hostMigrationTimer ) )
448  return;
449 
450  level endon( "host_migration_begin" );
451  wait duration;
452 }
453 
455 {
456  if ( duration == 0 )
457  return;
458  assert( duration > 0 );
459 
460  starttime = gettime();
461 
462  endtime = gettime() + duration * 1000;
463 
464  while ( gettime() < endtime )
465  {
466  ‪waitTillHostMigrationStarts( (endtime - gettime()) / 1000 );
467 
468  if ( isdefined( level.hostMigrationTimer ) )
469  {
470  timePassed = ‪waitTillHostMigrationDone();
471  endtime += timePassed;
472  }
473  }
474 
475  if( gettime() != endtime )
476 
477 
479 
480  return gettime() - starttime;
481 }
482 
484 {
485  if ( duration == 0 )
486  return;
487  assert( duration > 0 );
488 
489  starttime = gettime();
490 
491  endtime = gettime() + duration * 1000;
492 
493  while ( gettime() < endtime )
494  {
495  ‪waitTillHostMigrationStarts( (endtime - gettime()) / 1000 );
496 
497  while ( isdefined( level.hostMigrationTimer ) )
498  {
499  endTime += 1000;
500  setGameEndTime( int( endTime ) );
501  wait 1;
502  }
503  }
504  while ( isdefined( level.hostMigrationTimer ) )
505  {
506  endTime += 1000;
507  setGameEndTime( int( endTime ) );
508  wait 1;
509  }
510 
511  return gettime() - starttime;
512 }
513 
514 function ‪find_alternate_player_place( v_origin, min_radius, max_radius, max_height, ignore_targetted_nodes )
515 {
516  found_node = undefined;
517 
518  a_nodes = GetNodesInRadiusSorted( v_origin, max_radius, min_radius, max_height, "pathnodes" );
519 
520  if( IsDefined(a_nodes) && (a_nodes.size > 0) )
521  {
522  // Get the playable areas
523  a_player_volumes = getentarray( "player_volume", "script_noteworthy" );
524 
525  // We have a bunch of suitable nodes, check that we won't telefrag if we use them
526  index = a_nodes.size - 1;
527  for( i=index; i>=0; i-- )
528  {
529  n_node = a_nodes[ i ];
530 
531  // Don't use nodes thar are targetting things, like elevator shaft nodes for example
532  if( ignore_targetted_nodes == true )
533  {
534  if( IsDefined(n_node.target) )
535  {
536  continue;
537  }
538  }
539 
540  // Make sure we don't telefrag at this position
541  if( !positionWouldTelefrag(n_node.origin) )
542  {
543  if( ‪zm_utility::check_point_in_enabled_zone(n_node.origin, true, a_player_volumes) )
544  {
545  // Sanity check - Is the node on the ground
546  v_start = ( n_node.origin[0], n_node.origin[1], n_node.origin[2]+30 );
547  v_end = ( n_node.origin[0], n_node.origin[1], n_node.origin[2]-30 );
548  ‪trace = bulletTrace( v_start, v_end, false, undefined );
549  if(‪trace["fraction"] < 1)
550  {
551  override_abort = 0;
552 
553  // Finally we have a potential custum level reject function for bad nodes, if they are found after ship
554  if( IsDefined(level._whoswho_reject_node_override_func) )
555  {
556  override_abort = [[ level._whoswho_reject_node_override_func ]]( v_origin, n_node );
557  }
558 
559  if( !override_abort )
560  {
561  found_node = n_node;
562  break;
563  }
564  }
565  }
566  }
567  }
568  }
569 
570  return (found_node);
571 }
572 
574 {
575  spawnPoint = undefined;
576 
577  // Safety default range to get a required node from
578  spawnPoint = ‪find_alternate_player_place(self.origin, 50, 150, 64, true);
579 
580  // We failed, lets try again but further out
581 
582  if( !IsDefined(spawnPoint) )
583  {
584  spawnPoint = ‪find_alternate_player_place(self.origin, 150, 400, 64, true);
585  }
586 
587  // If we failed again, try again with much loser restrictions
588  if( !IsDefined(spawnPoint) )
589  {
590  spawnPoint = ‪find_alternate_player_place(self.origin, 50, 400, 256, false);
591  }
592 
593 
594  // If no luck, try and get a spawn point near the team
595  if( !IsDefined(spawnPoint) )
596  {
597  spawnPoint = ‪zm::check_for_valid_spawn_near_team( self, true );
598  }
599 
600  // Still no luck, then use the start location
601  if( !Isdefined(spawnPoint) )
602  {
603  match_string = "";
604 
605  location = level.scr_zm_map_start_location;
606  if ((location == "default" || location == "" ) && IsDefined(level.default_start_location))
607  {
608  location = level.default_start_location;
609  }
610 
611  match_string = level.scr_zm_ui_gametype + "_" + location;
612 
613  spawnPoints = [];
614  structs = ‪struct::get_array("initial_spawn", "script_noteworthy");
615  if(IsDefined(structs))
616  {
617  foreach(struct in structs)
618  {
619  if(IsDefined(struct.script_string) )
620  {
621 
622  tokens = strtok(struct.script_string," ");
623  foreach(token in tokens)
624  {
625  if(token == match_string )
626  {
627  spawnPoints[spawnPoints.size] = struct;
628  }
629  }
630  }
631 
632  }
633  }
634 
635  if(!IsDefined(spawnPoints) || spawnPoints.size == 0) // old method, failed new method.
636  {
637  spawnPoints = ‪struct::get_array("initial_spawn_points", "targetname");
638  }
639 
640  assert(IsDefined(spawnPoints), "Could not find initial spawn points!");
641 
642  spawnPoint = ‪zm::getFreeSpawnpoint( spawnPoints, self );
643  }
644 
645  if(isdefined(spawnPoint))
646  {
647  self SetOrigin( spawnPoint.origin );
648  }
649 }
‪pauseTimer
‪function pauseTimer()
Definition: _hostmigration.gsc:53
‪clear
‪function clear(str_flag)
Definition: flag_shared.csc:130
‪getFreeSpawnpoint
‪function getFreeSpawnpoint(spawnpoints, player)
Definition: _zm.gsc:690
‪hostMigrationTimerThink
‪function hostMigrationTimerThink()
Definition: _hostmigration.gsc:405
‪get_array
‪function get_array(kvp_value, kvp_key="targetname")
Definition: struct.csc:34
‪setPoint
‪function setPoint(point, relativePoint, xOffset, yOffset, moveTime)
Definition: hud_util_shared.gsc:53
‪matchStartTimerConsole_Internal
‪function matchStartTimerConsole_Internal(countTime, matchStartTimer)
Definition: _hostmigration.gsc:281
‪waitLongDurationWithHostMigrationPause
‪function waitLongDurationWithHostMigrationPause(duration)
Definition: _hostmigration.gsc:454
‪trace
‪function trace(from, to, target)
Definition: grapple.gsc:369
‪destroyElem
‪function destroyElem()
Definition: hud_util_shared.gsc:755
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪check_point_in_enabled_zone
‪function check_point_in_enabled_zone(origin, zone_is_active, player_zones)
Definition: _zm_utility.gsc:512
‪get
‪function get(kvp_value, kvp_key="targetname")
Definition: struct.csc:13
‪upload_zm_dash_counters
‪function upload_zm_dash_counters(force_upload=false)
Definition: _zm_utility.gsc:6258
‪is_player_valid
‪function is_player_valid(player, checkIgnoreMeFlag, ignore_laststand_players)
Definition: skeleton.gsc:256
‪matchStartBlacscreen
‪function matchStartBlacscreen(duration)
Definition: _hostmigration.gsc:339
‪redo_link_changes
‪function redo_link_changes()
Definition: _zm_utility.gsc:5824
‪undo_link_changes
‪function undo_link_changes()
Definition: _zm_utility.gsc:5812
‪Callback_PreHostMigrationSave
‪function Callback_PreHostMigrationSave()
Definition: _hostmigration.gsc:12
‪font_pulse_init
‪function font_pulse_init()
Definition: hud_shared.gsc:187
‪font_pulse
‪function font_pulse(player)
Definition: hud_shared.gsc:196
‪Callback_HostMigration
‪function Callback_HostMigration()
Definition: _hostmigration.gsc:13
‪Callback_HostMigrationSave
‪function Callback_HostMigrationSave()
Definition: _hostmigration.gsc:11
‪post_migration_become_vulnerable
‪function post_migration_become_vulnerable()
Definition: _hostmigration.gsc:228
‪hostMigrationWait
‪function hostMigrationWait()
Definition: _hostmigration.gsc:351
‪waitTillHostMigrationStarts
‪function waitTillHostMigrationStarts(duration)
Definition: _hostmigration.gsc:445
‪host_migration_respawn
‪function host_migration_respawn()
Definition: _hostmigration.gsc:244
‪createServerFontString
‪function createServerFontString(font, fontScale, team)
Definition: hud_util_shared.gsc:353
‪initialBlack
‪function initialBlack()
Definition: _zm.gsc:633
‪set
‪function set(str_field_name, n_value)
Definition: clientfield_shared.gsc:34
‪resumeTimer
‪function resumeTimer()
Definition: _hostmigration.gsc:58
‪post_migration_invulnerability
‪function post_migration_invulnerability()
Definition: _hostmigration.gsc:234
‪UpdateTimerPausedness
‪function UpdateTimerPausedness()
Definition: _hostmigration.gsc:17
‪lockTimer
‪function lockTimer()
Definition: _hostmigration.gsc:63
‪hostmigration_put_player_in_better_place
‪function hostmigration_put_player_in_better_place()
Definition: _hostmigration.gsc:573
‪hostMigrationTimerThink_Internal
‪function hostMigrationTimerThink_Internal()
Definition: _hostmigration.gsc:376
‪matchStartTimerConsole
‪function matchStartTimerConsole(type, duration)
Definition: _hostmigration.gsc:298
‪find_alternate_player_place
‪function find_alternate_player_place(v_origin, min_radius, max_radius, max_height, ignore_targetted_nodes)
Definition: _hostmigration.gsc:514
‪matchStartTimer
‪function matchStartTimer()
Definition: _globallogic.gsc:1015
‪check_for_valid_spawn_near_team
‪function check_for_valid_spawn_near_team(revivee, return_struct)
Definition: _zm.gsc:3361
‪hostMigrationWaitForPlayers
‪function hostMigrationWaitForPlayers()
Definition: _hostmigration.gsc:370
‪fade_out_intro_screen_zm
‪function fade_out_intro_screen_zm(hold_black_time, fade_out_time, destroyed_afterwards)
Definition: _zm.gsc:469
‪waitTillHostMigrationDone
‪function waitTillHostMigrationDone()
Definition: _hostmigration.gsc:435
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265
‪waitLongDurationWithGameEndTimeUpdate
‪function waitLongDurationWithGameEndTimeUpdate(duration)
Definition: _hostmigration.gsc:483