## XIII
Class XIIIBulletsAmmo

source: C:\XIII\XIII\Classes\XIIIBulletsAmmo.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Inventory
             |
             +--Engine.Ammunition
                |
                +--XIII.XIIIAmmo
                   |
                   +--XIII.XIIIBulletsAmmo

Direct Known Subclasses:KalashAmmo, M16Ammo, M60Ammo, MiniUziAmmo, PompeAmmo, bmg50Ammo, c44Ammo, c9mmAmmo

class XIIIBulletsAmmo
extends XIII.XIIIAmmo

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`BulletScorch` | `DecalProjector` projector to update (to avoid spawn each time)
`class` | `DecalProjectorClass` Visual Impact to leave on geometry
`SRDamages,` | `LRDamages` ShortRange and LongRange damages
`float` | `LongRange` Range at wich we do LRDamages (decreasing)
`float` | `ShortRange` Range at wich we do SRDamages (decreasing)
`bool` | `bInfiniteAmmo` always set ammoamount to default after processtracehit

Function Summary
`void` | `PostBeginPlay()`
    //_____________________________________________________________________________
    // ELR Default
`void` | `ProcessTraceHit(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)`
    //_____________________________________________________________________________
`void` | `ProcessTraceHitNoAmmo(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)`
    //_____________________________________________________________________________
`void` | `SetUpImpactEmitter(Sound S)`
    //_____________________________________________________________________________
`void` | `SpawnDecal(vector HL, vector HN)`
    //_____________________________________________________________________________

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class XIIIBulletsAmmo extends XIIIAmmo
    00005	  abstract;
    00006
    00007	var bool bInfiniteAmmo;             // always set ammoamount to default after processtracehit
    00008
    00009	var float ShortRange;                 // Range at wich we do SRDamages (decreasing)
    00010	var float LongRange;                  // Range at wich we do LRDamages (decreasing)
    00011	var int SRDamages, LRDamages;         // ShortRange and LongRange damages
    00012	var class<BulletScorch> DecalProjectorClass;  // Visual Impact to leave on geometry
    00013	var BulletScorch DecalProjector;              // projector to update (to avoid spawn each time)
    00014
    00015	//_____________________________________________________________________________
    00016	// ELR Default
    00017	function PostBeginPlay()
    00018	{
    00019	    // Convert ShortRange & LongRange from Meters into Engine Units
    00020	    ShortRange = ShortRange * 200 / 2.54;
    00021	    LongRange = LongRange * 200 / 2.54;
    00022	    Super.PostBeginPlay();
    00023	//    log("@@"@self@"SR="$ShortRange@"LR="$LongRange);
    00024	}
    00025
    00026	//_____________________________________________________________________________
    00027	function ProcessTraceHitNoAmmo(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
    00028	{
    00029	    if (AmmoAmount > 0)
    00030	    {
    00031	      AmmoAmount += 1;
    00032	      ProcessTraceHit(W, Other, HitLocation, HitNormal, X, Y, Z);
    00033	    }
    00034	}
    00035
    00036	//_____________________________________________________________________________
    00037	function ProcessTraceHit(Weapon W, Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
    00038	{
    00039	    Local int ActualDamages;
    00040	    local int Loc;
    00041	    local bool bSpawnHeadBlood;
    00042	    local ImpactEmitter B;
    00043
    00044	//    Log("Processing TraceHit on "$Other);
    00045
    00046	    if (AmmoAmount > 0)
    00047	      AmmoAmount -= 1; // Fire
    00048	    else
    00049	      return; // EmptyShot.
    00050
    00051	    if ( bInfiniteAmmo )
    00052	      AmmoAmount = default.AmmoAmount;
    00053
    00054	    if ( Other == None )
    00055	      return;
    00056
    00057	    ActualDamages = min( SRDAmages, LRDamages - (LongRange - VSize(HitLocation - W.Location))*(LRDAmages - SRDamages) / (LongRange - ShortRange) );
    00058	//    log(self@"shot for"@ActualDamages@"range"@VSize(HitLocation - W.Location)); // ::DBUG::
    00059
    00060	    if ( ActualDamages <= 0)
    00061	      return;
    00062
    00063	    if ( Other.bWorldGeometry )
    00064	    {
    00065	      if ( ImpactEmitterMem != none )
    00066	      {
    00067	        // check that we don't spawn to far behind the player, it's useless
    00068	        if (
    00069	          ((W.bRapidFire || (Level.Game.DetailLevel < 2) ) && Level.bLonePlayer)
    00070	          && (vector(XIIIGameInfo(Level.Game).MapInfo.XIIIController.Rotation) dot (Hitlocation - XIIIGameInfo(Level.Game).MapInfo.XIIIController.Pawn.Location) < 0.0)
    00071	          && (vSize(Hitlocation - XIIIGameInfo(Level.Game).MapInfo.XIIIController.Pawn.Location) > 800.0)
    00072	          )
    00073	        {
    00074	          //Log("avoid spawning ImpactEmitterSFX as not seen & not really heard");
    00075	        }
    00076	        else
    00077	        {
    00078	          B = Spawn(ImpactEmitterMem,,, HitLocation+HitNormal, Rotator(HitNormal));
    00079	        }
    00080	        if (B != none)
    00081	        {
    00082	          B.NoiseMake(XIIIPawn(Owner), ImpactNoise);
    00083	          if ( bPlayHitSound )
    00084	          {
    00085	            bPlayHitSound = false;
    00086	            B.PlaySound(HitSoundMem, HitSoundType);
    00087	          }
    00088	        }
    00089	      }
    00090	      if ( (DecalProjectorClass != None) && (!Other.bNoImpact) )
    00091	//        ClientSpawnDecal(HitLocation, X);
    00092	        SpawnDecal(HitLocation, HitNormal);
    00093	    }
    00094	    else if ( (Other != self) && (Other != Owner) )
    00095	    {
    00096	      if ( XIIIPawn(Other) != none )
    00097	      {
    00098	        Loc = XIIIPawn(Other).GetDamageLocation( HitLocation, Other.Location - Instigator.Location );
    00099	        if ( Loc <= 1 )
    00100	        {
    00101	          if ( !Pawn(Other).bIsDead )
    00102	            bSpawnHeadBlood = true;
    00103	          Other.TakeDamage(ActualDamages, Pawn(Owner), HitLocation, 30000.0*X, MyDamageType);
    00104	          if ( Pawn(Other)!=none )
    00105	          {
    00106	            if ( (Level.Game != none) && (Level.Game.GoreLevel == 0) )
    00107	            {
    00108	              B = Spawn(class'XIIIDamageType'.default.BloodShotEmitterClass,Other,, HitLocation+HitNormal, Rotator(-X));
    00109	              if ( bSpawnHeadBlood && Pawn(Other).bIsDead )
    00110	              {
    00111	                if ( XIIIPawn(Other).LastBoneHit == 'X Head' )
    00112	                  Spawn(class'ProjectileInHead',Other,,HitLocation, rotator(-HitNormal));
    00113	              }
    00114	            }
    00115	            else
    00116	              B = Spawn(class'BulletDustEmitter',,, HitLocation+HitNormal, Rotator(HitNormal));
    00117
    00118	            if ( B != none )
    00119	              B.NoiseMake(XIIIPawn(Owner), SoftImpactNoise);
    00120	          }
    00121	        }
    00122	        else
    00123	        {
    00124	          if ( ImpactEmitterMem != none )
    00125	          {
    00126	            B = Spawn(ImpactEmitterMem,,, HitLocation+HitNormal, Rotator(HitNormal));
    00127	            if (B != none)
    00128	            {
    00129	              B.NoiseMake(XIIIPawn(Owner), ImpactNoise);
    00130	              if ( bPlayHitSound )
    00131	              {
    00132	                bPlayHitSound = false;
    00133	                B.PlaySound(HitSoundMem, HitSoundType);
    00134	              }
    00135	            }
    00136	          }
    00137	        }
    00138	      }
    00139	      else
    00140	      {
    00141	        Other.TakeDamage(ActualDamages, Pawn(Owner), HitLocation, 30000.0*X, MyDamageType);
    00142	        if ( ImpactEmitterMem != none )
    00143	        {
    00144	          B = Spawn(ImpactEmitterMem,,, HitLocation+HitNormal, Rotator(HitNormal));
    00145	          if (B!=none)
    00146	          {
    00147	            B.NoiseMake(XIIIPawn(Owner), ImpactNoise);
    00148	            if ( bPlayHitSound )
    00149	            {
    00150	              bPlayHitSound = false;
    00151	              B.PlaySound(HitSoundMem, HitSoundType);
    00152	            }
    00153	          }
    00154	        }
    00155	        if ( (DecalProjectorClass != None) && (!Other.bNoImpact) )
    00156	  //        ClientSpawnDecal(HitLocation, X);
    00157	          SpawnDecal(HitLocation, HitNormal);
    00158	      }
    00159	    }
    00160	}
    00161
    00162	//_____________________________________________________________________________
    00163	function SpawnDecal(vector HL, vector HN)
    00164	{
    00165	    if ( (DecalProjector == none) && (DecalProjectorClass != none) )
    00166	    {
    00167	      DecalProjector = Spawn(DecalProjectorClass,Owner,,HL + HN, rotator(-HN));
    00168	    }
    00169	    else if (DecalProjector != none)
    00170	    {
    00171	      DecalProjector.SetLocation( HL+HN );
    00172	      DecalProjector.SetRotation( rotator(-HN) );
    00173	      DecalProjector.UpdateScorch();
    00174	    }
    00175	}
    00176
    00177	//_____________________________________________________________________________
    00178	function SetUpImpactEmitter(Sound S)
    00179	{
    00180	    local string Str;
    00181	    local int i;
    00182
    00183	    // First get rid of the beginning of the sound name just to keep whet is needed
    00184	    Str = string(S);
    00185	    i = InStr(S, 'hPlay');
    00186	    Str = Right(Str, Len(Str) - i - 5);
    00187	//    Log("SetUpImpactEmitter Bullet --'"$Str$"'--");
    00188
    00189	    // Then switch/case the result to setup the SFX class
    00190	    switch (Str)
    00191	    {
    00192	      case "ImpBtE":
    00193	      case "ImpBtI":
    00194	      case "ImpCar":
    00195	      case "ImpMar":
    00196	      case "ImpTil":
    00197	      case "ImpPie":
    00198	        // Concrete type
    00199
    00200	        if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorch') )
    00201	        {
    00202	          DecalProjector.LifeSpan = 2.0+fRand();
    00203	          DecalProjector = none;
    00204	        }
    00205	        DecalProjectorClass = Class'XIII.BulletScorch';
    00206	        ImpactEmitterMem = class'BulletDustEmitter';
    00207	        break;
    00208	      case "ImpGra":
    00209	        // Gravel type
    00210	        if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorch') )
    00211	        {
    00212	          DecalProjector.LifeSpan = 2.0+fRand();
    00213	          DecalProjector = none;
    00214	        }
    00215	        DecalProjectorClass = Class'XIII.BulletScorch';
    00216	        ImpactEmitterMem = class'GravelDustEmitter';
    00217	        break;
    00218	      case "ImpBoiC":
    00219	      case "ImpBoiP":
    00220	      case "ImpPar":
    00221	      case "ImpFeu":
    00222	        // Wood type
    00223	        if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorchWood') )
    00224	        {
    00225	          DecalProjector.LifeSpan = 2.0+fRand();
    00226	          DecalProjector = none;
    00227	        }
    00228	        DecalProjectorClass = Class'XIII.BulletScorchWood';
    00229	        ImpactEmitterMem = class'WoodDustEmitter';
    00230	        break;
    00231	      case "ImpEau":
    00232	        // Water type (should not happen but maybe....)
    00233	        if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorch') )
    00234	        {
    00235	          DecalProjector.LifeSpan = 2.0+fRand();
    00236	          DecalProjector = none;
    00237	        }
    00238	        DecalProjectorClass = Class'XIII.BulletScorch';
    00239	        ImpactEmitterMem = class'BulletDustEmitter';
    00240	        break;
    00241	      case "ImpGla":
    00242	      case "ImpVer":
    00243	        // Glass type
    00244	        if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorchGlass') )
    00245
{ 00246 DecalProjector.LifeSpan = 2.0+fRand(); 00247 DecalProjector = none; 00248 } 00249 DecalProjectorClass = Class'XIII.BulletScorchGlass'; 00250 ImpactEmitterMem = class'GlassImpactEmitter'; 00251 break; 00252 case "ImpGri": 00253 case "ImpMet": 00254 case "ImpTol": 00255 // Metal type 00256 if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorchMetal') ) 00257 { 00258 DecalProjector.LifeSpan = 2.0+fRand(); 00259 DecalProjector = none; 00260 } 00261 DecalProjectorClass = Class'XIII.BulletScorchMetal'; 00262 ImpactEmitterMem = class'BulletMetalEmitter'; 00263 break; 00264 case "ImpHrb": 00265 // Grass Type 00266 if ( DecalProjector != none ) 00267 DecalProjector.LifeSpan = 2.0+fRand(); 00268 DecalProjector = none; 00269 DecalProjectorClass = none; 00270 ImpactEmitterMem = class'GrassDustEmitter'; 00271 break; 00272 case "ImpTer": 00273 // Earth type 00274 if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorch') ) 00275 { 00276 DecalProjector.LifeSpan = 2.0+fRand(); 00277 DecalProjector = none; 00278 } 00279 DecalProjectorClass = Class'XIII.BulletScorch'; 00280 ImpactEmitterMem = class'EarthDustEmitter'; 00281 break; 00282 case "ImpNei": 00283 // Snow 00284 if ( DecalProjector != none ) 00285 DecalProjector.LifeSpan = 2.0+fRand(); 00286 DecalProjector = none; 00287 DecalProjectorClass = none; 00288 ImpactEmitterMem = class'SnowDustEmitter'; 00289 break; 00290 case "ImpMol": 00291 case "ImpMoq": 00292 // Soft Types 00293 if ( DecalProjector != none ) 00294 DecalProjector.LifeSpan = 2.0+fRand(); 00295 DecalProjector = none; 00296 DecalProjectorClass = Class'XIII.BulletScorch'; 00297 ImpactEmitterMem = class'MoqDustEmitter'; 00298 break; 00299 case "ImpCdvr": 00300 // Body Type 00301 if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorchMetal') ) 00302 { 00303 DecalProjector.LifeSpan = 2.0+fRand(); 00304 DecalProjector = none; 00305 } 00306 DecalProjectorClass = Class'XIII.BulletScorchMetal'; 00307 ImpactEmitterMem = class'BloodShotEmitter'; 00308 break; 00309 case "ImpLin": 00310 default: 00311 // other types, not spawn any SFX 00312 if ( (DecalProjector != none) && (DecalProjector.Class != Class'XIII.BulletScorch') ) 00313 { 00314 DecalProjector.LifeSpan = 2.0+fRand(); 00315 DecalProjector = none; 00316 } 00317 DecalProjectorClass = Class'XIII.BulletScorch'; 00318 ImpactEmitterMem = class'BulletDustEmitter'; 00319 break; 00320 } 00321 } 00322 00323 event Destroyed() 00324 { 00325 Super.Destroyed(); 00326 if ( DecalProjector != none ) 00327 DecalProjector.Destroy(); 00328 } 00329 00330 00331 00332 defaultproperties 00333 { 00334 DecalProjectorClass=Class'XIII.BulletScorch' 00335 bDrawTracingBullets=True 00336 ImpactNoise=0.500000 00337 SoftImpactNoise=0.100000 00338 TraceType=16384 00339 HitSoundType=0 00340 TBTexture=Texture'XIIIMenu.SFX.TraceBullet1' 00341 fTraceFrequency=0.333330 00342 }

End Source Code