From f4aae21bab1515a1229d2b8cdb625402e2423082 Mon Sep 17 00:00:00 2001 From: wdbee Date: Tue, 23 Mar 2010 17:09:49 +0000 Subject: [PATCH] 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 --- src/drivers/usr_trb1/driver.cpp | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/drivers/usr_trb1/driver.cpp b/src/drivers/usr_trb1/driver.cpp index e55b19667..e2de06394 100644 --- a/src/drivers/usr_trb1/driver.cpp +++ b/src/drivers/usr_trb1/driver.cpp @@ -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; } }