Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Gameplay.Buggy

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
00578
00579

    // Buggy

    class Buggy extends HavokCar implements InventoryStationAccessControl
    	dependsOn(InventoryStationAccess)
    	native;

    cppText
    {
    	UBOOL IsNetRelevantFor(APlayerController* RealViewer, AActor* Viewer, FVector SrcLocation);
    }

    const DRIVER_INDEX = 0;
    const GUNNER_INDEX = 1;

    const FORCE_DEACTIVATE_DISTANCE = 5;
    const FORCE_DEACTIVATE_TIME = 4;

    var (Buggy) name turretBone;

    // inventory station
    var (Buggy) class<InventoryStationAccess> inventoryStationAccessClass;
    var (Buggy) vector inventoryStationOffset;
    var array<InventoryStationAccess> inventoryStationAccess;

    var VehicleMountedTurret turret;
    var class<VehicleMountedTurret> turretClass;

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

    var (Buggy) int numberInventoryStationPositions;
    var int maximumNumberInventoryStationPositions;

    var (Boost) class<Buggy> boostClass;
    var (Boost) class<HavokCarWheel> frontBoostWheelClass;
    var (Boost) class<HavokCarWheel> rearBoostWheelClass;

    var (Buggy) array<class<Weapon> > spawnDefaultWeapons;

    var vector forceDeactivatePosition;
    var float forceDeactivateTime;

    // keeps track of whether or not this vehicle has been registered as a respawn vehicle on TeamInfo
    var bool isRegisteredRespawnVehicle;

    replication
    {
    	reliable if (Role == ROLE_Authority)
    		turret;
    }

    function int getMinorPositionEntryIndex(int positionIndex)
    {
    	return getAccessIndex(positionIndex);
    }

    function spawnCharacter(Character character)
    {
    	local int inventoryStationPositionI;

    	super.spawnCharacter(character);

    	// put character into first available inventory station position
    	for (inventoryStationPositionI = 2; inventoryStationPositionI < positions.length; ++inventoryStationPositionI)
    	{
    		if (positions[inventoryStationPositionI].occupant == None)
    		{
    			occupantEnter(character, inventoryStationPositionI);
    			return;
    		}
    	}

    	warn("attempted to spawn character in invalid position");
    }

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

    	// initialise vehicle position data

    	// ... gunner
    	if ((positions[GUNNER_INDEX].toBePossessed == None) && (turret != None))
    		positions[GUNNER_INDEX].toBePossessed = turret;
    }

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

    	return None;
    }

    simulated event PostNetBeginPlay()
    {
    	local vector xAxis, yAxis, zAxis;
    	local int inventoryI;

        Super.PostNetBeginPlay();

    	// 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;

    	// create inventory stations
    	assert(numberInventoryStationPositions <= maximumNumberInventoryStationPositions);
    	positions.length = positions.length - (maximumNumberInventoryStationPositions - numberInventoryStationPositions);
    	if (Level.NetMode != NM_Client)
    	{
    		GetAxes(rotation, xAxis, yAxis, zAxis);
    		inventoryStationAccess.length = inventoryI;
    		for (inventoryI = 0; inventoryI < numberInventoryStationPositions; ++inventoryI)
    		{
    			inventoryStationAccess[inventoryI] = spawn(inventoryStationAccessClass, self, ,location +
    					inventoryStationOffset.X * xAxis + inventoryStationOffset.Y * yAxis + inventoryStationOffset.Z * zAxis);
    			inventoryStationAccess[inventoryI].setBase(self);
    			inventoryStationAccess[inventoryI].setCollision(false, false, false);
    			inventoryStationAccess[inventoryI].initialise(self);
    		}
    	}

    	// init AI
    	initGunnerAI( GUNNER_INDEX );
    }

    simulated event Destroyed()
    {
    	local int inventoryI;

    	// unregister vehicle respawn
    	if (Level.NetMode != NM_Client && m_team != None)
    	{
    		m_team.removeVehicleRespawn(self);
    		isRegisteredRespawnVehicle = false;
    	}

    	// clean up stuff attached to the buggy
    	if (Level.NetMode != NM_Client)
    	{
    		turret.destroy();
    	}

    	// this will destroy wheels & joints
    	Super.Destroyed();

    	for (inventoryI = 0; inventoryI < inventoryStationAccess.length; ++inventoryI)
    	{
    		if (inventoryStationAccess[inventoryI] != None)
    			inventoryStationAccess[inventoryI].destroy();
    	}

    	UnTriggerEffectEvent('ThrustingLoop');
    }

    function bool driverLeave(bool bForceLeave, int positionIndex)
    {
    	if (Super.driverLeave(bForceLeave, positionIndex))
    	{
    		updateRespawnState();
    		return true;
    	}
    	else
    		return false;
    }

    function accessRequired(Character accessor, InventoryStationAccess access, int armorIndex)
    {

    }

    function bool isAccessible(Character accessor)
    {
    	return true;
    }

    function bool isFunctional()
    {
    	return true;
    }

    function changeApplied(InventoryStationAccess access)
    {

    }

    function accessNoLongerRequired(Character accessor)
    {

    }

    // Inventory station usage.
    function bool directUsage()
    {
    	return false;
    }

    function bool isOnCharactersTeam(Character testCharacter)
    {
    	return team().isFriendly(testCharacter.team());
    }

    function occupantEnter(Character occupant, int positionIndex)
    {
    	super.occupantEnter(occupant, positionIndex);

    	inventoryStationEnterProcessing(occupant, positionIndex);
    }

    function occupantSwitchPosition(Character occupant, int targetPositionIndex)
    {
    	super.occupantSwitchPosition(occupant, targetPositionIndex);

    	inventoryStationEnterProcessing(occupant, targetPositionIndex);
    }

    function InventoryStationAccess getUnusedInventoryStation()
    {
    	local int accessI;

    	// find one that is not being used
    	for (accessI = 0; accessI < numberInventoryStationPositions; ++accessI)
    	{
    		if (inventoryStationAccess[accessI].currentUser == None)
    			return inventoryStationAccess[accessI];
    	}

    	return None;
    }

    function int getAccessIndex(int positionIndex)
    {
    	if (positions[positionIndex].type == VP_INVENTORY_STATION_ONE)
    		return 0;
    	else if (positions[positionIndex].type == VP_INVENTORY_STATION_TWO)
    		return 1;
    	else if (positions[positionIndex].type == VP_INVENTORY_STATION_THREE)
    		return 2;
    	else if (positions[positionIndex].type == VP_INVENTORY_STATION_FOUR)
    		return 3;
    	return -1;
    }

    function inventoryStationEnterProcessing(Character occupant, int positionIndex)
    {
    	local bool result;
    	local int accessI;

    	// handle inventory station case
    	accessI = getAccessIndex(positionIndex);
    	if (accessI >= 0)
    	{
    		result = inventoryStationAccess[accessI].usedByProcessing(occupant);
    		if (!result)
    			warn("failed to use invnetory station on buggy");
    	}

    	updateRespawnState();
    }

    function settledUpsideDownChanged()
    {
    	updateRespawnState();
    }

    function updateRespawnState()
    {
    	if (isRegisteredRespawnVehicle)
    	{
    		if (!canCharacterRespawnAt())
    		{
    			m_team.removeVehicleRespawn(self);
    			isRegisteredRespawnVehicle = false;
    		}
    	}
    	else
    	{
    		if (canCharacterRespawnAt())
    		{
    			m_team.addVehicleRespawn(self);
    			isRegisteredRespawnVehicle = true;
    		}
    	}
    }

    simulated function bool canCharacterRespawnAt()
    {
    	local int inventoryStationI;
    	local TeamInfo occupantTeam;

    	if (!isAlive())
    		return false;

    	// cannot respawn if being driven by an enemy
    	occupantTeam = getOccupantTeam();
    	if (occupantTeam != None && occupantTeam != m_team)
    		return false;

    	// cannot respawn if all inventory station slots are occupied
    	for (inventoryStationI = 2; inventoryStationI < 2 + numberInventoryStationPositions; ++inventoryStationI)
    		if (clientPositions[inventoryStationI].occupant == None)
    			break;
    	if (inventoryStationI == 2 + numberInventoryStationPositions)
    		return false;

    	// cannot respawn if settled upside down
    	if (bSettledUpsideDown)
    		return false;

    	// cannot respawn if yet to be driven
    	if (!bHasBeenOccupied)
    		return false;

    	return true;
    }

    function aboutToDie()
    {
    	kickInventoryStationUsers();

    	super.aboutToDie();
    }

    function aboutToSettleUpsideDown()
    {
    	kickInventoryStationUsers();

    	super.aboutToSettleUpsideDown();
    }

    function kickInventoryStationUsers()
    {
    	local int positionI;

    	// terminate access for any inventory station users
    	for (positionI = 2; positionI < positions.length; ++positionI)
    	{
    		if (positions[positionI].occupant != None)
    		{
    			PlayerCharacterController(positions[positionI].occupant.Controller).serverTerminateInventoryStationAccess();
    		}
    	}
    }

    // Inventory station access is complete.
    function accessFinished(Character user, bool returnToUsualMovment)
    {
    	local int positionI;

    	// get user position index
    	for (positionI = 0; positionI < positions.length; ++positionI)
    	{
    		if (positions[positionI].occupant == user)
    			break;
    	}

    	if (positionI == positions.length)
    	{
    		warn("inventory station user was not using this Buggy");
    		return;
    	}

    	if (returnToUsualMovment)
    		driverLeave(true, positionI);
    }

    simulated event vehicleUpdateParams()
    {
    	super.vehicleUpdateParams();

    	// apply turret camera changes
    	positions[GUNNER_INDEX].firstPersonCameraLocation = gunnerCameraOffset;
    	positions[GUNNER_INDEX].firstPersonWeaponLocation = gunnerWeaponOffset;
    }

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

    	return super.ShouldProjectileHit(projInstigator);
    }

    simulated function tick(float deltaSeconds)
    {
    	local array<class<HavokCarWheel> > localWheelClasses;

    	super.tick(deltaSeconds);

    	// deactivate if we have been stationary for a while
    	if (Physics == PHYS_Havok && HavokIsActive() && clientPositions[driverIndex].occupant == None)
    	{
    		if (VSizeSquared(Location - forceDeactivatePosition) < FORCE_DEACTIVATE_DISTANCE * FORCE_DEACTIVATE_DISTANCE)
    		{
    			if (Level.TimeSeconds > forceDeactivateTime)
    			{
    				HavokActivate(false);
    			}
    		}
    		else
    		{
    			forceDeactivatePosition = Location;
    			forceDeactivateTime = Level.TimeSeconds + FORCE_DEACTIVATE_TIME;
    		}
    	}
    	else
    	{
    		forceDeactivateTime = Level.TimeSeconds + FORCE_DEACTIVATE_TIME;
    	}

    	// boost processing
    	if (Physics == PHYS_Havok)
    	{
    		if (ThrustInput > 0.5 && gear != -1)
    		{
    			if (currentSwitchClass != boostClass)
    			{
    				localWheelClasses[leftFrontWheelIndex] = frontBoostWheelClass;
    				localWheelClasses[rightFrontWheelIndex] = frontBoostWheelClass;
    				localWheelClasses[leftRearWheelIndex] = rearBoostWheelClass;
    				localWheelClasses[rightRearWheelIndex] = rearBoostWheelClass;
    				switchWheelClasses(localWheelClasses);
    				switchClass(boostClass);

    				TriggerEffectEvent('ThrustingLoop');
    			}
    		}
    		else
    		{
    			if (currentSwitchClass != None && currentSwitchClass != class)
    			{
    				switchWheelClasses(havokCarWheelClasses);
    				switchClass(class);

    				UnTriggerEffectEvent('ThrustingLoop');
    			}
    		}
    	}
    }

    //
    simulated function bool InventoryCalcView(out actor viewActor, out vector cameraLocation, out rotator cameraRotation)
    {
    	local vector lookAt;
    	local vector HitLocation, HitNormal, OffsetVector;

    	// always third person
    	ViewActor = self;

    	// calculate camera look at position
    	cameraRotation = cameraRotation;
    	cameraRotation.Roll = 0;
    	cameraRotation.Pitch = 0;

    	if(cameraRotation.yaw != Rotation.yaw)
    	{
    		if(cameraRotation.yaw > Rotation.yaw)
    			cameraRotation.yaw -= (cameraRotation.yaw - Rotation.yaw) * 0.2;
    		else
    			cameraRotation.yaw += ( Rotation.yaw - cameraRotation.yaw) * 0.2;
    	}

    	lookAt = Location + (TPCameraLookat >> cameraRotation);

    	// calculate camera location
    	OffsetVector = vect(0, 0, 0);
    	OffsetVector.X = -1.0 * TPCameraDistance;
    	CameraLocation = lookAt + (OffsetVector >> cameraRotation);

    	// ... handle case of obstruction between vehicle and camera location
    	if (cameraTrace(HitLocation, HitNormal, CameraLocation, Location, false, vect(10, 10, 10)) != None)
    		CameraLocation = HitLocation;

    	return true;
    }

    simulated function bool getCurrentLoadoutWeapons(out InventoryStationAccess.InventoryStationLoadout weaponLoadout, Character user)
    {
    	local int i;

    	if (!user.bSpawningAtVehicle)
    		return false;

    	for(i = 0; i < 10; ++i)
    		weaponLoadout.weapons[i].weaponClass = None;

    	for (i = 0; i < class'Character'.const.NUM_WEAPON_SLOTS && i < spawnDefaultWeapons.length; ++i)
    	{
    		weaponLoadout.weapons[i].weaponClass = spawnDefaultWeapons[i];
    	}

    	return true;
    }

    defaultproperties
    {
    	DrawType=DT_Mesh
    	Mesh=SkeletalMesh'Vehicles.Buggy'

    	DrawScale=1.0

    	Gear=1
    	StopThreshold=40

    	ChassisMass=750

    	AirSpeed = 5000

    	Health=800

    	bDrawDriverInTP = true

    	rootBone=Buggy

    	inventoryStationAccessClass = class'Gameplay.InventoryStationAccess'
    	inventoryStationOffset = (X=-250,Y=0,Z=150)

    	// inventory station positions must be last in array
    	positions(0)=(type=VP_DRIVER,hideOccupant=false,occupantControllerState=TribesPlayerDriving,thirdPersonCamera=true,occupantAnimation=Buggy_Stand,occupantConnection=character,enterAnimation=HatchClosing,occupiedAnimation=HatchClosed,unoccupiedAnimation=HatchOpen,exitAnimation=HatchOpening,ManifestXPosition=50,ManifestYPosition=20)
    	positions(1)=(type=VP_GUNNER,hideOccupant=true,occupantControllerState=PlayerVehicleTurreting,thirdPersonCamera=false,ManifestXPosition=30,ManifestYPosition=20)
    	positions(2)=(type=VP_INVENTORY_STATION_ONE,hideOccupant=true,thirdPersonCamera=false,ManifestXPosition=33,ManifestYPosition=53,bNotLabelledInManifest=true)
    	positions(3)=(type=VP_INVENTORY_STATION_TWO,hideOccupant=true,thirdPersonCamera=false,ManifestXPosition=33,ManifestYPosition=67,bNotLabelledInManifest=true)
    	positions(4)=(type=VP_INVENTORY_STATION_THREE,hideOccupant=true,thirdPersonCamera=false,ManifestXPosition=47,ManifestYPosition=53,bNotLabelledInManifest=true)
    	positions(5)=(type=VP_INVENTORY_STATION_FOUR,hideOccupant=true,thirdPersonCamera=false,ManifestXPosition=47,ManifestYPosition=67,bNotLabelledInManifest=true)

    	turretClass = class'Gameplay.BuggyMountedTurret'
    	gunnerWeaponClass = class'Gameplay.AntiAircraftWeapon'
    	turretBone = turret
    	gunnerCameraOffset = (X=0,Y=0,Z=50)
    	gunnerWeaponOffset = (X=0,Y=0,Z=25)
    	gunnerMaximumPitch = 10000
    	gunnerMinimumPitch = -3000

    	motorClass = class'BuggyMotor'

    	HavokDataClass = class'BuggyHavokData'

    	numberInventoryStationPositions = 4
    	maximumNumberInventoryStationPositions = 4

    	gunnerClientTurnRate = 30000

    	flipTriggers(0)=(radius=400,height=400,offset=(X=0,Y=0,Z=0))

    	collisionDamageMagnitudeScale = 0.00075

    	gunnerAITurnRate = 12000

    	ManifestLayoutMaterial = Texture'HUD.RoverSchematic';

    	driveYawCoefficient = 0.1

    	bEnableHavokBackstep = true

    	localizedName = "rover"

    	bVehicleCameraTrace = true

    	vehicleCameraTraceExtents = (X=10,Y=10,Z=10)
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: ne 17.10.2004 13:27:40.000 - Creation time: st 23.5.2018 00:10:42.548 - Created with UnCodeX