XIDCine
Class BeachBoatRock

source: C:\XIII\XIDCine\Classes\BeachBoatRock.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Triggers
         |
         +--XIDCine.BeachBoatRock
Direct Known Subclasses:None

class BeachBoatRock
extends Engine.Triggers

//----------------------------------------------------------- // BeachBoatRock // Created by iKi // Last Modification by iKi //-----------------------------------------------------------
Variables
 BaseFlashColor, CurrentFlashColor
 Sound EndMusic
 Color MyFlashColor
 XIIIPlayerController PC
 Pawn Player
 float TimeStamp
 float WaterHeight
 bPosOK, bRotOK
 Vector vSpeed

States
LetsRock_03_Floating, LetsRock_02_Swing, LetsRock_01_GoNearTheEdge, Waiting, Init
State LetsRock_03_Floating Function Summary


State LetsRock_02_Swing Function Summary


State LetsRock_01_GoNearTheEdge Function Summary


State Waiting Function Summary
 float Magic(float f, float dt)


State Init Function Summary



Source Code


00001	//-----------------------------------------------------------
00002	// BeachBoatRock
00003	// Created by iKi
00004	// Last Modification by iKi
00005	//-----------------------------------------------------------
00006	class BeachBoatRock extends Triggers;
00007	
00008	#exec Texture Import File=Textures\Rock_ico.pcx Name=Rock_ico Mips=Off
00009	
00010	CONST StaggerringTime=1;
00011	//CONST FloatingTime=11;
00012	CONST FeedBackPitch=-4096;
00013	VAR() Sound EndMusic;
00014	VAR float WaterHeight;
00015	VAR TRANSIENT XIIIPlayerController PC;
00016	VAR TRANSIENT Pawn Player;
00017	VAR TRANSIENT float TimeStamp;
00018	VAR TRANSIENT Color BaseFlashColor, CurrentFlashColor;
00019	VAR TRANSIENT Vector vSpeed;
00020	VAR bool bUnderwater, bPosOK, bRotOK;
00021	VAR Color MyFlashColor;
00022	
00023	EVENT PostBeginPlay()
00024	{
00025	}
00026	/*
00027	AUTO STATE Init
00028	{
00029		EVENT BeginState()
00030		{
00031			SetTimer(0.1,true);
00032		}
00033		
00034		EVENT Timer()
00035		{
00036			if (XIIIGameInfo(Level.Game).MapInfo!=none && XIIIGameInfo(Level.Game).MapInfo.XIIIController!=none && XIIIGameInfo(Level.Game).MapInfo.XIIIController.Pawn!=none)
00037			{
00038				PC=XIIIGameInfo(Level.Game).MapInfo.XIIIController;
00039				Player=PC.Pawn;
00040				LOG ( "PLAYER ="@Player$", XIIIPawn ="@XIIIGameInfo(Level.Game).MapInfo.XIIIPawn );
00041				SetTimer( 0, false );
00042				GotoState( 'Waiting' );
00043			}
00044		}
00045	}*/
00046	
00047	AUTO STATE Waiting
00048	{
00049		EVENT Trigger( Actor Other, Pawn EventInstigator )
00050		{
00051	//		if ( Pawn(Other)!=none && Pawn(Other).IsPlayerPawn() )
00052			GotoState( 'LetsRock_01_GoNearTheEdge' );
00053		}
00054	
00055		EVENT Touch( Actor Other )
00056		{
00057			if ( Pawn(Other)!=none && Pawn(Other).IsPlayerPawn() )
00058				GotoState( 'LetsRock_01_GoNearTheEdge' );
00059		}
00060	}
00061	
00062	FUNCTION float Magic(float f, float dt)
00063	{
00064		return 1.0f - ((1.0f-f)**(150*dt));
00065	}
00066	
00067	STATE LetsRock_01_GoNearTheEdge
00068	{
00069		EVENT BeginState()
00070		{
00071			PC=XIIIGameInfo(Level.Game).MapInfo.XIIIController;
00072			Player=PC.Pawn;
00073			LOG ( "PLAYER ="@Player$", XIIIPawn ="@XIIIGameInfo(Level.Game).MapInfo.XIIIPawn );
00074	
00075			TimeStamp=0;
00076			PC.GotoState( 'NoControl' );
00077			Player.SetPhysics( PHYS_None );
00078			bRotOK = false;
00079			bPosOk = false;
00080		}
00081		EVENT Tick( float dt )
00082		{
00083			LOCAL Rotator r, rWanted;
00084			LOCAL Vector v;
00085			LOCAL float f, fLimitAngle;
00086	
00087			TimeStamp+=dt;
00088	
00089			f = FMin( 1.0, TimeStamp/StaggerringTime );
00090			if (f==1 && Player.bCollideWorld )
00091				Player.bCollideWorld=false;
00092	
00093			CurrentFlashColor = (1-f)*BaseFlashColor+f*MyFlashColor;
00094			PC.Region.Zone.FlashEffectDesc.LayerColor=CurrentFlashColor;
00095	
00096	
00097			PC.DesiredFOV=85+2*cos(2.5*TimeStamp);
00098			PC.SetRotation(r*Magic(0.015,dt)+PC.Rotation);
00099	
00100			if ( !bRotOK )
00101			{
00102				rWanted.Yaw   = Rotation.Yaw;
00103				rWanted.Roll  = 1024 * cos( 3 * TimeStamp );
00104				rWanted.Pitch = FeedBackPitch - 1024 * sin( 2 * TimeStamp );
00105				r       = rWanted - PC.Rotation;
00106				
00107				fLimitAngle = 182*80*dt;
00108	
00109				r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
00110				r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
00111				r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
00112	
00113				if ( abs(r.Yaw)<fLimitAngle /*&& abs(r.Pitch)<fLimitAngle && abs(r.Roll)<fLimitAngle*/ )
00114				{
00115					bRotOK = true;
00116					PC.SetRotation( rWanted );
00117				}
00118				else
00119				{
00120					r.Yaw   = Clamp( r.Yaw  , -fLimitAngle, fLimitAngle );
00121					r.Roll  = Clamp( r.Roll , -fLimitAngle, fLimitAngle );
00122					r.Pitch = Clamp( r.Pitch, -fLimitAngle, fLimitAngle );
00123					PC.SetRotation( PC.Rotation + r );
00124				}
00125			}
00126	
00127			if ( !bPosOK )
00128			{
00129				v = Location-Player.Location;
00130				v.Z = 0;
00131				if ( vSize(v)>10 )
00132				{
00133					Player.SetLocation( Player.Location + 320*dt*Normal(v) );
00134				}
00135				else
00136				{
00137					Player.SetLocation( Player.Location + v*dt );
00138					bPosOK = true;
00139				}
00140			}
00141	
00142			if ( bPosOK && bRotOk )
00143				GotoState( 'LetsRock_02_Swing' );
00144	
00145		}		
00146	}
00147	
00148	STATE LetsRock_02_Swing
00149	{
00150		EVENT BeginState()
00151		{
00152			vSpeed=500*Vector(Rotation);
00153			TimeStamp=0;
00154			bRotOK = false;
00155			bPosOk = false;
00156		}
00157	
00158		EVENT Tick( float dt )
00159		{
00160			LOCAL Rotator r, rWanted;
00161			LOCAL Vector v;
00162			LOCAL float fLimitAngle;
00163	
00164			if ( !bUnderwater && PC.IsInState('PlayerSwimming'))
00165			{
00166				bUnderwater=true;
00167	//			PC.GotoState( 'NoControl' );
00168				vSpeed = vect(0,0,0); //Magic( 0.95, dt );
00169				bPosOk=true;
00170	//			if ( vSize(vSpeed)<10 )
00171				GotoState( 'LetsRock_03_Floating' );
00172			}
00173	
00174			TimeStamp+=dt;
00175	
00176			if ( !bRotOK )
00177			{
00178				if ( !bUnderWater /*Player.Location.Z>WaterHeight*/ )
00179				{
00180					rWanted = Rotation;
00181					rWanted.Pitch = FeedBackPitch-65535*TimeStamp;
00182				}
00183				else
00184					rWanted=Rotator(Location-Player.Location);
00185	
00186				r = rWanted - PC.Rotation;
00187				r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
00188				r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
00189				r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
00190				
00191				fLimitAngle = 182*180*dt;
00192	
00193				r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
00194				r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
00195				r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
00196	
00197				if ( abs(r.Yaw)<fLimitAngle /*&& abs(r.Pitch)<fLimitAngle && abs(r.Roll)<fLimitAngle*/ )
00198				{
00199					bRotOK = true;
00200					PC.SetRotation( rWanted );
00201				}
00202				else
00203				{
00204					r.Yaw   = Clamp( r.Yaw  , -fLimitAngle, fLimitAngle );
00205					r.Roll  = Clamp( r.Roll , -fLimitAngle, fLimitAngle );
00206					r.Pitch = Clamp( r.Pitch, -fLimitAngle, fLimitAngle );
00207					PC.SetRotation( PC.Rotation + r );
00208				}
00209			}
00210	
00211	
00212			Player.SetLocation( Player.Location + vSpeed*dt );
00213	
00214			if ( bUnderwater )
00215			{
00216			}
00217			else
00218				vSpeed-=vect(0,0,950)*dt;
00219		}		
00220	
00221	}
00222	
00223	STATE LetsRock_03_Floating
00224	{
00225		EVENT BeginState( )
00226		{
00227			LOCAL Vector v;
00228	
00229			TimeStamp=0;
00230			vSpeed = vector(Rotation);
00231			vSpeed.Z = 0;
00232			vSpeed = 280*Normal(vSpeed);
00233	//		SetTimer( FloatingTime, false );
00234			PlayMusic( EndMusic );
00235		}
00236	
00237		EVENT Tick( float dt )
00238		{
00239			LOCAL Rotator r, rWanted;
00240			LOCAL Vector v;
00241			LOCAL float f, fLimitAngle;
00242	
00243			if ( PC.IsInState('PlayerSwimming') )
00244			{
00245				PC.GotoState( 'NoControl' );
00246			}
00247	
00248			TimeStamp+=dt;
00249			rWanted = Rotator(Location-Player.Location);
00250			rWanted.Roll+=1024*cos(3*TimeStamp);
00251			rWanted.Pitch-=1024*sin(2*TimeStamp);
00252	
00253			r = rWanted - PC.Rotation;
00254			r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
00255			r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
00256			r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
00257			
00258			fLimitAngle = 182*180*dt;
00259	
00260			r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
00261			r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
00262			r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
00263	
00264			r.Yaw   = Clamp( r.Yaw  , -fLimitAngle, fLimitAngle );
00265			r.Roll  = Clamp( r.Roll , -fLimitAngle, fLimitAngle );
00266			r.Pitch = Clamp( r.Pitch, -fLimitAngle, fLimitAngle );
00267			PC.SetRotation( PC.Rotation + r );
00268	
00269			PC.DesiredFOV=85+2*cos(2.5*TimeStamp);
00270	
00271			v = Player.Location + vSpeed*dt;
00272			v.Z = WaterHeight+20*cos(TimeStamp);
00273			Player.SetLocation( v );
00274			if ( Level.FlashManager!=none && Level.FlashManager.IsInState('FinExtroFlash') )
00275			{
00276				Player.bCollideWorld=true;
00277				PC.DesiredFOV=PC.DefaultFOV;
00278				Destroy();
00279			}
00280		}
00281	/*
00282		EVENT Timer()
00283		{
00284			Player.bCollideWorld=true;
00285			Destroy();
00286		}*/
00287	}
00288	
00289	
00290	
00291	defaultproperties
00292	{
00293	     EndMusic=Sound'XIIIsound.Music__Plage00.Plage00__hFlashOff'
00294	     WaterHeight=4400.000000
00295	     MyFlashColor=(R=255)
00296	     InitialState="Waiting"
00297	     Texture=Texture'XIDCine.Rock_ico'
00298	     bDirectional=True
00299	}

End Source Code