From Scott

compile warnings - missing parentheses
Explicitly define operator precedence when mixing || with &&

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6936 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 6f59a4701321a28ed45a702e67177a6f48c7c388
Former-commit-id: 6de225e34ca4febc01ae146957c953a2393a1fca
This commit is contained in:
beaglejoe 2020-04-21 18:53:35 +00:00
parent 3f2cc68fbe
commit 030482ee30
7 changed files with 38 additions and 36 deletions

View file

@ -1441,7 +1441,7 @@ void Driver::SpeedControl6(
double& brk, double& brk,
bool traffic ) bool traffic )
{ {
if( spd0 > targetSpd || spd0 + 0.5 > targetSpd && targetAcc < -5 ) if (spd0 > targetSpd || (spd0 + 0.5 > targetSpd && targetAcc < -5))
{ {
double ta = MN(m_brk.adjAccForSpdError(targetAcc, spd0, targetSpd), 0); double ta = MN(m_brk.adjAccForSpdError(targetAcc, spd0, targetSpd), 0);
@ -3045,9 +3045,9 @@ void Driver::AvoidOtherCars(
double catTime = fabs(k) > maxSpdK ? 0.5 : 2.5; double catTime = fabs(k) > maxSpdK ? 0.5 : 2.5;
double cacTime = fabs(k) > maxSpdK ? 0.5 : 2.5; double cacTime = fabs(k) > maxSpdK ? 0.5 : 2.5;
bool catching = bool catching =
oi.catchTime < colTime && fabs(oi.catchY) < 5 && oi.GotFlags(Opponent::F_COLLIDE) || (oi.catchTime < colTime && fabs(oi.catchY) < 5 && oi.GotFlags(Opponent::F_COLLIDE)) ||
oi.catchTime < catTime && fabs(oi.catchY) < 5 && oi.GotFlags(Opponent::F_CATCHING) || (oi.catchTime < catTime && fabs(oi.catchY) < 5 && oi.GotFlags(Opponent::F_CATCHING)) ||
oi.catchAccTime < cacTime && fabs(oi.catchAccY) < 5 && oi.GotFlags(Opponent::F_CATCHING_ACC); (oi.catchAccTime < cacTime && fabs(oi.catchAccY) < 5 && oi.GotFlags(Opponent::F_CATCHING_ACC));
if(( !ignoreTeamMate && oi.avoidLatchTime > 0 )|| catching || oi.GotFlags(Opponent::F_DANGEROUS)) if(( !ignoreTeamMate && oi.avoidLatchTime > 0 )|| catching || oi.GotFlags(Opponent::F_DANGEROUS))
{ {
LogSHADOW.debug( "%.3f catch %d (dgr %d) catch[%d%d t %.3f y %.4g] acc[%d t %.3f y %.4g]\n", LogSHADOW.debug( "%.3f catch %d (dgr %d) catch[%d%d t %.3f y %.4g] acc[%d t %.3f y %.4g]\n",
@ -3177,8 +3177,8 @@ void Driver::AvoidOtherCars(
double targetS = 1 - target.y; double targetS = 1 - target.y;
if( m_avoidS != 1 && m_attractor == 0 || if ((m_avoidS != 1 && m_attractor == 0) ||
m_avoidS != targetS && m_attractor != 0 ) (m_avoidS != targetS && m_attractor != 0))
{ {
targetS = (m_attractor == 0) ? 1 : 0;//0.35; targetS = (m_attractor == 0) ? 1 : 0;//0.35;
double avoidA = targetS > m_avoidS ? avoidSMaxA : -avoidSMaxA; double avoidA = targetS > m_avoidS ? avoidSMaxA : -avoidSMaxA;
@ -3218,9 +3218,9 @@ void Driver::AvoidOtherCars(
m_avoidS = 1; m_avoidS = 1;
m_avoidSVel = 0; m_avoidSVel = 0;
} }
else if( oldAvoidS < targetS && m_avoidS >= targetS || else if ((oldAvoidS < targetS && m_avoidS >= targetS) ||
oldAvoidS > targetS && m_avoidS <= targetS || (oldAvoidS > targetS && m_avoidS <= targetS) ||
fabs(targetS - m_avoidS) < 0.0005 ) fabs(targetS - m_avoidS) < 0.0005)
{ {
m_avoidS = targetS; m_avoidS = targetS;
m_avoidSVel = 0; m_avoidSVel = 0;
@ -3288,8 +3288,8 @@ void Driver::AvoidOtherCars(
m_avoidT = 1; m_avoidT = 1;
m_avoidTVel = 0; m_avoidTVel = 0;
} }
else if( oldAvoidT < attractT && m_avoidT >= attractT || else if ((oldAvoidT < attractT && m_avoidT >= attractT) ||
oldAvoidT > attractT && m_avoidT <= attractT ) (oldAvoidT > attractT && m_avoidT <= attractT))
{ {
m_avoidT = attractT; m_avoidT = attractT;
m_avoidTVel = 0; m_avoidTVel = 0;

View file

@ -249,10 +249,10 @@ void MyTrack::NewTrack( tTrack* pNewTrack, const vector<double>* pInnerMod, bool
double segDist = m_pSegs[i].segDist; double segDist = m_pSegs[i].segDist;
double t = (segDist - pseg->lgfromstart) / pseg->length; double t = (segDist - pseg->lgfromstart) / pseg->length;
bool inPitMain = (pitStart < pitEnd && pitStart <= i && i <= pitEnd || bool inPitMain = ((pitStart < pitEnd && pitStart <= i && i <= pitEnd) ||
pitStart > pitEnd && (i <= pitEnd || i >= pitStart)); (pitStart > pitEnd && (i <= pitEnd || i >= pitStart)));
bool inPitTotal = (pitEntry < pitExit && pitEntry <= i && i <= pitExit || bool inPitTotal = ((pitEntry < pitExit && pitEntry <= i && i <= pitExit) ||
pitEntry > pitExit && (i <= pitExit || i >= pitEntry)); (pitEntry > pitExit && (i <= pitExit || i >= pitEntry)));
const double MIN_MU = pseg->surface->kFriction * 0.8; const double MIN_MU = pseg->surface->kFriction * 0.8;
const double MAX_ROUGH = MX(0.005, pseg->surface->kRoughness * 1.2); const double MAX_ROUGH = MX(0.005, pseg->surface->kRoughness * 1.2);
@ -285,8 +285,8 @@ void MyTrack::NewTrack( tTrack* pNewTrack, const vector<double>* pInnerMod, bool
// never go up a curb on the outside of a corner that has lower friction // never go up a curb on the outside of a corner that has lower friction
// than the main track. // than the main track.
if( (s == TR_SIDE_LFT && pseg->type == TR_RGT || if( ((s == TR_SIDE_LFT && pseg->type == TR_RGT) ||
s == TR_SIDE_RGT && pseg->type == TR_LFT) && (s == TR_SIDE_RGT && pseg->type == TR_LFT)) &&
pSide->surface->kFriction < pseg->surface->kFriction ) pSide->surface->kFriction < pseg->surface->kFriction )
{ {
extra_w = MN(extra_w, w_so_far); extra_w = MN(extra_w, w_so_far);
@ -308,8 +308,8 @@ void MyTrack::NewTrack( tTrack* pNewTrack, const vector<double>* pInnerMod, bool
extra_w = MN(extra_w, w_so_far); extra_w = MN(extra_w, w_so_far);
} }
bool inner = s == TR_SIDE_LFT && pseg->type == TR_LFT || bool inner = (s == TR_SIDE_LFT && pseg->type == TR_LFT) ||
s == TR_SIDE_RGT && pseg->type == TR_RGT; (s == TR_SIDE_RGT && pseg->type == TR_RGT);
bool pitEntryOrExit = pitSide == s && inPitTotal && !inPitMain; bool pitEntryOrExit = pitSide == s && inPitTotal && !inPitMain;
if( inner && !pitEntryOrExit ) if( inner && !pitEntryOrExit )
{ {
@ -325,9 +325,9 @@ void MyTrack::NewTrack( tTrack* pNewTrack, const vector<double>* pInnerMod, bool
extra_w = MN(extra_w, w_so_far); extra_w = MN(extra_w, w_so_far);
} }
if( (s == TR_SIDE_LFT && pseg->type == TR_RGT || if (((s == TR_SIDE_LFT && pseg->type == TR_RGT) ||
s == TR_SIDE_RGT && pseg->type == TR_LFT) && (s == TR_SIDE_RGT && pseg->type == TR_LFT)) &&
pSide->surface->kFriction < pseg->surface->kFriction ) pSide->surface->kFriction < pseg->surface->kFriction)
{ {
extra_w = MN(extra_w, w_so_far); extra_w = MN(extra_w, w_so_far);
} }
@ -348,8 +348,8 @@ void MyTrack::NewTrack( tTrack* pNewTrack, const vector<double>* pInnerMod, bool
extra_w = MN(extra_w, w_so_far - WALL_MARGIN); // there's always a wall/fence at the edge of the track. extra_w = MN(extra_w, w_so_far - WALL_MARGIN); // there's always a wall/fence at the edge of the track.
bool inner = s == TR_SIDE_LFT && pseg->type == TR_LFT || bool inner = (s == TR_SIDE_LFT && pseg->type == TR_LFT) ||
s == TR_SIDE_RGT && pseg->type == TR_RGT; (s == TR_SIDE_RGT && pseg->type == TR_RGT);
if( inner ) if( inner )
{ {
int innerId = m_pSegs[i].bendId; int innerId = m_pSegs[i].bendId;

View file

@ -826,8 +826,8 @@ void Path::ModifySection( int from, int len, double delta, int important, double
offset /= fabs(dot); offset /= fabs(dot);
double offs = l1.offs + offset; double offs = l1.offs + offset;
if( offset < 0 && offs < -l1.Wl() + lBuf || if ((offset < 0 && offs < -l1.Wl() + lBuf) ||
offset > 0 && offs > l1.Wr() - rBuf ) (offset > 0 && offs > l1.Wr() - rBuf))
{ {
if( i < (important - from + NSEG) % NSEG) if( i < (important - from + NSEG) % NSEG)
newFrom = j; newFrom = j;
@ -1173,9 +1173,9 @@ bool Path::LoadPath( const char* pDataFile )
} }
int version = -1; int version = -1;
if( fgets(buf, sizeof(buf), pFile) == NULL || if (fgets(buf, sizeof(buf), pFile) == NULL ||
sscanf(buf, "%d", &version) != 1 || sscanf(buf, "%d", &version) != 1 ||
version != 0 && version != 1 && version != 2 ) (version != 0 && version != 1 && version != 2))
{ {
// LogSHADOW.debug( "Failed to open data file -- version\n" ); // LogSHADOW.debug( "Failed to open data file -- version\n" );
fclose( pFile ); fclose( pFile );

View file

@ -240,8 +240,8 @@ void Stuck::executeReorient( const MyTrack& track, const tSituation* s, tCarElt*
double front_speed = (w1_speed + w2_speed) * 0.5; double front_speed = (w1_speed + w2_speed) * 0.5;
if( gear > 0 && (w3_speed > front_speed + 2 || w4_speed > front_speed + 2) || if ((gear > 0 && (w3_speed > front_speed + 2 || w4_speed > front_speed + 2)) ||
gear < 0 && (w3_speed < front_speed - 2 || w4_speed < front_speed - 2) ) (gear < 0 && (w3_speed < front_speed - 2 || w4_speed < front_speed - 2)))
acc = 0.1; acc = 0.1;
me->ctrl.steer = steer; me->ctrl.steer = steer;
@ -1230,7 +1230,7 @@ void Stuck::getUnstuck( const MyTrack& track, tCarElt* me, const tSituation* s )
int gear = fw ? 1 : -1; int gear = fw ? 1 : -1;
// me->ctrl.accelCmd = MN(0.25f, (8 - fabs(spd)) * 0.05); // me->ctrl.accelCmd = MN(0.25f, (8 - fabs(spd)) * 0.05);
me->ctrl.accelCmd = MN(0.25f, (10 - fabs(spd)) * 0.25); me->ctrl.accelCmd = MN(0.25f, (10 - fabs(spd)) * 0.25);
me->ctrl.brakeCmd = fw && spd < -0.1 || !fw && spd > 0.1 ? 0.5 : 0; me->ctrl.brakeCmd = (fw && spd < -0.1) || (!fw && spd > 0.1 ? 0.5 : 0);
me->ctrl.clutchCmd = 0;//gear == me->ctrl.gear ? 0.0f : 0.5f; me->ctrl.clutchCmd = 0;//gear == me->ctrl.gear ? 0.0f : 0.5f;
me->ctrl.gear = gear; me->ctrl.gear = gear;
me->ctrl.steer = (spd > 0 ? deltaAng : -deltaAng) * 2 / me->info.steerLock; me->ctrl.steer = (spd > 0 ? deltaAng : -deltaAng) * 2 / me->info.steerLock;

View file

@ -1813,7 +1813,9 @@ float Driver::getOffset()
{ {
avoidmode |= avoidright; avoidmode |= avoidright;
rightMargin = MAX(leftMargin, MIN(rightMargin, (oppCarTL + MIN(0.0, o->getAvgLateralMovt() * 2)) / track->width)); rightMargin = MAX(leftMargin, MIN(rightMargin, (oppCarTL + MIN(0.0, o->getAvgLateralMovt() * 2)) / track->width));
if (sidedist < car->_dimension_y + 1.0 || o->getAvgLateralMovt() < avgLateralMovt && (avgLateralMovt - o->getAvgLateralMovt()) / deltaTime * 2.0 > sidedist - 0.5) if (sidedist < car->_dimension_y + 1.0 ||
(o->getAvgLateralMovt() < avgLateralMovt &&
(avgLateralMovt - o->getAvgLateralMovt()) / deltaTime * 2.0 > sidedist - 0.5))
{ {
if (rightMargin < car->_trkPos.toLeft / track->width) if (rightMargin < car->_trkPos.toLeft / track->width)
avoidCritical = true; avoidCritical = true;

View file

@ -2151,7 +2151,7 @@ double LRaceLine::getLookAhead(int rl, double leftMargin, double rightMargin, bo
if ((rl == LINE_LEFT && tRInverse[rl][Next] < 0.0) || (rl == LINE_RIGHT && tRInverse[rl][Next] > 0.0)) if ((rl == LINE_LEFT && tRInverse[rl][Next] < 0.0) || (rl == LINE_RIGHT && tRInverse[rl][Next] > 0.0))
factor += fabs(tRInverse[rl][Next]) * 15; factor += fabs(tRInverse[rl][Next]) * 15;
else if ((rl == LINE_LEFT && tRInverse[rl][Next] > 0.0 || (rl == LINE_RIGHT && tRInverse[rl][Next] < 0.0))) else if ((rl == LINE_LEFT && tRInverse[rl][Next] > 0.0) || (rl == LINE_RIGHT && tRInverse[rl][Next] < 0.0))
factor -= MIN(0.5, fabs(tRInverse[rl][Next]) * 15); factor -= MIN(0.5, fabs(tRInverse[rl][Next]) * 15);
if (driver->currentCollision && car->_accel_x < 0.0) if (driver->currentCollision && car->_accel_x < 0.0)

View file

@ -526,9 +526,9 @@ bool SimpleStrategy::needPitstop(tCarElt* car, tSituation *s)
aFT = aFT / 2; aFT = aFT / 2;
if (tRL < raceRemainingLaps && raceRemainingLaps > 1 && if ((tRL < raceRemainingLaps && raceRemainingLaps > 1 &&
((cardata->TYREWEAR / 100 ) < cardata->CRITICAL_TYREWEAR)|| m_checkFuel ((cardata->TYREWEAR / 100 ) < cardata->CRITICAL_TYREWEAR)) ||
|| (m_checkDamage && mW > 0.4)) m_checkFuel || (m_checkDamage && mW > 0.4))
{ {
pitNeeded = true; pitNeeded = true;
m_nNT = true; m_nNT = true;