‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_microwave_turret.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 #using scripts\shared\clientfield_shared;
3 #using scripts\shared\system_shared;
4 #using scripts\shared\util_shared;
5 #insert scripts\shared\shared.gsh;
6 #insert scripts\shared\version.gsh;
7 #insert scripts\mp\killstreaks\_killstreaks.gsh;
8 
9 #precache( "client_fx", "killstreaks/fx_sg_distortion_cone_ash" );
10 #precache( "client_fx", "killstreaks/fx_sg_distortion_cone_ash_sm" );
11 
12 #using_animtree( "mp_microwaveturret" );
13 
14 #define MICROWAVE_TURRET_ROW_SPREAD ( 150 )
15 #define MICROWAVE_TURRET_FX_SIZE ( 200 )
16 #define MICROWAVE_TURRET_FX_HALF_SIZE ( 125 )
17 #define MICROWAVE_TURRET_FX_TRACE ( MICROWAVE_TURRET_RADIUS + 40 )
18 #define MICROWAVE_TURRET_FX "killstreaks/fx_sg_distortion_cone_ash"
19 #define MICROWAVE_TURRET_FX_HALF "killstreaks/fx_sg_distortion_cone_ash_sm"
20 #define MICROWAVE_TURRET_STUN_FX "killstreaks/fx_sg_emp_stun"
21 #define MICROWAVE_TURRET_FX_TRACE_ANGLE ( 55 )
22 #define MICROWAVE_TURRET_FX_CHECK_TIME ( 1.0 )
23 
24 #namespace microwave_turret;
25 
26 ‪REGISTER_SYSTEM( "microwave_turret", &‪__init__, undefined )
27 
28 function ‪__init__()
29 {
33 }
34 
35 function ‪turret_microwave_sounds( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
36 {
37  if( newVal == ‪MICROWAVE_TURRET_START_SOUND )
38  {
39  self thread ‪turret_microwave_sound_start( localClientNum );
40  }
41  else if( newVal == ‪MICROWAVE_TURRET_STOP_SOUND )
42  {
43  self notify( "sound_stop" );
44  }
45 }
46 
47 function ‪turret_microwave_sound_start( localClientNum )
48 {
49  self endon( "entityshutdown" );
50  self endon( "sound_stop" );
51 
52  if ( ‪IS_TRUE( self.sound_loop_enabled ) )
53  return;
54 
55  self playsound ( 0, "wpn_micro_turret_start");
56 
57  wait 0.7; // wait until deploy animation is finished
58 
59  origin = self GetTagOrigin( "tag_flash" );
60  angles = self GetTagAngles( "tag_flash" );
61 
62  forward = AnglesToForward( angles );
63  forward = VectorScale( forward, 750 );
64 
65  ‪trace = BulletTrace( origin, origin + forward, false, self );
66 
67  start = origin;
68  ‪end = ‪trace[ "position" ];
69 
70  self.microwave_audio_start = start;
71  self.microwave_audio_end = ‪end;
73 
74  if ( !‪IS_TRUE( self.sound_loop_enabled ) )
75  {
76  self.sound_loop_enabled = true;
77  soundLineEmitter( "wpn_micro_turret_loop", self.microwave_audio_start, self.microwave_audio_end );
78  self thread ‪turret_microwave_sound_off_waiter( localClientNum );
79  }
80 }
81 
82 function ‪turret_microwave_sound_off_waiter( localClientNum )
83 {
84  msg = self ‪util::waittill_any( "sound_stop", "entityshutdown" );
85 
86  if ( ‪IS_EQUAL( msg, "sound_stop" ) )
87  playsound (0, "wpn_micro_turret_stop", self.microwave_audio_start);
88 
89  soundStopLineEmitter ( "wpn_micro_turret_loop", self.microwave_audio_start, self.microwave_audio_end );
90 
91  if ( isdefined( self ) )
92  {
93  self.sound_loop_enabled = false;
94  }
95 }
96 
98 {
99  self endon( "beam_stop" );
100  self endon( "entityshutdown" );
101 
102  while( 1 )
103  {
104  origin = self GetTagOrigin( "tag_flash" );
105 
106  if ( origin[0] != self.microwave_audio_start[0] || origin[1] != self.microwave_audio_start[1] || origin[2] != self.microwave_audio_start[2] )
107  {
108  previousStart = self.microwave_audio_start;
109  previousEnd = self.microwave_audio_end;
110 
111  angles = self GetTagAngles( "tag_flash" );
112 
113  forward = AnglesToForward( angles );
114  forward = VectorScale( forward, 750 );
115 
116  ‪trace = BulletTrace( origin, origin + forward, false, self );
117 
118  self.microwave_audio_start = origin;
119  self.microwave_audio_end = ‪trace[ "position" ];
120 
121  soundUpdateLineEmitter( "wpn_micro_turret_loop", previousStart, previousEnd, self.microwave_audio_start, self.microwave_audio_end );
122  }
123 
124  wait 0.1;
125  }
126 }
127 
128 function ‪microwave_init_anim( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
129 {
130  if ( !newVal )
131  return;
132 
133  self UseAnimTree( #animtree );
134  self SetAnimRestart( %o_turret_guardian_close, 1.0, 0.0, 1.0 );
135  self SetAnimTime( %o_turret_guardian_close, 1.0 );
136 }
137 
138 function ‪microwave_open( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
139 {
140  if ( !newVal )
141  {
142  self UseAnimTree( #animtree );
143  self SetAnim( %o_turret_guardian_open, 0.0 ); // stop open anim
144  self SetAnimRestart( %o_turret_guardian_close, 1.0, 0.0, 1.0 );
145 
146  self notify( "beam_stop" );
147  self notify( "sound_stop" );
148  return;
149  }
150 
151  self UseAnimTree( #animtree );
152  self SetAnim( %o_turret_guardian_close, 0.0 ); // stop close anim
153  self SetAnimRestart( %o_turret_guardian_open, 1.0, 0.0, 1.0 );
154 
155  self thread ‪StartMicrowaveFx(localClientNum);
156 }
157 
158 function ‪microwave_close_anim( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
159 {
160  if ( !newVal )
161  return;
162 
163  self UseAnimTree( #animtree );
164  self SetAnimRestart( %o_turret_guardian_close, 1.0, 0.0, 1.0 );
165 }
166 
167 /#
168 function ‪debug_trace(origin, ‪trace)
169 {
170  if ( ‪trace[ "fraction" ] < 1.0 )
171  {
172  color = ( 0.95, 0.05, 0.05 );
173  }
174  else
175  {
176  color = ( 0.05, 0.95, 0.05 );
177  }
178 
179  Sphere( ‪trace[ "position" ], 5, color, 0.75, true, 10, 100 );
180  ‪util::debug_line( origin, ‪trace[ "position" ], color, 100 );
181 }
182 #/
183 
184 function ‪StartMicrowaveFx( localClientNum )
185 {
186  turret = self;
187  turret endon( "entityshutdown" );
188  turret endon( "beam_stop" );
189 
190  turret.should_update_fx = true;
191 
192  self thread ‪turret_microwave_sound_start( localClientNum );
193 
194  origin = turret GetTagOrigin( "tag_flash" );
195  angles = turret GetTagAngles( "tag_flash" );
196  microwaveFXEnt = ‪spawn(localClientNum, origin, "script_model");
197  microwaveFXEnt SetModel("tag_microwavefx");
198  microwaveFXEnt.angles = angles;
199  microwaveFXEnt linkto(turret, "tag_flash");
200 
201  microwaveFXEnt.fxHandles = [];
202  microwaveFXEnt.fxNames = [];
203  microwaveFXEnt.fxHashs = [];
204 
205  self thread ‪UpdateMicrowaveAim( microwaveFXEnt );
206  self thread ‪CleanupFx( localClientNum, microwaveFXEnt );
207  wait 0.3;
208 
209  while( true )
210  {
211 /#
212  if ( GetDvarInt( "scr_microwave_turret_fx_debug" ) )
213  {
214  turret.should_update_fx = true;
215  microwaveFXEnt.fxHashs["center"] = 0;
216  }
217 #/
218  if ( turret.should_update_fx == false )
219  {
221  continue;
222  }
223 
224  // limit traces per frame when there are multiple microwave turrets on the field
225  if ( isdefined( level.last_microwave_turret_fx_trace ) && level.last_microwave_turret_fx_trace == GetTime() )
226  {
227  wait(0.05);
228 
229  // /# IPrintLnBold( "Delaying microwave turret fx! Time: " + GetTime() ); #/
230  continue;
231  }
232 
233  angles = turret GetTagAngles( "tag_flash" );
234  origin = turret GetTagOrigin( "tag_flash" );
235  forward = AnglesToForward( angles );
236  forward = VectorScale( forward, ‪MICROWAVE_TURRET_FX_TRACE );
237  forwardRight = AnglesToForward( angles - (0, ‪MICROWAVE_TURRET_FX_TRACE_ANGLE / 3, 0) );
238  forwardRight = VectorScale( forwardRight, ‪MICROWAVE_TURRET_FX_TRACE );
239  forwardLeft = AnglesToForward( angles + (0, ‪MICROWAVE_TURRET_FX_TRACE_ANGLE / 3, 0) );
240  forwardLeft = VectorScale( forwardLeft, ‪MICROWAVE_TURRET_FX_TRACE );
241 
242  ‪trace = BulletTrace( origin, origin + forward, false, turret );
243  traceRight = BulletTrace( origin, origin + forwardRight, false, turret );
244  traceLeft = BulletTrace( origin, origin + forwardLeft, false, turret );
245 
246 /#
247  if ( GetDvarInt( "scr_microwave_turret_fx_debug" ) )
248  {
249  ‪debug_trace( origin, ‪trace );
250  ‪debug_trace( origin, traceRight );
251  ‪debug_trace( origin, traceLeft );
252  }
253 #/
254 
255  need_to_rebuild = microwaveFXEnt ‪MicrowaveFxHash( ‪trace, origin, "center" );
256  need_to_rebuild |= microwaveFXEnt ‪MicrowaveFxHash( traceRight, origin, "right" );
257  need_to_rebuild |= microwaveFXEnt ‪MicrowaveFxHash( traceLeft, origin, "left" );
258 
259  level.last_microwave_turret_fx_trace = getTime();
260 
261  if( !need_to_rebuild )
262  {
264  continue;
265  }
266 
267  wait( 0.1 );
268 
269  microwaveFXEnt ‪PlayMicrowaveFx( localClientNum, ‪trace, traceRight, TraceLeft, origin );
270 
271  turret.should_update_fx = false;
273  }
274 }
275 
276 function ‪UpdateMicrowaveAim( microwaveFXEnt )
277 {
278  turret = self;
279  turret endon( "entityshutdown" );
280  turret endon( "beam_stop" );
281 
282  last_angles = turret GetTagAngles( "tag_flash" );
283 
284  while( true )
285  {
286  angles = turret GetTagAngles( "tag_flash" );
287 
288  if ( last_angles != angles )
289  {
290  turret.should_update_fx = true;
291  last_angles = angles;
292  }
293 
294  wait 0.1;
295  }
296 }
297 
298 function ‪MicrowaveFxHash( ‪trace, origin, ‪name )
299 {
300  hash = 0;
301  counter = 2;
302  for ( i = 0; i < 5; i++ )
303  {
306 
307  traceDistSq = DistanceSquared( origin, ‪trace[ "position" ] );
308  if( traceDistSq >= endOfHalfFxSq || i == 0 )
309  {
310  if ( traceDistSq < endOfFullFxSq )
311  {
312  hash += 1;
313  }
314  else
315  {
316  hash += counter;
317  }
318  }
319 
320  counter *= 2;
321  }
322 
323  if ( !isDefined( self.fxHashs[‪name] ) )
324  self.fxHashs[‪name] = 0;
325 
326  last_hash = self.fxHashs[‪name];
327 
328  self.fxHashs[‪name] = hash;
329 
330  return last_hash != hash;
331 }
332 
333 function ‪CleanupFx( localClientNum, microwaveFXEnt )
334 {
335  self ‪util::waittill_any( "entityshutdown", "beam_stop" );
336 
337  foreach ( handle in microwaveFXEnt.fxHandles )
338  {
339  if ( isdefined( handle ) )
340  {
341  StopFx( localClientNum, handle );
342  }
343  }
344 
345  microwaveFXEnt delete();
346 }
347 
348 function ‪play_fx_on_tag( localClientNum, fxName, tag )
349 {
350  if ( !isdefined( self.fxHandles[tag] ) || fxName != self.fxNames[tag] )
351  {
352  ‪stop_fx_on_tag( localClientNum, fxName, tag );
353 
354  self.fxNames[tag] = fxName;
355  self.fxHandles[tag] = PlayFxOnTag( localCLientNum, fxName, self, tag );
356  }
357 }
358 
359 function ‪stop_fx_on_tag( localClientNum, fxName, tag )
360 {
361  if ( isdefined( self.fxHandles[tag] ) )
362  {
363  StopFx( localClientNum, self.fxHandles[tag] );
364 
365  self.fxHandles[tag] = undefined;
366  self.fxNames[tag] = undefined;
367  }
368 }
369 
370 /#
371 function ‪render_debug_sphere( tag, color, fxName )
372 {
373  if ( GetDvarInt( "scr_microwave_turret_fx_debug" ) )
374  {
375  origin = self GetTagOrigin( tag );
376 
377  Sphere( origin, 2, color, 0.75, true, 10, 100 );
378  }
379 }
380 #/
381 
382 function ‪stop_or_start_fx( localClientNum, fxName, tag, start )
383 {
384  if ( start )
385  {
386  self ‪play_fx_on_tag( localClientNum, fxName, tag );
387 /#
388  if ( fxName == ‪MICROWAVE_TURRET_FX_HALF )
389  {
390  ‪render_debug_sphere( tag, ( 0.5, 0.5, 0 ), fxName );
391  }
392  else
393  {
394  ‪render_debug_sphere( tag, ( 0, 1, 0 ), fxName );
395  }
396 #/
397  }
398  else
399  {
400  ‪stop_fx_on_tag( localClientNum, fxName, tag );
401 /#
402  ‪render_debug_sphere( tag, ( 1, 0, 0 ), fxName );
403 #/
404  }
405 }
406 
407 function ‪PlayMicrowaveFx( localCLientNum, ‪trace, traceRight, traceLeft, origin )
408 {
409  rows = 5;
410 
411  // /# IPrintLnBold( "Playing Microwave Fx: " + GetTime() ); #/
412 
413  for ( i = 0; i < rows; i++ )
414  {
417 
418  traceDistSq = DistanceSquared( origin, ‪trace[ "position" ] );
419 
420  startFx = traceDistSq >= endOfHalfFxSq || i == 0;
421  fxName = ( ( traceDistSq < endOfFullFxSq ) ? ‪MICROWAVE_TURRET_FX_HALF : ‪MICROWAVE_TURRET_FX );
422 
423  switch ( i )
424  {
425  case 0:
426  // we always want this one to play
427  self ‪play_fx_on_tag( localCLientNum, fxName, "tag_fx11" );
428  break;
429  case 1:
430  break;
431  case 2:
432  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx32", startFx );
433  break;
434  case 3:
435  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx42", startFx );
436  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx43", startFx );
437  break;
438  case 4:
439  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx53", startFx );
440  break;
441  }
442 
443  traceDistSq = DistanceSquared( origin, traceLeft[ "position" ] );
444 
445  startFx = traceDistSq >= endOfHalfFxSq;
446  fxName = ( ( traceDistSq < endOfFullFxSq ) ? ‪MICROWAVE_TURRET_FX_HALF : ‪MICROWAVE_TURRET_FX );
447 
448  switch ( i )
449  {
450  case 0:
451  break;
452  case 1:
453  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx22", startFx );
454  break;
455  case 2:
456  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx33", startFx );
457  break;
458  case 3:
459  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx44", startFx );
460  break;
461  case 4:
462  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx54", startFx );
463  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx55", startFx );
464  break;
465  }
466 
467  traceDistSq = DistanceSquared( origin, traceRight[ "position" ] );
468 
469  startFx = traceDistSq >= endOfHalfFxSq;
470  fxName = ( ( traceDistSq < endOfFullFxSq ) ? ‪MICROWAVE_TURRET_FX_HALF : ‪MICROWAVE_TURRET_FX );
471 
472  switch ( i )
473  {
474  case 0:
475  break;
476  case 1:
477  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx21", startFx );
478  break;
479  case 2:
480  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx31", startFx );
481  break;
482  case 3:
483  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx41", startFx );
484  break;
485  case 4:
486  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx51", startFx );
487  self ‪stop_or_start_fx( localCLientNum, fxName, "tag_fx52", startFx );
488  break;
489  }
490  }
491 
492  // /# IPrintLnBold( "Done playing Microwave Fx: " + GetTime() ); #/
493 }
‪turret_microwave_sound_start
‪function turret_microwave_sound_start(localClientNum)
Definition: _microwave_turret.csc:47
‪StartMicrowaveFx
‪function StartMicrowaveFx(localClientNum)
Definition: _microwave_turret.csc:184
‪debug_trace
‪function debug_trace(origin, trace)
Definition: _microwave_turret.csc:168
‪CF_CALLBACK_ZERO_ON_NEW_ENT
‪#define CF_CALLBACK_ZERO_ON_NEW_ENT
Definition: version.gsh:103
‪VERSION_SHIP
‪#define VERSION_SHIP
Definition: version.gsh:36
‪MICROWAVE_TURRET_START_SOUND
‪#define MICROWAVE_TURRET_START_SOUND
Definition: _killstreaks.gsh:46
‪trace
‪function trace(from, to, target)
Definition: grapple.gsc:369
‪turret_microwave_sound_updater
‪function turret_microwave_sound_updater()
Definition: _microwave_turret.csc:97
‪PlayMicrowaveFx
‪function PlayMicrowaveFx(localCLientNum, trace, traceRight, traceLeft, origin)
Definition: _microwave_turret.csc:407
‪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
‪SQR
‪#define SQR(__var)
Definition: shared.gsh:293
‪MICROWAVE_TURRET_FX_TRACE_ANGLE
‪#define MICROWAVE_TURRET_FX_TRACE_ANGLE
Definition: _microwave_turret.csc:21
‪stop_fx_on_tag
‪function stop_fx_on_tag(localClientNum, fxName, tag)
Definition: _microwave_turret.csc:359
‪render_debug_sphere
‪function render_debug_sphere(tag, color, fxName)
Definition: _microwave_turret.csc:371
‪turret_microwave_sound_off_waiter
‪function turret_microwave_sound_off_waiter(localClientNum)
Definition: _microwave_turret.csc:82
‪CleanupFx
‪function CleanupFx(localClientNum, microwaveFXEnt)
Definition: _microwave_turret.csc:333
‪microwave_init_anim
‪function microwave_init_anim(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _microwave_turret.csc:128
‪MICROWAVE_TURRET_FX_HALF
‪#define MICROWAVE_TURRET_FX_HALF
Definition: _microwave_turret.csc:19
‪UpdateMicrowaveAim
‪function UpdateMicrowaveAim(microwaveFXEnt)
Definition: _microwave_turret.csc:276
‪MICROWAVE_TURRET_FX_HALF_SIZE
‪#define MICROWAVE_TURRET_FX_HALF_SIZE
Definition: _microwave_turret.csc:16
‪microwave_open
‪function microwave_open(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _microwave_turret.csc:138
‪MICROWAVE_TURRET_FX
‪#define MICROWAVE_TURRET_FX
Definition: _microwave_turret.csc:18
‪end
‪function end(final)
Definition: _killcam.gsc:511
‪CF_HOST_ONLY
‪#define CF_HOST_ONLY
Definition: version.gsh:102
‪waittill_any
‪function waittill_any(str_notify1, str_notify2, str_notify3, str_notify4, str_notify5)
Definition: util_shared.csc:375
‪MICROWAVE_TURRET_STOP_SOUND
‪#define MICROWAVE_TURRET_STOP_SOUND
Definition: _killstreaks.gsh:45
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪stop_or_start_fx
‪function stop_or_start_fx(localClientNum, fxName, tag, start)
Definition: _microwave_turret.csc:382
‪IS_EQUAL
‪#define IS_EQUAL(__a, __b)
Definition: shared.gsh:250
‪play_fx_on_tag
‪function play_fx_on_tag(localClientNum, fxName, tag)
Definition: _microwave_turret.csc:348
‪MicrowaveFxHash
‪function MicrowaveFxHash(trace, origin, name)
Definition: _microwave_turret.csc:298
‪MICROWAVE_TURRET_FX_SIZE
‪#define MICROWAVE_TURRET_FX_SIZE
Definition: _microwave_turret.csc:15
‪register
‪function register()
Definition: _ai_tank.gsc:126
‪debug_line
‪function debug_line(from, to, color, time, depthTest)
Definition: _airsupport.gsc:1089
‪microwave_close_anim
‪function microwave_close_anim(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _microwave_turret.csc:158
‪MICROWAVE_TURRET_FX_CHECK_TIME
‪#define MICROWAVE_TURRET_FX_CHECK_TIME
Definition: _microwave_turret.csc:22
‪name
‪class GroundFx name
‪MICROWAVE_TURRET_ROW_SPREAD
‪#define MICROWAVE_TURRET_ROW_SPREAD
Definition: _microwave_turret.csc:14
‪MICROWAVE_TURRET_FX_TRACE
‪#define MICROWAVE_TURRET_FX_TRACE
Definition: _microwave_turret.csc:17
‪__init__
‪function __init__()
Definition: _microwave_turret.csc:28
‪turret_microwave_sounds
‪function turret_microwave_sounds(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _microwave_turret.csc:35