void OtherCar::init(TrackDesc* itrack, tCarElt* car, tSituation *situation) { track = itrack; dt = situation->deltaTime; setCarPtr(car); currentsegid = track->getCurrentSegment(car); initCGh(); updatePos(); updateDir(); updateSpeedSqr(); updateSpeed(); }
MyCar::MyCar(TrackDesc* track, tCarElt* car, tSituation *situation) { AEROMAGIC = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_AMAGIC, (char*)NULL, 1.6f); CFRICTION = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_FMAGIC, (char*)NULL, 1.0f); /* init pointer to car data */ setCarPtr(car); initCGh(); initCarGeometry(); updatePos(); updateDir(); updateSpeedSqr(); updateSpeed(); /* damage and fuel status */ lastfuel = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_FUEL, NULL, 100.0); undamaged = situation->_maxDammage; if (undamaged == 0) undamaged = 10000; MAXDAMMAGE = undamaged / 2; fuelperlap = 0.0; lastpitfuel = 0.0; /* set up some car properties */ wheelbase = car->priv.wheel[FRNT_RGT].relPos.x - car->priv.wheel[REAR_RGT].relPos.x; wheeltrack = 2* fabs(car->priv.wheel[REAR_RGT].relPos.y); carmass = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_MASS, NULL, 0.0); mass = carmass + lastfuel; /* which wheels are driven */ char *traintype = GfParmGetStr(car->_carHandle, SECT_DRIVETRAIN, PRM_TYPE, VAL_TRANS_RWD); if (strcmp(traintype, VAL_TRANS_RWD) == 0) { drivetrain = DRWD; } else if (strcmp(traintype, VAL_TRANS_FWD) == 0) { drivetrain = DFWD; } else if (strcmp(traintype, VAL_TRANS_4WD) == 0) { drivetrain = D4WD; } updateCa(); double cx = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_CX, (char*)NULL, 0.0); double frontarea = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_FRNTAREA, (char*)NULL, 0.0); cw = 0.625*cx*frontarea; cgcorr_b = 0.46; pf = new Pathfinder(track, car, situation); currentsegid = destsegid = pf->getCurrentSegment(car); currentseg = track->getSegmentPtr(currentsegid); destseg = track->getSegmentPtr(destsegid); currentpathseg = pf->getPathSeg(currentsegid); destpathseg = pf->getPathSeg(destsegid); turnaround = 0.0; tr_mode = 0; accel = 1.0; fuelchecked = false; startmode = true; trtime = 0.0; derror = 0.0; /* DIST; MAXRELAX; MAXANGLE; ACCELINC; SPEEDSQRFACTOR; GCTIME; ACCELLIMIT; PATHERRFACTOR */ double ba[6][8] = { {1.2, 0.9, 25.0, 0.1, 1.2, 0.2, 1.0, 5.0}, {1.2, 0.9, 20.0, 0.1, 1.1, 0.5, 1.0, 5.0}, {1.2, 0.9, 15.0, 0.1, 1.0, 0.5, 1.0, 5.0}, {1.3, 0.9, 15.0, 0.02, 0.98, 0.5, 1.0, 5.0}, {1.6, 0.9, 15.0, 0.01, 0.95, 0.5, 1.0, 5.0}, {1.2, 0.9, 45.0, 0.1, 1.0, 0.5, 1.0, 1.0} }; for (int i = 0; i < 6; i++) { for (int j = 0; j < 8; j++) { behaviour[i][j] = ba[i][j]; } } loadBehaviour(NORMAL); /* this call is needed! perhaps i shold move it into the constructor of pathfinder. */ pf->plan(this); }
MyCar::MyCar(TrackDesc* track, tCarElt* car, tSituation *situation) { AEROMAGIC = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_AMAGIC, (char*)NULL, 1.6f); CFRICTION = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_FMAGIC, (char*)NULL, 1.0f); setCarPtr(car); initCGh(); initCarGeometry(); updatePos(); updateDir(); updateSpeedSqr(); updateSpeed(); // Damage and fuel status. lastfuel = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_FUEL, NULL, 100.0); undamaged = situation->_maxDammage; if (undamaged == 0) { undamaged = 10000; } MAXDAMMAGE = undamaged / 2; fuelperlap = 0.0; lastpitfuel = 0.0; // Set up some car properties. wheelbase = car->priv.wheel[FRNT_RGT].relPos.x - car->priv.wheel[REAR_RGT].relPos.x; wheeltrack = 2* fabs(car->priv.wheel[REAR_RGT].relPos.y); carmass = GfParmGetNum(car->_carHandle, SECT_CAR, PRM_MASS, NULL, 0.0); mass = carmass + lastfuel; // Which wheels are driven. const char *traintype = GfParmGetStr(car->_carHandle, SECT_DRIVETRAIN, PRM_TYPE, VAL_TRANS_RWD); if (strcmp(traintype, VAL_TRANS_RWD) == 0) { drivetrain = DRWD; } else if (strcmp(traintype, VAL_TRANS_FWD) == 0) { drivetrain = DFWD; } else if (strcmp(traintype, VAL_TRANS_4WD) == 0) { drivetrain = D4WD; } updateCa(); double cx = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_CX, (char*)NULL, 0.0); double frontarea = GfParmGetNum(car->_carHandle, SECT_AERODYNAMICS, PRM_FRNTAREA, (char*)NULL, 0.0); cw = 0.625*cx*frontarea; // Get PGAIN. STEER_P_CONTROLLER_GAIN = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_STEERPGAIN, (char*)NULL, 0.02f); STEER_P_CONTROLLER_MAX = GfParmGetNum(car->_carHandle, BERNIW_SECT_PRIV, BERNIW_ATT_STEERPGAIN_MAX, (char*)NULL, 0.1f); //printf("PC: %f, %f\n", STEER_P_CONTROLLER_GAIN, STEER_P_CONTROLLER_MAX); // Magic number for friction in pit lane, because the current code does not consider the pit surface. // TODO: Consider the pit surface properties. cgcorr_b = 0.46; pf = new Pathfinder(track, car, situation); currentsegid = destsegid = pf->getCurrentSegment(car); currentseg = track->getSegmentPtr(currentsegid); destseg = track->getSegmentPtr(destsegid); currentpathsegid = currentsegid; destpathsegid = destsegid; dynpath = pf->getPath(); turnaround = 0.0; tr_mode = 0; accel = 1.0; fuelchecked = false; startmode = true; trtime = 0.0; derror = 0.0; clutchtime = 0.0; // DIST; MAXRELAX; MAXANGLE; ACCELINC; SPEEDSQRFACTOR; GCTIME; ACCELLIMIT; PATHERRFACTOR double ba[6][8] = { {1.2, 0.9, 25.0, 0.1, 1.2, 0.2, 1.0, 5.0}, {1.2, 0.9, 20.0, 0.1, 1.1, 0.5, 1.0, 5.0}, {1.2, 0.9, 15.0, 0.1, 1.0, 0.5, 1.0, 5.0}, {1.3, 0.9, 15.0, 0.02, 0.98, 0.5, 1.0, 5.0}, {1.6, 0.9, 15.0, 0.01, 0.95, 0.5, 1.0, 5.0}, {1.2, 0.9, 45.0, 0.1, 1.0, 0.5, 1.0, 1.0} }; for (int i = 0; i < 6; i++) { for (int j = 0; j < 8; j++) { behaviour[i][j] = ba[i][j]; } } loadBehaviour(NORMAL); // Init optimal trajectory. pf->plan(this, currentsegid); }