SFVehicle.SFHelicopter

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
//=============================================================================
// Spatial Fear
// Name: SFHelicopter
// Description: A vehicle class with helicopter-like behavior
//
// Author: Gert Jen Peltenburg
//=============================================================================
class SFHelicopter expands SFVehicle;
var (SpatialFear_Helicopter) float AirDrag;
var (SpatialFear_Helicopter) bool TailRotorControllable; // allows aim left/right to turn the helicopter during a hover
var (SpatialFear_Helicopter) float TranslationalYawRate; // how quickly will the helicopter turn as a result of roll
var (SpatialFear_Helicopter) float MaxRotorLift;         // how much lift will the rotor generate at maximum collective
var (SpatialFear_Helicopter) float MaxTranslationalLift; // how much lift will there be when traveling at max speed
var (SpatialFear_Helicopter) float ClimbRate;            // maximum climb rate the player indicates
var bool OnGround;
var float CollectiveSetting; // influenced by the jump/duck keys
var float ControlInputCollective;

// helicopter uses strafing and forward/backward controls for rotation and collective (rotor lift)
// uses look for pitching the rotor. (look left for skidding left, look down for forward movement)
// a separate gunner will be needed if you want a swiveling weapon.
simulated function InterpretControls(bool bJustFired,bool bFire,bool bJustAltFired,bool bAltFire,
                           float aVehicleSpeedControl,float aTurretTurn,float aVehicleTurn,
                           float aVehicleUp,float aTurretUp,bool bJustJumped,bool bJustDucked)
{
 if(aVehicleTurn<0)       // skidding. Note, at speed, this influences yaw
  controlinputRoll = max(MinRoll,MinRoll*(-aVehicleTurn/16384.0));
 else
  controlinputRoll = min(MaxRoll,MaxRoll*(aVehicleTurn/16384.0));

 if(TailRotorControllable) {  
  if(aTurretTurn<0)       // rotating by varying the force from the tail rotor. Note, at speed, this has very little effect
   controlinputYaw = (aTurretTurn/16384.0)*YawLeftRate;
  else
   controlinputYaw = (aTurretTurn/16384.0)*YawRightRate;
 }
 else
  controlinputYaw = 0.0;
  
 if(aVehicleSpeedControl<0)  // accelerating means pushing the nose down, not up, so inverted
  ControlInputPitch = min(MaxPitch,MaxPitch*(-aVehicleSpeedControl/16384.0));
 else
  ControlInputPitch = max(MinPitch,MinPitch*(aVehicleSpeedControl/16384.0));
 
 ControlInputCollective=ClimbRate*aVehicleUp/16384.0;
 if(ControlInputCollective< -ClimbRate)
  ControlInputCollective= -ClimbRate;
 else
 if(ControlInputCollective> ClimbRate)
  ControlInputCollective= ClimbRate;
}

// UpdateSpeed overridden because helicopter can skid (all handled in dophysics)
simulated function UpdateSpeed(float DeltaTime,float traction)
{
}

simulated function ModifyAmbientSound()   // helicopter
{
 SoundRadius=255;
 SoundVolume=MIN(MAX(64,64+192*collectivesetting),255);
}

// helicopter can have translational lift (lift through speed) as well as rotor lift.
// at low speeds, this isn't apparent, but at high speeds, the helicopter flies pretty much like
// a fixed wing aircraft.
simulated function DoPhysics(float DeltaTime)
{
 local vector acceleration;
 local vector tempvel,templocation,O,N,HitLocation,HitNormal;
 local actor groundobject;
 local float neededacceleration;
 
 if(groundfeedbackindex<0)
  return;

 PreviousLocation=CurrentLocation;

 neededacceleration=ControlInputCollective-linearvelocity.Z;
 templocation=RealWorldLocation(vect(0,0,1),CurrentRotation);

 // calculate collective setting to counter gravity AND climb at a certain rate
 if(templocation.Z>0) {
  collectivesetting=(neededacceleration+VSize(region.zone.zonegravity))/MaxRotorLift/TempLocation.Z;
  if(collectivesetting< 0.0)
   collectivesetting= 0.0;
  else
  if(collectivesetting> 1.0)
   collectivesetting= 1.0;
 }

 tempvel=virtuallocation(linearvelocity,rotation);
 
 if(passengerof!=None)
  tempvel += virtuallocation(passengerof.velocity,rotation);

 tempvel.Z=0.0;
 
 acceleration=templocation*(collectivesetting*MaxRotorLift+VSize(tempvel)*MaxTranslationalLift/MaxSpeed)+region.zone.zonegravity;

 if(!OnGround && acceleration.Z<=0.0) { // check if we're now on the ground
  TempLocation    = Feedback[groundfeedbackindex].originoffset;
  TempLocation.X=0; 
  TempLocation.Y=0; 
  TempLocation.Z+=2.0;
  N=CurrentLocation+RealWorldLocation(RealWorldLocation(TempLocation,CurrentRotation),planeangles);
  TempLocation    = Feedback[groundfeedbackindex].originoffset;
  TempLocation.X=0; 
  TempLocation.Y=0; 
  TempLocation.Z-=2.0;
  O=CurrentLocation+RealWorldLocation(RealWorldLocation(TempLocation,CurrentRotation),planeangles);
  if(passengerof!=None) {
    N=RealWorldLocation(N,passengerof.rotation)+passengerof.location;
    O=RealWorldLocation(O,passengerof.rotation)+passengerof.location;
  }
  groundobject=Trace(HitLocation,HitNormal,O,N,false);
  while(groundobject!=None && SFVehicle(groundobject)==Self) {
   groundobject=Trace(HitLocation,HitNormal,O,HitLocation+normal(O-HitLocation),false);
  }
  if(GroundObject!=None && groundobject!=self) 
   OnGround=true;
 }
 if(acceleration.Z>0) 
  OnGround=false;

 if(OnGround) { // on the ground, a helicopter can not rotate (or move)
  LinearVelocity=vect(0,0,0);
  super.DoPhysics(DeltaTime);
  return;
 }
// From here on, specific helicopter physics
 LastGoodLocation=CurrentLocation;
 LastGoodRotation=CurrentRotation;
 
 CurrentLocation+=(LinearVelocity)*deltatime;
 // drag
 LinearVelocity-=deltatime*normal(LinearVelocity)*MIN(AirDrag,VSize(LinearVelocity));

 CurrentSpeed=VirtualLocation(LinearVelocity,CurrentRotation).X;

 // slow speed stuff
 CurrentRotation.Yaw+=ControlInputYaw*DeltaTime;

 // high speed stuff /////////////////////////////////////////
 tempvel=VirtualLocation(LinearVelocity,PreviousRotation);
 tempvel.Z=0;
 
 LinearVelocity+=acceleration*deltatime;

 CurrentRotation.Yaw+=VirtualLocation(acceleration,CurrentRotation).Y*abs(CurrentSpeed/MaxSpeed)*TranslationalYawRate*DeltaTime;
 
// cap the speed
 LinearVelocity=min(VSize(LinearVelocity),MaxSpeed)*normal(LinearVelocity);
   
// Check for collision        ------- when hitting something, the helo will be damaged!
 if(CheckForCollision(deltatime)) {
  CurrentLocation = PreviousLocation;
  gravityinducedvelocity=vect(0,0,0);
  CurrentRotation = PreviousRotation;
  linearvelocity=-linearvelocity;
  if(linearvelocity.Z>0.0)
   linearvelocity.Z=0.0;
// TakeDamage(   )
 } 
}
  
simulated function RotationPhysics(float DeltaTime)
{
 local rotator NewRotation;
 local rotator NewStabilizedRotation;
 local float compensationYaw,compensationPitch,compensationRoll; // not using rotator because these values are generally<1
 local vector eyelocation,hitnormal,hitlocation,targetvector;
 local float high_angle,low_angle,flighttime;
 local rotator actualrot;
 
 if(DeltaTime<=0)
  return;
  
 if(!bPhysics)
  return;
   
 if(OnGround) // the helicopter cannot rotate while on the ground
  return;
  
 PreviousRotation = CurrentRotation;
 CurrentRotation = CurrentRotation+AngularVelocity*deltatime;
 CurrentRotation.Roll=normalizeangle(CurrentRotation.Roll);
 CurrentRotation.Pitch=normalizeangle(CurrentRotation.Pitch);
 CurrentRotation.Yaw=normalizeangle(CurrentRotation.Yaw);
 NewRotation = CurrentRotation;

 // only tail rotor is direct. Main rotor is stabilized. (meaning: if you let go of the stick, the helicopter will slow down)
 compensationyaw=ControlInputYaw*deltatime;
  
 // combined rotation rate may not exceed maximum values
 if(compensationYaw<-YawLeftRate*DeltaTime)
  compensationYaw=-YawLeftRate*DeltaTime;
 else
 if(compensationYaw>YawRightRate*DeltaTime)
  compensationYaw=YawRightRate*DeltaTime;
   
 compensationPitch=normalizeangle(ControlInputPitch-CurrentRotation.Pitch);
 compensationRoll=normalizeangle(ControlInputRoll-CurrentRotation.Roll);

 NewRotation.Roll = normalizeangle(NewRotation.Roll+compensationRoll);
 NewRotation.Pitch = normalizeangle(NewRotation.Pitch+compensationPitch);
 NewRotation.Yaw = normalizeangle(NewRotation.Yaw+compensationYaw);

 if(NewRotation.Pitch>MaxPitch+OffsetRotation.Pitch)
  NewRotation.Pitch=MaxPitch+OffsetRotation.Pitch;
 if(NewRotation.Pitch<MinPitch+OffsetRotation.Pitch)
  NewRotation.Pitch=MinPitch+OffsetRotation.Pitch;

 if(NewRotation.Roll>MaxRoll+OffsetRotation.Roll)
  NewRotation.Roll=MaxRoll+OffsetRotation.Roll;
 if(NewRotation.Roll<MinRoll+OffsetRotation.Roll)
  NewRotation.Roll=MinRoll+OffsetRotation.Roll;
  
 CurrentRotation = NewRotation; 
}

defaultproperties
{
     AirDrag=80.000000
     TranslationalYawRate=48.000000
     MaxRotorLift=1100.000000
     MaxTranslationalLift=100.000000
     ClimbRate=400.000000
     bHUD_ShowsPitch=True
     bHUD_ShowsYaw=True
     bHUD_ShowsRoll=True
     bHUD_ShowsSpeed=True
     bBot_ShowVehicleLocation=True
     Armor=50
     InitialHitPoints=80
     FullHitPoints=80
     DestructionEffect=None
     PhysicalRotationRate=(Pitch=16384,Yaw=16384,Roll=16384)
     AirTraction=1.000000
     bRestrictPitch=True
     MinPitch=-2048.000000
     maxPitch=2048.000000
     PitchUpRate=16384.000000
     PitchDownRate=16384.000000
     bRestrictRoll=True
     MinRoll=-2048.000000
     MaxRoll=2048.000000
     RollLeftRate=16384.000000
     RollRightRate=16384.000000
     YawLeftRate=2048.000000
     YawRightRate=2048.000000
     Elasticity=0.000000
     MaxSpeed=500.000000
     MaxAcceleration=200.000000
     bRepairable=False
     bFullTimePhysics=True
     bDamageTriggered=True
}

class file time: 12/7/2003 3:58:26 PM - creation time: 12/7/2003 4:03:44 PM
Created with UnCodeX