From 66cedb917ffff28232feed495b747d985c28a3af Mon Sep 17 00:00:00 2001 From: wdbee Date: Sat, 28 Feb 2009 15:10:16 +0000 Subject: [PATCH] Update to release pit if drivers is eliminated by TORCS-NG git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@794 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 635ca9ddc1c583322a3aa79d57b5bdf30eacf452 Former-commit-id: 9aa73458ea92ecf5d460c7086ee605be666ca07d --- src/drivers/simplix/src/unitdriver.cpp | 6 +++--- src/drivers/usr_GP3601/driver.cpp | 6 ++++-- src/libs/robottools/rtteammanager.cpp | 16 ++++++++++++++++ src/libs/robottools/teammanager.h | 5 +++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/drivers/simplix/src/unitdriver.cpp b/src/drivers/simplix/src/unitdriver.cpp index d6db0177a..1dc664fea 100644 --- a/src/drivers/simplix/src/unitdriver.cpp +++ b/src/drivers/simplix/src/unitdriver.cpp @@ -1052,9 +1052,9 @@ int TDriver::PitCmd() //--------------------------------------------------------------------------* void TDriver::EndRace() { - //GfOut("#TDriver::EndRace() >>>\n"); - // This is never called by TORCS! Don't use it! - //GfOut("#<<< TDriver::EndRace()\n"); + GfOut("#TDriver::EndRace() >>>\n"); + oStrategy->PitRelease(); // Release pit if eliminated + GfOut("#<<< TDriver::EndRace()\n"); } //==========================================================================* diff --git a/src/drivers/usr_GP3601/driver.cpp b/src/drivers/usr_GP3601/driver.cpp index 1e5789108..68b2d841e 100644 --- a/src/drivers/usr_GP3601/driver.cpp +++ b/src/drivers/usr_GP3601/driver.cpp @@ -685,10 +685,12 @@ int Driver::pitCommand(tSituation *s) } -// Never called by TORCS!!! End of the current race. +// End of the current race for this driver, may be +// it was eliminated from a continuing race, so release pit! void Driver::endRace(tSituation *s) { - // Nothing for now. + RtTeamReleasePit(teamIndex); // Release pit if eliminated + car->ctrl.raceCmd = 0; } // Clean up diff --git a/src/libs/robottools/rtteammanager.cpp b/src/libs/robottools/rtteammanager.cpp index 639d4cec5..7a08a2c3f 100644 --- a/src/libs/robottools/rtteammanager.cpp +++ b/src/libs/robottools/rtteammanager.cpp @@ -163,6 +163,7 @@ tTeamManager* RtTeamManager() TeamManager->TeamDrivers = NULL; TeamManager->Drivers = NULL; TeamManager->Track = NULL; + TeamManager->State = RT_TM_STATE_INIT; TeamManager->Count = 0; TeamManager->PitSharing = false; TeamManager->RaceDistance = 500000; @@ -200,6 +201,15 @@ bool RtTeamManagerInit() RtTM = RtTeamManager(); return true; } + else + { + if (RtTM->State != RT_TM_STATE_NULL) + { + RtTeamManagerFree(); + RtTM = NULL; + return RtTeamManagerInit(); + } + } return false; } @@ -448,6 +458,7 @@ int RtTeamManagerIndex(CarElt* const Car, tTrack* const Track, tSituation* Situa { TeamDriver->MinLaps = TeamDriver->TeamPit->Teammates->Count + RtTMLaps; TeamDriver = TeamDriver->Next; + RtTM->State = RT_TM_STATE_INIT; } return TeamIndex; } @@ -615,6 +626,11 @@ bool RtTeamNeedPitStop(const int TeamIndex, const float FuelPerM, const int Repa GotoPit = (TeamDriver->TeamPit->PitState == TeamDriver->Car); } + + if(GotoPit) + { + RtTM->State = RT_TM_STATE_USED; + } return GotoPit; }; diff --git a/src/libs/robottools/teammanager.h b/src/libs/robottools/teammanager.h index 9be45f704..cb6734230 100644 --- a/src/libs/robottools/teammanager.h +++ b/src/libs/robottools/teammanager.h @@ -113,6 +113,10 @@ extern float RtTeamDriverRemainingDistance // Get the remaining distance t #define RT_TM_PIT_IS_FREE NULL // = *Car if reserved/used +#define RT_TM_STATE_NULL 0 // Team manager was created +#define RT_TM_STATE_INIT 1 // Team manager was initialized +#define RT_TM_STATE_USED 2 // Team manager was used + // Teammanager Utilities @@ -206,6 +210,7 @@ typedef struct tTeamDriver* TeamDrivers; // Linked list of drivers belonging to a team tTrack* Track; // Track tTeamDriver** Drivers; // Array of pointers to TeamDrivers + int State; // State of team manager int Count; // Nbr of drivers in race bool PitSharing; // Pit sharing activated? float RaceDistance; // Distance to race