Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UTGame.UTVehicleWeapon


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
/**
 * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
 */

class UTVehicleWeapon extends UTWeapon
	abstract
	native(Vehicle)
	nativereplication
	dependson(UTPhysicalMaterialProperty);

/** Holds a link in to the Seats array in MyVehicle that represents this weapon */
var int SeatIndex;

/** Holds a link to the parent vehicle */
var RepNotify UTVehicle	MyVehicle;

/** Triggers that should be activated when a weapon fires */
var array<name>	FireTriggerTags, AltFireTriggerTags;

/** impact effects by material type */
var array<MaterialImpactEffect> ImpactEffects, AltImpactEffects;

/** default impact effect to use if a material specific one isn't found */
var MaterialImpactEffect DefaultImpactEffect, DefaultAltImpactEffect;

/** sound that is played when the bullets go whizzing past your head */
var SoundCue BulletWhip;

/** last time aim was correct, used for looking up GoodAimColor */
var float LastCorrectAimTime;

/** last time aim was incorrect, used for looking up GoodAimColor */
var float LastInCorrectAimTime;

var float CurrentCrosshairScaling;

/** cached max range of the weapon used for aiming traces */
var float AimTraceRange;

/** actors that the aiming trace should ignore */
var array<Actor> AimingTraceIgnoredActors;

/** This value is used to cap the maximum amount of "automatic" adjustment that will be made to a shot
    so that it will travel at the crosshair.  If the angle between the barrel aim and the player aim is
    less than this angle, it will be adjusted to fire at the crosshair.  The value is in radians */
var float MaxFinalAimAdjustment;

var bool bPlaySoundFromSocket;

/** used for client to tell server when zooming, as that is clientside
 * but on console it affects the controls so the server needs to know
 */
var bool bCurrentlyZoomed;

/**
 * If the weapon is attached to a socket that doesn't pitch with
 * player view, and should fire at the aimed pitch, then this should be enabled.
 */
var bool bIgnoreSocketPitchRotation;
/**
 * Same as above, but only allows for downward direction, for vehicles with 'bomber' like behavior.
 */
var bool bIgnoreDownwardPitch;

/** Vehicle class used for drawing kill icons */
var class<UTVehicle> VehicleClass;

/** for debugging turret aiming */
var bool bDebugTurret;

// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)

replication
{
	if (Role == ROLE_Authority && bNetInitial && bNetOwner)
		SeatIndex, MyVehicle;
}

simulated function PostBeginPlay()
{
	Super.PostBeginPlay();

	AimTraceRange = MaxRange();
}

simulated event ReplicatedEvent(name VarName)
{
	local UTVehicle_Deployable DeployableVehicle;

	if (VarName == 'MyVehicle')
	{
		DeployableVehicle = UTVehicle_Deployable(MyVehicle);
		if (DeployableVehicle != None && DeployableVehicle.IsDeployed())
		{
			NotifyVehicleDeployed();
		}
	}
	else
	{
		Super.ReplicatedEvent(VarName);
	}
}

/** checks if the weapon is actually capable of hitting the desired target, including trace test (used by crosshair)
 * if false because trace failed, RealAimPoint is set to what the trace hit
 */
simulated function bool CanHitDesiredTarget(vector SocketLocation, rotator SocketRotation, vector DesiredAimPoint, Actor TargetActor, out vector RealAimPoint)
{
	local int i;
	local array<Actor> IgnoredActors;
	local Actor HitActor;
	local vector HitLocation, HitNormal;
	local bool bResult;

	if ((Normal(DesiredAimPoint - SocketLocation) dot Normal(RealAimPoint - SocketLocation)) >= GetMaxFinalAimAdjustment())
	{
		// turn off bProjTarget on Actors we should ignore for the aiming trace
		for (i = 0; i < AimingTraceIgnoredActors.length; i++)
		{
			if (AimingTraceIgnoredActors[i] != None && AimingTraceIgnoredActors[i].bProjTarget)
			{
				AimingTraceIgnoredActors[i].bProjTarget = false;
				IgnoredActors[IgnoredActors.length] = AimingTraceIgnoredActors[i];
			}
		}
		// perform the trace
		HitActor = GetTraceOwner().Trace(HitLocation, HitNormal, DesiredAimPoint, SocketLocation, true,,, TRACEFLAG_Bullet);
		if (HitActor == None || HitActor == TargetActor)
		{
			bResult = true;
		}
		else
		{
			RealAimPoint = HitLocation;
		}
		// restore bProjTarget on Actors we turned it off for
		for (i = 0; i < IgnoredActors.length; i++)
		{
			IgnoredActors[i].bProjTarget = true;
		}
	}

	return bResult;
}


simulated static function DrawKillIcon(Canvas Canvas, float ScreenX, float ScreenY, float HUDScaleX, float HUDScaleY)
{
	if ( default.VehicleClass != None )
	{
		default.VehicleClass.static.DrawKillIcon(Canvas, ScreenX, ScreenY, HUDScaleX, HUDScaleY);
	}
}

simulated function GetCrosshairScaling(Hud HUD)
{
	if ( LastCorrectAimTime > LastInCorrectAimTime )
	{
		CrosshairScaling = FMax(CurrentCrosshairScaling - 0.6*(WorldInfo.TimeSeconds - LastInCorrectAimTime), 1.0);
	}
	else
	{
		CrosshairScaling = FMin(CurrentCrosshairScaling + 0.6*(WorldInfo.TimeSeconds - LastCorrectAimTime), 2.0);
	}
}
simulated function DrawWeaponCrosshair( Hud HUD )
{
	local vector SocketLocation, DesiredAimPoint, RealAimPoint;
	local rotator SocketRotation;
	local Actor TargetActor;
	local bool bAimIsCorrect;
	local float CenterSize;
	local UTPlayerController PC;

	PC = UTPlayerController(Instigator.Controller);
	if ( (PC != None) && PC.bSimpleCrosshair )
	{
		super.DrawWeaponCrosshair(HUD);
		return;
	}
	DesiredAimPoint = GetDesiredAimPoint(TargetActor);
	GetFireStartLocationAndRotation(SocketLocation, SocketRotation);
	RealAimPoint = SocketLocation + Vector(SocketRotation) * GetTraceRange();
	bAimIsCorrect = CanHitDesiredTarget(SocketLocation, SocketRotation, DesiredAimPoint, TargetActor, RealAimPoint);

	GetCrosshairScaling(Hud);
	CurrentCrosshairScaling = CrosshairScaling;

	CrosshairColor.A = 255.0 - 127.0 * (CrosshairScaling - 1.0);
	Super.DrawWeaponCrosshair(HUD);

	if (bAimIsCorrect)
	{
		// if recently aim became correct, show center part of crosshair
		CenterSize = UTHUD(HUD).ConfiguredCrosshairScaling * 20.0*HUD.Canvas.ClipX/1024;
		Hud.Canvas.SetPos(0.5*(HUD.Canvas.ClipX - CenterSize), 0.5*(HUD.Canvas.ClipY - CenterSize));
		Hud.Canvas.DrawTile(Texture2D'UI_HUD.HUD.UTCrossHairs', CenterSize, CenterSize, 380, 320, 26, 26);
		LastCorrectAimTime = WorldInfo.TimeSeconds;
	}
	else
	{
		LastInCorrectAimTime = WorldInfo.TimeSeconds;
		// show debug actual aim position of turret
		if ( bDebugTurret )
		{
			RealAimPoint = Hud.Canvas.Project(RealAimPoint);
			if (RealAimPoint.X < 12 || RealAimPoint.X > Hud.Canvas.ClipX-12)
			{
				RealAimPoint.X = Clamp(RealAimPoint.X,12,Hud.Canvas.ClipX-12);
			}
			if (RealAimPoint.Y < 12 || RealAimPoint.Y > Hud.Canvas.ClipY-12)
			{
				RealAimPoint.Y = Clamp(RealAimPoint.Y,12,Hud.Canvas.ClipY-12);
			}
			Hud.Canvas.SetPos(RealAimPoint.X - 10.0, RealAimPoint.Y - 10.0);
			CenterSize = UTHUD(HUD).ConfiguredCrosshairScaling * 21.0*HUD.Canvas.ClipX/1024;
			Hud.Canvas.DrawTile(Texture2D'UI_HUD.HUD.UTCrossHairs', CenterSize, CenterSize, 380, 320, 26, 26);
		}
	}

	DrawTowingIndicator(HUD,CenterSize);
}

simulated function DrawTowingIndicator(Hud HUD, Float CenterSize)
{

	if ( (myVehicle != None) && myVehicle.bIsTowingHoverboard )
	{
		// draw towing indicator
		CenterSize = UTHUD(HUD).ConfiguredCrosshairScaling * 64.0*HUD.Canvas.ClipX/1280;
		Hud.Canvas.SetPos(0.5*(HUD.Canvas.ClipX - CenterSize), 0.5*(HUD.Canvas.ClipY + CenterSize));
		Hud.Canvas.DrawTile(Texture2D'UI_HUD.HUD.UTCrossHairs', CenterSize, CenterSize, 256, 188, 64, 64);
	}
}

/** GetDesiredAimPoint - Returns the desired aim given the current controller
 * @param TargetActor (out) - if specified, set to the actor being aimed at
 * @return The location the controller is aiming at
 */
simulated event vector GetDesiredAimPoint(optional out Actor TargetActor)
{
	local vector CameraLocation, HitLocation, HitNormal, DesiredAimPoint;
	local rotator CameraRotation;
	local Controller C;
	local PlayerController PC;

	C = (MyVehicle != None) ? MyVehicle.Seats[SeatIndex].SeatPawn.Controller : None;

	PC = PlayerController(C);
	if (PC != None)
	{
		PC.GetPlayerViewPoint(CameraLocation, CameraRotation);
		DesiredAimPoint = CameraLocation + Vector(CameraRotation) * GetTraceRange();
		TargetActor = GetTraceOwner().Trace(HitLocation, HitNormal, DesiredAimPoint, CameraLocation);
		if (TargetActor != None)
		{
			DesiredAimPoint = HitLocation;
		}
	}
	else if ( C != None )
	{
		DesiredAimPoint = C.FocalPoint;
		TargetActor = C.Focus;
	}
	return DesiredAimPoint;
}

/** returns the location and rotation that the weapon's fire starts at */
simulated function GetFireStartLocationAndRotation(out vector StartLocation, out rotator StartRotation)
{
	if ( MyVehicle == None )
	{
		return;
	}
	if ( MyVehicle.Seats[SeatIndex].GunSocket.Length>0 )
	{
		MyVehicle.GetBarrelLocationAndRotation(SeatIndex, StartLocation, StartRotation);
	}
	else
	{
		StartLocation = MyVehicle.Location;
		StartRotation = MyVehicle.Rotation;
	}
}

/**
 * IsAimCorrect - Returns true if the turret associated with a given seat is aiming correctly
 *
 * @return TRUE if we can hit where the controller is aiming
 */
simulated event bool IsAimCorrect()
{
	local vector SocketLocation, DesiredAimPoint, RealAimPoint;
	local rotator SocketRotation;

	DesiredAimPoint = GetDesiredAimPoint();

	GetFireStartLocationAndRotation(SocketLocation, SocketRotation);

	RealAimPoint = SocketLocation + Vector(SocketRotation) * GetTraceRange();
	return ((Normal(DesiredAimPoint - SocketLocation) dot Normal(RealAimPoint - SocketLocation)) >= GetMaxFinalAimAdjustment());
}


simulated static function Name GetFireTriggerTag(int BarrelIndex, int FireMode)
{
	if (FireMode==0)
	{
		if (default.FireTriggerTags.Length > BarrelIndex)
		{
			return default.FireTriggerTags[BarrelIndex];
		}
	}
	else
	{
		if (default.AltFireTriggerTags.Length > BarrelIndex)
		{
			return default.AltFireTriggerTags[BarrelIndex];
		}
	}
	return '';
}

/**
 * Returns interval in seconds between each shot, for the firing state of FireModeNum firing mode.
 *
 * @param	FireModeNum	fire mode
 * @return	Period in seconds of firing mode
 */
simulated function float GetFireInterval( byte FireModeNum )
{
	local UTPawn UTP;

	if (Vehicle(Owner) != None)
	{
		UTP = UTPawn(Vehicle(Owner).Driver);
		if (UTP != None)
		{
			return (FireInterval[FireModeNum] * UTP.FireRateMultiplier);
		}
	}

	return Super.GetFireInterval(FireModeNum);
}

/** returns the impact effect that should be used for hits on the given actor and physical material */
simulated static function MaterialImpactEffect GetImpactEffect(Actor HitActor, PhysicalMaterial HitMaterial, byte FireModeNum)
{
	local int i;
	local UTPhysicalMaterialProperty PhysicalProperty;

	if (HitMaterial != None)
	{
		PhysicalProperty = UTPhysicalMaterialProperty(HitMaterial.GetPhysicalMaterialProperty(class'UTPhysicalMaterialProperty'));
	}
	if (FireModeNum > 0)
	{
		if (PhysicalProperty != None && PhysicalProperty.MaterialType != 'None')
		{
			i = default.AltImpactEffects.Find('MaterialType', PhysicalProperty.MaterialType);
			if (i != -1)
			{
				return default.AltImpactEffects[i];
			}

		}
		return default.DefaultAltImpactEffect;
	}
	else
	{
		if (PhysicalProperty != None && PhysicalProperty.MaterialType != 'None')
		{
			i = default.ImpactEffects.Find('MaterialType', PhysicalProperty.MaterialType);
			if (i != -1)
			{
				return default.ImpactEffects[i];
			}
		}
		return default.DefaultImpactEffect;
	}
}

simulated function AttachWeaponTo( SkeletalMeshComponent MeshCpnt, optional Name SocketName );
simulated function DetachWeapon();

simulated function Activate()
{
	// don't reactivate if already firing
	if (!IsFiring())
	{
		GotoState('Active');
	}
}

simulated function PutDownWeapon()
{
	GotoState('Inactive');
}

simulated function Vector GetPhysicalFireStartLoc(optional vector AimDir)
{
	if ( MyVehicle != none )
		return MyVehicle.GetPhysicalFireStartLoc(self);
	else
		return Location;
}

simulated function BeginFire(byte FireModeNum)
{
	local UTVehicle V;

	// allow the vehicle to override the call
	V = UTVehicle(Instigator);
	if (V == None || (!V.bIsDisabled && !V.OverrideBeginFire(FireModeNum)))
	{
		Super.BeginFire(FireModeNum);
	}
}

simulated function EndFire(byte FireModeNum)
{
	local UTVehicle V;

	// allow the vehicle to override the call
	V = UTVehicle(Instigator);
	if (V == None || !V.OverrideEndFire(FireModeNum))
	{
		Super.EndFire(FireModeNum);
	}
}

simulated function Rotator GetAdjustedAim( vector StartFireLoc )
{
	// Start the chain, see Pawn.GetAdjustedAimFor()
	// @note we don't add in spread here because UTVehicle::GetWeaponAim() assumes
	// that a return value of Instigator.Rotation or Instigator.Controller.Rotation means 'no adjustment', which spread interferes with
	return Instigator.GetAdjustedAimFor( Self, StartFireLoc );
}

/**
 * Create the projectile, but also increment the flash count for remote client effects.
 */
simulated function Projectile ProjectileFire()
{
	local Projectile SpawnedProjectile;

	IncrementFlashCount();

	if (Role==ROLE_Authority)
	{
		SpawnedProjectile = Spawn(GetProjectileClass(),,, MyVehicle.GetPhysicalFireStartLoc(self));

		if ( SpawnedProjectile != None )
		{
			SpawnedProjectile.Init( vector(AddSpread(MyVehicle.GetWeaponAim(self))) );
		}
	}
	return SpawnedProjectile;
}

/**
* Overriden to use vehicle starttrace/endtrace locations
* @returns position of trace start for instantfire()
*/
simulated function vector InstantFireStartTrace()
{
	return (MyVehicle != None) ? MyVehicle.GetPhysicalFireStartLoc(self) : vect(0,0,0);
}

/**
* @returns end trace position for instantfire()
*/
simulated function vector InstantFireEndTrace(vector StartTrace)
{
	if  (MyVehicle == None )
	{
		return StartTrace;
	}	
	return StartTrace + vector(AddSpread(MyVehicle.GetWeaponAim(self))) * GetTraceRange();;
}

simulated function Actor GetTraceOwner()
{
	return (MyVehicle != None) ? MyVehicle : Super.GetTraceOwner();
}

simulated function float GetMaxFinalAimAdjustment()
{
	return MaxFinalAimAdjustment;
}

/** notification that MyVehicle has been deployed/undeployed, since that often changes how its weapon works */
simulated function NotifyVehicleDeployed();
simulated function NotifyVehicleUndeployed();

simulated function WeaponPlaySound( SoundCue Sound, optional float NoiseLoudness )
{
	local int Barrel;
	local name Pivot;
	local vector Loc;
	local rotator Rot;
	if(bPlaySoundFromSocket && MyVehicle != none && MyVehicle.Mesh != none)
	{
		if( Sound == None || Instigator == None )
		{
			return;
		}
		Barrel = MyVehicle.GetBarrelIndex(SeatIndex);
		Pivot = MyVehicle.Seats[SeatIndex].GunSocket[Barrel];
		MyVehicle.Mesh.GetSocketWorldLocationAndRotation(Pivot, Loc, Rot);
		Instigator.PlaySound(Sound, false, true,false,Loc);
	}
	else
		super.WeaponPlaySound(Sound,NoiseLoudness);
}

simulated function EZoomState GetZoomedState()
{
	// override on server to use what the client told us
	if (Role == ROLE_Authority && Instigator != None && !Instigator.IsLocallyControlled())
	{
		return bCurrentlyZoomed ? ZST_Zoomed : ZST_NotZoomed;
	}
	else
	{
		return Super.GetZoomedState();
	}
}

reliable server function ServerSetZoom(bool bNowZoomed)
{
	bCurrentlyZoomed = bNowZoomed;
}

simulated function StartZoom(UTPlayerController PC)
{
	Super.StartZoom(PC);

	ServerSetZoom(true);
}

simulated function EndZoom(UTPlayerController PC)
{
	Super.EndZoom(PC);

	ServerSetZoom(false);
}

defaultproperties
{
   DefaultImpactEffect=(DurationOfDecal=4.000000,DecalDissolveParamName="DissolveAmount")
   DefaultAltImpactEffect=(DurationOfDecal=4.000000,DecalDissolveParamName="DissolveAmount")
   MaxFinalAimAdjustment=0.995000
   bExportMenuData=False
   ShotCost(0)=0
   ShotCost(1)=0
   CrossHairCoordinates=(U=320.000000,V=320.000000,UL=60.000000,VL=56.000000)
   InventoryGroup=100
   GroupWeight=0.500000
   aimerror=600.000000
   Begin Object Class=UTSkeletalMeshComponent Name=FirstPersonMesh ObjName=FirstPersonMesh Archetype=UTSkeletalMeshComponent'UTGame.Default__UTWeapon:FirstPersonMesh'
      ObjectArchetype=UTSkeletalMeshComponent'UTGame.Default__UTWeapon:FirstPersonMesh'
   End Object
   Mesh=FirstPersonMesh
   Begin Object Class=SkeletalMeshComponent Name=PickupMesh ObjName=PickupMesh Archetype=SkeletalMeshComponent'UTGame.Default__UTWeapon:PickupMesh'
      ObjectArchetype=SkeletalMeshComponent'UTGame.Default__UTWeapon:PickupMesh'
   End Object
   DroppedPickupMesh=PickupMesh
   PickupFactoryMesh=PickupMesh
   TickGroup=TG_PostAsyncWork
   Name="Default__UTVehicleWeapon"
   ObjectArchetype=UTWeapon'UTGame.Default__UTWeapon'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: tr 31-1-2018 17:18:28.000 - Creation time: sk 18-3-2018 10:01:28.531 - Created with UnCodeX