1 #using scripts\shared\ai_shared;
2 #using scripts\shared\animation_debug_shared;
3 #using scripts\shared\clientfield_shared;
4 #using scripts\shared\flag_shared;
5 #using scripts\shared\flagsys_shared;
6 #using scripts\shared\math_shared;
7 #using scripts\shared\string_shared;
8 #using scripts\shared\system_shared;
9 #using scripts\shared\util_shared;
11 #insert scripts\shared\shared.gsh;
12 #insert scripts\shared\version.gsh;
13 #insert scripts\shared\archetype_shared\archetype_shared.gsh;
14 #insert scripts\shared\ai\systems\animation_state_machine.gsh;
36 function first_frame( animation, v_origin_or_ent, v_angles_or_tag )
38 self thread
play( animation, v_origin_or_ent, v_angles_or_tag, 0 );
52 function last_frame( animation, v_origin_or_ent, v_angles_or_tag )
54 self thread
play( animation, v_origin_or_ent, v_angles_or_tag, 0, 0, 0, 0, 1 );
76 function play( animation, v_origin_or_ent, v_angles_or_tag, n_rate = 1, n_blend_in = .2, n_blend_out = .2, n_lerp = 0, n_start_time = 0, b_show_player_firstperson_weapon =
false, b_unlink_after_completed =
true )
78 if ( SessionModeIsZombiesGame() &&
self IsRagdoll() )
83 self endon(
"death" );
84 self thread
_play( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp, n_start_time, b_show_player_firstperson_weapon, b_unlink_after_completed );
85 self waittill(
"scriptedanim" );
100 self StopAnimScripted( n_blend );
103 function _play( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp, n_start_time, b_show_player_firstperson_weapon, b_unlink_after_completed )
105 self endon(
"death" );
107 self notify(
"new_scripted_anim" );
108 self endon(
"new_scripted_anim" );
119 if ( isdefined(
self.n_script_anim_rate ) )
121 n_rate =
self.n_script_anim_rate;
124 if ( IsVec( v_origin_or_ent ) && IsVec( v_angles_or_tag ) )
126 self AnimScripted( animation, v_origin_or_ent, v_angles_or_tag, animation,
"normal", undefined, n_rate, n_blend_in, n_lerp, n_start_time,
true, b_show_player_firstperson_weapon );
130 if ( IsString( v_angles_or_tag ) )
132 Assert( isdefined( v_origin_or_ent.model ),
"Cannot align animation '" + animation +
"' to tag '" + v_angles_or_tag +
"' because the animation is not aligned to a model." );
138 v_pos = v_origin_or_ent GetTagOrigin( v_angles_or_tag );
139 v_ang = v_origin_or_ent GetTagAngles( v_angles_or_tag );
143 prevOrigin =
self.origin;
144 prevAngles =
self.angles;
147 if ( !isdefined(v_pos) )
149 v_pos = v_origin_or_ent.origin;
150 v_ang = v_origin_or_ent.angles;
153 if ( IsActor(
self ) )
155 self ForceTeleport( v_pos, v_ang );
166 self LinkTo( v_origin_or_ent, v_angles_or_tag, ( 0, 0, 0 ), ( 0, 0, 0 ) );
170 if ( IsActor(
self ) )
172 self ForceTeleport( prevOrigin, prevAngles );
176 self.origin = prevOrigin;
177 self.angles = prevAngles;
181 self AnimScripted( animation, v_pos, v_ang, animation,
"normal", undefined, n_rate, n_blend_in, n_lerp, n_start_time,
true, b_show_player_firstperson_weapon );
185 v_angles = ( isdefined( v_origin_or_ent.angles ) ? v_origin_or_ent.angles : ( 0, 0, 0 ) );
186 self AnimScripted( animation, v_origin_or_ent.origin, v_angles, animation,
"normal", undefined, n_rate, n_blend_in, n_lerp, n_start_time,
true, b_show_player_firstperson_weapon );
190 if ( IsPlayer(
self ) )
195 if ( !IsAnimLooping( animation ) && ( n_blend_out > 0 ) && ( n_rate > 0 ) && ( n_start_time < 1 ) )
199 self thread
_blend_out( animation, n_blend_out, n_rate, n_start_time );
205 if ( GetAnimFrameCount( animation ) > 1 || IsAnimLooping( animation ) )
207 self waittillmatch( animation,
"end" );
214 if ( b_link &&
IS_TRUE(b_unlink_after_completed) )
229 self endon(
"death" );
231 self endon(
"scriptedanim" );
232 self endon(
"new_scripted_anim" );
234 n_server_length = Floor( GetAnimLength( animation ) / .05 ) * .05;
238 n_current_time =
self GetAnimTime( animation ) * n_server_length;
239 n_time_left = n_server_length - n_current_time;
241 if ( n_time_left <= n_blend )
243 self StopAnimScripted( n_blend );
254 if ( isdefined( e_align ) )
265 DEFAULT( v_origin_or_ent,
self.origin );
266 DEFAULT2( v_angles_or_tag,
self.angles, ( 0, 0, 0 ) );
270 if ( IsVec( v_origin_or_ent ) )
272 Assert( IsVec( v_angles_or_tag ),
"Angles must be a vector if origin is." );
274 s.origin = v_origin_or_ent;
275 s.angles = v_angles_or_tag;
281 if ( IsString( v_angles_or_tag ) )
283 s.origin = e_align GetTagOrigin( v_angles_or_tag );
284 s.angles = e_align GetTagAngles( v_angles_or_tag );
288 s.origin = e_align.origin;
289 s.angles = e_align.angles;
311 function teleport( animation, v_origin_or_ent, v_angles_or_tag, time )
313 if ( !IsDefined( time ) )
319 v_pos = GetStartOrigin( s.origin, s.angles, animation, time );
320 v_ang = GetStartAngles( s.origin, s.angles, animation, time );
322 if ( IsActor(
self ) )
324 self ForceTeleport( v_pos, v_ang );
333 #define MIN_REACH_DIST_SQ 4 * 4
335 function reach( animation, v_origin_or_ent, v_angles_or_tag, b_disable_arrivals =
false )
337 self endon(
"death" );
338 s_tracker = SpawnStruct();
339 self thread
_reach( s_tracker, animation, v_origin_or_ent, v_angles_or_tag, b_disable_arrivals );
340 s_tracker waittill(
"done" );
343 function _reach( s_tracker, animation, v_origin_or_ent, v_angles_or_tag, b_disable_arrivals =
false )
345 self endon(
"death" );
347 self notify(
"stop_going_to_node" );
348 self notify(
"new_anim_reach" );
354 goal = GetStartOrigin( s.origin, s.angles, animation );
356 n_delta = DistanceSquared( goal,
self.origin );
359 self StopAnimScripted( .2 );
361 if ( b_disable_arrivals )
369 self.stopanimdistsq = 0.0001;
384 self util::waittill_any(
"goal",
"new_anim_reach",
"new_scripted_anim",
"stop_scripted_anim" );
389 self.stopanimdistsq = 0;
403 s_tracker notify(
"done" );
404 self notify(
"reach_done" );
423 function set_death_anim( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp )
425 self notify(
"new_death_anim" );
426 if ( isdefined( animation ) )
428 self.skipdeath =
true;
429 self thread
_do_death_anim( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp );
433 self.skipdeath =
false;
437 function _do_death_anim( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp )
439 self endon(
"new_death_anim" );
441 self waittill(
"death" );
443 if ( isdefined(
self ) && !
self IsRagdoll() )
445 self play( animation, v_origin_or_ent, v_angles_or_tag, n_rate, n_blend_in, n_blend_out, n_lerp );
451 if (
IS_TRUE(
self.player_anim_look_enabled ) )
453 self SetViewClamp(
self.player_anim_clamp_right,
self.player_anim_clamp_left,
self.player_anim_clamp_top,
self.player_anim_clamp_bottom );
460 #define CF_CRACKS_RED 1
461 #define CF_CRACKS_BLUE 2
462 #define CF_CRACKS_GREEN 3
463 #define CF_CRACKS_ALL 4
467 DEFAULT( level._animnotifyfuncs, [] );
469 Assert( !isdefined( level._animnotifyfuncs[ funcname ] ),
"Notetrack function already exists." );
471 level._animnotifyfuncs[ funcname ] = func;
476 DEFAULT( level._animnotetrackhandlers, [] );
477 DEFAULT( level._animnotetrackhandlers[ str_note ], [] );
479 ARRAY_ADD( level._animnotetrackhandlers[ str_note ],
array( func, pass_notify_params, vararg ) );
484 if ( isdefined( level._animnotetrackhandlers[ str_note ] ) )
486 foreach ( handler
in level._animnotetrackhandlers[ str_note ] )
489 passNotifyParams = handler[1];
492 if( passNotifyParams )
494 self [[ func ]]( param1, param2 );
501 self [[ func ]]( args[0], args[1], args[2], args[3], args[4], args[5] );
504 self [[ func ]]( args[0], args[1], args[2], args[3], args[4] );
507 self [[ func ]]( args[0], args[1], args[2], args[3] );
510 self [[ func ]]( args[0], args[1], args[2] );
513 self [[ func ]]( args[0], args[1] );
516 self [[ func ]]( args[0] );
521 default: AssertMsg(
"Too many args passed to notetrack handler." );
560 self endon(
"death" );
561 self endon(
"new_scripted_anim" );
565 self waittill( animation, str_note, param1, param2 );
567 if ( isdefined( str_note ) )
569 if ( str_note !=
"end" && str_note !=
"loop_end" )
621 if ( IsActor(
self ) )
636 if ( IsActor(
self ) )
651 return ( isdefined( weaponObject ) && ( weaponObject != level.weaponNone ) );
656 if ( IsActor(
self ) )
673 weaponObject =
self.last_item;
678 if (
self.item != level.weaponNone )
683 assert( isdefined( weaponObject.worldModel ) );
685 self Attach( weaponObject.worldModel, tag );
686 self SetEntityWeapon( weaponObject );
688 self.gun_removed = undefined;
689 self.last_item = weaponObject;
696 if ( IsActor(
self ) )
705 weaponObject =
self.item;
710 self Detach( weaponObject.worldModel, tag );
711 self SetEntityWeapon( level.weaponNone );
714 self.gun_removed =
true;
722 if(
self.item != level.weaponNone )
724 startPos =
self GetTagOrigin(
"tag_flash" );
725 endPos = startPos + VectorScale( AnglesToForward(
self GetTagAngles(
"tag_flash" ) ), 100 );
729 MagicBullet(
self.item, startPos, endPos,
self );