Global team manager for use with teams of different robots

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

Former-commit-id: 9e0c1fb0d1a3a0626401944f3ad5b06c1398ce2a
Former-commit-id: a1f936b430c6d3734076c96c8fbdd5ad4d0f90ba
This commit is contained in:
wdbee 2009-02-22 16:23:10 +00:00
parent 111b809f1b
commit e96c90c48d
13 changed files with 481 additions and 31 deletions

View file

@ -49,7 +49,7 @@
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="../../../export/include;../../../../3rdParty/include;../../windows/include;../../.." AdditionalIncludeDirectories="../../../export/include;../../../../3rdParty/include;../../windows/include;../../.."
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;DEBUG;DEBUG_OUT" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;DEBUG;DEBUG_OUT;_USE_RTTEAMMANAGER_"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
PrecompiledHeaderFile=".\Debug/simplix.pch" PrecompiledHeaderFile=".\Debug/simplix.pch"
@ -152,7 +152,7 @@
Optimization="2" Optimization="2"
InlineFunctionExpansion="2" InlineFunctionExpansion="2"
AdditionalIncludeDirectories="../../../export/include;../../../../3rdParty\include;../../windows/include;../../.." AdditionalIncludeDirectories="../../../export/include;../../../../3rdParty\include;../../windows/include;../../.."
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_DEPRECATE;_USE_RTTEAMMANAGER_"
StringPooling="true" StringPooling="true"
RuntimeLibrary="0" RuntimeLibrary="0"
EnableFunctionLevelLinking="true" EnableFunctionLevelLinking="true"
@ -890,4 +890,3 @@
<Globals> <Globals>
</Globals> </Globals>
</VisualStudioProject> </VisualStudioProject>

View file

@ -66,6 +66,9 @@
TCommonData::TCommonData(): TCommonData::TCommonData():
Track(NULL) Track(NULL)
{ {
#ifdef _USE_RTTEAMMANAGER_
TeamManager = RtGetGlobalTeamManager();
#endif
} }
//==========================================================================* //==========================================================================*

View file

@ -60,7 +60,11 @@
#include <track.h> #include <track.h>
#include "unitglobal.h" #include "unitglobal.h"
#ifdef _USE_RTTEAMMANAGER_
#include <teammanager.h>
#else
#include "unitteammanager.h" #include "unitteammanager.h"
#endif
#include "unitclothoid.h" #include "unitclothoid.h"
//==========================================================================* //==========================================================================*
@ -73,7 +77,11 @@ class TCommonData
~TCommonData(); // Destructor ~TCommonData(); // Destructor
public: public:
#ifdef _USE_RTTEAMMANAGER_
tTeamManager* TeamManager; // Team manager
#else
TTeamManager TeamManager; // Team manager TTeamManager TeamManager; // Team manager
#endif
PTrack Track; // TORCS Track data PTrack Track; // TORCS Track data
}; };
//==========================================================================* //==========================================================================*

View file

@ -10,7 +10,7 @@
// File : unitdriver.cpp // File : unitdriver.cpp
// Created : 2007.11.25 // Created : 2007.11.25
// Last changed : 2009.02.14 // Last changed : 2009.02.14
// Copyright : © 2007-2009 Wolf-Dieter Beelitzf // Copyright : © 2007-2009 Wolf-Dieter Beelitz
// eMail : wdb@wdbee.de // eMail : wdb@wdbee.de
// Version : 2.00.000 // Version : 2.00.000
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
@ -1052,6 +1052,7 @@ void TDriver::EndRace()
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
void TDriver::Shutdown() void TDriver::Shutdown()
{ {
RtFreeGlobalTeamManager();
} }
//==========================================================================* //==========================================================================*
@ -1111,7 +1112,11 @@ void TDriver::FindRacinglines()
if(oCommonData->Track != oTrackDesc.Track()) // New track? if(oCommonData->Track != oTrackDesc.Track()) // New track?
{ {
oCommonData->Track = oTrackDesc.Track(); // Save pointer oCommonData->Track = oTrackDesc.Track(); // Save pointer
#ifdef _USE_RTTEAMMANAGER_
// oCommonData->TeamManager->Clear(); // release old informations
#else
oCommonData->TeamManager.Clear(); // release old informations oCommonData->TeamManager.Clear(); // release old informations
#endif
} }
GfOut("# ... load smooth path ...\n"); GfOut("# ... load smooth path ...\n");
@ -1232,7 +1237,11 @@ void TDriver::FindRacinglines()
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
void TDriver::TeamInfo() void TDriver::TeamInfo()
{ {
#ifdef _USE_RTTEAMMANAGER_
oTeam = RtTeamManagerAdd(oCommonData->TeamManager,oCar);
#else
oTeam = oCommonData->TeamManager.Add(oCar); oTeam = oCommonData->TeamManager.Add(oCar);
#endif
//GfOut("#\n\n# Team: %s\n\n\n",oTeam->TeamName); //GfOut("#\n\n# Team: %s\n\n\n",oTeam->TeamName);
} }
//==========================================================================* //==========================================================================*
@ -1312,7 +1321,10 @@ void TDriver::Update(tCarElt* Car, tSituation* S)
for (int I = 0; I < oNbrCars; I++) for (int I = 0; I < oNbrCars; I++)
{ {
oOpponents[I].Update(oCar, oOpponents[I].Update(oCar,
#ifdef _USE_RTTEAMMANAGER_
#else
&oCommonData->TeamManager, &oCommonData->TeamManager,
#endif
MyDomX, MyDomY, MinDistBack, MinTimeSlot); MyDomX, MyDomY, MinDistBack, MinTimeSlot);
} }

View file

@ -155,7 +155,11 @@ class TDriver
(void* RobotSettings, char* Value); (void* RobotSettings, char* Value);
inline void SetCommonData // Set pointer to common data inline void SetCommonData // Set pointer to common data
(TCommonData* CommonData); (TCommonData* CommonData);
#ifdef _USE_RTTEAMMANAGER_
inline tTeam* GetTeam();
#else
inline TTeamManager::TTeam* GetTeam(); inline TTeamManager::TTeam* GetTeam();
#endif
inline char* GetBotName(); inline char* GetBotName();
inline float CurrSpeed(); inline float CurrSpeed();
@ -216,7 +220,11 @@ private:
double oAvoidScale; // scale avoiding double oAvoidScale; // scale avoiding
double oAvoidWidth; // In m. double oAvoidWidth; // In m.
bool oGoToPit; // Enter pit flag bool oGoToPit; // Enter pit flag
#ifdef _USE_RTTEAMMANAGER_
tTeam* oTeam;
#else
TTeamManager::TTeam* oTeam; // Team TTeamManager::TTeam* oTeam; // Team
#endif
int oDriveTrainType; // Drive train type int oDriveTrainType; // Drive train type
TPidController oPIDCLine; // Controller for line error. TPidController oPIDCLine; // Controller for line error.
@ -387,7 +395,11 @@ void TDriver::SetCommonData
//==========================================================================* //==========================================================================*
// Get Team // Get Team
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
#ifdef _USE_RTTEAMMANAGER_
tTeam* TDriver::GetTeam()
#else
TTeamManager::TTeam* TDriver::GetTeam() TTeamManager::TTeam* TDriver::GetTeam()
#endif
{ {
return oTeam; return oTeam;
} }

View file

@ -238,7 +238,11 @@ enum
// ... my own planet // ... my own planet
// pit states ... // pit states ...
#ifdef _USE_RTTEAMMANAGER_
#define PIT_IS_FREE NULL
#else
#define PIT_IS_FREE (-1) #define PIT_IS_FREE (-1)
#endif
// ... pit states // ... pit states
// Shortcuts for TORCS commands ... // Shortcuts for TORCS commands ...

View file

@ -132,13 +132,19 @@ TOpponent::TInfo& TOpponent::Info()
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
void TOpponent::Update( void TOpponent::Update(
const PCarElt MyCar, const PCarElt MyCar,
#ifdef _USE_RTTEAMMANAGER_
#else
PTeamManager TeamManager, PTeamManager TeamManager,
#endif
double MyDirX, double MyDirX,
double MyDirY, double MyDirY,
float &MinDistBack, float &MinDistBack,
double &MinTimeSlot) double &MinTimeSlot)
{ {
#ifdef _USE_RTTEAMMANAGER_
#else
oTeamManager = TeamManager; // Save Pointer oTeamManager = TeamManager; // Save Pointer
#endif
if((CarState & RM_CAR_STATE_NO_SIMU) && // omit cars out of race if((CarState & RM_CAR_STATE_NO_SIMU) && // omit cars out of race
(CarState & RM_CAR_STATE_PIT) == 0 ) // if not in pit (CarState & RM_CAR_STATE_PIT) == 0 ) // if not in pit
@ -317,7 +323,11 @@ bool TOpponent::Classify(
DistAhead = MIN(MAX(50, DistAhead), 100); // view to min 50 max 100 m DistAhead = MIN(MAX(50, DistAhead), 100); // view to min 50 max 100 m
// Teammate? // Teammate?
#ifdef _USE_RTTEAMMANAGER_
if (RtIsTeamMate(MyCar,oCar)) // If Opp. is teammate
#else
if (oTeamManager->IsTeamMate(MyCar,oCar)) // If Opp. is teammate if (oTeamManager->IsTeamMate(MyCar,oCar)) // If Opp. is teammate
#endif
{ {
oInfo.Flags |= F_TEAMMATE; // Set teammate flag oInfo.Flags |= F_TEAMMATE; // Set teammate flag
oInfo.TeamMateDamage = oCar->_dammage; // Save his damages oInfo.TeamMateDamage = oCar->_dammage; // Save his damages

View file

@ -61,7 +61,10 @@
#include "unitglobal.h" #include "unitglobal.h"
#include "unitcommon.h" #include "unitcommon.h"
#ifdef _USE_RTTEAMMANAGER_
#else
#include "unitteammanager.h" #include "unitteammanager.h"
#endif
//==========================================================================* //==========================================================================*
// Class TOpponent // Class TOpponent
@ -134,7 +137,10 @@ class TOpponent
void Update // Update void Update // Update
(const PCarElt MyCar, (const PCarElt MyCar,
#ifdef _USE_RTTEAMMANAGER_
#else
PTeamManager TeamManager, PTeamManager TeamManager,
#endif
double MyDirX, double MyDirY, double MyDirX, double MyDirY,
float &MinDistBack, float &MinDistBack,
double &MinTimeSlot); double &MinTimeSlot);
@ -151,7 +157,10 @@ class TOpponent
double oDeltaTime; // Simulation delta time double oDeltaTime; // Simulation delta time
int oIndex; // Opponents cars index int oIndex; // Opponents cars index
TInfo oInfo; // info of this opponent TInfo oInfo; // info of this opponent
#ifdef _USE_RTTEAMMANAGER_
#else
PTeamManager oTeamManager; // Teammanager PTeamManager oTeamManager; // Teammanager
#endif
double LapBackTimer; double LapBackTimer;
}; };

View file

@ -106,9 +106,15 @@ bool TSimpleStrategy::IsPitFree()
{ {
if (CarPit != NULL) if (CarPit != NULL)
{ {
#ifdef _USE_RTTEAMMANAGER_
tTeam* Team = oDriver->GetTeam();
if ((CarPit->pitCarIndex == TR_PIT_STATE_FREE)
&& ((Team->PitState == oCar) || (Team->PitState == PIT_IS_FREE)))
#else
TTeamManager::TTeam* Team = oDriver->GetTeam(); TTeamManager::TTeam* Team = oDriver->GetTeam();
if ((CarPit->pitCarIndex == TR_PIT_STATE_FREE) if ((CarPit->pitCarIndex == TR_PIT_STATE_FREE)
&& ((Team->PitState == CarDriverIndex) || (Team->PitState == PIT_IS_FREE))) && ((Team->PitState == CarDriverIndex) || (Team->PitState == PIT_IS_FREE)))
#endif
return true; return true;
} }
return false; return false;
@ -161,14 +167,25 @@ bool TSimpleStrategy::NeedPitStop()
} }
else // Ansonsten prüfen, für else // Ansonsten prüfen, für
{ // welche Anzahl von Runden { // welche Anzahl von Runden
TTeamManager::TTeam* Team = // alle Teammitglieder // alle Teammitglieder
oDriver->GetTeam(); // noch Treibstoff haben // noch Treibstoff haben
#ifdef _USE_RTTEAMMANAGER_
tTeam* Team = oDriver->GetTeam();
#else
TTeamManager::TTeam* Team = oDriver->GetTeam();
#endif
FuelNeeded = FuelConsum * oTrackLength; // Treibstoff für eine Runde FuelNeeded = FuelConsum * oTrackLength; // Treibstoff für eine Runde
#ifdef _USE_RTTEAMMANAGER_
int FuelForLaps = // Eigene Reichweite
(int) (CarFuel / FuelNeeded - 1);
RtTeamSetMinLaps(Team,oCar,FuelForLaps); // Eigene Reichweite melden
int MinLaps = RtTeamGetMinLaps(Team,oCar); // Mindestreichweite der anderen
#else
int FuelForLaps = // Eigene Reichweite int FuelForLaps = // Eigene Reichweite
Team->FuelForLaps[CarDriverIndex] = Team->FuelForLaps[CarDriverIndex] =
(int) (CarFuel / FuelNeeded - 1); (int) (CarFuel / FuelNeeded - 1);
int MinLaps = Team->GetMinLaps(oCar); // Mindestreichweite der anderen int MinLaps = Team->GetMinLaps(oCar); // Mindestreichweite der anderen
#endif
// Wenn Tanken, dann der, der weniger Runden weit kommen würde // Wenn Tanken, dann der, der weniger Runden weit kommen würde
if (FuelForLaps < MinLaps) if (FuelForLaps < MinLaps)
@ -194,8 +211,13 @@ bool TSimpleStrategy::NeedPitStop()
if (Result) if (Result)
{ {
#ifdef _USE_RTTEAMMANAGER_
tTeam* Team = oDriver->GetTeam();
Team->PitState = oCar; // Box reserviert
#else
TTeamManager::TTeam* Team = oDriver->GetTeam(); TTeamManager::TTeam* Team = oDriver->GetTeam();
Team->PitState = CarDriverIndex; // Box reserviert Team->PitState = CarDriverIndex; // Box reserviert
#endif
} }
return Result; return Result;
}; };
@ -206,8 +228,13 @@ bool TSimpleStrategy::NeedPitStop()
//--------------------------------------------------------------------------* //--------------------------------------------------------------------------*
void TAbstractStrategy::PitRelease() void TAbstractStrategy::PitRelease()
{ {
#ifdef _USE_RTTEAMMANAGER_
tTeam* Team = oDriver->GetTeam();
if (Team->PitState == oCar) // Box für mich reserviert?
#else
TTeamManager::TTeam* Team = oDriver->GetTeam(); TTeamManager::TTeam* Team = oDriver->GetTeam();
if (Team->PitState == CarDriverIndex) // Box für mich reserviert? if (Team->PitState == CarDriverIndex) // Box für mich reserviert?
#endif
{ {
Team->PitState = PIT_IS_FREE; Team->PitState = PIT_IS_FREE;
oCar->ctrl.raceCmd = 0; oCar->ctrl.raceCmd = 0;
@ -447,11 +474,11 @@ void TSimpleStrategy::Update(PtCarElt Car,
oLastPitFuel = 0.0; // Refueled oLastPitFuel = 0.0; // Refueled
oFuelChecked = true; // We did the estimation in this lap oFuelChecked = true; // We did the estimation in this lap
if (!oGoToPit) // If decision isn'd made if (!oGoToPit) // If decision isn't made
oGoToPit = NeedPitStop(); // Check if we sholud have a pitstop oGoToPit = NeedPitStop(); // Check if we should have a pitstop
} }
else if (DL < 50) // I we are out of the window else if (DL < 50) // I we are out of the window
{ // to estimate { // to estimate fuel consumption
oFuelChecked = false; // reset flag oFuelChecked = false; // reset flag
}; };
}; };

View file

@ -19,3 +19,16 @@ EXPORTS
RtGetDistFromStart2 RtGetDistFromStart2
RtDistToPit RtDistToPit
RtTrackGetSeg RtTrackGetSeg
RtIsTeamMate
RtTeamManager
RtTeamManagerFree
RtTeamManagerAdd
RtGetGlobalTeamManager
RtFreeGlobalTeamManager
RtTeam
RtTeamFree
RtTeamGetMinLaps
RtTeamSetMinLaps
RtTeamAdd
RtTeammate
RtTeammateFree

View file

@ -4,6 +4,7 @@
Version="8,00" Version="8,00"
Name="robottools" Name="robottools"
ProjectGUID="{65130FEC-5171-4924-B6AE-0456FB4029A1}" ProjectGUID="{65130FEC-5171-4924-B6AE-0456FB4029A1}"
RootNamespace="robottools"
> >
<Platforms> <Platforms>
<Platform <Platform
@ -234,6 +235,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\rtteammanager.cpp"
>
</File>
<File <File
RelativePath="rttelem.cpp" RelativePath="rttelem.cpp"
> >
@ -287,6 +292,10 @@
RelativePath="robottools.h" RelativePath="robottools.h"
> >
</File> </File>
<File
RelativePath=".\teammanager.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"

View file

@ -0,0 +1,240 @@
/***************************************************************************
file : rtteammanager.cpp
created : Sun Feb 22 28:43:00 CET 2009
copyright : (C) 2009 by Wolf-Dieter Beelitz
email : wdb@wdbee.de
version :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/** @file
This is a collection of useful functions for using a teammanager with
teams being build of different robots.
You can see an example of teammanager usage in the robots of GP36:
simplix_36GP and usr_36GP.
@author <a href=mailto:wdb@wdbee.de>Wolf-Dieter Beelitz</a>
@version
@ingroup robottools
*/
/** @defgroup teammanager Teammanager for robots.
@ingroup robottools
*/
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#ifdef WIN32
#include <windows.h>
#endif
#include <car.h>
#include "robottools.h"
#include "teammanager.h"
static tTeamManager* GlobalTeamManager;
//
// Check if Car0 is teammate of Car1
//
bool RtIsTeamMate(const CarElt* Car0, const CarElt* Car1)
{
return strcmp(Car0->_teamname, Car1->_teamname) == 0;
}
//
// Create a team manager
//
tTeamManager* RtTeamManager() // Default constructor
{
tTeamManager* TeamManager = (tTeamManager*) // get memory
malloc(sizeof(tTeamManager));
TeamManager->Count = 0; // Nbr of Teams
TeamManager->Teams = NULL; // The next team member
return TeamManager;
}
//
// Destroy a team manager
//
void RtTeamManagerFree(tTeamManager *TeamManager)// Destructor
{
tTeam* Team = TeamManager->Teams;
while (Team != NULL)
{
tTeam* NextTeam = Team->Teams;
tTeammate* Teammate = Team->Teammates;
while (Teammate != NULL)
{
tTeammate* NextTeammate = Teammate->Next;
RtTeammateFree(Teammate);
Teammate = NextTeammate;
}
RtTeamFree(Team);
Team = NextTeam;
}
free(TeamManager); // Release memory
}
//
// Add a car to his team
//
tTeam* RtTeamManagerAdd(tTeamManager *TeamManager, CarElt* Car)
{
tTeammate* NewTeammate = RtTeammate(); // Add car: new teammate
NewTeammate->Car = Car ; // Set car pointer
NewTeammate->Next = NULL; // Empty list
tTeam* Team = TeamManager->Teams; // Get first Team;
while (Team != NULL) // Loop over all teams
{
if (strcmp(Car->_teamname,Team->TeamName) == 0)
{ // If Team is cars team add car to team
RtTeamAdd(Team, NewTeammate);
return Team;
}
else
Team = Team->Teams;
}
// If the team doesn't exists yet
tTeam* NewTeam = RtTeam(); // Create a new team
NewTeam->TeamName = Car->_teamname; // Set its teamname
RtTeamAdd(NewTeam, NewTeammate); // Add new teammate
if (TeamManager->Teams == NULL) // Add new team to
TeamManager->Teams = NewTeam; // linked list of
else // teams
{
Team = TeamManager->Teams;
while (Team->Teams != NULL)
Team = Team->Teams;
Team->Teams = NewTeam;
}
return NewTeam;
}
//
// Get a pointer to the global teammanager
//
tTeamManager* RtGetGlobalTeamManager()
{
if (GlobalTeamManager == NULL)
GlobalTeamManager = RtTeamManager();
return GlobalTeamManager;
}
//
// Release the global teammanager
//
void RtFreeGlobalTeamManager()
{
if (GlobalTeamManager != NULL)
RtTeamManagerFree(GlobalTeamManager);
GlobalTeamManager = NULL;
}
//
// Create a team
//
tTeam* RtTeam() // Default constructor
{
tTeam* Team = (tTeam*) malloc(sizeof(tTeam));// get memory
Team->Count = 0; // Nbr of Teammates
Team->PitState = PIT_IS_FREE; // Request for shared pit
Team->TeamName = NULL; // Name of team
Team->Teams = NULL; // Empty list
Team->Teammates = NULL; // Empty list
for (int I = 0; I < TR_PIT_MAXCARPERPIT; I++)// Loop over all
{ // possible members
Team->Cars[I] = NULL; // No Cars
Team->FuelForLaps[I] = 99; // Fuel still unlimited
}
return Team;
}
//
// Destroy a team
//
void RtTeamFree(tTeam *Team) // Destructor
{
free(Team); // Release memory
}
//
// Get nbr of laps all other teammates can race with current fuel
//
int RtTeamGetMinLaps(tTeam *Team, CarElt* Car) // Get Nbr of laps, all
{ // teammates has fuel for
int MinL = 99; // Assume unlimited
for (int I = 0; I < TR_PIT_MAXCARPERPIT; I++)// Loop over all possible
if (Team->Cars[I] != Car) // entries!
MinL = MIN(MinL,Team->FuelForLaps[I]); // If not self, calculate
return MinL; // Nbr of laps all can race
}
//
// Set nbr of laps this teammate can race with current fuel
//
void RtTeamSetMinLaps(tTeam *Team, CarElt* Car, int FuelForLaps)
{
for (int I = 0; I < TR_PIT_MAXCARPERPIT; I++)// Loop over all teammates
{
if (Team->Cars[I] == Car) // If self, set value
{
Team->FuelForLaps[I] = FuelForLaps;
break;
}
}
}
//
// Add a teammate to the team
//
void RtTeamAdd(tTeam *Team, tTeammate* NewTeammate)
{
tTeammate* Teammate = Team->Teammates;
if (Teammate == NULL)
Team->Teammates = NewTeammate;
else
{
while (Teammate->Next)
Teammate = Teammate->Next;
Teammate->Next = NewTeammate;
}
Team->Cars[Team->Count++] = NewTeammate->Car;
}
//
// Create a teammate
//
tTeammate* RtTeammate() // Default constructor
{
tTeammate* Teammate = (tTeammate*) malloc(sizeof(tTeammate));
Teammate->Car = NULL; // Teammates car
Teammate->Next = NULL; // Empty list
return Teammate;
}
//
// Destroy a teammate
//
void RtTeammateFree(tTeammate* Teammate)
{
free(Teammate); // Release memory
}

View file

@ -0,0 +1,104 @@
/***************************************************************************
file : teammanager.h
created : Sun Feb 22 28:43:00 CET 2009
copyright : (C) 2009 by Wolf-Dieter Beelitz
email : wdb@wdbee.de
version :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/** @file
Teammanager
@author <a href=mailto:wdb@wdbee.de>Wolf-Dieter Beelitz</a>
@version
*/
#ifndef _TEAMMANAGER_H_
#define _TEAMMANAGER_H_
#include <car.h>
#include <track.h> // TR_PIT_MAXCARPERPIT = 4
// Teammanager defines
#define PIT_IS_FREE NULL
// Teammanager Utilities
//
// Data of a teammate
//
typedef struct tTeammate
{
CarElt* Car; // The car of this team member
tTeammate* Next; // The next team member
} tTeammate;
//
// Data of a team
//
typedef struct tTeam
{
int Count; // Nbr of Teammates
CarElt* PitState; // Request for shared pit
char* TeamName; // Name of team
tTeam* Teams; // Linked list of teams
tTeammate* Teammates; // Linked list of teammates
CarElt* Cars[TR_PIT_MAXCARPERPIT]; // Cars
int FuelForLaps[TR_PIT_MAXCARPERPIT]; // Fuel for laps
} tTeam;
//
// Data of a team manager
//
typedef struct
{
int Count; // Nbr of Teammates
tTeam* Teams; // Linked list of teams
} tTeamManager;
//
// Utility functions
//
bool RtIsTeamMate(const CarElt* Car0, const CarElt* Car1);
//
// Teammanager related functions
//
extern tTeamManager* RtTeamManager();
extern void RtTeamManagerFree(tTeamManager* Teammanager);
extern tTeam* RtTeamManagerAdd(tTeamManager *TeamManager, CarElt* Car);
extern tTeamManager* RtGetGlobalTeamManager();
extern void RtFreeGlobalTeamManager();
//
// Team related functions
//
extern tTeam* RtTeam();
extern void RtTeamFree(tTeam* Team);
extern int RtTeamGetMinLaps(tTeam* Team, CarElt* Car);
extern void RtTeamSetMinLaps(tTeam *Team, CarElt* Car, int FuelForLaps);
extern void RtTeamAdd(tTeam *Team, tTeammate* Teammate);
//
// Teammate related functions
//
extern tTeammate* RtTeammate();
extern void RtTeammateFree(tTeammate* Teammate);
#endif /* _TEAMMANAGER_H_ */