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:
parent
111b809f1b
commit
e96c90c48d
13 changed files with 481 additions and 31 deletions
|
@ -49,7 +49,7 @@
|
|||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
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"
|
||||
RuntimeLibrary="1"
|
||||
PrecompiledHeaderFile=".\Debug/simplix.pch"
|
||||
|
@ -152,7 +152,7 @@
|
|||
Optimization="2"
|
||||
InlineFunctionExpansion="2"
|
||||
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"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
|
@ -890,4 +890,3 @@
|
|||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
|
||||
|
|
|
@ -66,6 +66,9 @@
|
|||
TCommonData::TCommonData():
|
||||
Track(NULL)
|
||||
{
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
TeamManager = RtGetGlobalTeamManager();
|
||||
#endif
|
||||
}
|
||||
//==========================================================================*
|
||||
|
||||
|
|
|
@ -60,7 +60,11 @@
|
|||
|
||||
#include <track.h>
|
||||
#include "unitglobal.h"
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#include <teammanager.h>
|
||||
#else
|
||||
#include "unitteammanager.h"
|
||||
#endif
|
||||
#include "unitclothoid.h"
|
||||
|
||||
//==========================================================================*
|
||||
|
@ -73,7 +77,11 @@ class TCommonData
|
|||
~TCommonData(); // Destructor
|
||||
|
||||
public:
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
tTeamManager* TeamManager; // Team manager
|
||||
#else
|
||||
TTeamManager TeamManager; // Team manager
|
||||
#endif
|
||||
PTrack Track; // TORCS Track data
|
||||
};
|
||||
//==========================================================================*
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
// File : unitdriver.cpp
|
||||
// Created : 2007.11.25
|
||||
// Last changed : 2009.02.14
|
||||
// Copyright : © 2007-2009 Wolf-Dieter Beelitzf
|
||||
// Copyright : © 2007-2009 Wolf-Dieter Beelitz
|
||||
// eMail : wdb@wdbee.de
|
||||
// Version : 2.00.000
|
||||
//--------------------------------------------------------------------------*
|
||||
|
@ -1052,6 +1052,7 @@ void TDriver::EndRace()
|
|||
//--------------------------------------------------------------------------*
|
||||
void TDriver::Shutdown()
|
||||
{
|
||||
RtFreeGlobalTeamManager();
|
||||
}
|
||||
//==========================================================================*
|
||||
|
||||
|
@ -1111,7 +1112,11 @@ void TDriver::FindRacinglines()
|
|||
if(oCommonData->Track != oTrackDesc.Track()) // New track?
|
||||
{
|
||||
oCommonData->Track = oTrackDesc.Track(); // Save pointer
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
// oCommonData->TeamManager->Clear(); // release old informations
|
||||
#else
|
||||
oCommonData->TeamManager.Clear(); // release old informations
|
||||
#endif
|
||||
}
|
||||
|
||||
GfOut("# ... load smooth path ...\n");
|
||||
|
@ -1232,7 +1237,11 @@ void TDriver::FindRacinglines()
|
|||
//--------------------------------------------------------------------------*
|
||||
void TDriver::TeamInfo()
|
||||
{
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
oTeam = RtTeamManagerAdd(oCommonData->TeamManager,oCar);
|
||||
#else
|
||||
oTeam = oCommonData->TeamManager.Add(oCar);
|
||||
#endif
|
||||
//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++)
|
||||
{
|
||||
oOpponents[I].Update(oCar,
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
&oCommonData->TeamManager,
|
||||
#endif
|
||||
MyDomX, MyDomY, MinDistBack, MinTimeSlot);
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,11 @@ class TDriver
|
|||
(void* RobotSettings, char* Value);
|
||||
inline void SetCommonData // Set pointer to common data
|
||||
(TCommonData* CommonData);
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
inline tTeam* GetTeam();
|
||||
#else
|
||||
inline TTeamManager::TTeam* GetTeam();
|
||||
#endif
|
||||
inline char* GetBotName();
|
||||
inline float CurrSpeed();
|
||||
|
||||
|
@ -216,7 +220,11 @@ private:
|
|||
double oAvoidScale; // scale avoiding
|
||||
double oAvoidWidth; // In m.
|
||||
bool oGoToPit; // Enter pit flag
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
tTeam* oTeam;
|
||||
#else
|
||||
TTeamManager::TTeam* oTeam; // Team
|
||||
#endif
|
||||
|
||||
int oDriveTrainType; // Drive train type
|
||||
TPidController oPIDCLine; // Controller for line error.
|
||||
|
@ -387,7 +395,11 @@ void TDriver::SetCommonData
|
|||
//==========================================================================*
|
||||
// Get Team
|
||||
//--------------------------------------------------------------------------*
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
tTeam* TDriver::GetTeam()
|
||||
#else
|
||||
TTeamManager::TTeam* TDriver::GetTeam()
|
||||
#endif
|
||||
{
|
||||
return oTeam;
|
||||
}
|
||||
|
|
|
@ -238,7 +238,11 @@ enum
|
|||
// ... my own planet
|
||||
|
||||
// pit states ...
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#define PIT_IS_FREE NULL
|
||||
#else
|
||||
#define PIT_IS_FREE (-1)
|
||||
#endif
|
||||
// ... pit states
|
||||
|
||||
// Shortcuts for TORCS commands ...
|
||||
|
|
|
@ -132,13 +132,19 @@ TOpponent::TInfo& TOpponent::Info()
|
|||
//--------------------------------------------------------------------------*
|
||||
void TOpponent::Update(
|
||||
const PCarElt MyCar,
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
PTeamManager TeamManager,
|
||||
#endif
|
||||
double MyDirX,
|
||||
double MyDirY,
|
||||
float &MinDistBack,
|
||||
double &MinTimeSlot)
|
||||
{
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
oTeamManager = TeamManager; // Save Pointer
|
||||
#endif
|
||||
|
||||
if((CarState & RM_CAR_STATE_NO_SIMU) && // omit cars out of race
|
||||
(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
|
||||
|
||||
// Teammate?
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
if (RtIsTeamMate(MyCar,oCar)) // If Opp. is teammate
|
||||
#else
|
||||
if (oTeamManager->IsTeamMate(MyCar,oCar)) // If Opp. is teammate
|
||||
#endif
|
||||
{
|
||||
oInfo.Flags |= F_TEAMMATE; // Set teammate flag
|
||||
oInfo.TeamMateDamage = oCar->_dammage; // Save his damages
|
||||
|
|
|
@ -61,7 +61,10 @@
|
|||
#include "unitglobal.h"
|
||||
#include "unitcommon.h"
|
||||
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
#include "unitteammanager.h"
|
||||
#endif
|
||||
|
||||
//==========================================================================*
|
||||
// Class TOpponent
|
||||
|
@ -134,7 +137,10 @@ class TOpponent
|
|||
|
||||
void Update // Update
|
||||
(const PCarElt MyCar,
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
PTeamManager TeamManager,
|
||||
#endif
|
||||
double MyDirX, double MyDirY,
|
||||
float &MinDistBack,
|
||||
double &MinTimeSlot);
|
||||
|
@ -151,7 +157,10 @@ class TOpponent
|
|||
double oDeltaTime; // Simulation delta time
|
||||
int oIndex; // Opponents cars index
|
||||
TInfo oInfo; // info of this opponent
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
#else
|
||||
PTeamManager oTeamManager; // Teammanager
|
||||
#endif
|
||||
double LapBackTimer;
|
||||
|
||||
};
|
||||
|
|
|
@ -106,9 +106,15 @@ bool TSimpleStrategy::IsPitFree()
|
|||
{
|
||||
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();
|
||||
if ((CarPit->pitCarIndex == TR_PIT_STATE_FREE)
|
||||
&& ((Team->PitState == CarDriverIndex) || (Team->PitState == PIT_IS_FREE)))
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -161,14 +167,25 @@ bool TSimpleStrategy::NeedPitStop()
|
|||
}
|
||||
else // Ansonsten prüfen, für
|
||||
{ // welche Anzahl von Runden
|
||||
TTeamManager::TTeam* Team = // alle Teammitglieder
|
||||
oDriver->GetTeam(); // noch Treibstoff haben
|
||||
|
||||
// alle Teammitglieder
|
||||
// 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
|
||||
#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
|
||||
Team->FuelForLaps[CarDriverIndex] =
|
||||
(int) (CarFuel / FuelNeeded - 1);
|
||||
int MinLaps = Team->GetMinLaps(oCar); // Mindestreichweite der anderen
|
||||
#endif
|
||||
|
||||
// Wenn Tanken, dann der, der weniger Runden weit kommen würde
|
||||
if (FuelForLaps < MinLaps)
|
||||
|
@ -194,8 +211,13 @@ bool TSimpleStrategy::NeedPitStop()
|
|||
|
||||
if (Result)
|
||||
{
|
||||
#ifdef _USE_RTTEAMMANAGER_
|
||||
tTeam* Team = oDriver->GetTeam();
|
||||
Team->PitState = oCar; // Box reserviert
|
||||
#else
|
||||
TTeamManager::TTeam* Team = oDriver->GetTeam();
|
||||
Team->PitState = CarDriverIndex; // Box reserviert
|
||||
#endif
|
||||
}
|
||||
return Result;
|
||||
};
|
||||
|
@ -206,8 +228,13 @@ bool TSimpleStrategy::NeedPitStop()
|
|||
//--------------------------------------------------------------------------*
|
||||
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();
|
||||
if (Team->PitState == CarDriverIndex) // Box für mich reserviert?
|
||||
#endif
|
||||
{
|
||||
Team->PitState = PIT_IS_FREE;
|
||||
oCar->ctrl.raceCmd = 0;
|
||||
|
@ -447,11 +474,11 @@ void TSimpleStrategy::Update(PtCarElt Car,
|
|||
oLastPitFuel = 0.0; // Refueled
|
||||
oFuelChecked = true; // We did the estimation in this lap
|
||||
|
||||
if (!oGoToPit) // If decision isn'd made
|
||||
oGoToPit = NeedPitStop(); // Check if we sholud have a pitstop
|
||||
if (!oGoToPit) // If decision isn't made
|
||||
oGoToPit = NeedPitStop(); // Check if we should have a pitstop
|
||||
}
|
||||
else if (DL < 50) // I we are out of the window
|
||||
{ // to estimate
|
||||
{ // to estimate fuel consumption
|
||||
oFuelChecked = false; // reset flag
|
||||
};
|
||||
};
|
||||
|
|
|
@ -19,3 +19,16 @@ EXPORTS
|
|||
RtGetDistFromStart2
|
||||
RtDistToPit
|
||||
RtTrackGetSeg
|
||||
RtIsTeamMate
|
||||
RtTeamManager
|
||||
RtTeamManagerFree
|
||||
RtTeamManagerAdd
|
||||
RtGetGlobalTeamManager
|
||||
RtFreeGlobalTeamManager
|
||||
RtTeam
|
||||
RtTeamFree
|
||||
RtTeamGetMinLaps
|
||||
RtTeamSetMinLaps
|
||||
RtTeamAdd
|
||||
RtTeammate
|
||||
RtTeammateFree
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
Version="8,00"
|
||||
Name="robottools"
|
||||
ProjectGUID="{65130FEC-5171-4924-B6AE-0456FB4029A1}"
|
||||
RootNamespace="robottools"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
|
@ -234,6 +235,10 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\rtteammanager.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="rttelem.cpp"
|
||||
>
|
||||
|
@ -287,6 +292,10 @@
|
|||
RelativePath="robottools.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\teammanager.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
|
240
src/libs/robottools/rtteammanager.cpp
Normal file
240
src/libs/robottools/rtteammanager.cpp
Normal 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
|
||||
}
|
104
src/libs/robottools/teammanager.h
Normal file
104
src/libs/robottools/teammanager.h
Normal 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_ */
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue