1 #using scripts\codescripts\struct;
2 #using scripts\shared\array_shared;
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\clientfield_shared;
5 #using scripts\shared\flagsys_shared;
6 #using scripts\shared\hud_util_shared;
7 #using scripts\shared\system_shared;
8 #using scripts\shared\util_shared;
9 #using scripts\shared\abilities\_ability_util;
11 #insert scripts\shared\weapons\antipersonnelguidance.gsh;
12 #insert scripts\shared\shared.gsh;
13 #insert scripts\shared\version.gsh;
15 #precache( "string", "MP_CANNOT_LOCKON_TO_TARGET" );
17 #namespace multilockap_guidance;
19 #define MAX_SIMULTANEOUS_LOCKONS GetDvarInt( "scr_max_simLocks" ) //#define MAX_SIMULTANEOUS_LOCKONS 5 this number corresponds to a code define
26 SetDvar(
"scr_max_simLocks",3 );
31 self endon(
"disconnect" );
40 if (!IsDefined(
self.multiLockList))
42 self.multiLockList=[];
47 for(i=0;i<
self.multiLockList.size;i++)
49 if (whom.apTarget ==
self.multiLockList[i].apTarget)
51 if (isdefined(
self.multiLockList[i].apTarget))
53 self.multiLockList[i].apTarget notify(
"missile_unlocked" );
55 self notify(
"stop_sound"+whom.apSoundId );
56 self WeaponLockRemoveSlot(i);
57 ArrayRemoveValue(
self.multiLockList,whom,
false);
64 for(i=0;i<
self.multiLockList.size;i++)
66 self.multiLockList[i].apTarget notify(
"missile_unlocked" );
67 self notify(
"stop_sound"+
self.multiLockList[i].apSoundId );
69 self.multiLockList = [];
72 if (
self.multiLockList.size==0)
74 self StopRumble(
"stinger_lock_rumble" );
76 self WeaponLockRemoveSlot(-1);
78 if (IsDefined(weapon))
80 if (IsDefined(weapon.lockonSeekerSearchSound))
81 self StopLocalSound( weapon.lockonSeekerSearchSound );
82 if (IsDefined(weapon.lockonSeekerLockedSound))
83 self StopLocalSound( weapon.lockonSeekerLockedSound );
93 self endon(
"disconnect" );
94 self endon (
"death" );
98 self waittill(
"missile_fire", missile, weapon );
100 if ( weapon.lockonType ==
"AP Multi" )
102 foreach(target
in self.multiLockList)
104 if( isdefined(target.apTarget) && target.apLockFinalized )
106 target.apTarget notify(
"stinger_fired_at_me", missile, weapon,
self );
115 self endon(
"disconnect" );
116 self endon (
"death" );
120 self waittill(
"weapon_change", weapon );
122 while ( weapon.lockonType ==
"AP Multi" )
126 while( !(
self PlayerAds() == 1.0 ) )
130 currentWeapon =
self GetCurrentWeapon();
131 if ( currentWeapon.lockonType !=
"AP Multi" )
145 while( (
self PlayerAds() == 1.0 ) )
150 self notify(
"ap_off" );
153 weapon =
self GetCurrentWeapon();
160 self endon(
"disconnect" );
161 self endon(
"death" );
162 self endon(
"ap_off" );
164 lockLength =
self getLockOnSpeed();
165 self.multiLockList = [];
182 foreach(target
in self.multiLockList)
184 if ( target.apLockFinalized )
199 inLockingState=
false;
204 for(i=0;i<
self.multiLockList.size;i++)
206 target=
self.multiLockList[i];
207 if ( target.apLocking )
219 timePassed = getTime() - target.apLockStartTime;
220 if ( timePassed < lockLength )
223 assert( isdefined( target.apTarget ) );
224 target.apLockFinalized =
true;
225 target.apLocking =
false;
226 target.apLockPending =
false;
227 self WeaponLockFinalize( target.apTarget, i );
228 self thread
SeekerSound( weapon.lockonSeekerLockedSound, weapon.lockonSeekerLockedSoundLoops, target.apSoundId );
229 target.apTarget notify(
"missile_lock",
self, weapon );
241 for(i=0;i<
self.multiLockList.size;i++)
243 target=
self.multiLockList[i];
244 if ( target.apLockPending )
254 target.apLockStartTime = getTime();
256 target.apLockFinalized =
false;
257 target.apLockPending =
false;
258 target.apLocking =
true;
260 self thread
SeekerSound( weapon.lockonSeekerSearchSound, weapon.lockonSeekerSearchSoundLoops, target.apSoundId );
277 if ( !IsDefined(bestTarget) &&
self.multiLockList.size==0 )
284 if (IsDefined(bestTarget) &&
self.multiLockList.size<
MAX_SIMULTANEOUS_LOCKONS &&
self.multiLockList.size<
self GetWeaponAmmoClip(weapon))
286 self WeaponLockStart(bestTarget.apTarget,
self.multiLockList.size);
287 self.multiLockList[
self.multiLockList.size] = bestTarget;
294 if( isdefined(
self.LockOnCanceledMessage ) )
295 self.LockOnCanceledMessage
destroy();
300 if( isdefined(
self.LockOnCanceledMessage ) )
303 self.LockOnCanceledMessage = newclienthudelem(
self );
304 self.LockOnCanceledMessage.fontScale = 1.25;
305 self.LockOnCanceledMessage.x = 0;
306 self.LockOnCanceledMessage.y = 50;
307 self.LockOnCanceledMessage.alignX =
"center";
308 self.LockOnCanceledMessage.alignY =
"top";
309 self.LockOnCanceledMessage.horzAlign =
"center";
310 self.LockOnCanceledMessage.vertAlign =
"top";
311 self.LockOnCanceledMessage.foreground =
true;
312 self.LockOnCanceledMessage.hidewhendead =
false;
313 self.LockOnCanceledMessage.hidewheninmenu =
true;
314 self.LockOnCanceledMessage.archived =
false;
315 self.LockOnCanceledMessage.alpha = 1.0;
316 self.LockOnCanceledMessage SetText( &
"MP_CANNOT_LOCKON_TO_TARGET" );
321 playerTargets = GetPlayers();
322 vehicleTargets = target_getArray();
323 targetsAll = GetAITeamArray();
324 targetsAll = ArrayCombine(targetsAll, playerTargets,
false,
false);
325 targetsAll = ArrayCombine(targetsAll, vehicleTargets,
false,
false);
328 for ( idx = 0; idx < targetsAll.size; idx++ )
330 if ( level.teamBased )
332 if ( isdefined(targetsAll[idx].team) && targetsAll[idx].team !=
self.team)
338 targetsValid[targetsValid.size] = targetsAll[idx];
347 if( isdefined( targetsAll[idx].owner ) &&
self != targetsAll[idx].owner )
351 targetsValid[targetsValid.size] = targetsAll[idx];
358 if ( targetsValid.size == 0 )
363 playerForward = AnglesToForward(
self GetPlayerAngles());
365 for (i=0;i<targetsValid.size;i++)
367 newitem=spawnstruct();
369 newitem.dot = VectorDot(playerForward,VectorNormalize(targetsValid[i].origin-
self.origin));
377 foreach(
lock in self.multiLockList)
379 if (
lock.apTarget == targetsValid[dot.index])
390 newEntry = spawnstruct();
391 newEntry.apTarget = targetsValid[dot.index];
392 newEntry.apLockStartTime = getTime();
393 newEntry.apLockPending =
true;
394 newEntry.apLocking =
false;
395 newEntry.apLockFinalized =
false;
396 newEntry.apLostSightlineTime = 0;
397 newEntry.apSoundId = RandomInt(
INT_MAX);
415 radius =
self getLockOnRadius();
416 return target_isincircle( target,
self, 65, radius );
421 radius = (
self getLockOnLossRadius());
422 return target_isincircle( target,
self, 65, radius );
427 if ( ! isdefined( ent ) )
431 if ( !IsAlive( ent ) )
441 self notify(
"stop_sound"+
id);
443 self endon (
"stop_sound"+
id );
444 self endon(
"disconnect" );
445 self endon (
"death" );
447 if (IsDefined(alias))
449 self PlayRumbleOnEntity(
"stinger_lock_rumble" );
450 time = SoundGetPlaybackTime(alias)*0.001;
453 self playLocalSound( alias );
457 self StopRumble(
"stinger_lock_rumble" );
463 eyePos =
self GetEye();
465 if ( !isdefined( target ) )
468 if ( !IsAlive( target ) )
471 pos = target GetShootAtPos();
474 passed = BulletTracePassed( eyePos, pos,
false, target, undefined,
true,
true );
479 pos = target GetCentroid();
482 passed = BulletTracePassed( eyePos, pos,
false, target, undefined,
true,
true );
488 passed = BulletTracePassed( eyePos, pos,
false, target, undefined,
true,
true );