## XIII
Class MitraillTop

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

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Decoration
             |
             +--XIII.MitraillTop

Direct Known Subclasses:None

class MitraillTop
extends Engine.Decoration

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

Variables
`BulletTrail` | `BT` to dynamicload it
`Texture` | `Crosshair` initial direction to limit the movement of the gun.
`class` | `DecalProjector` Visual Impact to leave on geometry
`int` | `MaxShootAngle` Visual Impact to leave on geometry
`MitraillTrigger` | `MitTrig` the trigger that will be used to use me
`class` | `MyDamageType` Accuracy of shots
`rotator` | `OldRotation` initial direction to limit the movement of the gun.
`Pawn` | `PawnControlling` Accuracy of shots
`float` | `ShakeCycles` Added this param for weapon shakes (was not handled by default)
`float` | `ShakeMag` Accuracy of shots
`vector` | `ShakeSpeed` Accuracy of shots
`float` | `ShakeTime` Accuracy of shots
`vector` | `ShakeVert` Accuracy of shots
`string` | `StaticMeshName` to dynamicload it
`int` | `TeamID` to dynamicload it
`float` | `TraceAccuracy` Accuracy of shots
`float` | `TraceDist` how far instant hit trace fires go
`DownAMax,` | `UpAMax` Visual Impact to leave on geometry
`float` | `fGuardReactionDelay` Visual Impact to leave on geometry
`sound` | `hControlSound` Visual Impact to leave on geometry
`sound` | `hFireSound` Accuracy of shots
`vector` | `vInitDir` initial direction to limit the movement of the gun.

States
GoToWaitingPos

Function Summary
`void` | `DrawCrossHair(Canvas Canvas)`
    //_____________________________________________________________________________
`void` | `Fire()`
    //_____________________________________________________________________________
`void` | `InvincibleGuard()`
    //_____________________________________________________________________________
`void` | `LeaveControl()`
`void` | `PostBeginPlay()`
    //_____________________________________________________________________________
`void` | `ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)`
    //_____________________________________________________________________________
`void` | `RenderOverlays(Canvas C)`
    //_____________________________________________________________________________
`void` | `SpawnGuard(mesh GuardMesh)`
    //_____________________________________________________________________________
`void` | `TakeControl(Pawn PControl)`
    //_____________________________________________________________________________
`void` | `Timer()`
    //_____________________________________________________________________________
    //state Firing
    //{
`bool` | `TrySetRotation(rotator NewRot)`
    //_____________________________________________________________________________

State GoToWaitingPos Function Summary
`void` | `Tick(float deltatime)`
`void` | `BeginState()`

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class MitraillTop extends Decoration
    00005	    NotPlaceable;
    00006
    00007	var MitraillTrigger MitTrig;  // the trigger that will be used to use me
    00008	var vector vInitDir;          // initial direction to limit the movement of the gun.
    00009	var rotator OldRotation;
    00010	var texture Crosshair;
    00011	var float TraceDist;          // how far instant hit trace fires go
    00012	var float TraceAccuracy;      // Accuracy of shots
    00013	var class<DamageType> MyDamageType;
    00014	var Pawn PawnControlling;
    00015	var sound hFireSound;
    00016	var float ShakeMag;
    00017	var float ShakeTime;
    00018	var vector ShakeVert;
    00019	var vector ShakeSpeed;
    00020	var float ShakeCycles;        // Added this param for weapon shakes (was not handled by default)
    00021
    00022	var class<Projector> DecalProjector; // Visual Impact to leave on geometry
    00023	var int MaxShootAngle;
    00024	var int DownAMax, UpAMax;
    00025	var float fGuardReactionDelay;
    00026
    00027	var sound hControlSound;
    00028	var string StaticMeshName;  // to dynamicload it
    00029
    00030	var BulletTrail BT;
    00031	var int TeamID;
    00032
    00033	CONST TRACEFREQ=1.0;
    00034
    00035	//_____________________________________________________________________________
    00036	function PostBeginPlay()
    00037	{
    00038	//    Log("PostBeginPlay for "$self$" StaticMesh="$StaticMesh$" StaticMeshName="$StaticMeshName);
    00039	    if ( (StaticMesh == none) && (StaticMeshName != "") )
    00040	    {
    00041	      StaticMesh = StaticMesh(dynamicloadobject(StaticMeshName, class'StaticMesh'));
    00042	      default.StaticMesh = StaticMesh;
    00043	    }
    00044	    MitTrig = Spawn(class'MitraillTrigger',self,,Location);
    00045	    MitTrig.Tag = 'MitTrig'; // to avoid auto-activation of an item with the none tag when using the trigger
    00046	    vInitDir = vector(Rotation);
    00047	    TraceDist = TraceDist * 200 / 2.54;
    00048	}
    00049
    00050	//_____________________________________________________________________________
    00051	function SpawnGuard(mesh GuardMesh)
    00052	{
    00053	    Local vector V,W;
    00054
    00055	    PawnControlling = spawn(class'MitraillGuard',self,,Location,Rotation);
    00056	    if ( GuardMesh != none )
    00057	      PawnControlling.Mesh = GuardMesh;
    00058	    PawnControlling.ControlledActor = Self;
    00059	    TakeControl(PawnControlling);
    00060
    00061	    V = location;
    00062	    W = vector(Owner.Rotation);
    00063	    W.z = 0.0;
    00064	    W = Normal(W);
    00065	    V -= CollisionRadius * W;
    00066	    V -= PawnControlling.CollisionRadius * W * 2;
    00067	    V.z = PawnControlling.Location.z;
    00068	    PawnControlling.SetCollision(false,false,false);
    00069	    PawnControlling.SetLocation(V);
    00070
    00071	    if( Level.bLonePlayer )
    00072	        PawnControlling.SetCollision(true,true,true);
    00073
    00074	    MitraillGuard(PawnControlling).TeamID = TeamID;
    00075	    //log("++++++++++ MitraillTop"@TEamID@"++++++++++++");
    00076	}
    00077
    00078	//_____________________________________________________________________________
    00079	function InvincibleGuard()
    00080	{
    00081	    PawnControlling.controller.bGodMode = true;
    00082	    PawnControlling.bHidden = true;
    00083	}
    00084
    00085	//_____________________________________________________________________________
    00086	function bool TrySetRotation(rotator NewRot)
    00087	{
    00088	    local vector X,Y,Z;
    00089	    local vector U;
    00090	    local float f;
    00091	    local bool bReturn;
    00092
    00093	    NewRot.Pitch = NewRot.Pitch & 65535;
    00094	    If ((NewRot.Pitch > UpAMax) && (NewRot.Pitch < DownAMax))
    00095	    {
    00096	      If (NewRot.Pitch < 32768)
    00097	        NewRot.Pitch = UpAMAx;
    00098	      else
    00099	        NewRot.Pitch = DownAMax;
    00100	    }
    00101	    GetAxes(NewRot, X,Y,Z);
    00102	    bReturn = true;
    00103	    if ( (MaxShootAngle <= 1) && (X dot vInitdir < 0.0) )
    00104	    {
    00105	      return false;
    00106	    }
    00107	    else if ( (MaxShootAngle == 0) && (X dot vInitdir < 0.707) )
    00108	    {
    00109	      bReturn = false;
    00110	      U = vInitDir + normal((vInitDir cross X) cross vInitDir);
    00111	      U = normal(U);
    00112	      Y.z = 0;
    00113	      Y = normal(Y);
    00114	      Z = U cross Y;
    00115	      NewRot = OrthoRotation(U,Y,Z);
    00116	    }
    00117	    else if ( (MaxShootAngle == 1) && (X dot vInitdir < 0.08) )
    00118	    {
    00119	      bReturn = false;
    00120	      U = vInitDir * 0.08 + normal((vInitDir cross X) cross vInitDir);
    00121	      U = normal(U);
    00122	      Y.z = 0;
    00123	      Y = normal(Y);
    00124	      Z = U cross Y;
    00125	      NewRot = OrthoRotation(U,Y,Z);
    00126	    }
    00127	    SetRotation(NewRot);
    00128	    return bReturn;
    00129	}
    00130
    00131	//_____________________________________________________________________________
    00132	function Fire()
    00133	{
    00134	    SetTimer(0.05, false);
    00135	}
    00136
    00137	//_____________________________________________________________________________
    00138	function ProcessTraceHit(Actor Other, Vector HitLocation, Vector HitNormal, Vector X, Vector Y, Vector Z)
    00139	{
    00140	    Local int ActualDamages;
    00141	    local ImpactEmitter B;
    00142
    00143	    PlayFiringSound();
    00144
    00145	    if (PlayerController(PawnControlling.Controller)!=None)
    00146	      PlayerController(PawnControlling.Controller).ShakeView(ShakeTime, ShakeMag, ShakeVert, 120000, ShakeSpeed, ShakeCycles);
    00147
    00148	    if ( Other == None )
    00149	      return;
    00150
    00151	    if( Level.bLonePlayer )
    00152	        ActualDamages = 50;
    00153	    else
    00154	        ActualDamages = 80;
    00155	//    log(self@"shot for"@ActualDamages@"range"@VSize(HitLocation - W.Location)); // ::DBUG::
    00156
    00157	    if ( ActualDamages <= 0)
    00158	      return;
    00159
    00160	    if ( Other.bWorldGeometry )
    00161	    {
    00162	      B = Spawn(class'BulletDustEmitter',,, HitLocation+HitNormal, Rotator(HitNormal));
    00163	      if (B!=none)
    00164	        B.NoiseMake(PawnControlling, 0.787);
    00165	      if ( (DecalProjector != None) && (Level.NetMode != NM_DedicatedServer) )
    00166	        Spawn(DecalProjector,self,,HitLocation + HitNormal, rotator(X-HitNormal));
    00167	//        Spawn(DecalProjector,self,,HitLocation + HitNormal, rotator(-HitNormal));
    00168	    }
    00169	    else if ( (Other != self) && (Other != PawnControlling) && (Other != Owner) )
    00170	    {
    00171	      Other.TakeDamage(ActualDamages, PawnControlling, HitLocation, 30000.0*X, MyDamageType);
    00172	      if ( (Pawn(Other) != none) && (Level.Game != none) && (Level.Game.GoreLevel == 0) )
    00173	        B = Spawn(class'XIIIDamageType'.default.BloodShotEmitterClass,,, HitLocation+HitNormal, Rotator(-X));
    00174	      else
    00175	      {
    00176	        B = Spawn(class'BulletDustEmitter',,, HitLocation+HitNormal, Rotator(HitNormal));
    00177	      }
    00178	      if (B!=none)
    00179	        B.NoiseMake(PawnControlling, 0.262);
    00180	    }
    00181	}
    00182
    00183	//_____________________________________________________________________________
    00184	function TakeControl(Pawn PControl)
    00185	{
    00186	    TriggerEvent('PlayerTakeMG', self, PControl);
    00187	    PawnControlling = PControl;
    00188	    if ( PControl.IsPlayerPawn() )
    00189	      TraceAccuracy = 2.0;
    00190	    else
    00191	      TraceAccuracy = 120.0;
    00192	    PlaySound(hControlSound, 0);
    00193	}
    00194
    00195	function LeaveControl()
    00196	{
    00197	    TriggerEvent('PlayerLeaveMG', self, PawnControlling);
    00198	    PawnControlling = none;
    00199	    GotoState('GoToWaitingPos');
    00200	    PlaySound(hControlSound, 1);
    00201	}
    00202
    00203	//_____________________________________________________________________________
    00204	function DrawCrossHair( canvas Canvas)
    00205	{
    00206	    local float XLength;
    00207
    00208	    if ( CrossHair == None )
    00209	      return;
    00210	    XLength = 32.0;
    00211	    Canvas.bNoSmooth = False;
    00212	    Canvas.Style = ERenderStyle.STY_Translucent;
    00213	    Canvas.SetDrawColor(255,255,255,255);
    00214	    Canvas.SetPos((Canvas.ClipX - XLength)/2.0, (Canvas.ClipY - XLength)/2.0);
    00215	    Canvas.DrawTile(CrossHair, XLength, XLength, 0, 0, CrossHair.USize, CrossHair.VSize);
    00216
    00217	    Canvas.bNoSmooth = True;
    00218	    Canvas.Style = Style;
    00219	}
    00220
    00221	//_____________________________________________________________________________
    00222	function RenderOverlays(Canvas C)
    00223	{
    00224	    DrawCrossHair(C);
    00225	}
    00226
    00227	//_____________________________________________________________________________
    00228	//state Firing
    00229	//{
    00230	    function Timer()
    00231	    {
    00232	      local vector HitLocation, HitNormal, StartTrace, EndTrace, X,Y,Z;
    00233	      local actor Other;
    00234	      local material HitMat;
    00235
    00236	      if( level.bLonePlayer )
    00237	          XIIIPlayerController(PawnControlling.Controller).RumbleFX(5); // Use Magnum Rumble ?
    00238	      GetAxes(Rotation,X,Y,Z);
    00239	      StartTrace = Location + 20*X + 16*Z; // ~EyePosition
    00240	      X = vector(Rotation);
    00241
EndTrace = StartTrace + (Tracedist * X); // compensation of eye position to have hits in the reticle 00242 EndTrace += vRand() * fRand() * (TraceAccuracy/100.0) * TraceDist; 00243 // Other = Trace(HitLocation,HitNormal,EndTrace,StartTrace,True,vect(0,0,0),HitMat,TRACETYPE_DiscardIfCanShootThroughWithRayCastingWeapon); 00244 Other = Trace(HitLocation, HitNormal, EndTrace, StartTrace, True, vect(0,0,0), HitMat, TRACETYPE_DiscardIfCanShootThroughWithRayCastingWeapon|TRACETYPE_RequestBones); 00245 if ( XIIIPawn(Other) != none ) 00246 XIIIPawn(Other).LastBoneHit = GetLastTraceBone(); 00247 00248 ProcessTraceHit(Other, HitLocation, HitNormal, X,Y,Z); 00249 00250 ShakeVert=X*1.1; 00251 if( level.bLonePlayer ) 00252 PawnControlling.Controller.ShakeView(ShakeTime, ShakeMag, ShakeVert, 120000, ShakeSpeed, 2); 00253 00254 if ( PawnControlling.Pressingfire() ) 00255 SetTimer(0.05, false); 00256 // else 00257 // GotoState(''); 00258 if ( TRACEFREQ > fRand() ) 00259 { 00260 Spawn(class'BulletTraces', self,,Location + 100*X, Rotation); 00261 /* 00262 if (BT == none) 00263 { 00264 BT = Spawn(Class'BulletTrail',self,,Location, Rotation); 00265 BT.RibbonColor = BT.default.RibbonColor * fRand(); 00266 BT.Init(); 00267 // LOG("TRAIL Spawned="$BT); 00268 } 00269 if ( BT != none ) 00270 { 00271 BT.Reset(); 00272 // LOG("TRAIL Section="$Location@"to"@HitLocation); 00273 BT.AddSection(HitLocation); 00274 BT.AddSection(Location); 00275 } 00276 */ 00277 } 00278 } 00279 //} 00280 00281 //_____________________________________________________________________________ 00282 auto state GoToWaitingPos 00283 { 00284 function BeginState() 00285 { 00286 // Log("####"@self@" GoToWaitingPos BeginState"); 00287 } 00288 function Tick(float deltatime) 00289 { 00290 local rotator R; 00291 00292 // log("####"@self@"rotation="$rotation); 00293 R = Rotation; 00294 R.Pitch += 25000 * DeltaTime; 00295 TrySetRotation(R); 00296 // Log("Pitch ="$rotation.pitch); 00297 if (Oldrotation == Rotation) 00298 { 00299 GotoState(''); 00300 return; 00301 } 00302 OldRotation = Rotation; 00303 00304 } 00305 } 00306 00307 //_____________________________________________________________________________ 00308 simulated function PlayFiringSound() 00309 { 00310 PawnControlling.MakeNoise(2.62); 00311 PawnControlling.PlaySound(hFireSound, 0, int(PawnControlling.IsPlayerPawn())); 00312 } 00313 00314 // DrawType=DT_Mesh 00315 // Mesh=VertMesh'XIIIArmes.Mit127TopM' 00316 // DrawType=DT_StaticMesh 00317 00318 00319 defaultproperties 00320 { 00321 CrossHair=Texture'XIIIMenu.HUD.MireM60' 00322 TraceDist=300.000000 00323 TraceAccuracy=2.000000 00324 MyDamageType=Class'XIII.DTGunned' 00325 hFireSound=Sound'XIIIsound.Guns__M60Fire.M60Fire__hM60Fire' 00326 ShakeMag=300.000000 00327 shaketime=5.000000 00328 ShakeVert=(Z=5.000000) 00329 ShakeSpeed=(X=300.000000,Y=300.000000,Z=300.000000) 00330 ShakeCycles=1.000000 00331 DecalProjector=Class'XIII.BulletScorch' 00332 DownAMax=55000 00333 UpAMax=12000 00334 hControlSound=Sound'XIIIsound.Guns__MitSelWp.MitSelWp__hMitSelWp' 00335 StaticMeshName="MeshArmesPickup.Mit127Top" 00336 bStatic=False 00337 bInteractive=False 00338 DrawType=DT_StaticMesh 00339 }

End Source Code