# SFVehicle.SFVehiclePathMover

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 |
    //=============================================================================
    // Spatial Fear
    // Name: SFVehiclePathMover
    // Description: Vehicle which moves between its pathnodes by means of its forward/backward control.  ou can make a
    //                   pathnode a child component of another SFVehicle.  Note that pathnodes need to have unique sequences
    //                   within their tag, or the results are pretty unpredictable. Also, there is currently a maximum of 25 nodes.
    //
    // Author: Gert Jen Peltenburg
    //=============================================================================
    class SFVehiclePathMover expands SFVehicle;

    enum PathControlMethod {
     VehicleSpeed,
     VehicleTurn,
     TurretUp,
     TurretTurn,
     JumpDuck,
     FireAltFire
    };

    var SFVehiclePathNode pathnode[25];
    var int pathnodecount;
    var (SpatialFear_PathMover) name PathTag;
    var (SpatialFear_PathMover) bool bLoopingPath;
    var (SpatialFear_PathMover) bool bElasticPath;
    var (SpatialFear_PathMover) PathControlMethod ControlMethod;
    var SFVehiclePathNode currentnode;
    var float currentposition;
    var bool bPathOK;

    simulated function PostBeginPlay()
    {
     local SFVehiclePathNode prevnode,firstnode,pn;
     local int i;

     super.PostBeginPlay();

     Origin=vect(0,0,0);
     PlaneAngles=rot(0,0,0);

     currentposition=0;
     currentnode=None;

     foreach allactors(class'SFVehiclePathNode',pn,pathtag)
     {
      if(pn.sequence<arraycount(pathnode)) {
       pathnode[pn.sequence]=pn;                      // this sorts the path nodes
      }
     }
     prevnode=None;
     firstnode=None;

     for(i=0;i<arraycount(pathnode);i++) {            // assign previous and next
      if(pathnode[i]!=None) {
       if(prevnode==None)                   // only on first pathnode encountered
        firstnode=pathnode[i];
       else
        prevnode.Next=pathnode[i];

       pathnode[i].Prev=prevnode;
       prevnode=pathnode[i];
      }
     }
     if(prevnode!=None && firstnode!=prevnode) { // at least two pathnodes
      if(bLoopingPath) {
       prevnode.Next=firstNode;
       firstnode.prev=prevnode;
      }
      bPathOK=true;
      CurrentNode=firstnode;
      CurrentRotation=rotator(currentnode.next.location-currentnode.location);
      CurrentLocation=currentnode.location+vector(CurrentRotation)*currentposition;
      SetRotation(CurrentRotation);
      SetLocation(CurrentLocation);
     }
     else {
      bPathOK=false;
     }
     currentspeed=0;
    }

    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)
    {
     local float newspeed;
     newspeed=0;

     switch(ControlMethod) {
      case VehicleSpeed:
           if(aVehicleSpeedControl>0)
            newspeed= (aVehicleSpeedControl/16384.0)*MaxSpeed;
           else
            newspeed= abs(aVehicleSpeedControl/16384.0)*MinSpeed;
           break;
      case VehicleTurn:
           if(aVehicleTurn>0)
            newspeed= (aVehicleTurn/16384.0)*MaxSpeed;
           else
            newspeed= abs(aVehicleTurn/16384.0)*MinSpeed;
           break;
      case TurretUp:
           if(aTurretUp>0)
            newspeed= (aTurretUp/16384.0)*MaxSpeed;
           else
            newspeed= abs(aTurretUp/16384.0)*MinSpeed;
           break;
      case TurretTurn:
           if(aTurretTurn>0)
            newspeed= (aTurretTurn/16384.0)*MaxSpeed;
           else
            newspeed= abs(aTurretTurn/16384.0)*MinSpeed;
           break;
      case JumpDuck:
           if(aVehicleUp>0)
            newspeed=MaxSpeed;
           else
           if(aVehicleUp<0)
            newspeed=MinSpeed;
           break;
      case FireAltFire:
           if(bFire)
            newspeed=MaxSpeed;
           else
           if(bAltFire)
            newspeed=MinSpeed;
           break;
     }
     desiredspeed=newspeed;
    }

    simulated function DoPhysics(float DeltaTime)
    {
     local float accel;
     local float PreviousPosition;
     local SFVehiclePathNode PreviousNode;

     if(bPathOK) {
      PreviousPosition=CurrentPosition;
      PreviousNode    =CurrentNode;
      PreviousRotation=CurrentRotation;
      PreviousLocation=CurrentLocation;

      currentposition+=currentspeed*deltatime;
      checknewposition();

      accel=0.0;
      if(MaxSpeed>0) {
       if(DesiredSpeed<CurrentSpeed)
        accel=MAX(DesiredSpeed-CurrentSpeed,-MaxDeceleration*deltatime); // note: desiredspeed-currentspeed is negative, so accel is negative

       if(DesiredSpeed>CurrentSpeed)
        accel=MIN(DesiredSpeed-CurrentSpeed,MaxAcceleration*deltatime);
      }
      CurrentSpeed+=accel;
      if(CurrentSpeed>MaxSpeed)
       CurrentSpeed=MaxSpeed;
      else
      if(CurrentSpeed<MinSpeed)
       CurrentSpeed=MinSpeed;

      linearvelocity=vector(rotator(currentnode.next.location-currentnode.location))*currentspeed;
      CurrentRotation=rotator(currentnode.next.location-currentnode.location);
      CurrentLocation=currentnode.location+vector(CurrentRotation)*currentposition;

      if(CheckForCollision(deltatime)) {
       CurrentNode=PreviousNode;
       CurrentPosition=PreviousPosition;
       CurrentSpeed=0;
      }
     }
    }

    // CheckNewPosition updates the currentposition and currentnode
    // this will temporarily 'halt' at the node so DoPhysics can use a linear CheckForCollision
    simulated function CheckNewPosition()
    {
     local bool c;

     if(currentposition>0 && currentnode.next==None) {
      currentposition=0;
      currentspeed=0;
      return;
     }

     c=true;
     while(c) {
      c=false;
      if(currentposition<0) {
       if(currentnode.prev!=None) { // travel to previous stretch
        c=true;
        currentnode=currentnode.prev;
        currentposition=vsize(currentnode.location-currentnode.next.location);
       }
       else {
        currentposition=0;
        currentspeed=0;
       }
      }
      else
      if(currentposition>vsize(currentnode.location-currentnode.next.location)) {
       if(currentnode.next!=None) { // travel to next stretch
        c=true;
        currentposition=0;
        currentnode=currentnode.next;
        if(currentposition>0 && currentnode.next==None) {
         currentposition=0;
         currentspeed=0;
         return;
        }
       }
       else {
        currentposition=vsize(currentnode.location-currentnode.next.location);
        currentspeed=0;
       }
      }
     }
    }

    simulated function RotationPhysics(float DeltaTime)
    {
    }

    defaultproperties
    {
         PhysicalRotationRate=(Pitch=0,Yaw=0,Roll=0)
         bRepairable=False
         RepairTime=0.000000
         bFullTimePhysics=True
         bDamageTriggered=True
    }

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