1 #using scripts\codescripts\struct;
3 #using scripts\shared\animation_shared;
4 #using scripts\shared\array_shared;
5 #using scripts\shared\clientfield_shared;
6 #using scripts\shared\flagsys_shared;
7 #using scripts\shared\postfx_shared;
8 #using scripts\shared\lui_shared;
9 #using scripts\shared\scene_debug_shared;
10 #using scripts\shared\scriptbundle_shared;
11 #using scripts\shared\system_shared;
12 #using scripts\shared\util_shared;
13 #using scripts\shared\filter_shared;
14 #using scripts\shared\math_shared;
15 #using scripts\shared\callbacks_shared;
17 #insert scripts\shared\shared.gsh;
18 #insert scripts\shared\version.gsh;
20 #using_animtree( "generic" );
24 #define NEW_STATE(__state) flagsys::clear( "ready" );\
25 flagsys::clear( "done" );\
26 flagsys::clear( "main_done" );\
27 self notify( "new_state" );\
28 self endon( "new_state" );\
29 self notify(__state);\
35 anim_name =
self GetCurrentAnimScriptedName();
37 if(isdefined(anim_name) && anim_name !=
"")
39 is_looping = IsAnimLooping(localClientNum, anim_name);
43 self SetAnimTimebyName(anim_name, 1,
true);
51 flushsubtitles( localClientNum );
54 SetDvar(
"r_graphicContentBlur",
false );
55 SetDvar(
"r_makeDark_enable",
false );
85 function first_init( s_objdef, o_scene, e_ent, localclientnum )
111 for ( clientNum = 1; clientNum < GetMaxLocalClients(); clientNum++ )
113 if ( isdefined( GetLocalPlayer( clientNum ) ) )
132 for ( clientNum = 1; clientNum < GetMaxLocalClients(); clientNum++ )
134 if ( isdefined( GetLocalPlayer( clientNum ) ) )
146 self endon(
"new_state");
150 if ( !
error( !isdefined(
_s.mainanim ),
"No animation defined for first frame." ) )
155 else if ( isdefined(
_s.initanim ) )
161 if ( isdefined(
_s.initanimloop ) )
163 _play_anim( clientNum,
_s.initanimloop, 0, 0, 1, undefined,
_s.initshotloop,
true );
167 else if ( isdefined(
_s.initanimloop ) )
169 _play_anim( clientNum,
_s.initanimloop,
_s.initdelaymin,
_s.initdelaymax, 1, undefined,
_s.initshotloop,
true );
192 for ( clientNum = 1; clientNum < GetMaxLocalClients(); clientNum++ )
194 if ( isdefined( GetLocalPlayer( clientNum ) ) )
206 self endon(
"new_state");
208 if ( isdefined(
_s.mainanim ) )
216 if ( isdefined(
_s.endanim ) )
222 if ( isdefined(
_s.endanimloop ) )
224 _play_anim( clientNum,
_s.endanimloop, 0, 0, 1, undefined,
_s.endshotloop,
true );
228 else if ( isdefined(
_s.endanimloop ) )
230 _play_anim( clientNum,
_s.endanimloop, 0, 0, 1, undefined,
_s.endshotloop,
true );
240 self notify(
"new_state" );
248 for ( clientNum = 1; clientNum < GetMaxLocalClients(); clientNum++ )
250 if ( isdefined( GetLocalPlayer( clientNum ) ) )
273 if ( isdefined(
_e_array[ clientNum ] ) )
288 if ( isdefined(
_s.aligntarget ) )
291 if ( isdefined( a_scene_ents[clientNum][
_s.aligntarget ] ) )
293 e_align = a_scene_ents[clientNum][
_s.aligntarget ];
300 error( !isdefined( e_align ),
"Align target '" +
STR(
_s.aligntarget ) +
"' doesn't exist for scene object." );
303 if ( !isdefined( e_align ) )
305 e_align = [[
scene()]]->get_align_ent( clientNum );
324 if ( isdefined(
_s.name ) )
333 level.scene_object_id++;
337 if ( isdefined(
_s.name ) )
360 if ( !isdefined(
_e_array[clientNum] ) )
362 b_allows_multiple = [[
scene()]]->allows_multiple();
365 error( b_allows_multiple &&
IS_TRUE(
_s.nospawn ),
"Scene that allow multiple instances must be allowed to spawn (uncheck 'Do Not Spawn')." ) )
371 if ( !isdefined(
_e_array[clientNum] ) && isdefined(
_s.name ) && !b_allows_multiple )
393 error( !
IS_TRUE(
_s.nospawn ),
"No entity exists with matching name of scene object." );
402 if ( !
error( !
IS_TRUE(
_s.nospawn ) && !isdefined(
_e_array[clientNum] ),
"No entity exists with matching name of scene object. Make sure a model is specified if you want to spawn it." ) )
423 if( !
_e_array[clientNum] HasAnimTree() )
425 _e_array[clientNum] UseAnimTree( #animtree );
435 _e_array[clientNum].finished_scene = undefined;
440 if ( isdefined(
_e_array[clientNum] ) && isdefined(
_e_array[clientNum].current_scene ) )
448 _e_array[clientNum].current_scene = undefined;
461 function _play_anim( clientNum, animation, n_delay_min = 0, n_delay_max = 0, n_rate = 1, n_blend, str_siege_shot,
loop )
463 n_delay = n_delay_min;
464 if ( n_delay_max > n_delay_min )
466 n_delay = RandomFloatRange( n_delay_min, n_delay_max );
503 if ( align == level )
514 /#
log(
"No entity for animation '" + animation +
"' so not playing it." ); #/
522 if ( isdefined(
_s.AlignTargetTag ) )
524 return _s.AlignTargetTag;
534 [[
scene()]]->wait_till_scene_ready();
544 return isdefined(
_e_array[ clientNum ] );
576 class cScene : cScriptBundleBase
593 function init( str_scenedef, s_scenedef, e_align,
a_ents, b_test_run )
599 if ( !
error(
a_ents.size >
_s.objects.size,
"Trying to use more entities than scene supports." ) )
608 foreach ( str_name, e_ent
in ArrayCopy(
a_ents ) )
610 foreach ( i, s_obj
in ArrayCopy( a_objs ) )
616 ArrayRemoveIndex(
a_ents, str_name );
617 ArrayRemoveIndex( a_objs, i );
624 foreach ( s_obj
in a_objs )
659 foreach ( s_obj
in _s.objects )
661 if (
_s.vmtype ==
"client" || s_obj.vmtype ==
"client" )
663 if ( isdefined( s_obj.name ) || isdefined( s_obj.model ) || isdefined( s_obj.initanim ) || isdefined( s_obj.mainanim ) )
677 self notify(
"new_state" );
678 self endon(
"new_state" );
687 thread [[o_obj]]->initialize();
707 function play( b_testing =
false, str_mode =
"" )
709 level endon(
"demo_jump");
710 self notify(
"new_state" );
711 self endon(
"new_state" );
720 thread [[o_obj]]->play();
732 array::flagsys_wait_any_flag(
_a_objects,
"done",
"main_done" );
754 thread
play( b_testing, str_mode );
760 thread
stop(
false,
true );
765 thread
stop(
false,
true );
771 if ( isdefined(
_s.nextscenebundle ) && (
_s.vmtype !=
"both" ) )
773 self waittill(
"stopped", b_finished );
777 if (
_s.scenetype ==
"fxanim" &&
IS_EQUAL(
_s.nextscenemode,
"init" ) )
779 if ( !
error( !
has_init_state(),
"Scene can't init next scene '" +
_s.nextscenebundle +
"' because it doesn't have an init state." ) )
806 function stop( b_clear =
false, b_finished =
false )
808 self notify(
"new_state" );
816 self.scene_stopped =
true;
820 if ( isdefined( o_obj ) && ![[ o_obj ]]->in_a_different_scene() )
822 thread [[o_obj]]->finish( b_clear );
826 self notify(
"stopped", b_finished );
828 if ( IsDefined( level.active_scenes[
_str_name ] ) )
832 if ( level.active_scenes[
_str_name ].size == 0 )
834 level.active_scenes[
_str_name ] = undefined;
840 ArrayRemoveValue(
_e_root.scenes,
self );
854 b_has_init_state =
false;
860 b_has_init_state =
true;
865 return b_has_init_state;
870 self endon(
"stopped" );
874 if ( str_state ==
"play" )
881 if ( isdefined( level.scene_funcs ) && isdefined( level.scene_funcs[
_str_name ] ) && isdefined( level.scene_funcs[
_str_name ][ str_state ] ) )
885 foreach ( clientnum,
a_ents in a_all_ents )
887 foreach ( handler
in level.scene_funcs[
_str_name ][ str_state ] )
895 _e_root thread [[ func ]](
a_ents, args[0], args[1], args[2], args[3], args[4], args[5] );
898 _e_root thread [[ func ]](
a_ents, args[0], args[1], args[2], args[3], args[4] );
901 _e_root thread [[ func ]](
a_ents, args[0], args[1], args[2], args[3] );
915 default: AssertMsg(
"Too many args passed to scene func." );
926 for ( clientNum = 0; clientNum < GetMaxLocalClients(); clientNum++ )
928 if ( isdefined( GetLocalPlayer( clientNum ) ) )
934 ent = [[ o_obj ]]->get_ent( clientNum );
936 if ( isdefined( o_obj._s.name ) )
938 a_ents[ clientNum ][ o_obj._s.name ] = ent;
960 if ( isdefined(
_s.aligntarget ) )
963 if ( isdefined( e_gdt_align ) )
965 e_align = e_gdt_align;
1001 if ( obj._is_valid && ![[obj]]->in_a_different_scene() )
1031 e = GetEnt( clientNum, str_name,
"animname" );
1032 if ( !isdefined( e ) )
1034 e = GetEnt( clientNum, str_name,
"script_animname" );
1035 if ( !isdefined( e ) )
1037 e = GetEnt( clientNum, str_name,
"targetname" );
1038 if ( !isdefined( e ) )
1064 level.server_scenes = [];
1066 foreach ( s_scenedef
in a_scenedefs )
1068 s_scenedef.editaction = undefined;
1069 s_scenedef.newobject = undefined;
1073 level.server_scenes[ s_scenedef.name ] = s_scenedef;
1075 else if ( s_scenedef.vmtype ==
"both" )
1077 n_clientbits = GetMinBitCountForNum( 3 );
1080 n_clientbits = GetMinBitCountForNum( 6 );
1100 level.scene_object_id = 0;
1101 level.active_scenes = [];
1106 function in_igc( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1108 player = GetLocalPlayer( localClientNum );
1109 n_entnum = player GetEntityNumber();
1111 b_igc_active =
false;
1113 if ( newVal & ( 1 << n_entnum ) )
1115 b_igc_active =
true;
1118 IGCactive( localClientNum, b_igc_active );
1125 #define TRANSITION_FILTER_INDEX 5
1126 #define TRANSITION_TIME 2000
1127 #define TRANSITION_STREAMER_TIMEOUT 5000
1128 #define TRANSITION_TIME_SHORT 850
1133 codeLocalPlayer = GetLocalPlayer( localClientNum );
1134 if ( isdefined( localPlayer ) && isdefined( localPlayer.localClientNum ) && isdefined( codeLocalPlayer ) && localPlayer == codeLocalPlayer )
1140 localPlayer.postfx_igc_on = undefined;
1141 localPlayer.pstfx_world_construction =
false;
1145 function postfx_igc( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1147 self endon(
"entityshutdown" );
1149 if (
IS_TRUE(
self.postfx_igc_on ) )
1154 if( SessionModeIsZombiesGame() )
1162 self thread
postfx_igc_short( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump );
1166 self.postfx_igc_on = 1;
1168 codeImageName =
"postfx_igc_image" + localClientNum;
1169 CreateSceneCodeImage( localClientNum, codeImageName );
1170 CaptureFrame( localClientNum, codeImageName );
1209 b_streamer_wait =
true;
1215 if ( b_streamer_wait && ( sT >= .65 ) )
1217 n_streamer_time_total = 0;
1221 n_streamer_time = GetTime();
1223 for ( j = ( .65 * 1000 ); j < ( 1.15 * 1000 ); j += (
CLIENT_FRAME * 1000 ) )
1230 for ( j = ( 1.15 * 1000 ); j < ( .65 * 1000 ); j -= (
CLIENT_FRAME * 1000 ) )
1237 n_streamer_time_total += ( GetTime() - n_streamer_time );
1240 b_streamer_wait =
false;
1247 else if ( sT > 0.5 && sT <= 0.85 )
1258 if ( sT > 1.0 && !
IS_TRUE(
self.pstfx_world_construction ) )
1260 self thread postfx::playpostfxbundle(
"pstfx_world_construction" );
1261 self.pstfx_world_construction =
true;
1266 if ( sT > 0.5 && sT <= 1.0 )
1268 n_hex = MapFloat( 0.5, 1.0, 0, 1, sT );
1276 else if ( sT > 1.0 && sT < 1.5 )
1288 if ( sT > 0.65 && sT <= 1.15 )
1292 else if ( sT > 1.21 && sT < 1.50 )
1302 if ( sT > 1.21 && sT <= 1.5 )
1310 else if ( sT > 1.5 )
1319 if ( sT > 1.0 && sT <= 1.45 )
1323 else if ( sT > 1.45 && sT < 1.75)
1327 else if ( sT >= 1.75 )
1334 val = 1.0 - MapFloat(1.75, 2.0, 0, 1, sT );
1341 val = 1.0 - MapFloat( 1.25, 1.75, 0, 1, sT );
1346 if ( sT >= 1.75 && sT < 2.0 )
1356 outer_radii = MapFloat( 1.0, 1.50, 0, 2000, sT );
1360 if ( sT > 1.15 && sT < 1.85 )
1364 else if ( sT >= 1.85 )
1377 self.pstfx_world_construction =
false;
1379 FreeCodeImage( localClientNum, codeImageName );
1380 self.postfx_igc_on = undefined;
1391 self.postfx_igc_on = undefined;
1394 function postfx_igc_short( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1396 self endon(
"entityshutdown" );
1398 self.postfx_igc_on = 1;
1400 codeImageName =
"postfx_igc_image" + localClientNum;
1401 CreateSceneCodeImage( localClientNum, codeImageName );
1402 CaptureFrame( localClientNum, codeImageName );
1418 b_streamer_wait =
true;
1428 else if ( sT > 0.5 && sT <= 0.85 )
1444 FreeCodeImage( localClientNum, codeImageName );
1445 self.postfx_igc_on = undefined;
1448 function cf_server_sync( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1475 a_invalid_object_indexes = [];
1477 foreach ( i, s_object
in s_scenedef.objects )
1479 if ( !isdefined( s_object.name ) && !isdefined( s_object.model ) )
1485 for ( i = a_invalid_object_indexes.size - 1; i >= 0 ; i-- )
1487 ArrayRemoveIndex( s_scenedef.objects, a_invalid_object_indexes[i] );
1495 return ( IsString(
self.cameraswitcher )
1496 || IsString(
self.extraCamSwitcher1 )
1497 || IsString(
self.extraCamSwitcher2 )
1498 || IsString(
self.extraCamSwitcher3 )
1499 || IsString(
self.extraCamSwitcher4 ) );
1510 if ( isdefined( level.disableFXAnimInSplitscreenCount ) )
1512 if ( isdefined( level.localplayers ) )
1514 if ( level.localplayers.size >= level.disableFXAnimInSplitscreenCount )
1521 a_instances = ArrayCombine(
1527 foreach ( s_instance
in a_instances )
1568 foreach ( s_instance
in a_instances )
1572 Assert( isdefined( s_scenedef ),
"Scriptbundle @ " + s_instance.origin +
" uses scriptbundle '" + s_instance.scriptbundlename +
"' that doesn't exist." );
1574 if ( s_scenedef.vmtype ==
"client" )
1578 s_instance thread
play();
1582 s_instance thread
init();
1590 trig endon(
"entityshutdown" );
1591 trig waittill(
"trigger" );
1597 trig endon(
"entityshutdown" );
1601 trig waittill(
"trigger" );
1609 trig endon(
"entityshutdown" );
1610 trig waittill(
"trigger" );
1631 Assert( isdefined(
get_scenedef( str_scenedef ) ),
"Trying to add a scene function for scene '" + str_scenedef +
"' that doesn't exist." );
1635 DEFAULT( level.scene_funcs[ str_scenedef ], [] );
1636 ARRAY_ADD( level.scene_funcs[ str_scenedef ][ str_state ], Array( func, vararg ) );
1655 Assert( isdefined(
get_scenedef( str_scenedef ) ),
"Trying to remove a scene function for scene '" + str_scenedef +
"' that doesn't exist." );
1660 if ( isdefined( level.scene_funcs[ str_scenedef ] ) && isdefined( level.scene_funcs[ str_scenedef ][ str_state ] ) )
1662 for ( i = level.scene_funcs[ str_scenedef ][ str_state ].size - 1; i >= 0; i-- )
1664 if ( level.scene_funcs[ str_scenedef ][ str_state ][ i ][ 0 ] == func )
1666 ArrayRemoveIndex( level.scene_funcs[ str_scenedef ][ str_state ], i );
1695 function spawn( arg1, arg2, arg3, arg4, b_test_run )
1697 str_scenedef = arg1;
1699 Assert( isdefined( str_scenedef ),
"Cannot create a scene without a scene def." );
1701 if ( IsVec( arg2 ) )
1714 s_instance = SpawnStruct();
1715 s_instance.origin = ( isdefined( v_origin ) ? v_origin : (0, 0, 0) );
1716 s_instance.angles = ( isdefined( v_angles ) ? v_angles : (0, 0, 0) );
1717 s_instance.classname =
"scriptbundle_scene";
1718 s_instance.scriptbundlename = str_scenedef;
1760 function init( arg1, arg2, arg3, b_test_run )
1762 if (
self == level )
1764 if ( IsString( arg1 ) )
1766 if ( IsString( arg2 ) )
1778 if ( isdefined( str_key ) )
1783 Assert( a_instances.size,
"No scene instances with KVP '" + str_key +
"'/'" + str_value +
"'." );
1789 if ( !a_instances.size )
1795 if ( !a_instances.size )
1801 foreach ( s_instance
in a_instances )
1803 if ( isdefined( s_instance ) )
1813 if ( IsString( arg1 ) )
1837 if ( s_scenedef.sceneType == str_type )
1848 DEFAULT( str_scenedef,
self.scriptbundlename );
1854 Assert( isdefined( str_scenedef ),
"Scene at (" + ( isdefined(
self.origin ) ?
self.origin :
"level" ) +
") is missing its scene def." );
1855 Assert( isdefined( s_bundle ),
"Scene at (" + ( isdefined(
self.origin ) ?
self.origin :
"level" ) +
") is using a scene name '" + str_scenedef +
"' that doesn't exist." );
1861 if ( isdefined( o_scene ) )
1863 if ( isdefined(
self.scriptbundlename ) && !b_test_run )
1868 thread [[o_scene]]->initialize(
true );
1872 o_scene =
new cScene();
1873 [[o_scene]]->init( str_scenedef, s_bundle,
self,
a_ents, b_test_run );
1913 function play( arg1, arg2, arg3, b_test_run =
false, str_mode =
"" )
1915 s_tracker = SpawnStruct();
1916 s_tracker.n_scene_count = 1;
1918 if (
self == level )
1920 if ( IsString( arg1 ) )
1922 if ( IsString( arg2 ) )
1934 str_scenedef = str_value;
1936 if ( isdefined( str_key ) )
1940 str_scenedef = undefined;
1943 Assert( a_instances.size,
"No scene instances with KVP '" + str_key +
"'/'" + str_value +
"'." );
1949 if ( !a_instances.size )
1955 str_scenedef = undefined;
1959 if ( isdefined( str_scenedef ) )
1962 a_instances = ArrayCombine( a_active_instances, a_instances,
false,
false );
1965 if ( !a_instances.size )
1971 s_tracker.n_scene_count = a_instances.size;
1973 foreach ( s_instance
in a_instances )
1975 if ( isdefined( s_instance ) )
1985 if ( IsString( arg1 ) )
1987 self thread
_play_instance( s_tracker, arg1, arg2, b_test_run, str_mode );
1991 self thread
_play_instance( s_tracker, arg2, arg1, b_test_run, str_mode );
2000 level endon(
"demo_jump");
2002 for ( i = 0; i < s_tracker.n_scene_count; i++ )
2004 s_tracker waittill(
"scene_done" );
2011 DEFAULT( str_scenedef,
self.scriptbundlename );
2013 if (
self.scriptbundlename === str_scenedef )
2015 str_scenedef =
self.scriptbundlename;
2032 self.scene_played =
true;
2036 if ( isdefined(o_scene) )
2038 thread [[o_scene]]->play( b_test_run, str_mode );
2043 if ( isdefined(
self ) )
2045 if ( isdefined(
self.scriptbundlename ) &&
IS_TRUE(
get_scenedef(
self.scriptbundlename ).looping ) )
2047 self.scene_played =
false;
2051 s_tracker notify(
"scene_done" );
2056 level endon(
"demo_jump");
2058 self waittillmatch(
"scene_done", str_scenedef );
2097 function stop( arg1, arg2, arg3, b_cancel, b_no_assert =
false )
2099 if (
self == level )
2101 if ( IsString( arg1 ) )
2103 if ( IsString( arg2 ) )
2115 if ( isdefined( str_key ) )
2120 Assert( b_no_assert || a_instances.size,
"No scene instances with KVP '" + str_key +
"'/'" + str_value +
"'." );
2123 str_value = undefined;
2128 if ( !a_instances.size )
2134 str_value = undefined;
2138 foreach ( s_instance
in ArrayCopy( a_instances ) )
2140 if ( isdefined( s_instance ) )
2149 if ( IsString( arg1 ) )
2162 if ( isdefined(
self.scenes ) )
2164 foreach ( o_scene
in ArrayCopy(
self.scenes ) )
2166 str_scene_name = [[o_scene]]->get_name();
2168 if ( !isdefined( str_scenedef ) || ( str_scene_name == str_scenedef ) )
2170 thread [[o_scene]]->stop( b_clear, b_cancel );
2178 stop( arg1, arg2, arg3,
true );
2184 foreach ( s_obj
in s_scenedef.objects )
2197 return (
IS_TRUE(
self.spawnoninit ) || isdefined(
self.initanim ) || isdefined(
self.initanimloop ) ||
IS_TRUE(
self.firstframe ) );
2289 foreach ( s_obj
in s_scenedef.objects )
2291 if ( isdefined( s_obj.type ) )
2293 if ( ToLower( s_obj.type ) == ToLower( str_type ) )
2316 if (
self == level )
2338 if (
self == level )
2340 return ( level
flagsys::get( str_scenedef +
"_playing" ) );
2344 DEFAULT( str_scenedef,
self.scriptbundlename );
2347 if ( isdefined( o_scene ) )
2349 return (
IS_EQUAL( o_scene._str_state,
"play" ) );
2358 DEFAULT( level.active_scenes, [] );
2360 if ( isdefined( str_scenedef ) )
2362 return ( isdefined( level.active_scenes[ str_scenedef ] ) ? level.active_scenes[ str_scenedef ] : [] );
2366 a_active_scenes = [];
2367 foreach ( str_scenedef, _
in level.active_scenes )
2369 a_active_scenes = ArrayCombine( a_active_scenes, level.active_scenes[ str_scenedef ],
false,
false );
2372 return a_active_scenes;
2378 if ( isdefined( str_scenedef ) && isdefined(
self.scenes ) )
2380 foreach ( o_scene
in self.scenes )
2382 if ( [[o_scene]]->
get_name() == str_scenedef )
2392 str_mode = GetDvarString(
"scene_menu_mode",
"default" );
2394 if ( IsSubStr( str_mode,
"capture" ) )