XIDCine
Class HelicoDeco

source: C:\XIII\XIDCine\Classes\HelicoDeco.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Decoration
         |
         +--XIII.VehicleDeco
            |
            +--XIDCine.HelicoDeco
Direct Known Subclasses:ApacheDeco, FBIHelico, NastyHelico, NiceHelico

class HelicoDeco
extends XIII.VehicleDeco

// //-----------------------------------------------------------
Variables
 int InitialHealth
 StabilityThreshold, PitchSlope
 RotationMustBeCorrected, bDying
 bInitiallyOn, bExplodeIfDead

States
Dying

Function Summary
 void Collapse()
 void HelicoTick(float dt)
 void PostBeginPlay()
     
//_____________________________________________________________________________
 void RefreshDisplaying()


State Dying Function Summary



Source Code


00001	//
00002	//-----------------------------------------------------------
00003	class HelicoDeco extends VehicleDeco;
00004	
00005	VAR(Crash) bool bDamagedByAllPawns;
00006	VAR() bool bInitiallyOn, bExplodeIfDead;
00007	VAR bool RotationMustBeCorrected, bDying;
00008	VAR() float StabilityThreshold, PitchSlope;
00009	VAR(Crash) string CrashLabel;
00010	VAR(Crash) int Health, DamageAmount, DamageRadius;
00011	VAR int InitialHealth;
00012	VAR(Sound) Sound SoundExplosion;
00013	VAR(Events) name CrashEvent, DeadEvent;
00014	VAR	Emitter SmokeEmitter, ExploEmitter;
00015	
00016	//_____________________________________________________________________________
00017	FUNCTION PostBeginPlay()
00018	{
00019		LOCAL int i;
00020	
00021		InitialHealth=Health;
00022		if( bActorShadows && (Shadow==None) )
00023		{
00024			Shadow = Spawn(class'ShadowProjector',Self,'',Location/*+vect(0,0,150)*/);
00025			Shadow.ShadowScale = 8; //4.4;
00026			Shadow.MaxTraceDistance=2500;
00027			Shadow.ShadowIntensity=196;
00028		}
00029	
00030		for ( i=0; i<2; i++ )
00031		{
00032			if ( PartClass[i] != None )
00033			{
00034				VehicleParts[i] = spawn(PartClass[i],self,,Location+((PartOffset[i]/**scale*/)>>Rotation),Rotation);
00035				if ( VehicleParts[i] == None )
00036					log("WARNING - "$PartClass[i]$" failed to spawn for "$self);
00037				else
00038				{
00039					log(self@"HELICO SPAWN - "$VehicleParts[i]);
00040					VehicleParts[i].SetRotation(Rotation);
00041					VehicleParts[i].SetBase(self);
00042					VehicleParts[i].SetDrawScale(DrawScale);
00043					VehicleParts[i].bForceInUniverse = bForceInUniverse;
00044				}
00045			}
00046			else
00047				break;
00048		}
00049		
00050		if ( LinkedTo == none )
00051		{
00052			Disable('Tick');
00053		}
00054		else
00055		{
00056			YawOffset=Rotation.Yaw-LinkedTo.Rotation.Yaw;
00057			PositionOffset=(Location-LinkedTo.Location)<<Rotation;
00058		}
00059	}
00060	
00061	FUNCTION RefreshDisplaying()
00062	{
00063		LOCAL int i;
00064	
00065		for ( i=0; i<2; i++ )
00066		{
00067			if ( PartClass[i] != None )
00068			{
00069				VehicleParts[i].bHidden=bHidden;
00070				VehicleParts[i].RefreshDisplaying();
00071			}
00072		}
00073		if ( SmokeEmitter!=none )
00074		{
00075			SmokeEmitter.Emitters[0].Disabled=bHidden;
00076		}
00077		Super.RefreshDisplaying();
00078	}
00079	
00080	STATE() InvisibleUntilTriggered
00081	{
00082		EVENT BeginState( )
00083		{
00084			DebugLog( self@"InvisibleUntilTriggered::BeginState" );
00085			SetTimer( 0.1, false );
00086		}
00087	
00088		EVENT Timer( )
00089		{
00090			DebugLog( self@"InvisibleUntilTriggered::Timer" );
00091			Tag=LinkedTo.Tag;
00092			bHidden=true;
00093			RefreshDisplaying();
00094			if ( VehicleParts[0] != None )
00095			{
00096				VehicleParts[0].bHidden=bHidden;
00097				VehicleParts[0].RefreshDisplaying( );
00098				VehicleParts[0].Disable( 'Tick' );
00099			}
00100			if ( VehicleParts[1] != None )
00101			{
00102				VehicleParts[1].bHidden=bHidden;
00103				VehicleParts[1].RefreshDisplaying( );
00104				VehicleParts[1].Disable( 'Tick' );
00105			}
00106		}
00107	
00108		EVENT Trigger(actor Other, Pawn EventInstigator)
00109		{
00110			DebugLog( self@"InvisibleUntilTriggered::Trigger" );
00111			GotoState( '' );
00112		}
00113	
00114		EVENT EndState( )
00115		{
00116			DebugLog( self@"InvisibleUntilTriggered::EndState" );
00117			bHidden=false;
00118			RefreshDisplaying();
00119			if ( VehicleParts[0] != None )
00120			{
00121				VehicleParts[0].bHidden=bHidden;
00122				VehicleParts[0].RefreshDisplaying( );
00123				VehicleParts[0].Enable( 'Tick' );
00124			}
00125			if ( VehicleParts[1] != None )
00126			{
00127				VehicleParts[1].bHidden=bHidden;
00128				VehicleParts[1].RefreshDisplaying( );
00129				VehicleParts[1].Enable( 'Tick' );
00130			}
00131		}
00132	
00133		EVENT Tick(float dt) {}
00134	}
00135	
00136	EVENT Trigger(actor Other, Pawn EventInstigator)
00137	{
00138		LOCAL int i;
00139		for ( i=0; i<2; i++ )
00140		{
00141			if ( VehicleParts[i] != None )
00142			{
00143				VehicleParts[i].Trigger(none,none);
00144			}
00145		}
00146	}
00147	
00148	EVENT Destroyed( )
00149	{
00150		LOCAL int i;
00151	
00152		DebugLog( self@"Destroyed" );
00153		LinkedTo.Destroy();
00154		for ( i=0; i<2; i++ )
00155		{
00156			if ( VehicleParts[i]!=none )
00157				VehicleParts[i].Destroy();
00158		}
00159		if ( SmokeEmitter!=none )
00160		{
00161			SmokeEmitter.Destroy();
00162		}
00163	
00164		Super.Destroyed( );
00165	}
00166	
00167	FUNCTION Collapse()
00168	{
00169		LOCAL int i;
00170	
00171		if ( BrokenSM!=none )
00172		{
00173			LinkedTo.Destroy();
00174			for ( i=0; i<2; i++ )
00175			{
00176				if ( VehicleParts[i]!=none )
00177				{
00178					VehicleParts[i].Destroy();
00179	//				VehicleParts[i].SetBase( none );
00180	//				VehicleParts[i].bCollideWorld=true;
00181	//				VehicleParts[i].SetPhysics( PHYS_Falling );
00182				}
00183			}
00184			if ( SmokeEmitter!=none )
00185			{
00186				SmokeEmitter.Destroy();
00187			}
00188			StaticMesh=BrokenSM;
00189			SetPhysics( PHYS_FALLING );
00190		}
00191	}
00192	
00193	EVENT Tick(float dt)
00194	{
00195		if ( !bool( LinkedTo ) )
00196		{
00197			Disable('Tick');
00198			return;
00199		}
00200		
00201		HelicoTick( dt );
00202	}
00203	
00204	FUNCTION HelicoTick( float dt )
00205	{
00206		LOCAL rotator r;
00207		LOCAL vector vTmp,gSpot,X,Y,Z;
00208		LOCAL float SpeedZ, SpeedH;
00209	//	LOCAL bool bTeleport;
00210	
00211		gSpot = LinkedTo.Location + (PositionOffset>>Rotation) - Location;
00212		gSpot = gSpot*(1-inertia)+Location;
00213		vTmp=gSpot-Location;
00214		SpeedZ=vTmp.Z/dt;
00215		SpeedH=sqrt(vTmp.X*vTmp.X+vTmp.Y*vTmp.Y)/dt;
00216		r = LinkedTo.Rotation;
00217		
00218		if ( SpeedH < StabilityThreshold )
00219			r.Pitch= -SpeedH * PitchSlope;
00220		else
00221			r.Pitch= -StabilityThreshold * PitchSlope;
00222		SetLocation(gSpot);
00223		if ( RotationMustBeCorrected )
00224		{
00225			GetAxes( r, x, y, z);
00226			r=OrthoRotation(y,-x,z);
00227		}
00228		r.Yaw  = (((r.Yaw  -Rotation.Yaw  +32768)&65535)-32768);
00229		r.Roll = (((r.Roll -Rotation.Roll +32768)&65535)-32768);
00230		r.Pitch= (((r.Pitch-Rotation.Pitch+32768)&65535)-32768);
00231		r = r * (1-inertia**(dt*100)) + Rotation;
00232		SetRotation(r);
00233	}
00234	
00235	FUNCTION TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType )
00236	{
00237		LOCAL Rotator r;
00238		LOCAL Float f;
00239	
00240		switch (DamageType)
00241		{
00242		case class'DTBladeCut':
00243		case class'DTStunned':
00244		case class'DTPierced':
00245		case class'DTFisted':
00246			return;
00247		case class'DTRocketed':
00248		case class'DTGrenaded':
00249			Damage*=5;
00250		}
00251		
00252		if ( !bDying && ( bDamagedByAllPawns || instigatedBy.IsPlayerPawn() ) )
00253		{
00254			Health= Max(0,Health-Damage);
00255			if (SmokeEmitter==none)
00256			{
00257				SmokeEmitter=Spawn(class'HelicoHSEmitter');
00258				r=SmokeEmitter.Rotation;
00259				r.Yaw-=16384;
00260				SmokeEmitter.SetRotation(r);
00261				SmokeEmitter.SetBase(self);
00262			}
00263			if ( SmokeEmitter!=none )
00264			{
00265				f = 1-float(Health)/InitialHealth;
00266				SmokeEmitter.Emitters[0].InitialParticlesPerSecond = 25*f; // PS2 E3 sinon 50 * f;	
00267	//			SmokeEmitter.Emitters[0].ParticlesPerSecond = 25*f; // PS2 E3 sinon 50 * f;	
00268				SmokeEmitter.Emitters[0].Acceleration.X=-100-900*f;
00269				SmokeEmitter.Emitters[0].Acceleration.Z=30+270*f;
00270				SmokeEmitter.Emitters[0].StartSizeRange.X.Max=50+50*f;
00271				SmokeEmitter.Emitters[0].LifetimeRange.Min=3-2*f;
00272				SmokeEmitter.Emitters[0].LifetimeRange.Max=3-2*f;
00273			}
00274			if (Health==0)
00275			{
00276				bDying=true;
00277	
00278				if ( bExplodeIfDead )
00279				{
00280					ExploEmitter= spawn(class'HelicoExploEMitter',,,HitLocation+400*Normal(instigatedBy.Location-HitLocation));
00281	//				HurtRadius( 5000/*DamageAmount*/, 500/*DamageRadius*/, class'DTGrenaded', 0, HitLocation );	
00282					
00283					if ( LinkedTo!=none )
00284						LinkedTo.PlaySound( SoundExplosion );
00285					else
00286						PlaySound( SoundExplosion );
00287	
00288					if ( SmokeEmitter!=none)
00289						SmokeEmitter.Destroy();
00290					GotoState( 'Dying' );
00291				}
00292				else
00293					if ( Cine2(LinkedTo)!=none )
00294					{
00295						DebugLog( self@"CRASH sent to cine2" );
00296						Cine2(LinkedTo).CineController.CineGoto( CrashLabel );
00297					}
00298			}
00299		}
00300	}
00301	
00302	STATE Dying
00303	{
00304		EVENT Tick(float dt) {}
00305	
00306		FUNCTION TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType )
00307		{
00308		}
00309	Begin:
00310		SetCollision(false,false,false);
00311		TriggerEvent( CrashEvent, self, none );
00312		Sleep( 0.1 );
00313		TriggerEvent( DeadEvent, self, none );
00314		if ( BrokenSM==none )
00315			Destroy( );
00316		else
00317			Collapse( );
00318	}
00319	
00320	//	SMMangHelCab=StaticMesh'Meshes_Vehicules.helicomangouste'
00321	//	SMMangHelTop=StaticMesh'Meshes_Vehicules.helicomangoustetop'
00322	//	SMMangHelBck=StaticMesh'Meshes_Vehicules.helicomangousteback'
00323	//    PartOffset(0)=(X=0,Y=-165,Z=48)
00324	//    PartOffset(1)=(X=0,Y=475,Z=0)
00325	
00326	
00327	
00328	defaultproperties
00329	{
00330	     bInitiallyOn=True
00331	     bExplodeIfDead=True
00332	     RotationMustBeCorrected=True
00333	     StabilityThreshold=500.000000
00334	     PitchSlope=10.000000
00335	     CrashLabel="Crash"
00336	     Health=350
00337	     SoundExplosion=Sound'XIIIsound.Explo__GenExplo.GenExplo__hGenExplo'
00338	     CrashEvent="Crash"
00339	     PartClass(0)=Class'XIDCine.HelicoTopRotor'
00340	     PartClass(1)=Class'XIDCine.HelicoRearRotor'
00341	     PartOffset(0)=(Y=-324.000000)
00342	     PartOffset(1)=(Y=755.000000,Z=100.000000)
00343	     DrawType=DT_StaticMesh
00344	     StaticMesh=StaticMesh'Meshes_Vehicules.helicomangouste'
00345	     CollisionHeight=140.000000
00346	}

End Source Code