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

UTGame.UTCTFFlag


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
/**
 * Copyright 1998-2008 Epic Games, Inc. All Rights Reserved.
 */
class UTCTFFlag extends UTCarriedObject
	native
	abstract;

/** particle system to play when the flag respawns at home base */
var ParticleSystem RespawnEffect;
/** if true the flag is just starting to res out and needs its bright param ramped up*/
var bool bBringUpBright;
/** if true the bright param has peaked and now we need to phase the flag out */
var bool bBringDownFromBright;
/** The Skeletal Mesh of the flag */
var SkeletalMeshComponent SkelMesh;

var repnotify bool  bFadingOut;
var repnotify bool  bRespawning;
var array<MaterialInstanceConstant> MICArray;
var bool bWasClothEnabled;

var	vector	RunningClothVelClamp;
var	vector	HoverboardingClothVelClamp;

var ParticleSystemComponent SuccessfulCaptureSystem;

/** Hide flag if closer than this, to avoid camera clipping */
var float FlagMinViewDist;

/** The Flags's light environment */
var DynamicLightEnvironmentComponent LightEnvironment;

var float LastLocationPingTime;

replication
{
	if(Role == ROLE_AUTHORITY)
		bFadingOut, bRespawning;
}
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)
// (cpptext)


simulated event ReplicatedEvent(name VarName)
{
	if(VarName=='bFadingOut')
	{
		if(bFadingOut)
		{
			CustomFadeOutEffects();
		}
	}
	else if(VarName=='bRespawning')
	{
		if(bRespawning)
		{
			CustomRespawnEffects();
		}
	}
	else
	{
		Super.ReplicatedEvent(VarName);
	}
}


simulated function PostBeginPlay()
{
	local int i;
	local UTPlayerController UTPC;

	super.PostBeginPlay();
	for(i=0;i<SkelMesh.Materials.Length;++i)
	{
		MICArray.Insert(i,1);
		MICArray[i] = SkelMesh.CreateAndSetMaterialInstanceConstant(i);
	}

	//Make sure every local player with a hud has an update on the visibility of this flag
	ForEach LocalPlayerControllers(class'UTPlayerController', UTPC)
	{
		if (UTHUD(UTPC.myHUD) != None)
		{
			UTHUD(UTPC.myHUD).UpdateCTFFlagVisibility(self);
		}
	}
}


// @TODO: Make this native
simulated function Tick(float DeltaTime)
{
	local int i;
	local name TimerInUse;
	if(WorldInfo.NetMode != NM_DEDICATEDSERVER)
	{
		if(bFadingOut)
		{
			TimerInUse='CustomFadeOutEffects';
		}
		else if(bRespawning)
		{
			TimerInUse='bringUpBrightOff';
		}
		if(bBringUpBright)
		{
			for(i=0;i<MICArray.Length;++i)
			{
				MICArray[i].setScalarParameterValue('FlagBrightness',1 - (GetTimerRate(TimerInUse)-GetTimerCount(TimerInUse))/0.5);
			}
		}
		else if(bBringDownFromBright)
		{
			for(i=0;i<MICArray.Length;++i)
			{
				MICArray[i].setScalarParameterValue('FlagOpacity',(GetTimerRate(TimerInUse)-GetTimerCount(TimerInUse))/0.5);
			}
		}
	}
}


/** Update damping on the cloth sim based on what we are doing. */
simulated event OnBaseChainChanged()
{
	local UTPawn UTP;
	UTP = UTPawn(Base);

	if (UTP != None)
	{
		if(UTVehicle_Hoverboard(Base.Base) != None)
		{
			SkelMesh.bClothBaseVelClamp = TRUE;
			SkelMesh.ClothBaseVelClampRange = HoverboardingClothVelClamp;
			//`log("HOVERBOARD---------");
		}
		else if(UTVehicle_Hoverboard(OldBaseBase) != None)
		{
			SkelMesh.bClothBaseVelClamp = TRUE;
			SkelMesh.ClothBaseVelClampRange = RunningClothVelClamp;
			SkelMesh.SetAttachClothVertsToBaseBody(FALSE);
			//`log("RUNNING------");
		}

		// When pawn is holding flag, make sure attachments are updated in tick
		UTP.Mesh.bForceUpdateAttachmentsInTick = TRUE;
		SkelMesh.SetShadowParent(UTP.Mesh);
		ClearTimer( 'SetFlagDynamicLightToNotBeDynamic' );
		LightEnvironment.bDynamic = TRUE;
		//`log("PARENTING TO PAWN------");
	}
	else
	{
		SkelMesh.bClothBaseVelClamp = FALSE;
		SkelMesh.SetAttachClothVertsToBaseBody(FALSE);
		SkelMesh.SetShadowParent(None);
		LightEnvironment.bDynamic = TRUE;
		SetTimer( 5.0f, FALSE, 'SetFlagDynamicLightToNotBeDynamic' );
		//`log("DROPPED PARENTING TO SELF------");

		// When pawn is no longer holding flag, reset 'force update attachments' flag
		if (UTPawn(OldBase) != None)
		{
			UTPawn(OldBase).Mesh.bForceUpdateAttachmentsInTick = FALSE;
		}
	}
}


/** returns true if should be rendered for passed in player */
simulated function bool ShouldMinimapRenderFor(PlayerController PC)
{
	return bHome || (PC.PlayerReplicationInfo.Team != Team) || (WorldInfo.TimeSeconds - LastLocationPingTime < 5.0);
}


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

	if (HomeBase != None)
	{
		SetBase(HomeBase);
	}
}


// State transitions
function SetHolder(Controller C)
{
	local UTCTFSquadAI S;
	local UTPawn UTP;
	local UTBot B;

	// when the flag is picked up we need to set the flag translation so it doesn't stick in the ground
	SkelMesh.SetTranslation( vect(0.0,0.0,0.0) );
	UTP = UTPawn(C.Pawn);
	LightEnvironment.bDynamic = TRUE;
	SkelMesh.SetShadowParent( UTP.Mesh );

	ClearTimer( 'SetFlagDynamicLightToNotBeDynamic' );

	// AI Related
	B = UTBot(C);
	if ( B != None )
	{
		S = UTCTFSquadAI(B.Squad);
	}
	else if ( PlayerController(C) != None )
	{
		S = UTCTFSquadAI(UTTeamInfo(C.PlayerReplicationInfo.Team).AI.FindHumanSquad());
	}

	if ( S != None )
	{
		S.EnemyFlagTakenBy(C);
	}

	Super.SetHolder(C);
	if ( B != None )
	{
		B.SetMaxDesiredSpeed();
	}
}

function bool ValidHolder(Actor Other)
{
    local Controller C;

    if ( !Super.ValidHolder(Other) )
	{
		return false;
	}

    C = Pawn(Other).Controller;

	if ( WorldInfo.GRI.OnSameTeam(self,C) )
	{
		SameTeamTouch(c);
		return false;
	}

    return true;
}

function SameTeamTouch(Controller C)
{
}

/** Intended to have different flags override if they need custom effects such as material params set on a respawn */
simulated function CustomRespawnEffects()
{
	local int i;

	bRespawning = true;
	bFadingOut = false;
	ClearTimer('CustomFadeOutEffects');
	setTimer(1.0,false,'BringUpBrightOff');

	if (WorldInfo.NetMode != NM_DedicatedServer)
	{
		if (RespawnEffect != None)
		{
			WorldInfo.MyEmitterPool.SpawnEmitter(RespawnEffect, Location, Rotation, self);
		}

		bBringUpBright = true;
		bBringDownFromBright = false;
		for(i = 0;i < MICArray.Length; i++)
		{
			MICArray[i].setScalarParameterValue('FlagOpacity', 1.0f);
		}

		bWasClothEnabled = SkelMesh.bEnableClothSimulation;
		SkelMesh.SetEnableClothSimulation(false); // to prevent cloth flag from going nutty due to teleport
	}
}
simulated function bringUpBrightOff()
{
	local int i;

	if(WorldInfo.NetMode != NM_DEDICATEDSERVER)
	{
		bBringUpBright = false;

		for(i=0;i<MICArray.Length;++i)
		{
			MICArray[i].setScalarParameterValue('FlagBrightness',0.0f);
		}

		SkelMesh.SetEnableClothSimulation(bWasClothEnabled); // re-enable from above.
	}

	bRespawning = false;
}

/** intended to have different flags override if they need custom effects just before a flag is returned to it's base */
simulated function CustomFadeOutEffects()
{
	local int i;

	if(WorldInfo.NetMode != NM_DEDICATEDSERVER)
	{
		if(bBringUpBright) // we've been brought up to bright, so now fade down
		{
			bBringUpBright=false;
			bBringDownFromBright=true;
			for(i=0;i<MICArray.Length;++i)
			{
				MICArray[i].setScalarParameterValue('FlagBrightness',0.0f);
			}
		}
		else if(bBringDownFromBright) // we've done the whole sequence, so call super and don't do this any more
		{
			for(i=0;i<MICArray.Length;++i)
			{
				MICArray[i].setScalarParameterValue('FlagOpacity',1.0f);
			}
			bBringDownFromBright = false;
			return;
		}
		else // we haven't done anything, so bring up brights.
		{
			bBringUpBright=true;
		}

		setTimer(0.5,false,'CustomFadeOutEffects');
	}
}

// States
auto state Home
{
	ignores SendHome, Score, Drop;

	function BeginState(Name PreviousStateName)
	{
		// need to reset the flag skel mesh translation
		SetFlagPropertiesToStationaryFlagState();

		CustomRespawnEffects();
		Super.BeginState(PreviousStateName);

		if ( Team != None )
		{
			// note team is none at start of match, but flagstate is already correctly set
			UTGameReplicationInfo(WorldInfo.GRI).SetFlagHome(Team.TeamIndex);
		}

		HomeBase.SetAlarm(false);
		HomeBase.bForceNetUpdate = TRUE;
		bForceNetUpdate = TRUE;
		SetBase(HomeBase);
		HomeBase.ObjectiveChanged();
	}

	function EndState(Name NextStateName)
	{
		Super.EndState(NextStateName);
		HomeBase.SetAlarm(true);
		HomeBase.bForceNetUpdate = TRUE;
	}

	function SameTeamTouch(Controller C)
	{
		local UTCTFFlag flag;

		if (C.PlayerReplicationInfo.bHasFlag)
		{
			// Score!
			flag = UTCTFFlag(UTPlayerReplicationInfo(C.PlayerReplicationInfo).GetFlag());
			UTCTFGame(WorldInfo.Game).ScoreFlag(C, flag);
			SuccessfulCaptureSystem.SetActive(true);
			flag.Score();

			if (C.Pawn != None && UTBot(C) != None && UTBot(C).Squad.GetOrders() == 'Attack')
			{
				UTBot(C).Pawn.SetAnchor(HomeBase);
				UTBot(C).Squad.SetAlternatePathTo(UTCTFSquadAI(UTBot(C).Squad).EnemyFlag.HomeBase, UTBot(C));
			}
		}
	}
}

state Dropped
{
	ignores Drop;

	function SameTeamTouch(Controller c)
	{
		// returned flag
		UTCTFGame(WorldInfo.Game).ScoreFlag(C, self);
		SendHome(C);
	}

	function Timer() // TODO: Look into resetting scalars on endstate too, just in case picked up mid-fade
	{
		if(bFadingOut)
		{
			super.Timer();
			bFadingOut=false;
		}
		else
		{
			bFadingOut = true;
			CustomFadeOutEffects();
			SetTimer(1.0f);
		}

	}
}

/** need to reset the flag skel mesh translation **/
function Drop(optional Controller Killer)
{
	SetFlagPropertiesToStationaryFlagState();

	Super.Drop(Killer);
}


/**
 * This function will set the flag properties back to what they should be when the flag is stationary.  (i.e. dropped or at a flag base
 **/
function SetFlagPropertiesToStationaryFlagState()
{
	SkelMesh.SetTranslation( vect(0.0,0.0,-40.0) );
	LightEnvironment.bDynamic = TRUE;
	SkelMesh.SetShadowParent( None );
	SetTimer( 5.0f, FALSE, 'SetFlagDynamicLightToNotBeDynamic' );
}

/**
 * This is used to set the LightEnvironment to not be dynamic.
 * Basically when a flag is dropped we need to update the LightEnvironment and then set it to not update anymore.
 **/
function SetFlagDynamicLightToNotBeDynamic()
{
	ClearTimer( 'SetFlagDynamicLightToNotBeDynamic' );
	LightEnvironment.bDynamic = FALSE;
}

defaultproperties
{
   Begin Object Class=SkeletalMeshComponent Name=TheFlagSkelMesh ObjName=TheFlagSkelMesh Archetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
      bUpdateSkelWhenNotRendered=False
      bHasPhysicsAssetInstance=True
      bEnableClothSimulation=True
      bAutoFreezeClothWhenNotRendered=True
      ClothWind=(X=20.000000,Y=10.000000,Z=0.000000)
      LightEnvironment=DynamicLightEnvironmentComponent'UTGame.Default__UTCTFFlag:FlagLightEnvironment'
      bUseAsOccluder=False
      BlockRigidBody=True
      RBChannel=RBCC_Nothing
      RBCollideWithChannels=(Cloth=True)
      Translation=(X=0.000000,Y=0.000000,Z=-40.000000)
      Name="TheFlagSkelMesh"
      ObjectArchetype=SkeletalMeshComponent'Engine.Default__SkeletalMeshComponent'
   End Object
   SkelMesh=TheFlagSkelMesh
   RunningClothVelClamp=(X=500.000000,Y=500.000000,Z=200.000000)
   HoverboardingClothVelClamp=(X=300.000000,Y=300.000000,Z=200.000000)
   FlagMinViewDist=50.000000
   Begin Object Class=DynamicLightEnvironmentComponent Name=FlagLightEnvironment ObjName=FlagLightEnvironment Archetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
      bDynamic=False
      Name="FlagLightEnvironment"
      ObjectArchetype=DynamicLightEnvironmentComponent'Engine.Default__DynamicLightEnvironmentComponent'
   End Object
   LightEnvironment=FlagLightEnvironment
   LastLocationPingTime=-100.000000
   bHome=True
   bUseTeamColorForIcon=True
   HomeBaseOffset=(X=0.000000,Y=0.000000,Z=1.000000)
   MapSize=0.400000
   IconCoords=(U=843.000000,V=86.000000,UL=46.000000,VL=44.000000)
   GameObjBone3P="b_Spine2"
   GameObjOffset3P=(X=0.000000,Y=16.000000,Z=0.000000)
   GameObjRot3P=(Pitch=0,Yaw=16384,Roll=-16384)
   GameObjOffset1P=(X=-45.000000,Y=-8.000000,Z=30.000000)
   GameObjRot1P=(Pitch=0,Yaw=16384,Roll=-3640)
   Begin Object Class=PointLightComponent Name=FlagLightComponent ObjName=FlagLightComponent Archetype=PointLightComponent'Engine.Default__PointLightComponent'
      Radius=250.000000
      Brightness=5.000000
      CastShadows=False
      LightingChannels=(Dynamic=False,CompositeDynamic=False)
      Name="FlagLightComponent"
      ObjectArchetype=PointLightComponent'Engine.Default__PointLightComponent'
   End Object
   FlagLight=FlagLightComponent
   Begin Object Class=CylinderComponent Name=CollisionCylinder ObjName=CollisionCylinder Archetype=CylinderComponent'UTGame.Default__UTCarriedObject:CollisionCylinder'
      CollisionHeight=85.000000
      ObjectArchetype=CylinderComponent'UTGame.Default__UTCarriedObject:CollisionCylinder'
   End Object
   Components(0)=CollisionCylinder
   Components(1)=FlagLightComponent
   Components(2)=FlagLightEnvironment
   Components(3)=TheFlagSkelMesh
   bHardAttach=True
   bCollideActors=True
   NetPriority=3.000000
   CollisionComponent=CollisionCylinder
   Name="Default__UTCTFFlag"
   ObjectArchetype=UTCarriedObject'UTGame.Default__UTCarriedObject'
}

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