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

Gameplay.Tank


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
class Tank extends TreadVehicle
	placeable
	native;

const DRIVER_INDEX = 0;
const GUNNER_INDEX = 1;

cpptext
{
	virtual FVector GetViewDirection();

	void TickAuthoritative(float deltaSeconds);
}

var vector cannonOffset;
var vector turretOffset;

var rotator cannonWorldSpaceNoRollRotation;
var rotator cannonVehicleSpaceRotation;

var (Tank) float cannonMinimumPitch;
var (Tank) float cannonMaximumPitch;

var float boostAvailableTime;
var (Tank) float timeBetweenBoosts;
var (Tank) float boostAngle;
var (Tank) float boostStrength;
var (Tank) float boostUpStrength;
var (Tank) float boostUpDuration;
var bool boostInProgress;
var float boostSecondStageTime;

var VehicleMountedTurret turret;
var class<VehicleMountedTurret> turretClass;
var name turretBone;

var (Tank) vector gunnerCameraOffset;
var (Tank) vector gunnerWeaponOffset;
var (Tank) class<Weapon> gunnerWeaponClass;
var (Tank) float gunnerMaximumPitch;
var (Tank) float gunnerMinimumPitch;
var (Tank) float gunnerClientTurnRate;
var (Tank) float gunnerAITurnRate;

var (Tank) float cannonAITurnRate;
var (Tank) float cannonClientTurnRate;

var rotator cannonTargetRotation;
var rotator cannonDisplayVehicleSpaceRotation;

var bool localBoostEventSignal;
var bool boostEventSignal;

var const bool gripping;

var bool bCanHitTarget;

var rotator currentViewRotation;

var int boostChannel;
var float boostOpenAnimationLength;
var bool openAnimationPlayed;
var bool closeAnimationPlayed;
var float boostCloseTime;
var (Tank) float boostEffectDuration;

var int gripAnimationChannel;
var name gripAnimation;
var (Tank) float gripAnimationBlendTime;

var (Tank) float landingEffectAirTime;
var int landingChannel;

var float lastTreadContactTime;

var int throttleForwardAndGroundContactIndex;

replication
{
	reliable if (!bNetOwner && Role == ROLE_Authority)
		cannonVehicleSpaceRotation;

	reliable if (Role == ROLE_Authority)
		boostEventSignal;
}

simulated native function setGripping(bool grippingEnabled);

simulated function initialiseEffects()
{
	super.initialiseEffects();

	addEffect('throttleForwardAndGroundContact', false, throttleForwardAndGroundContactIndex);
}

simulated function bool isEffectCauserActive(int effectCauserIndex)
{
	switch (effectCauserIndex)
	{
	case throttleForwardAndGroundContactIndex:
		return (ThrottleInput > 0) && (leftTreadContact || rightTreadContact);
	}

	return super.isEffectCauserActive(effectCauserIndex);
}

simulated event PostNetBeginPlay()
{
	Super.PostNetBeginPlay();

	turretOffset = getBoneCoords('tankTurret', true).origin - Location;
	turretOffset = turretOffset << Rotation;
	cannonOffset = getBoneCoords('cannon', true).origin - Location - turretOffset;

	// initialise vehicle position data

	// ... gunner
	if (Level.NetMode != NM_Client)
	{
		// ... turret
		turret = spawn(turretClass, self, , getBoneCoords(turretBone, true).origin, rotation);
		assert(turret != None);
		turret.SetBase(self);
		turret.setTeam(team());
		positions[GUNNER_INDEX].toBePossessed = turret;
		turret.initialise(gunnerWeaponClass, turretBone, gunnerMaximumPitch, gunnerMinimumPitch, false, 0, 0, true, gunnerClientTurnRate,
				gunnerAITurnRate);
	}
	positions[GUNNER_INDEX].firstPersonCameraLocation = gunnerCameraOffset;
	positions[GUNNER_INDEX].firstPersonWeaponLocation = gunnerWeaponOffset;

	// init AI
	initGunnerAI( GUNNER_INDEX );

	// setup boost animation channel
	AnimBlendParams(2, 1);

	boostOpenAnimationLength = GetAnimLength('jetopen');
}

simulated function PostNetReceive()
{
	super.PostNetReceive();

	// handle the boost effect
	if (boostEventSignal != localBoostEventSignal)
	{
		TriggerEffectEvent('TankBoost');
		localBoostEventSignal = boostEventSignal;
		boostAvailableTime = Level.TimeSeconds + timeBetweenBoosts;
		boostCloseTime = Level.TimeSeconds + boostEffectDuration;
		closeAnimationPlayed = false;
	}
}

simulated function Material getTeamSkin()
{
	if (m_team != None)
		return m_team.tankSkin;

	return None;
}

simulated function getThirdPersonEquippableAttachment(Equippable subject, out Rook attachTo, out name boneName)
{
	attachTo = self;
	boneName = 'cannon';
}

function vector getProjectileSpawnLocation()
{
	local vector workLocation;
	local rotator workRotation;

	// cannot simply do a getBoneCoords here becuase this code will needs to run on dedicated server
	workLocation = driverWeapon.projectileSpawnOffset;
	workRotation = cannonDisplayVehicleSpaceRotation;
	workRotation.Yaw = 0;
	workLocation = (workLocation >> workRotation);
	workLocation += cannonOffset;
	workRotation = cannonDisplayVehicleSpaceRotation;
	workRotation.Pitch = 0;
	workLocation = (workLocation >> workRotation);
	workLocation += turretOffset;
	workLocation = (workLocation >> Rotation);
	workLocation += Location;
	return workLocation;
}

simulated function applyOutput()
{
	local vector boostImpulse;

	super.applyOutput();

	// boost processing
	if (Role == ROLE_Authority && Level.TimeSeconds > boostAvailableTime && ThrustInput > 0.5)
	{
		// apply first stage
		boostImpulse = vect(0, 0, 1);
		boostImpulse *= boostUpStrength;
		HavokImpartCOMImpulse(boostImpulse);

		boostCloseTime = Level.TimeSeconds + boostEffectDuration;
		closeAnimationPlayed = false;

		// update boost available time
		boostAvailableTime = Level.TimeSeconds + timeBetweenBoosts;

		boostSecondStageTime = Level.TimeSeconds + boostUpDuration;
		boostInProgress = true;

		// effect processing
		boostEventSignal = !boostEventSignal;
		TriggerEffectEvent('TankBoost');
	}
}

simulated function playerMoveProcessing(float deltaTime)
{
	super.playerMoveProcessing(deltaTime);
}

simulated function rotator getViewRotation()
{
	// AI case
	if (controller != None && !controller.bIsPlayer)
		return QuatToRotator(QuatProduct(QuatFromRotator(cannonDisplayVehicleSpaceRotation), QuatFromRotator(rotation)));

	return currentViewRotation;
}

function setViewRotation(Rotator r)
{
	cannonTargetRotation = r;
}

simulated function tick(float deltaSeconds)
{
	local rotator workRotation;
	local PlayerCharacterController playerController;
	local PlayerCharacterController.DynamicTurretRotationProcessingOutput output;
	local vector boostImpulse;

	super.tick(deltaSeconds);

	// In the following code the player driving the tank uses his rotation which may not be the exact same rotation the server currently
	// has. Is the reduced latency offered by the technique a overcome the inaccuracy introduced?

	// if we are the server or the player controlling the tank update the cannon rotation based on the controller rotation
	playerController = PlayerCharacterController(controller);
	if ((driverWeapon != None) &&
			// player case
			((playerController != None) && ((Level.GetLocalPlayerController() == playerController) || (ROLE >= ROLE_Authority))) ||
			// ai case
			((controller != None) && (!controller.bIsPlayer))
			)
	{
		if (controller.bIsPlayer)
			currentViewRotation = playerController.Rotation;
		else
			currentViewRotation = cannonTargetRotation;

		// position turret based on raw rotation
		output = class'PlayerCharacterController'.static.dynamicTurretRotationProcessing(currentViewRotation,
				Rotation, cannonMinimumPitch, cannonMaximumPitch, false);
		cannonWorldSpaceNoRollRotation = output.worldSpaceNoRollRotation;
		cannonVehicleSpaceRotation = output.vehicleSpaceRotation;

		// aim adjust rotation
		if (controller.bIsPlayer)
		{
			currentViewRotation = getAimAdjustedViewRotation(playerController, getProjectileSpawnLocation(), driverIndex);
			output = class'PlayerCharacterController'.static.dynamicTurretRotationProcessing(currentViewRotation,
					Rotation, cannonMinimumPitch, cannonMaximumPitch, false);

			// if we are constrained do not aim adjust the rotation
			if (currentViewRotation != output.worldSpaceNoRollRotation)
			{
				bCanHitTarget = false;
				currentViewRotation = cannonWorldSpaceNoRollRotation;
			}
			else
			{
				bCanHitTarget = true;
			}
		}
	}

	// update cannon display rotation
	if ((playerController != None) && ((Level.GetLocalPlayerController() == playerController) || (ROLE >= ROLE_Authority)))
	{
		// authoritative player case
		cannonDisplayVehicleSpaceRotation = cannonVehicleSpaceRotation;
	}
	else if (controller != None && !controller.bIsPlayer)
	{
		// ai case
		cannonDisplayVehicleSpaceRotation = interpolateRotation(cannonDisplayVehicleSpaceRotation, cannonVehicleSpaceRotation,
				cannonAITurnRate, deltaSeconds);
	}
	else if (clientPositions[driverIndex].occupant != None)
	{
		// other client case
		cannonDisplayVehicleSpaceRotation = interpolateRotation(cannonDisplayVehicleSpaceRotation, cannonVehicleSpaceRotation,
				cannonClientTurnRate, deltaSeconds);
	}
	

	// rotate cannon
	
	// ... base
	workRotation = rot(0, 0, 0);
	workRotation.Pitch = cannonDisplayVehicleSpaceRotation.Yaw;
	setBoneDirection('tankturret', workRotation, , , 2);

	// ... barrel
	workRotation = rot(0, 0, 0);
	workRotation.Yaw = -cannonDisplayVehicleSpaceRotation.Pitch;
	if (driverWeapon != None)
		driverWeapon.setBoneDirection('tankgun', workRotation, , , 2);

	// gripping processing processing
	if (DiveInput)
	{
		if (!gripping)
			setGripping(true);
	}
	else
	{
		if (gripping)
			setGripping(false);
	}

	// boost processing
	if (Role == ROLE_Authority && boostInProgress && Level.TimeSeconds > boostSecondStageTime)
	{
		// apply second stage
		boostImpulse = vect(1, 0, 0) >> Rotation;
		boostImpulse.Z = 0;
		boostImpulse = Normal(boostImpulse);
		boostImpulse.Z = tan(boostAngle);
		boostImpulse = Normal(boostImpulse);
		boostImpulse *= boostStrength;
		HavokImpartCOMImpulse(boostImpulse);

		boostInProgress = false;
	}

	// boost animation
	if (Level.TimeSeconds + boostOpenAnimationLength > boostAvailableTime && !openAnimationPlayed)
	{
		PlayAnim('jetopen', , , boostChannel);
		openAnimationPlayed = true;
	}
	if (Level.TimeSeconds > boostCloseTime && !closeAnimationPlayed)
	{
		PlayAnim('jetclose', , , boostChannel);
		closeAnimationPlayed = true;
		openAnimationPlayed = false;
	}

	// check if need to play landing effect
	if (Level.TimeSeconds - lastTreadContactTime > landingEffectAirTime && (leftTreadContact || rightTreadContact) &&
			!IsAnimating(landingChannel))
	{
		PlayAnim('landing', , , landingChannel);
		TriggerEffectEvent('Landed');
	}

	// update lastTreadContactTime
	if (leftTreadContact || rightTreadContact)
		lastTreadContactTime = Level.TimeSeconds;
}

simulated function rotator getAimAdjustedViewRotation(PlayerController pc, Vector fireLocation, int positionIndex)
{
	local Vector startLocation;
	local Rotator workRotation;
	local Vector hitLocation;

	// calculate trace start as camera look at point
	workRotation = pc.rotation;
	workRotation.Roll = 0;
	if (!positions[positionIndex].lookAtInheritPitch)
		workRotation.Pitch = 0;
	startLocation = positions[positionIndex].toBePossessed.Location + (TPCameraLookat >> workRotation);

	driverWeapon.aimTrace(hitLocation, startLocation, Vector(pc.rotation));

	return Rotator(hitLocation - fireLocation);
}

simulated event bool ShouldProjectileHit(Actor projInstigator)
{
	// do not collide if it originated from us
	if (turret == projInstigator)
		return false;

	return super.ShouldProjectileHit(projInstigator);
}

simulated event destroyed()
{
	// clean up stuff attached to the tank
	if (Level.NetMode != NM_Client)
		turret.destroy();

	super.destroyed();
}

simulated event Vector unifiedGetNaturalCOMPosition()
{
	return Location;
}

defaultProperties
{
	DrawType = DT_Mesh
	Mesh = SkeletalMesh'Vehicles.Tank'

	HavokDataClass = class'TankHavokData'

	positions(0)=(type=VP_DRIVER,hideOccupant=true,occupantControllerState=TribesPlayerDriving,thirdPersonCamera=true,lookAtInheritPitch=false)
	positions(1)=(type=VP_GUNNER,hideOccupant=true,occupantControllerState=PlayerVehicleTurreting,thirdPersonCamera=false)

	driverWeaponClass=class'TankWeapon'

	timeBetweenBoosts = 2

	stayUprightEnabled = true
	stayUprightDamping = 0.9
	stayUprightStrength = 30

	boostAngle = 0.785
	boostStrength = 5000000
	boostUpStrength = 9000000
	boostUpDuration = 1

	cannonMaximumPitch = 10000
	cannonMinimumPitch = -3000

	turretBone = gunner

	gunnerMaximumPitch = 10000
	gunnerMinimumPitch = -3000
	gunnerClientTurnRate = 30000

	turretClass = class'TankMountedTurret'

	gunnerWeaponClass = class'TankGunnerWeapon'

	bCollisionDamageEnabled = false

	gripping = false

	gunnerAITurnRate = 12000

	motorClass = class'TankMotor'

	gunnerCameraOffset = (X=0,Y=0,Z=50)
	gunnerWeaponOffset = (X=0,Y=0,Z=25)

	maximumYawChange = 450

	cannonAITurnRate = 12000
	cannonClientTurnRate = 24000

	stopForEnemies = false

	driveYawCoefficient = 0.1

	cornerSlowDownSpeedCoefficient = 1000000

	boostChannel = 2

	boostEffectDuration = 0.5

	closeAnimationPlayed = true

	gripAnimationChannel = 4
	gripAnimation = ski
	gripAnimationBlendTime = 0.5

	driveThrottleCoefficient = 0.13

	minimumNavigationThrottle = 0.5

	localizedName = "jump tank"

	landingChannel = 0
	landingEffectAirTime = 1

	retriggerEffectEvents = true

	bVehicleCameraTrace = true

	inverseCosUprightAngle = 0.85
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:28.000 - Creation time: st 23.5.2018 00:10:47.495 - Created with UnCodeX