===============================================================================
"Other_Models.txt" - Tips for using the Move_Car script for other model types  Version 1.1  April 21, 2002
===============================================================================
                 Also see "Other_Models2.txt" for tips on additional models
===============================================================================
The Move_Car script does not know what kind of a vehicle, or model, you are using.  
You can assign the action "player_car" to a car, a boat, a tank, a bicycle, an airplane,
a space ship, a person, or even just a cube, and the script will provide all the effects
for motion of the object.

Regardless of what your model looks like, you will get all the movement and special
effects that are set in the table entries.  Each model is considered to be a "box", 
and will accelerate, tilt, roll, fly off of ramps, etc. just like a car.  
(Make a model of a tool box, or a house, and the script will move it along, just fine!)

There are two major differences between types of models:
  1.  How it is animated, and
  2.  How it behaves.
(We will ignore the on-screen displays, since they can be modified with a paint program,
or turned off completely.  Sound files can also easily be replaced, or removed.  Collision
detection is not really a part of this movement script.)

The Move_Car script does not provide any model animation.  (You will have to provide
that programming for your own model.)

What we can change in the script, is how the model behaves.  Many of the behaviours
can be changed just by entering different table values.  For example, if you change the
model to a snowmobile, you should only have to change "Num_Gears" to 1, and set
whatever gear ratio you want, such as 2.0.  You may find that is all you need to do, to 
have a realistic snowmobile!  (You may want to "fine tune" other table entries such as 
horsepower, acceleration value, rock back, leaning, hill effect, etc.)

More complex motions, such as the ability to fly, (for flight simulators), will require 
additional programming functions, to calculate lift, and the ability to "steer" up or down.  
These additional effects can be added to the script by adding a function, such as "flying".  
Then insert the function call in the "cook book" list of functions that are used.  
(See the section on "Airplanes", near the end of "Other_Models2.txt".

Please see the documentation file, "Changes.txt" for more detailed information on what 
happens when you change values in table entries.

Following this section, are suggestions for different model types.  I have not tested them.
However, they should give you some hints on how to get started.

Line numbers are given to help you find different parts of the script.  (The script 
currently has 1,088 lines of programming.)  If your text editor does not display line 
numbers, they will still help you know the approximate location.   Because future 
releases of the script may have more, or less, lines of code, the numbers are only 
approximate.  You can also use the "search" feature of your editor.

Script lines are shown in brackets:      [  This is what you will see in the script; ]
The brackets "[" and "]" are only for the documentation, to show that a line was taken  
directly from the C-Script file.    ***  Do NOT include them in your script!  ***
_______________________________________________________________
ANIMATING WHEELS
The Move_Car script is designed to handle the motion physics for a lot of different types 
of vehicles.  To animate wheels, or make them steerable, you need to know the exact 
type and dimensions of the model you plan to use. Since the script doesn't know where the 
wheels would attach for your model, this feature is not included in the script.  However, 
once you have the model you want, it isn't that difficult to add wheels that rotate, or steer.

To make the wheels rotate, you need to position, or attach, models of wheels to the main 
model.  You can either rotate the wheel models, the same way as the spedometer or the 
tachometer does with their needles, or you can use animation frames.  Rotating the wheel
models should be the most realistic, since you can very easily control how fast they rotate,
and which direction they turn.

The "axle_rpm" (line 105) variable provides you with the data you need, to know when, 
which direction, and how fast to rotate your wheel models.  
[  var axle_rpm = 0;   // Rotation speed of the axles/wheels, in rpm (calculated) ]

The "steer_force" or "steer_speed" variables (lines 136 and 138) should give you the 
values you need to steer the front wheels, or turn the steering wheel.
[   var steer_force=0;      // Used instead of aforce.pan (calculated)  ]
[   var steer_speed=0;      // Used instead of aspeed.pan (calculated) ]
________________________________________________________________
VANS

See ANIMATING WHEELS near the beginning of this document.

Very similar to a car. You may only have to change the table value for (Air) Drag. (Line 
number 28.)  Rolling Resistance is calculated from the value in (Air) Drag.  To change 
the calculation, see line number 1074:
[   Resistance = Drag * 60; // Rolling resistance, based on air Drag (calculated) ]

You may also want to change the sound of the engine.  This is controlled in the function
"tune_esound".  (Line 416)  Look for the calculation for "eng_pitch"  (line 422).
       [ eng_pitch = RPM/15;   // tune the sound depending on rpm   ]
Tuning of the engine sound is based on the RPM of the engine.  If you change the "15"
to, say, "20", the sound of the engine will stay in the lower frequencies.  Experiment with 
this number until you get the sound you want.  (Never set it to zero!)  Or, change the
sound file as shown in line 67  [sound engsound = <Car_Engine.wav>;  // Engine sound file].
___________________________________________________________
TRUCKS

See ANIMATING WHEELS near the beginning of this document.

Generally the same as for a van, for drag and engine sound tuning.  
You may want to add more gears.  You can have up to six forward gears without doing 
any programming.  Set "num_gears" to the number of gears you want to have.  (Line 31)  
   [  var num_gears = 6;  // Number of forward gears (at least 1, but no more than 6) ]
Then enter the gear ratios (lines 1052 - 1058).

If you want to have 10, 12 or more forward gears, you will have to increase the size of the 
gear array, to hold more gear ratios.  Change the number in the brackets to increase the 
size of the gear array.   There is no limit to the number of gears you can add.
(Gear zero is always the reverse gear.)    (line 120)

   [   var gear_ratio[7];      // Gear ratios for 6 forward, and 1 reverse (gear zero)  ]

You will also have to add more gear ratio lines of code for the extra gears (line 1058+)
And, if you are going to use the on-screen gear number display, you will have to 
add more numbers to the bit map (bmap) file.  (See line 93)
   [ bmap gears = <gearpix.pcx>;   // Gear number display - numbers are 20 pixels wide ]

You may want to replace the horn sound file, to make your model sound more like a truck.
(line 63)  [  sound horn_sound = <Car_Horn.wav>;   // Horn sound file ]

See "VANS" (above) for tips on changing the engine sound.

Increase the number for "Accel_val" to make your truck accelerate slower (line 38).
   [  var Acel_Val = 6;     // Acceleration value - increase to accelerate slower ]

Finally, change the horsepower, vehicle weight, differential ratio, gear efficiency,  and
RPM shift points to make your model behave more like a truck.  (lines 25 - 50)
______________________________________________________________
TRAINS
Trains are just like a truck, or a bus, except you can't steer them.  And - for diesel
locomotives, the diesel engine generates electricity, which then powers the electric
motors, which is what really moves the train engine.
For steam engines, the biggest challenge will be the animation frames for the model.
Electric locomotives should use identical table values as steam or diesel locomotives.

The script should move steam, diesel, or electric engines equally well.

Follow the instructions for a Truck, except you may want to have only one gear.
(Enter "num_gears" (Line 31)  and the gear ratios  (lines 1052 - 1058).)

See "VANS" (above) for tips on changing the engine sound.

Increase the number for "Accel_val" to make your train accelerate slower (line 38).
   [  var Acel_Val = 6;     // Acceleration value - increase to accelerate slower ]

Finally, change the table entries for horsepower, vehicle weight, differential ratio, Drag,
and gear efficiency to make your model behave more like a train.  (lines 25 - 50)

There is a function especially for steering.  You only have to look in one place - the 
function called "Car_Steering()"  (line 990).
(Keyboard, mouse or joystick input is in the function "Car_Player_Intentions()" (line 733).
 You shouldn't have to change anything there, and it will continue to provide inputs for you,
 whether you use "steering" or not.  You will probably want to continue using the throttle.)
Lay down some "paths" in your level, that follow the railroad track.  Then replace the
instructions in the "Car_Steering()" function with instructions that will follow your 
path (railroad track).  (Just like you would for AI entities.) See the "ent_path"
and "ent_nextpoint" instructions in the 3DGS manual.

You can "switch tracks" with the "ent_path (string);" instruction.  When you approach
the switch, or the siding, issue the ent_path instruction with the name of the new path
for the new track.  (Should work just fine!)
______________________________________________________________
BUSES
Generally the same modifications as for a truck and/or a van.
______________________________________________________________
DRAGSTERS

See ANIMATING WHEELS near the beginning of this document.

Enter "num_gears" (Line 31)  and the gear ratios  (lines 1052 - 1058).
You may want to change your UpShift RPM if you are using multiple gears. (line 49)

   [ var UpShift = 6000;  // Specify RPM to shift to higher gear (+500 if accelerator floored) ]

You may want to change the sound file, to sound harsher, and less like it has a 
muffler -  (line 67)  [sound engsound = <Car_Engine.wav>;  // Engine sound file].

The most important change will probably be for the rate at which your dragster will
accelerate.  Lower the number for "Accel_val" to make your dragster accelerate 
faster (line 38). [var Acel_Val = 6; // Acceleration value - increase to accelerate slower ]
NOTE:  This value can not be less than 1.

Finally, change the horsepower, vehicle weight, differential ratio, gear efficiency,  and
RPM shift points to make your model behave more like a dragster.  (lines 25 - 50)

Q. I want my dragster to have a drouge parachute for stopping.  How do I do that?
A. A drogue chute only opens when you get to the end of the drag race.  Let's assume 
     you created your drag strip in the "X" direction, with the start at zero, and the finish
     line 10,000 quants away.  (If you built it in the "Y" direction, just use "Y" wherever
     it says "X".  You can check this by placing your mouse cursor at the starting line, and 
     look at the X & Y numbers at the bottom of your screen.  Then put your mouse cursor
     at the finish line, and see which number gets bigger.)  Let's assume you see X: 10000 
     at the finish line.
     Now, you need to do two things:
        1. Attach an animated drogue chute model to the back of the dragster, and 
        2. Simulate the braking effect of the parachute.

      To know when to deploy the chute, add this line of script:
                   if (my.pos.x >= 10000) {pop_chute();}
      Insert this line of code in the cookbook list of functions, somewhere in  lines 716 - 730.
      The "IF" statement will be true, when you are at, or have crossed the finish line. And, 
       it will execute the function "pop_chute()".  (You will need to define this function 
      somewhere else.)  In your function "pop_chute", you will need to attach a chute model 
      to a rear vertex number of your dragster model.  Set a variable to indicate you have opened 
      the chute, so next time through, you won't try to open a second chute.  For example, start out
      with "var chute = 0;" and use an IF statement to test if it is still zero.  If it is, deploy the 
      chute, and set the variable equal to one.  (chute =1;)  Next time, the "IF" statement will
      fail, and you won't try to open another chute.
      After the "IF" statement section in the function, you can change the animation frame, 
      to make your drogue chute flap, spin, or whatever you have in your animation frames.

      Now we need to "trick" the script into thinking the handbrake has been applied.
      Go to function "check_brake()", which is around line 330 in the script.  Look through
      the function, and right before the ending brace "}" is the line that turns on the hand brake.
      Let's insert one new line of code, between lines 345 and 346.  It should come right after:
  [ if((joy_1= = 1)||(key_x= = 1)){T_Brake += (sign(car_velocity))*(-Brake_Torque);} ]
     Assuming you are using the "chute" variable as suggested above, 
      here is the new line you will have to add: 
              if (chute = = 1) {T_Brake += (sign(car_velocity))*(-Brake_Torque);}
      That will do it!  
      Now you have a dragster that automatically opens a drogue chute, and then slows down.

      But suppose you want to manually open the chute yourself.  How do we do that?
      Let's say you plan to use the keyboard key "C", for "Chute".  Change the first line we added:
                  if (my.pos.x >= 10000) {pop_chute();}
      to this instead:
                  if (key_c = = 1) {pop_chute();}
      Now you can control when it opens.  And, you can use the same technique, to get rid of it.
________________________________________________________________
MOTORCYCLES   (Also mopeds and motor scooters)

You will be able to drive your motorcycle around, and jump off of ramps, or over 
mounds of dirt (for motocross) without changing anything in the car table entries.  
But, let's make it a little more realistic:

See ANIMATING WHEELS near the beginning of this document.

Change the horsepower, vehicle weight, differential ratio, gear efficiency,  drag, and
RPM shift points to make your model behave more like a motorcycle.  (lines 25 - 50)
Set "num_gears" to the number of gears you want to have.  (Line 31)  
Then enter the gear ratios (lines 1052 - 1058).  (See "TRUCKS" (above) if you want 
more than 6 forward gears.)
You may want to play around with "Accel_Val" - Acceleration Value - (line 38).
     [ var Acel_Val = 6;     // Acceleration value - increase to accelerate slower ]
Set Accel_Val to a lower number to accelerate more quickly, but never less than one!

We probably want our motorcycle to lean "into" the turns, rather than away from them.  And, 
the motorcycle will lean more than a car.  Play with the value of "Corner Lean" - line 41.
   [ var Corner_Lean = -0.1; // Leaning amount for cornering, reverse sign to reverse lean ]
You might want to try using a value of +0.3, or +0.5 for starters, then see how it works!
(Don't forget the amount of lean is also affected by the speed of the vehicle.)

To get the sound of "racking the pipes", change the engine sound file, and/or the tuning 
for the engine sound, as described in "VANS", above.

You may want to eliminate the sound of tires squealing, when you are in a tight turn.
Set the table value of "T_Chirp" very high, such as 100   (line 47).
  [ var T_Chirp = 0.4;  // Turning force needed to cause tire squeal, or "chirp" ]
The turning force shouldn't get high enough to cause a squeal.

You now have to decide if your rider should "lean" with the ground, or stay upright. That is 
controlled by the function: "car_scan_floor()"  (line 885).  (Actually, the control that is 
used is not "tilt", but "roll".)  I think you can make the rider stay upright, regardless of the
angle of the ground, just by commenting out line 920:
            [    my_angle.roll = -asin(my_floornormal.y);    ]
The rider will still "nose up" when climbing a hill, or "nose down" when descending. (tilt)

Finally, any good motorcycle should be able to do "wheelies".  This is called "roll".
There is a table entry called "Rock_Back", to control the "roll" effect (line 45):
    [ var Rock_Back = .8; // For accelerating and braking - set high for wheelies  ]
You might want to try setting this somewhere between 2 and 6, to see what happens.

"Rock_Back" is calculated in the function: "car_scan_floor()" (line 885).
The Rock_Back calculation is done in line 940:
     [ my.tilt += Rock_Back * car_accel;  ]
Notice that the Rock_Back variable is multiplied by "Car_Accel", or the amount the
vehicle is accelerating.  If you change  "Accel_Val" (Acceleration Value - line 38), the
"Rock_Back" effect will automatically change accordingly.
That's good for raising the front wheel for wheelies, but it will also raise the back wheel 
when you are stopping quickly.  To fix this, change line 940 (as shown above) to:
        if (car_accel > 0) { my.tilt += Rock_Back * car_accel;}
Now the Rock_Back effect will only work when taking off (positive acceleration) , 
and not when braking (negative acceleration).

Note:  Because the model looks like a "box", it will rotate around the origin of the
model.  So when the front wheel raises up, the back wheel will dip down into the ground.
You might be able to compensate for this, in the function "On_Ground" (line 371).
Just before the end of this function, (between lines 390 and 391) add the line:
       if (car_accel > 0) {absdist.z  +=  Rock_Back * car_accel * SomeNumber;}
The value in "absdist.z" determines how much your model moves up or down.  So by 
modifying "absdist.z", you can change the height of the origin, above the ground.  You want
to raise the origin by the amout the rear wheel will "dip" down.  How much you raise the
origin of the model, will depend on the length of the model, and where the origin is, within 
the model.  "SomeNumber" is a fudge factor to help adjust the height of the origin, based 
on the amount of Rock_Back and Car_Accel.  You will have to play with this, until it 
looks right for your model!
One final note: "absdist.z" will move your model straight up and down, even if you are on 
a hill.  You might want to experiment with "dist.z" instead, which will move you up and down, 
relative to the model, instead of in relation to flat, level ground.
____________________________________________________________________
BICYCLES
At first glance, it would seem that bicycles would need a radically different script, than a
motorcycle.  But the script is just moving a "box", and has no idea if your engine is using
pumping pistons, or pumping legs.  That difference is in the animation frames for your model.
Look through the instructions for MOTORCYCLES, above to make adjustments for 
two wheelers.

For a twelve speed mountain bike, you will have to increase the size of the gear array, and 
add more numbers to the on-screen gear indicator (if you want to use it)..   (See TRUCKS)
Instead of a "Differential_Ratio", you will need to enter the overall gear ratio of the pedal gear, 
chain and rear wheel gear.

Change the engine sound file to that of the sounds of the chain going round and round.
(line 67)  [sound engsound = <Car_Engine.wav>;  // Engine sound file]

Also change the "horn.wav" sound file to one with the "ding" of a bicycle bell.
(line 63)  [  sound horn_sound = <Car_Horn.wav>;   // Horn sound file ]

Finally, change the horsepower, vehicle weight, Accel_Val, gear efficiency,  and
RPM shift points to make your model behave more like a bicycle.  (lines 25 - 50)
____________________________________________________________________
ATVs  (All Terrain Vehicles)
Sonetimes they are tricycles, and sometimes they have four wheels.  In either case, the 
script will treat them as if they are a box.  The number of wheels won't matter, unless you 
want to animate moving wheels, or steerable wheels.  (See ANIMATING WHEELS near 
the beginning of this document.)

Your ATV behaves like both a car, and a motorcycle.  The table entries are already set for
a car.  Take a look at the Motorcycle instructions (above), and adjust them for more, or less,
of the same effects you would want in an ATV.
____________________________________________________________________
SNOWMOBILES
The movement physics for a snowmobile is very similar to that of an ATV (above). 
The major difference is the way the model looks.  And (maybe) what you display in 
animation frames for the model.  Simply follow the instructions for ATVs.
_____________________________________________________________________
TANKS        You're welcome!          [   sorry!   :-)   ]
If you want, (and have the cpu cycles to spare), you can animate not only the rotation of the tread, 
but also each of the idler wheels that make the tread move. See ANIMATING WHEELS near 
the beginning of this document.

What you need to adjust, depends on the tank you are trying to simulate.  Tanks from WW I and
even WW II were generally slow, lumbering vehicles that couldn't go very fast.  But modern,
turbine powered tanks, can behave more like a fairly fast truck, than like their ancestors.
Take a look at some of the adjustments you can make, in TRUCKS (above).

You may also want to change the sound of the engine.  This is controlled in the function
"tune_esound".  (Line 416)  Look for the calculation for "eng_pitch"  (line 422).
       [   eng_pitch = RPM/15;   // tune the sound depending on rpm   ]
Tuning of the engine sound is based on the RPM of the engine.  If you change the "15"
to, say, "20", the sound of the engine will stay in the lower frequencies.  Experiment with 
this number until you get the sound you want.  (Never set it to zero!)  Or, change the
sound file as shown in line 67  [sound engsound = <Car_Engine.wav>;  // Engine sound file].

Besides adjustments mentioned in TRUCKS, you will also want to increase the value of 
"Acel_Val", which slows down how much the vehicle can accelerate (line 38). 
       [var Acel_Val = 6; // Acceleration value - increase to accelerate slower ]

With slow acceleration, you probably won't have to worry about tire squealing, or the
"Rock Back" effect.  Set the table entry for A_Chirp (line 37) to a high value (100+).
  [ var A_Chirp = 0.2;  // Amount of acceleration to cause tire squeal, or "chirp" ]

To cancel any Rock Back effect, set the table entry for Rock_Back (line 45) to zero.
  [ var Rock_Back = .8;     // For accelerating and braking - set high for wheelies ]
OR - you can also comment out line 939:
              [  my.tilt += Rock_Back * car_accel; ]

We probably don't want our tank to lean very much in turns. See "Corner_Lean  (line 41).
  [ var Corner_Lean = -0.1; // Leaning amount for cornering, reverse sign to reverse lean  ]
If you set the table value for Corner_Lean to zero, it will turn off both leaning and squealing
while you are turning.

You might want the tank to lose a lot of forward speed while turning.  To do this, just
lower the number in the table entry for Turn_Effect (line 48):
  [ var Turn_Effect = 4;    // Power loss when turning (Bigger number is less effect) ]
You can not set this number to less that one.
The calculation where Turn_Effect is used, is at line 831, in the function "car_physics()".
  [ if(abs(car_velocity) > 10) {Torq_Drive_Train -= (abs(steering)/Turn_Effect)*Max_Torq;} ]

Regardless of how you animate the treads, the most important thing is how you turn the "box"
of the model.  The default table entries (with variable ratio steering) are designed to prevent a 
car from rotating in place.  (Which is something a tank does very well!)
You only have to look in one place - the function called "Car_Steering()"  (line 990).
(Keyboard, mouse or joystick input is in the function "Car_Player_Intentions()" (line 733) .
 You shouldn't have to change anything there, and it will continue to provide inputs for you.)

To eliminate the variable ratio steering, comment out line number 1002:
       [  steer_ratio = sin(car_velocity/2) * steer_damage; ]
and replace it with a line similar to:
        [  steer_ratio = steer_damage;   ]
Steer_Damage is usually always equal to one.  But if you reduce this number, you will make 
the steering less effective.  If you set it to zero, the tank won't turn at all.
With this change, the tank can rotate in place, even if there is no forward speed.

Most of the other changes you will need to make have more to do with the animation of
the tank model, such as rotating the turret, and raising or lowering the main gun barrel.  
Take a look at "DRAGSTERS" (above) for ideas on adding functions to control models 
attached to your main model.

You will also want to disable the forced downshift, and use joystick buton number one (the
trigger) to fire the gun, instead of activating a handbrake.
The downshift function is at line 316:
  [ Use_Gear = gear-(key_shift || mouse_left || joy_5); // Sets gear to use - possible down shift ]
Change this line to:    Use_Gear = gear;
This also frees up the left button on the mouse to be used as a "fire" button.

The joystick "buton number one" assignment is at line 345:
  [  if((joy_1= =1)||(key_x= =1)){T_Brake += (sign(car_velocity))*(-Brake_Torque);} ]
Simply comment out this line.
__________________________________________________________________
OTHER MILITARY VEHICLES
Almost every other military vehicle that I can think of, (APCs, Hum Vees, etc.) will likely 
be a cross between a car, a truck and/or a tank.  Look at the adjustments available to you 
in TRUCKS and TANKS, and you should be able to simulate almost any kind of military 
vehicle.
Remember - the script just changes the movement behaviour - not the appearance or 
animation of the model.  
__________________________________________________________________
TRACTORS and other motorized farm machinery and construction equipment
Should be the same as for "Other Military Vehicles" (above).
A combine has different animation frames than a truck, bus, or a tank, but the movement
physics is pretty much the same.  Just change the table entries for horsepower, gearing, 
acceleration, etc. until it behaves like the machinery it is.
_____________________________________________________________________
