- Update USR's driver for better pit stop
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7425 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 228595030f9d0ae6d455806051bb1016311f2603 Former-commit-id: 473f8b8136b6f101322b01b3b62cfb02ba918a7b
This commit is contained in:
parent
7cedca52a9
commit
c63dc1d66d
4 changed files with 85 additions and 51 deletions
|
@ -15,6 +15,8 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <teammanager.h>
|
||||
|
||||
#include "driver.h"
|
||||
|
||||
#include "MyParam.h"
|
||||
|
@ -27,6 +29,7 @@
|
|||
|
||||
#include <portability.h>
|
||||
|
||||
|
||||
//#define TIME_ANALYSIS
|
||||
#ifdef TIME_ANALYSIS
|
||||
#include "Timer.h"
|
||||
|
@ -58,7 +61,18 @@ Driver::Driver(int index) :
|
|||
mFlagNames.push_back("FAST_BEHIND");
|
||||
}
|
||||
|
||||
void Driver::InitTrack(tTrack* Track, void* carHandle, void** carParmHandle, const tSituation* situation)
|
||||
//==========================================================================*
|
||||
// Get Team info
|
||||
//--------------------------------------------------------------------------*
|
||||
void Driver::TeamInfo(tCarElt* car, tSituation* situation)
|
||||
{
|
||||
//RtTeamManagerShowInfo();
|
||||
mTeamIndex = RtTeamManagerIndex(car, track, situation);
|
||||
LogUSR.info("#Team index = %i\n", mTeamIndex);
|
||||
RtTeamManagerDump();
|
||||
}
|
||||
|
||||
void Driver::InitTrack(tTrack* Track, void* carHandle, void** carParmHandle, tSituation* situation)
|
||||
{
|
||||
LogUSR.debug(".......... %s Driver initrack .........\n", mDriverName);
|
||||
track = Track;
|
||||
|
@ -135,6 +149,7 @@ void Driver::InitTrack(tTrack* Track, void* carHandle, void** carParmHandle, con
|
|||
// Set initial fuel
|
||||
double distance = 0.0;
|
||||
|
||||
|
||||
if (mPitTest > 0)
|
||||
distance = mTrack.length() * 2 + 0.3;
|
||||
else
|
||||
|
@ -193,7 +208,7 @@ void Driver::InitTrack(tTrack* Track, void* carHandle, void** carParmHandle, con
|
|||
LogUSR.info("Couldn't load : %s\n", buffer);
|
||||
}
|
||||
|
||||
void Driver::NewRace(tCarElt* car, const tSituation* situation)
|
||||
void Driver::NewRace(tCarElt* car, tSituation* situation)
|
||||
{
|
||||
LogUSR.info("********** %s : NewRace() **********\n", mDriverName);
|
||||
|
||||
|
@ -201,6 +216,7 @@ void Driver::NewRace(tCarElt* car, const tSituation* situation)
|
|||
mSimTime = -1.0;
|
||||
initVars();
|
||||
|
||||
TeamInfo(car, mSituation);
|
||||
mCar.init(car, &mTrack);
|
||||
mPit.init(mTrack.torcsTrack(), situation, &mCar, mPitDamage, mPitGripFactor, mPitEntryMargin);
|
||||
|
||||
|
|
|
@ -43,17 +43,19 @@ class Driver
|
|||
public:
|
||||
Driver(int index);
|
||||
|
||||
void InitTrack(tTrack *Track, void* carHandle, void** carParmHandle, const tSituation* situation);
|
||||
void NewRace(tCarElt* car, const tSituation* situation);
|
||||
void InitTrack(tTrack *Track, void* carHandle, void** carParmHandle, tSituation* situation);
|
||||
void NewRace(tCarElt* car, tSituation* situation);
|
||||
void Drive();
|
||||
int PitCmd();
|
||||
void EndRace();
|
||||
void Shutdown();
|
||||
|
||||
const char* mDriverName;
|
||||
int mTeamIndex; // Index of car in Teams arrays;
|
||||
|
||||
private:
|
||||
enum DriveState {STATE_RACE, STATE_STUCK, STATE_OFFTRACK, STATE_PITLANE, STATE_PITSTOP};
|
||||
void TeamInfo(tCarElt* car, tSituation* situation);
|
||||
void updateTime();
|
||||
void updateBasics();
|
||||
void updateOpponents();
|
||||
|
@ -121,7 +123,7 @@ private:
|
|||
double mDeltaTime;
|
||||
double mSimTime;
|
||||
double mLapSimTime;
|
||||
const tSituation* mSituation;
|
||||
tSituation* mSituation;
|
||||
MyCar mCar;
|
||||
MyTrack mTrack;
|
||||
|
||||
|
@ -212,6 +214,7 @@ private:
|
|||
double mOvtMargin;
|
||||
|
||||
tTrack* track;
|
||||
tCarElt* car;
|
||||
};
|
||||
|
||||
#endif // _DRIVER_H_
|
||||
|
|
|
@ -95,7 +95,7 @@ void Pit::init(const tTrack* track, const tSituation* situation, MyCar* car, int
|
|||
|
||||
if (mPit != NULL)
|
||||
{
|
||||
mSpeedLimit = mPitInfo->speedLimit - 0.2;
|
||||
mSpeedLimit = mPitInfo->speedLimit - 0.5;
|
||||
// Compute pit spline points along the track
|
||||
mPitp[3].x = mPit->pos.seg->lgfromstart + mPit->pos.toStart;
|
||||
mPitp[2].x = mPitp[3].x - mPitInfo->len;
|
||||
|
@ -103,7 +103,9 @@ void Pit::init(const tTrack* track, const tSituation* situation, MyCar* car, int
|
|||
mPitp[0].x = mPitInfo->pitEntry->lgfromstart;
|
||||
mPitp[1].x = mPitInfo->pitStart->lgfromstart - mPitInfo->len;
|
||||
mPitp[5].x = mPitInfo->pitEnd->lgfromstart + mPitInfo->pitEnd->length + mPitInfo->len;
|
||||
//mPitp[5].x = mPitInfo->pitEnd->lgfromstart + mPitInfo->nPitSeg * mPitInfo->len;
|
||||
mPitp[6].x = mPitInfo->pitExit->lgfromstart + mPitInfo->pitExit->length;
|
||||
//mPitp[6].x = mPitInfo->pitExit->lgfromstart;
|
||||
mDtp[0].x = mPitp[0].x;
|
||||
mDtp[1].x = mPitp[1].x;
|
||||
mDtp[2].x = mPitp[5].x;
|
||||
|
@ -127,26 +129,38 @@ void Pit::init(const tTrack* track, const tSituation* situation, MyCar* car, int
|
|||
mDtp[i].x = toSplineCoord(mDtp[i].x);
|
||||
}
|
||||
|
||||
// Fix broken pit exit.
|
||||
if (mPitp[6].x < mPitp[5].x)
|
||||
{
|
||||
//fprintf(stderr,"bt: Pitexit broken on track %s.\n", track->name);fflush(stderr);
|
||||
mPitp[6].x = mPitp[5].x;// +50.0f;
|
||||
}
|
||||
|
||||
mPitp[1].x = std::min(mPitp[1].x, mPitp[2].x);
|
||||
mPitp[5].x = std::max(mPitp[4].x, mPitp[5].x);
|
||||
|
||||
mPitOnLeftSide = mPitInfo->side == TR_LFT;
|
||||
double sign = mPitOnLeftSide ? 1.0 : -1.0;
|
||||
mPitp[0].y = sign * (mTrack->width / 2.0 - 2.0);
|
||||
mPitp[6].y = sign * (mTrack->width / 2.0 - 2.0);
|
||||
//mPitp[0].y = 0.0;
|
||||
//mPitp[6].y = 0.0;
|
||||
mDtp[0].y = mPitp[0].y;
|
||||
mDtp[3].y = mPitp[6].y;
|
||||
|
||||
for (i = 1; i < PITPOINTS - 1; i++)
|
||||
{
|
||||
mPitp[i].y = sign * (fabs(mPitInfo->driversPits->pos.toMiddle) - 0.3 * mPitInfo->width - 2.2);
|
||||
//mPitp[i].y = sign * (fabs(mPitInfo->driversPits->pos.toMiddle) - mPitInfo->width);
|
||||
}
|
||||
|
||||
for (i = 1; i < DTPOINTS - 1; i++)
|
||||
{
|
||||
mDtp[i].y = sign * (fabs(mPitInfo->driversPits->pos.toMiddle) - 0.3 * mPitInfo->width - 2.2);
|
||||
//mDtp[i].y = sign * (fabs(mPitInfo->driversPits->pos.toMiddle) - mPitInfo->width);
|
||||
}
|
||||
|
||||
mPitp[3].y = sign * fabs(mPitInfo->driversPits->pos.toMiddle);
|
||||
mPitp[3].y = sign * (fabs(mPitInfo->driversPits->pos.toMiddle) + 1.0);
|
||||
mPitSpline.init(PITPOINTS, mPitp);
|
||||
mDtSpline.init(DTPOINTS, mDtp);
|
||||
}
|
||||
|
@ -295,7 +309,7 @@ void Pit::update()
|
|||
mPenalty = 0; // fuel, damage and tires served before penalty
|
||||
bool pittyres = false;
|
||||
// Check for fuel, damage and tyres
|
||||
bool pitfuel = mCar->_fuel < mAvgFuelPerLap;
|
||||
bool pitfuel = mCar->_fuel < (mAvgFuelPerLap + 2.0);
|
||||
bool pitdamage = (mCar->_dammage > mPitDamage && remaininglaps * mTrack->length > mMaxDamageDist && mLastFuel > 15.0) || (mCar->_dammage > mMaxDamage);
|
||||
//bool pittyres = (mMyCar->tires()->distLeft() < 1.0 * mTrack->length && mMyCar->tires()->gripFactor() < mPitGripFactor && remaininglaps * mTrack->length > 10000.0);
|
||||
|
||||
|
@ -304,7 +318,7 @@ void Pit::update()
|
|||
else {
|
||||
pittyres = false;
|
||||
}
|
||||
if (fs > mPitEntry - mEntryMargin - mPreEntryMargin - 3.0 && fs < mPitEntry - mEntryMargin - mPreEntryMargin && !mStopChecked)
|
||||
if ((fs > mPitEntry - mEntryMargin - mPreEntryMargin - 3.0) && (fs < mPitEntry - mEntryMargin - mPreEntryMargin) && !mStopChecked)
|
||||
{
|
||||
if (pitBeforeTeammate(remaininglaps))
|
||||
{
|
||||
|
@ -321,7 +335,7 @@ void Pit::update()
|
|||
|
||||
mStopChecked = true;
|
||||
}
|
||||
else if (fs >= mPitEntry - mEntryMargin && fs < mPitEntry - mEntryMargin + 3.0)
|
||||
else if ((fs >= mPitEntry - mEntryMargin) && (fs < mPitEntry - mEntryMargin + 3.0))
|
||||
{
|
||||
mStopChecked = false;
|
||||
}
|
||||
|
@ -337,7 +351,7 @@ bool Pit::pitBeforeTeammate(int remaininglaps) const
|
|||
teamcarfuel = mTeamCar->_fuel;
|
||||
}
|
||||
|
||||
if (teamcarrunning && mCar->_fuel < teamcarfuel && mCar->_fuel < remaininglaps * mAvgFuelPerLap)
|
||||
if (teamcarrunning && (mCar->_fuel < teamcarfuel) && (mCar->_fuel < remaininglaps * mAvgFuelPerLap))
|
||||
{
|
||||
double matelaps = teamcarfuel / mAvgFuelPerLap;
|
||||
double matetoentry;
|
||||
|
@ -348,7 +362,7 @@ bool Pit::pitBeforeTeammate(int remaininglaps) const
|
|||
}
|
||||
else
|
||||
{
|
||||
matetoentry = mTrack->length - mTeamCar->_distFromStartLine + (mPitEntry - mEntryMargin);
|
||||
matetoentry = mTrack->length - (mTeamCar->_distFromStartLine + (mPitEntry - mEntryMargin));
|
||||
}
|
||||
|
||||
double matefulllaps = floor(matelaps - matetoentry / mTrack->length);
|
||||
|
@ -442,7 +456,7 @@ double Pit::calcRefuel()
|
|||
int pitstops = std::max(fuelpitstops, tirespitstops);
|
||||
|
||||
// Calc the stint fuel
|
||||
double stintfuel = fueltoend / (pitstops + 1) + 2.0;
|
||||
double stintfuel = fueltoend / (pitstops + 1) +2.0;
|
||||
|
||||
if (pitstops)
|
||||
{
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
/***************************************************************************
|
||||
|
||||
file : spline.cpp
|
||||
created : Wed Mai 14 20:10:00 CET 2003
|
||||
copyright : (C) 2003 by Bernhard Wymann
|
||||
email : berniw@bluewin.ch
|
||||
file : spline.cpp
|
||||
created : Wed Mai 14 20:10:00 CET 2003
|
||||
copyright : (C) 2003 by Bernhard Wymann
|
||||
email : berniw@bluewin.ch
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "spline.h"
|
||||
|
||||
|
@ -24,37 +24,38 @@ Spline::Spline()
|
|||
|
||||
void Spline::init(int dim, SplinePoint* spl)
|
||||
{
|
||||
mSpl = spl;
|
||||
mDim = dim;
|
||||
mSpl = spl;
|
||||
mDim = dim;
|
||||
}
|
||||
|
||||
double Spline::evaluate(double z) const
|
||||
{
|
||||
int i, a, b;
|
||||
double t, a0, a1, a2, a3, h;
|
||||
a = 0; b = mDim-1;
|
||||
int i, a, b;
|
||||
double t, a0, a1, a2, a3, h;
|
||||
a = 0; b = mDim - 1;
|
||||
|
||||
do
|
||||
{
|
||||
i = (a + b) / 2;
|
||||
if (mSpl[i].x <= z)
|
||||
{
|
||||
a = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = i;
|
||||
}
|
||||
} while ((a + 1) != b);
|
||||
do
|
||||
{
|
||||
i = (a + b) / 2;
|
||||
|
||||
i = a;
|
||||
h = mSpl[i+1].x - mSpl[i].x;
|
||||
t = (z-mSpl[i].x) / h;
|
||||
a0 = mSpl[i].y;
|
||||
a1 = mSpl[i+1].y - a0;
|
||||
a2 = a1 - h*mSpl[i].s;
|
||||
a3 = h * mSpl[i+1].s - a1;
|
||||
a3 -= a2;
|
||||
if (mSpl[i].x <= z)
|
||||
{
|
||||
a = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
b = i;
|
||||
}
|
||||
} while ((a + 1) != b);
|
||||
|
||||
return a0 + (a1 + (a2 + a3*t) * (t-1))*t;
|
||||
i = a;
|
||||
h = mSpl[i + 1].x - mSpl[i].x;
|
||||
t = (z - mSpl[i].x) / h;
|
||||
a0 = mSpl[i].y;
|
||||
a1 = mSpl[i + 1].y - a0;
|
||||
a2 = a1 - h * mSpl[i].s;
|
||||
a3 = h * mSpl[i + 1].s - a1;
|
||||
a3 -= a2;
|
||||
|
||||
return a0 + (a1 + (a2 + a3 * t) * (t - 1)) * t;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue