## XIDCine
Class RoofGrapnleDemonstrator

source: C:\XIII\XIDCine\Classes\RoofGrapnleDemonstrator.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Triggers
             |
             +--XIDCine.RoofGrapnleDemonstrator

Direct Known Subclasses:None

class RoofGrapnleDemonstrator
extends Engine.Triggers

    //-----------------------------------------------------------
    // RoofGrapnleDemonstrator
    // Created by iKi
    // Last Modification by iKi
    //-----------------------------------------------------------

Variables
`float` | `ActualPlayerRotationSpeed`
`Cine2` | `Jones`
`int` | `MemCurrentScript`
`HookPoint` | `PointGrappin`
`Actor` | `XIIIPosition`

States
STA_Retract, STA_Demonstrator_Swing_And_Jump, STA_Demonstrator_goes_up, STA_Demonstrator_CastHook, STA_Look_the_demonstrator, STA_Lets_the_show_begins, STA_Init

Function Summary
`bool` | `LookAtJones(float dt)`
    {
    	return 1.0f - ((1.0f-f)**(150*dt));
    }*/
`float` | `Magic(float f, float dt)`
    /*
`bool` | `MoveToRightThePlace(float dt)`

State STA_Retract Function Summary

State STA_Demonstrator_Swing_And_Jump Function Summary

State STA_Demonstrator_goes_up Function Summary

State STA_Demonstrator_CastHook Function Summary

State STA_Look_the_demonstrator Function Summary

State STA_Lets_the_show_begins Function Summary

State STA_Init Function Summary

Source Code

    00001	//-----------------------------------------------------------
    00002	// RoofGrapnleDemonstrator
    00003	// Created by iKi
    00004	// Last Modification by iKi
    00005	//-----------------------------------------------------------
    00006	class RoofGrapnleDemonstrator extends Triggers;
    00007
    00008	#exec Texture Import File=Textures\Rock_ico.pcx Name=Rock_ico Mips=Off
    00009
    00010	VAR()	Cine2					Jones;
    00011	VAR()	HookPoint				PointGrappin;
    00012	VAR()	Actor					XIIIPosition;
    00013	VAR(Sound) Sound				HookSelectSound, HookFireSound, HookStartSound, HookStopSound, HookLetSound;
    00014	VAR		Vector					WallNormal;
    00015	VAR		XIIIPlayerController	PC;
    00016	VAR		CineHook				Crochet;
    00017	VAR		CineHookLink			PremierFilin, DernierFilin;
    00018	VAR		float					TimeStamp, TaillePremierFilin;
    00019	VAR TRANSIENT int				MemCurrentScript;
    00020
    00021	CONST PlayerLinearSpeed=600;
    00022	CONST PlayerRotationSpeed=180;
    00023	CONST RotationAcceleration=245;
    00024	VAR TRANSIENT	float	ActualPlayerRotationSpeed;
    00025
    00026	CONST	LinkLength = 100.0;
    00027
    00028	//-----------------------------------------------------------
    00029
    00030	AUTO STATE STA_Init
    00031	{
    00032		EVENT Trigger(actor Other,pawn EventInstigator)
    00033		{
    00034			GotoState('STA_Lets_the_show_begins');
    00035		}
    00036	}
    00037
    00038	//-----------------------------------------------------------
    00039	/*FUNCTION float Magic(float f,float dt)
    00040	{
    00041		return 1.0f - ((1.0f-f)**(150*dt));
    00042	}*/
    00043
    00044	FUNCTION bool LookAtJones(float dt)
    00045	{
    00046		LOCAL rotator r, Roto;
    00047
    00048		ActualPlayerRotationSpeed= fMin( PlayerRotationSpeed, ActualPlayerRotationSpeed+RotationAcceleration*dt );
    00049		Roto=ROTATOR( Jones.Location+vect(0,0,10)-PC.Pawn.Location );
    00050
    00051		r.Yaw   = Clamp( ( ( Roto.Yaw   - PC.Rotation.Yaw   + 32768 ) & 65535 ) - 32768, -ActualPlayerRotationSpeed*dt*182,ActualPlayerRotationSpeed*dt*182 );
    00052		r.Roll  = Clamp( ( ( Roto.Roll  - PC.Rotation.Roll  + 32768 ) & 65535 ) - 32768, -ActualPlayerRotationSpeed*dt*182,ActualPlayerRotationSpeed*dt*182 );
    00053		r.Pitch = Clamp( ( ( Roto.Pitch - PC.Rotation.Pitch + 32768 ) & 65535 ) - 32768, -ActualPlayerRotationSpeed*dt* 41,ActualPlayerRotationSpeed*dt* 41 );
    00054
    00055		PC.SetRotation( r + PC.Rotation );
    00056		if ( r.Yaw==0 && r.Pitch==0 && r.Roll==0)
    00057		{
    00058			ActualPlayerRotationSpeed=0;
    00059			return true;
    00060		}
    00061		return false;
    00062	}
    00063
    00064	FUNCTION bool MoveToRightThePlace(float dt)
    00065	{
    00066		LOCAL vector v;
    00067
    00068		v = XIIIPosition.Location-PC.Pawn.Location;
    00069		v.Z = 0;
    00070		PC.Pawn.Velocity = fMin( vSize(v)/dt, PlayerLinearSpeed ) * Normal( v );
    00071		if ( vSize( v )<1 )
    00072			return true;
    00073		return false;
    00074	}
    00075
    00076	STATE STA_Lets_the_show_begins
    00077	{
    00078
    00079		EVENT BeginState()
    00080		{
    00081			// Player
    00082			PC=XIIIGameInfo(Level.Game).MapInfo.XIIIController;
    00083			PC.GotoState('NoControl');
    00084
    00085			// Jones
    00086			Jones.CineController.LockedActor=none;
    00087			Jones.CineController.rWantedRotation=ROTATOR(-WallNormal);
    00088			MemCurrentScript=Jones.CurrentScript;
    00089			Jones.CurrentScript=-1;
    00090		}
    00091
    00092		EVENT Tick(float dt)
    00093		{
    00094			LOCAL bool a,b;
    00095
    00096			a = MoveToRightThePlace(dt);
    00097			b = LookAtJones(dt);
    00098			if ( a && b )
    00099				GotoState( 'STA_Look_the_demonstrator' );
    00100
    00101	/*		LOCAL Vector v;
    00102			LOCAL Rotator r;
    00103
    00104			v = Jones.Location-PC.Pawn.Location;
    00105			v.Z = 0;
    00106			r = ROTATOR(v);
    00107			r-= PC.Rotation;
    00108			r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
    00109			r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
    00110			r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
    00111			PC.SetRotation( r * Magic(0.015,dt) + PC.Rotation );
    00112
    00113			v = XIIIPosition.Location - PC.Pawn.Location;
    00114			v.Z = 0;
    00115			if ( vSize(v)>100 )
    00116			{
    00117				PC.Pawn.SetLocation( PC.Pawn.Location + Magic(0.005,dt) * v );
    00118			}
    00119			else
    00120			{
    00121				if ( Abs( r.Yaw ) < 100 )
    00122					GotoState( 'STA_Look_the_demonstrator' );
    00123			}*/
    00124		}
    00125	}
    00126
    00127	//-----------------------------------------------------------
    00128
    00129	STATE STA_Look_the_demonstrator
    00130	{
    00131		EVENT BeginState( )
    00132		{
    00133	//		TriggerEvent( HookExitEvent, self, none );
    00134			Jones.PlaySound( HookSelectSound );
    00135	 		Jones.PlayAnim( 'LanceGrappin', , 0.5 );
    00136			Crochet = Spawn(class'CineHook',self,'Tag',Jones.GetBoneCoords('X R Finger1').Origin);
    00137
    00138			Jones.AttachToBone( Crochet, 'X R Finger1');
    00139			Crochet.SetRelativeLocation( vect( 2, -2, 8 ) );
    00140			Crochet.SetRelativeRotation( rot( 16384, 0, 0 ) );
    00141			SetTimer( 2.66, false );
    00142			TimeStamp = 0;
    00143		}
    00144
    00145		EVENT Timer( )
    00146		{
    00147			LOCAL Vector v;
    00148
    00149			v = 1200 * Normal( PointGrappin.Location - Crochet.Location );
    00150
    00151			Jones.DetachFromBone( Crochet );
    00152			Crochet.SetRotation( ROTATOR( PointGrappin.Location - Crochet.Location ) );
    00153			PremierFilin = Spawn(class'CineHookLink',self,'Tag',Jones.GetBoneCoords('X R Finger1').Origin,Rotator(PointGrappin.Location-Crochet.Location));
    00154
    00155			Crochet.Velocity=v;
    00156			GotoState( 'STA_Demonstrator_CastHook' );
    00157		}
    00158
    00159		EVENT Tick(float dt)
    00160		{
    00161	//		LOCAL Vector v;
    00162	//		LOCAL Rotator r;
    00163			TimeStamp += dt;
    00164	//		v=Jones.GetBoneCoords('X').Origin-Jones.Location;
    00165	//		Jones.SetLocation(Jones.Location+v);
    00166
    00167	//		Jones.PrePivot-=v;
    00168	/*
    00169			v = Jones.Location-PC.Pawn.Location;
    00170			r = ROTATOR(v);
    00171			r-= PC.Rotation;
    00172			r.Yaw   = ( ( r.Yaw   + 32768 ) & 65535 ) - 32768;
    00173			r.Roll  = ( ( r.Roll  + 32768 ) & 65535 ) - 32768;
    00174			r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768;
    00175			PC.SetRotation( r * Magic( 0.015, dt ) + PC.Rotation );*/
    00176			LookAtJones(dt);
    00177		}
    00178	}
    00179
    00180	//-----------------------------------------------------------
    00181
    00182	STATE STA_Demonstrator_CastHook
    00183	{
    00184		EVENT BeginState()
    00185		{
    00186	//		TriggerEvent( CastHookEvent, self, none );
    00187			Jones.PlaySound( HookFireSound );
    00188		}
    00189
    00190		EVENT Tick(float dt)
    00191		{
    00192			LOCAL vector /*v,*/ vDir, vDown, vUp, vHand;
    00193			LOCAL CineHookLink Filin;
    00194	//		LOCAL Rotator r;
    00195
    00196			vHand = Jones.GetBoneCoords('X R Finger0').Origin;
    00197			vUp = Crochet.Location;
    00198			vDir = Normal(Crochet.Location - vHand);
    00199			PremierFilin.SetRotation( rotator(vDir) );
    00200			PremierFilin.SetLocation( vUp - Normal(vDir) * LinkLength * 0.5 );
    00201			vDown = PremierFilin.Location + VECTOR(PremierFilin.Rotation) * 0.5 * LinkLength;
    00202
    00203			Filin = PremierFilin.NextLink ;
    00204			DernierFilin = PremierFilin;
    00205
    00206			while ( Filin != none )
    00207			{
    00208				Filin.SetRotation( ROTATOR(vDir) );
    00209				vUp = Filin.PrevLink.Location - VECTOR(Filin.PrevLink.Rotation) * 0.5 * LinkLength;
    00210				vDown = vUp - VECTOR(Filin.Rotation)*0.5*LinkLength;
    00211
    00212				Filin.SetLocation( Filin.PrevLink.Location - vDir * LinkLength );
    00213				DernierFilin=Filin;
    00214				Filin = Filin.NextLink ;
    00215			}
    00216			if ( vSize(vDown-vHand) > LinkLength )
    00217			{
    00218				DernierFilin.NextLink=Spawn(class'CineHookLink',,, DernierFilin.Location - VECTOR(DernierFilin.Rotation) * LinkLength,DernierFilin.Rotation);
    00219				if ( DernierFilin.NextLink != none)
    00220					DernierFilin.NextLink.PrevLink = DernierFilin;
    00221			}
    00222			if ( Crochet.Velocity.Z<1 )
    00223				GotoState('STA_Demonstrator_goes_up');
    00224	/*
    00225			v = Jones.Location-PC.Pawn.Location;
    00226			v.Z = 0;
    00227			r = ROTATOR(v);
    00228			r-= PC.Rotation;
    00229
r.Yaw = ( ( r.Yaw + 32768 ) & 65535 ) - 32768; 00230 r.Roll = ( ( r.Roll + 32768 ) & 65535 ) - 32768; 00231 r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768; 00232 PC.SetRotation( r * Magic( 0.015, dt ) + PC.Rotation );*/ 00233 LookAtJones(dt); 00234 } 00235 } 00236 00237 STATE STA_Demonstrator_goes_up 00238 { 00239 EVENT BeginState() 00240 { 00241 Jones.SetPhysics( PHYS_Flying ); 00242 Jones.LoopAnim( 'GrappinMonte',,0.5 ); 00243 Jones.AirSpeed=600; 00244 // TriggerEvent( ClimbUpEvent, self, none ); 00245 Jones.PlaySound( HookStartSound ); 00246 } 00247 00248 EVENT Tick(float dt) 00249 { 00250 LOCAL vector /*v,*/ vDir, vDown, vUp, vHand; 00251 // LOCAL Rotator r; 00252 LOCAL CineHookLink Filin; 00253 LOCAL int i; 00254 00255 00256 vHand = Jones.GetBoneCoords('X R Finger0').Origin; 00257 vUp = Crochet.Location; 00258 vDir = Normal(Crochet.Location - vHand); 00259 00260 Jones.Velocity.X = 900 * vDir.X; 00261 Jones.Velocity.Y = 900 * vDir.Y; 00262 Jones.Velocity.Z = 450 * vDir.Z; 00263 00264 PremierFilin.SetRotation( rotator(vDir) ); 00265 PremierFilin.SetLocation( vUp - Normal(vDir) * LinkLength * 0.5 ); 00266 vDown = PremierFilin.Location + VECTOR(PremierFilin.Rotation) * 0.5 * LinkLength; 00267 00268 Filin = PremierFilin.NextLink; 00269 DernierFilin = PremierFilin; 00270 i=0; 00271 while ( Filin != none ) 00272 { 00273 if (Filin.Location.Z<Jones.Location.Z) 00274 { 00275 Filin.SetRotation( Filin.Rotation+ 0.1*(ROTATOR(vDir)+ exp(i*0.05)*cos(0.7*i+Level.TimeSeconds)*rot(512,0,0) -Filin.Rotation)); 00276 i++; 00277 } 00278 else 00279 Filin.SetRotation( ROTATOR(vDir) ); 00280 vUp = Filin.PrevLink.Location - VECTOR(Filin.PrevLink.Rotation) * 0.5 * LinkLength; 00281 vDown = vUp - VECTOR(Filin.Rotation)*LinkLength; 00282 00283 Filin.SetLocation( 0.5*(vUp+vDown) ); 00284 DernierFilin=Filin; 00285 Filin = Filin.NextLink ; 00286 } 00287 00288 if ( Crochet.Location.Z-Jones.Location.Z < 675 ) // 475 00289 GotoState('STA_Demonstrator_Swing_And_Jump'); 00290 00291 LookAtJones(dt); 00292 /* 00293 v = Jones.Location-PC.Pawn.Location; 00294 r = ROTATOR(v); 00295 r-= PC.Rotation; 00296 r.Yaw= ((r.Yaw+32768)&65535)-32768; 00297 r.Roll= ((r.Roll+32768)&65535)-32768; 00298 r.Pitch= ((r.Pitch+32768)&65535)-32768; 00299 PC.SetRotation(r*Magic(0.045,dt)+PC.Rotation);*/ 00300 } 00301 } 00302 00303 STATE STA_Demonstrator_Swing_And_Jump 00304 { 00305 EVENT BeginState() 00306 { 00307 Jones.PlayAnim( 'GrappinFin' ); 00308 Jones.Velocity=WallNormal*-125; // 75 00309 TimeStamp=0; 00310 SetTimer( 2.0, false ); 00311 // TriggerEvent( ClimbEndEvent, self, none ); 00312 Jones.PlaySound( HookStopSound ); 00313 } 00314 00315 EVENT EndState() 00316 { 00317 LOCAL CineHookLink Filin, FilinSuivant; 00318 00319 Filin=PremierFilin.NextLink; 00320 while (Filin!=none) 00321 { 00322 FilinSuivant=Filin.NextLink; 00323 Filin.Destroy(); 00324 Filin=FilinSuivant; 00325 } 00326 } 00327 00328 00329 EVENT Tick(float dt) 00330 { 00331 LOCAL vector /*v,*/ vDir, vDown, vUp, vHand, ds3d; 00332 // LOCAL Rotator r; 00333 LOCAL CineHookLink Filin; 00334 LOCAL FLOAT ds; 00335 00336 TimeStamp+=dt; 00337 vHand = Jones.GetBoneCoords('X R Finger0').Origin; 00338 vUp = Crochet.Location; 00339 vDir = Normal(Crochet.Location - vHand); 00340 00341 ds= vSize(Crochet.Location - vHand)/LinkLength; 00342 00343 ds3d = PremierFilin.DrawScale3D; 00344 ds3d.X = ds; 00345 PremierFilin.SetDrawScale3D( ds3d ); 00346 00347 PremierFilin.SetRotation( rotator(vDir) ); 00348 PremierFilin.SetLocation( vUp - Normal(vDir) * LinkLength*ds * 0.5 ); 00349 vDown = PremierFilin.Location + VECTOR(PremierFilin.Rotation) * 0.5 * LinkLength*ds; 00350 vDir = vect(0,0,1); 00351 Crochet.SetRotation( PremierFilin.Rotation ); 00352 00353 Filin = PremierFilin.NextLink; 00354 DernierFilin = PremierFilin; 00355 00356 while ( Filin != none ) 00357 { 00358 Filin.SetRotation( Filin.Rotation+ 0.1*(ROTATOR(vDir)-Filin.Rotation)); 00359 00360 ds3d = Filin.DrawScale3D; 00361 ds3d.X = FMax(0.01,1-(TimeStamp*0.66)); 00362 Filin.SetDrawScale3D( ds3d ); 00363 00364 vUp = Filin.PrevLink.Location - VECTOR(Filin.PrevLink.Rotation) * 0.5 * LinkLength * Filin.PrevLink.DrawScale3D.X; 00365 vDown = vUp - VECTOR(Filin.Rotation)*LinkLength*Filin.DrawScale3D.X; 00366 00367 Filin.SetLocation( 0.5*(vUp+vDown) ); 00368 DernierFilin=Filin; 00369 Filin = Filin.NextLink ; 00370 } 00371 00372 LookAtJones(dt); 00373 /* v = Jones.Location-PC.Pawn.Location; 00374 r = ROTATOR(v); 00375 r-= PC.Rotation; 00376 r.Yaw = ( ( r.Yaw + 32768 ) & 65535 ) - 32768; 00377 r.Roll = ( ( r.Roll + 32768 ) & 65535 ) - 32768; 00378 r.Pitch = ( ( r.Pitch + 32768 ) & 65535 ) - 32768; 00379 PC.SetRotation(r*Magic(0.015,dt)+PC.Rotation);*/ 00380 00381 } 00382 EVENT Timer() 00383 { 00384 GotoState('STA_Retract'); 00385 } 00386 00387 } 00388 00389 STATE STA_Retract 00390 { 00391 EVENT BeginState() 00392 { 00393 TimeStamp=0; 00394 TaillePremierFilin=PremierFilin.DrawScale3D.X; 00395 PC.GotoState('PlayerWalking'); 00396 SetTimer( 1.5, false ); 00397 // TriggerEvent( HookOffEvent, self, none ); 00398 Jones.PlaySound( HookStopSound ); 00399 } 00400 00401 EVENT Tick(float dt) 00402 { 00403 LOCAL vector vDir, vDown, vUp, vHand, ds3d; 00404 LOCAL CineHookLink Filin; 00405 LOCAL FLOAT ds; 00406 00407 TimeStamp+=dt; 00408 vHand = Jones.GetBoneCoords('X R Finger0').Origin; 00409 vDir = VECTOR(PremierFilin.Rotation); 00410 vUp = vHand+ vDir*ds3d.X*LinkLength; 00411 00412 ds3d = PremierFilin.DrawScale3D; 00413 ds3d.X = FMax(0.01,(1-(TimeStamp*1.0))*TaillePremierFilin); 00414 PremierFilin.SetDrawScale3D( ds3d ); 00415 00416 PremierFilin.SetLocation( vHand + vDir*ds3d.X*0.5*LinkLength); 00417 Crochet.SetLocation( vHand + vDir*ds3d.X*LinkLength ); 00418 } 00419 00420 EVENT Timer() 00421 { 00422 PremierFilin.Destroy(); 00423 Crochet.Destroy(); 00424 Jones.SetPhysics(PHYS_Walking); 00425 Jones.DropToGround(); 00426 Jones.SetLocation(Jones.GetBoneCoords('X').Origin); 00427 Jones.LoopAnim('WaitNeutre',,0.5); 00428 Jones.CurrentScript=MemCurrentScript; 00429 TriggerEvent(event,none,none); 00430 Destroy(); 00431 } 00432 } 00433 00434 00435 00436 defaultproperties 00437 { 00438 HookFireSound=Sound'XIIIsound.SpecActions__JonesHook.JonesHook__hFire' 00439 HookStartSound=Sound'XIIIsound.SpecActions__JonesHook.JonesHook__hStartLoop' 00440 HookStopSound=Sound'XIIIsound.SpecActions__JonesHook.JonesHook__hStopLoop' 00441 WallNormal=(X=-1.000000) 00442 Texture=Texture'XIDCine.Rock_ico' 00443 }

End Source Code