Fix bug using opponent's pit without checking it to be defined

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

Former-commit-id: ba15b475516cd3e441035510e620f73ef229c104
Former-commit-id: 1106cac96b641cdc1cdaceb4370d0b6e8ac61d9a
This commit is contained in:
wdbee 2010-03-23 17:09:49 +00:00
parent 2dccc1720a
commit f4aae21bab

View file

@ -3072,33 +3072,35 @@ void Driver::update(tSituation *s)
break;
}
if (opponent[i].getCarPtr()->_pit->pos.seg == car->_pit->pos.seg)
{
// sharing a pit
if (opitpos == PIT_FRONT)
if (opponent[i].getCarPtr()->_pit != NULL)
{
if (opponent[i].getCarPtr()->_pit->pos.seg == car->_pit->pos.seg)
{
double pitloc = pit->getNPitLoc( PIT_MID );
double myfrompit = pitloc - car->_distFromStartLine;
double opfrompit = pitloc - opponent[i].getCarPtr()->_distFromStartLine;
if (myfrompit < 0.0) myfrompit += track->length;
if (opfrompit < 0.0) opfrompit += track->length;
// work out who's closest to the pit & therefore should go in front
if (opfrompit > myfrompit)
// sharing a pit
if (opitpos == PIT_FRONT)
{
pitpos = PIT_FRONT;
double pitloc = pit->getNPitLoc( PIT_MID );
double myfrompit = pitloc - car->_distFromStartLine;
double opfrompit = pitloc - opponent[i].getCarPtr()->_distFromStartLine;
if (myfrompit < 0.0) myfrompit += track->length;
if (opfrompit < 0.0) opfrompit += track->length;
// work out who's closest to the pit & therefore should go in front
if (opfrompit > myfrompit)
{
pitpos = PIT_FRONT;
}
else
{
pitpos = PIT_BACK; // go in behind other car
}
}
else
{
pitpos = PIT_BACK; // go in behind other car
pitpos = PIT_FRONT; // stop at end of pit space to leave room
}
}
else
{
pitpos = PIT_FRONT; // stop at end of pit space to leave room
}
}
}
break;
}
}