Advertisement
GreatEmerald

U2WeaponFire.uc

Mar 5th, 2011
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 5.12 KB | None | 0 0
  1. //-----------------------------------------------------------
  2. // U2WeaponFire.uc
  3. // Releasing all pointers to XMP again.
  4. // 2009, GreatEmerald
  5. //-----------------------------------------------------------
  6. class U2WeaponFire extends WeaponFire;
  7.  
  8. var     bool    bLastRound;     // just fired last round of current clip
  9.  
  10. var name    AnimFireLastRound,
  11.             AnimFireLastDown,
  12.             AnimFireLastReload;
  13.  
  14. var sound FireLastRoundSound;       // played for both FireLastReload (followed by ReloadUnloaded), and FireLastDown.
  15. var float   FireLastReloadTime;
  16. var float   FireLastRoundTime;
  17. //GE: What about FireLastDownTime? Interesting...
  18.  
  19. //GE: Percentage to speed up or slow down the anim. This is the formula to calculate it:
  20. //(Frames / (Sequence->Rate) ) / FireLastReloadTime
  21.  
  22. /*
  23.  * How to recheck values:
  24.  * U2Fire* -> FireLastReloadTime -> FireLastReloadAnimRate
  25.  *         -> FireLastDownAnimRate
  26.  * Alt is the same, just add Alt everywhere
  27.  * U2Weapon* -> ReloadTime -> ReloadAnimRate
  28.  *           -> PutDownTime -> PutDownAnimRate
  29.  */
  30. var float FireLastReloadAnimRate;
  31. var float FireLastDownAnimRate;
  32.  
  33. var Emitter FireEffect;
  34. var class<Emitter> FireEffectClass;
  35.  
  36.  
  37. simulated function DestroyEffects()
  38. {
  39.     Super.DestroyEffects();
  40.  
  41.     if (FireEffect != None)
  42.         FireEffect.Destroy();
  43. }
  44.  
  45. simulated function bool AllowFire()
  46. {
  47.  
  48.     if ( Instigator.Health <= 0 ){log(self$": AllowFire FALSE");
  49.         return false;}
  50.  
  51.     if ( Ammo_ReloadRequired(AmmoPerFire) ){log(self$": AllowFire FALSE");
  52.         return false;}
  53.  
  54.  
  55.     if ( Weapon.IsInState('Reloading') ){log(self$": AllowFire FALSE");
  56.         return false;}
  57.     log(self$": AllowFire SUPER - "$Weapon.AmmoAmount(ThisModeNum) >= AmmoPerFire);
  58.     return Super.AllowFire();
  59. }
  60.  
  61. simulated function bool HasAmmo()
  62. {
  63.     // use projected ammoamount for client
  64.     // note: only use this AFTER ConsumeAmmo (WeaponFire::ModeDoFire)
  65.     if ( Weapon.Role == ROLE_Authority )
  66.         return Weapon.HasAmmo();
  67.     else
  68.         return Weapon.AmmoAmount(0) > 1;
  69. }
  70.  
  71. simulated function bool Ammo_ReloadRequired( optional int AmountNeeded )
  72. {
  73.     if( AmountNeeded == 0 )
  74.         AmountNeeded = AmmoPerFire;
  75.  
  76.     if ( Weapon.Role == ROLE_Authority )
  77.         return AmountNeeded > U2Weapon(Weapon).ClipRoundsRemaining;
  78.     else
  79.         return AmountNeeded > U2Weapon(Weapon).ClientRoundsRemaining;
  80. }
  81.  
  82. event ModeDoFire()
  83. {
  84.     log(self$": ModeDoFire() and AllowFire"@AllowFire());
  85.     bLastRound = Ammo_ReloadRequired(AmmoPerFire + 1);
  86.     U2Weapon(Weapon).bLastRound = bLastRound;
  87.     if (Ammo_ReloadRequired(AmmoPerFire) )
  88.     {
  89.         U2Weapon(Weapon).Reload();
  90.         return;
  91.     }
  92.  
  93.     super.ModeDoFire();
  94. }
  95.  
  96. //// server propagation of firing ////
  97. function ServerPlayFiring()
  98. {
  99.     if( !bLastRound )
  100.     {
  101.         U2Weapon(Weapon).PlayAnimEx(FireAnim);
  102.         Weapon.PlayOwnedSound(FireSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  103.     }
  104.     else if ( HasAmmo() )
  105.     {
  106.         //log(self@"Server: playing AnimFireLastReload:"@AnimFireLastReload);
  107.         SetTimer(FireRate, false);
  108.         U2Weapon(Weapon).PlayAnimEx(AnimFireLastReload, FireLastReloadAnimRate);
  109.         U2Weapon(Weapon).ReloadTime = FireLastReloadTime - FireRate;
  110.         Weapon.PlayOwnedSound(FireLastRoundSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  111.     }
  112.     else
  113.     {
  114.         U2Weapon(Weapon).PlayAnimEx(AnimFireLastDown, FireLastDownAnimRate);
  115.         Weapon.PlayOwnedSound(FireLastRoundSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  116.     }
  117. }
  118.  
  119.  
  120. function PlayFiring()
  121. {
  122.     //log(self$": PlayFiring()");
  123.     U2Weapon(Weapon).ClientRoundsRemaining -= Load;
  124.  
  125.     if ( !bLastRound )
  126.     {
  127.         U2Weapon(Weapon).PlayAnimEx(FireAnim);
  128.         Weapon.PlayOwnedSound(FireSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  129.     }
  130.     else if ( HasAmmo() )
  131.     {
  132.         //log(self@"Client: playing AnimFireLastReload:"@AnimFireLastReload);
  133.         SetTimer(FireRate, false);
  134.         U2Weapon(Weapon).PlayAnimEx(AnimFireLastReload, FireLastReloadAnimRate);
  135.         U2Weapon(Weapon).ReloadTime = FireLastReloadTime - FireRate;
  136.         Weapon.PlayOwnedSound(FireLastRoundSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  137.     }
  138.     else
  139.     {
  140.         U2Weapon(Weapon).PlayAnimEx(AnimFireLastDown, FireLastDownAnimRate);
  141.         Weapon.PlayOwnedSound(FireLastRoundSound,SLOT_Interact,TransientSoundVolume,,TransientSoundRadius,,false);
  142.     }
  143.  
  144.     ClientPlayForceFeedback(FireForce);  // jdf
  145. }
  146.  
  147. simulated function Timer()
  148. {
  149.     bIsFiring = false;
  150.     if ( Instigator.PendingWeapon == none )
  151.         U2Weapon(Weapon).Reload();
  152. }
  153.  
  154. defaultproperties
  155. {
  156.      AnimFireLastRound="FireLastRound"
  157.      AnimFireLastDown="FireLastDown"
  158.      AnimFireLastReload="FireLastReload"
  159.      FireLastReloadTime=1.000000
  160.      FireLastRoundTime=1.000000
  161.      TransientSoundVolume=1.000000
  162.      AmmoClass=Class'XWeapons.SniperAmmo'
  163.      AmmoPerFire=1
  164.      ShakeRotMag=(X=50.000000,Y=50.000000,Z=50.000000)
  165.      ShakeRotRate=(X=10000.000000,Y=10000.000000,Z=10000.000000)
  166.      ShakeRotTime=2.000000
  167.      ShakeOffsetMag=(X=1.000000,Y=1.000000,Z=1.000000)
  168.      ShakeOffsetRate=(X=1000.000000,Y=1000.000000,Z=1000.000000)
  169.      ShakeOffsetTime=2.000000
  170.      SpreadStyle=SS_Random
  171.      FireLastDownAnimRate=1.0
  172.      FireLastReloadAnimRate=1.0
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement