## XIII
Class VehicleDeco

source: C:\XIII\XIII\Classes\VehicleDeco.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Decoration
             |
             +--XIII.VehicleDeco

Direct Known Subclasses:HelicoDeco, HarrierDeco, BoatDeco, LGBoat01Deco, TankDeco, TankNDeco, Voilier01Deco, Voilier02Deco, Voilier03Deco, WheelVehicle

class VehicleDeco
extends Engine.Decoration

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`StaticMesh` | `BrokenSM` (Vehicle)
`PositionOffset,` | `LinkedToOldPosition` (Vehicle)
`int` | `NumParts` (Vehicle)
`Actor` | `VehicleParts[MAX_PARTS]`
`float` | `YawOffset,LastTimeLinkedToMove` (Vehicle)

Function Summary
`void` | `PostBeginPlay()`
    //_____________________________________________________________________________

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class VehicleDeco extends Decoration;
    00005
    00006	CONST MAX_PARTS=8;
    00007
    00008	VAR(Actor) class<Actor> PartClass[MAX_PARTS];
    00009	VAR Actor VehicleParts[MAX_PARTS];
    00010	VAR(Actor) vector PartOffset[MAX_PARTS];
    00011	VAR(Vehicle) Actor LinkedTo;
    00012	VAR(Vehicle) float inertia;
    00013	VAR(Vehicle) float ZOffset;
    00014	VAR StaticMesh BrokenSM; // (Vehicle)
    00015
    00016	var int NumParts;
    00017	var float YawOffset,LastTimeLinkedToMove;
    00018	var vector PositionOffset, LinkedToOldPosition;
    00019
    00020	//_____________________________________________________________________________
    00021	FUNCTION PostBeginPlay()
    00022	{
    00023		LOCAL int i;
    00024
    00025		Super.PostBeginPlay();
    00026
    00027		for ( i=0; i<MAX_PARTS; i++ )
    00028		{
    00029			if ( PartClass[i] != None )
    00030			{
    00031				VehicleParts[i] = spawn(PartClass[i],self,,Location+(PartOffset[i]>>Rotation));
    00032				if ( VehicleParts[i] == None )
    00033					log("WARNING - "$PartClass[i]$" failed to spawn for "$self);
    00034				else
    00035				{
    00036					VehicleParts[i].SetRotation(Rotation);
    00037					NumParts++;
    00038				}
    00039			}
    00040			else
    00041				break;
    00042		}
    00043
    00044	// Can't Disable Tick in PostBeginPlay
    00045		if ( LinkedTo != none )
    00046		{
    00047			YawOffset=Rotation.Yaw-LinkedTo.Rotation.Yaw;
    00048			PositionOffset=Location-LinkedTo.Location;
    00049			LinkedToOldPosition = LinkedTo.Location;
    00050		}
    00051	    if ( (Shadow!=none) && (XIIIGameInfo(Level.Game).MapInfo != none) )
    00052	    {
    00053			Shadow.MaxTraceDistance=XIIIGameInfo(Level.Game).MapInfo.MaxTraceDistance;
    00054			Shadow.ShadowIntensity=XIIIGameInfo(Level.Game).MapInfo.ShadowIntensity;
    00055			Shadow.ShadowMaxDist=XIIIGameInfo(Level.Game).MapInfo.ShadowMaxDist;
    00056			Shadow.ShadowTransDist=XIIIGameInfo(Level.Game).MapInfo.ShadowTransDist;
    00057			Shadow.bShadowIsStatic = ( LinkedTo == none );
    00058	    }
    00059	}
    00060
    00061	EVENT VehicleSpecialHandling(float dt)
    00062	{
    00063	}
    00064
    00065	EVENT Tick(float dt)
    00066	{
    00067		LOCAL vector vWantedPosition,gSpot,vNormal;
    00068		LOCAL rotator r;
    00069		LOCAL int i;
    00070
    00071		LOCAL Pawn HitPawn;
    00072		LOCAL Vector HitLocation,HitNormal,MemHit;
    00073
    00074		LOCAL Vector X, Y, Z, OldPos;
    00075
    00076		if ( LinkedTo==none )
    00077		{
    00078			Disable('Tick');
    00079			return;
    00080		}
    00081
    00082		if ( ( LinkedToOldPosition != LinkedTo.Location ) || ( Level.TimeSeconds-LastTimeLinkedToMove < 1.0 )  )
    00083		{
    00084			if ( LinkedToOldPosition != LinkedTo.Location )
    00085				LastTimeLinkedToMove=Level.TimeSeconds;
    00086			if( NumParts != 0 )
    00087			{
    00088				for ( i=0; i<MAX_PARTS; i++ )
    00089				{
    00090					if ( VehicleParts[i] != None )
    00091					{
    00092						vWantedPosition=LinkedTo.Location+PositionOffset+(PartOffset[i]>>Rotation); //.X * RotX + PartOffset[i].Y * RotY + PartOffset[i].Z * RotZ;
    00093
    00094						if (Trace( HitLocation, HitNormal, vWantedPosition+vect(0,0,-1000), vWantedPosition+vect(0,0,10), false )!=none)
    00095						{
    00096							if ( XIIIWheel( VehicleParts[i] )!=none )
    00097								HitLocation.Z+= XIIIWheel(VehicleParts[i]).WheelRadius;
    00098							else
    00099								HitLocation.Z+= 44;
    00100							gSpot+=HitLocation-vWantedPosition;
    00101							vNormal+=HitNormal;
    00102						}
    00103						else
    00104						{
    00105							HitLocation=vWantedPosition;
    00106							vNormal+=vect(0,0,1);
    00107						}
    00108
    00109						VehicleParts[i].SetLocation(HitLocation);
    00110						r=VehicleParts[i].Rotation;
    00111						r.Yaw=Rotation.Yaw;
    00112						VehicleParts[i].SetRotation(r);
    00113						if ( VehiclePart(VehicleParts[i])!=none )
    00114							VehiclePart(VehicleParts[i]).Update(dt);
    00115					}
    00116				}
    00117				gSpot/=NumParts;
    00118				gSpot+=LinkedTo.Location+PositionOffset;
    00119				gSpot.z+=ZOffset;
    00120				SetLocation(/*Location*0.85+0.15**/gSpot);
    00121		//log(name@gSpot@Location);
    00122		//		SetLocation(LinkedTo.Location+PositionOffset);
    00123				vNormal/=Numparts;
    00124				r=LinkedTo.Rotation;
    00125				r.Yaw+=YawOffset;
    00126				r=OrthoRotation(vector(r),vNormal cross vector(r),vNormal);
    00127				r.Yaw   = ( ( r.Yaw   - Rotation.Yaw   + 32768 ) & 65535 ) - 32768 ;
    00128				r.Roll  = ( ( r.Roll  - Rotation.Roll  + 32768 ) & 65535 ) - 32768 ;
    00129				r.Pitch = ( ( r.Pitch - Rotation.Pitch + 32768 ) & 65535 ) - 32768 ;
    00130				r = r * (1-inertia) + Rotation;
    00131				SetRotation(r);
    00132			}
    00133			else
    00134			{
    00135				gSpot=LinkedTo.Location+PositionOffset;
    00136				gSpot.z+=ZOffset;
    00137				SetLocation(gSpot);
    00138				r=LinkedTo.Rotation;
    00139		//		r.Yaw+=YawOffset;
    00140				GetAxes(r,x,y,z);
    00141				r=OrthoRotation(y,-x,z);
    00142				r.Yaw  = ( ( r.Yaw   - Rotation.Yaw   + 32768 ) & 65535 ) - 32768;
    00143				r.Roll = ( ( r.Roll  - Rotation.Roll  + 32768 ) & 65535 ) - 32768;
    00144				r.Pitch= ( ( r.Pitch - Rotation.Pitch + 32768 ) & 65535 ) - 32768;
    00145				r = r * ( 1 - inertia ) + Rotation;
    00146				SetRotation( r );
    00147			}
    00148			VehicleSpecialHandling( dt );
    00149			if ( Shadow!=none )
    00150				Shadow.bShadowIsStatic = false;
    00151		}
    00152		else
    00153			if ( Shadow!=none )
    00154				Shadow.bShadowIsStatic = true;
    00155		LinkedToOldPosition = LinkedTo.Location;
    00156	}
    00157
    00158	EVENT Destroyed()
    00159	{
    00160		LOCAL int i;
    00161
    00162		for ( i=0; i<MAX_PARTS; i++ )
    00163		{
    00164			if ( VehicleParts[i] != None )
    00165			{
    00166				VehicleParts[i].Destroy();
    00167			}
    00168		}
    00169	}
    00170
    00171
    00172
    00173	defaultproperties
    00174	{
    00175	     inertia=0.900000
    00176	     bStatic=False
    00177	     bStasis=False
    00178	     bIgnoreDynLight=False
    00179	     bCollideActors=True
    00180	     bCollideWorld=True
    00181	     bBlockActors=True
    00182	     bBlockPlayers=True
    00183	     bActorShadows=True
    00184	     bRotateToDesired=True
    00185	     RotationRate=(Yaw=10000)
    00186	}

End Source Code