Update Teammanager: Protection if teamindex is taken more than once

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

Former-commit-id: e71bb06eb95f559d4752abf34f19d24cd817cc9f
Former-commit-id: ac19f1804d7ab638e36c69ffd5cba55eea018519
This commit is contained in:
wdbee 2009-07-26 16:37:04 +00:00
parent a03480e007
commit 4f1014eb0d

View file

@ -476,6 +476,18 @@ int RtTeamManagerIndex(CarElt* const Car, tTrack* const Track, tSituation* Situa
RtTM->Drivers =
(tTeamDriver**) malloc(Situation->_ncars * sizeof(tTeamDriver*));
}
else
{
// Avoid adding same car twice
tTeamDriver* TeamDriver = RtTM->TeamDrivers;
while (TeamDriver)
{
if (TeamDriver->Car == Car)
return TeamDriver->Count;
TeamDriver = TeamDriver->Next;
}
}
RtTM->Track = Track;
RtTM->RaceDistance = Track->length * Situation->_totLaps;
@ -562,6 +574,8 @@ void RtTeamReleasePit(const int TeamIndex)
return;
tTeamDriver* TeamDriver = RtTeamDriverGet(TeamIndex);
if (TeamDriver == NULL)
return;
if (TeamDriver->TeamPit->PitState == TeamDriver->Car)
TeamDriver->TeamPit->PitState = RT_TM_PIT_IS_FREE;
@ -576,8 +590,13 @@ bool RtTeamNeedPitStop(const int TeamIndex, const float FuelPerM, const int Repa
return false;
tTeamDriver* TeamDriver = RtTeamDriverGet(TeamIndex);
if (TeamDriver == NULL)
return false;
CarElt* Car = TeamDriver->Car;
if (Car == NULL)
return false;
if (Car->_pit == NULL)
return false;