Category : Recently Uploaded Files
Archive   : RARS03.ZIP
Filename : CNTRL2.CPP

 
Output of file : CNTRL2.CPP contained in archive : RARS03.ZIP
// CNTRL2.CPP - "driver" function for RARS - M. Timin, Dec. 1994
// (see CNTRL0.CPP for better comments)

#include
#include
#include
#include "car.h"

extern const double CARWID;
extern char* glob_name;

con_vec cntrl2(situation s)
{
const char name[] = "Ritchie";
static int init_flag = 1;
con_vec result;
double alpha, vc;
double width; // track width, feet
double steer_gain = .18;
const double steer_damp = .48;
static int lane_time = 0; // counts time when not in normal lane
const double normalane = 60.0;
static double lane = 60; // determines right-left position on straigtaway
const double corn_con = 6.4;
static double corn_spd = 55.0;

if(init_flag) {
strcpy(glob_name, name);
init_flag = 0;
result.alpha = result.vc = 0;
return result;
}

if(s.out) { // no action when out of race
result.vc = result.alpha = 0.0;
return result;
}

// get unstuck from goofy situation:
if(s.v < 15.0) { // totally different control when speed is very slow:
alpha = .05 * (steer_gain * (s.to_lft-s.to_rgt) - steer_damp * s.vn/s.v);
if(alpha > .05)
alpha = .05;
else if(alpha < -.05)
alpha = -.05;
vc = .5 * (s.v + 16); // accelerate toward 16 fps
if(s.to_lft < 0.0) { // maybe reverse:
if(s.vn > .7 * s.v) // (cause you are heading off the track)
vc = -vc;
}
else if(s.to_rgt < 0.0)
if(s.vn <-.7 * s.v)
vc = -vc;
result.vc = vc; result.alpha = alpha;
return result;
}

if(s.cur_rad == 0.0 && s.nex_rad != 0.0)
corn_spd = corn_con * sqrt(s.nex_rad > 0.0 ? s.nex_rad : -s.nex_rad);
else
corn_spd = corn_con * sqrt(s.cur_rad > 0.0 ? s.cur_rad : -s.cur_rad);

// maybe choose a different lane: (to help in passing)
if(!s.dead_ahead) {
if(lane_time <= 0) {
lane = normalane;
lane_time = 0;
}
}
else if(!lane_time) {
// pick a different lane:
if(lane >= 80) // pick a new lane somehow:
lane = random(60) - 20;
else if(lane <= -80)
lane = 20 - random(60);
else
lane = random(180) - 90;
lane_time = 175; // we will stay in the new lane this long
}
if(lane_time > 0)
--lane_time;

width = s.to_lft + s.to_rgt; // find width of track
if(s.cur_rad == 0)
alpha = .25 * steer_gain * (s.to_lft - s.to_rgt - lane) / width;
else if(s.cur_rad > 0)
alpha = steer_gain * (4 * (s.to_lft-1.6*CARWID) / width
+ .2 * width/s.to_rgt);
else
alpha = -steer_gain * (4 * (s.to_rgt-1.6*CARWID) / width
+ .2 * width/s.to_lft);
alpha -= steer_damp * s.vn / s.v; // This is damping, to prevent oscillation

if(s.cur_rad == 0) // If we are on a straightaway,
if(s.to_end/s.cur_len > .38) // if we are far from the end:
vc = s.v + 100/s.v; // keep accellerating near full power
else { // otherwise,
// maintain cornering speed, braking at first
vc = corn_spd + 9.0 * s.to_end/s.cur_len;
// this next formala will not work if a rt. turn follows the straight:
alpha += .4 * (s.cur_len/(s.to_end + s.cur_len) - (1/1.38));
}
else // if we're in the curve, maintain speed, +
vc = corn_spd + .9 / (s.to_end + .4);

result.vc = vc; result.alpha = alpha;
return result;
} // v;


  3 Responses to “Category : Recently Uploaded Files
Archive   : RARS03.ZIP
Filename : CNTRL2.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/