30#include <racescreens.h>
31#include <robottools.h>
32#include <portability.h>
35#include <portability.h>
36#include <musicplayer/musicplayer.h>
70 const int BUFSIZE = 1024;
76 GfOut(
"Loading Track Loader...\n");
78 snprintf(buf, BUFSIZE,
"%smodules/track/%s.%s",
GetLibDir (),
dllname, DLLEXT);
82 GfOut(
"Loading Graphic Engine...\n");
84 snprintf(buf, BUFSIZE,
"%smodules/graphic/%s.%s",
GetLibDir (),
dllname, DLLEXT);
88 capture = &(
ReInfo->movieCapture);
108 ReInfo->_reTrackItf.trkShutdown();
144 while ((m = strstr(s,
"/")) != 0) {
148 e = strstr(s, PARAMEXT);
150 ReInfo->_reFilename[e-s] =
'\0';
162 const int BUFSIZE = 1024;
169 GfOut(
"Loading Track Loader...\n");
171 snprintf(buf, BUFSIZE,
"%smodules/track/%s.%s",
GetLibDir (),
dllname, DLLEXT);
175 ReInfo->movieCapture.enabled = 0;
177 const char *s, *e, *m;
180 if (
ReInfo->params == 0) {
181 GfError(
"Could not open file: %s\n", raceconfig);
186 while ((m = strstr(s,
"/")) != 0) {
190 e = strstr(s, PARAMEXT);
192 ReInfo->_reFilename[e-s] =
'\0';
207 const int BUFSIZE = 1024;
210 snprintf(buf, BUFSIZE,
"%sconfig/raceman/%s",
GetLocalDir(), racemanCur->
name);
225 while (cur->
next != head) {
230 if (tmp->
next != cur) {
259 GfOut(
"No race manager available\n");
263 racemanCur = racemanList;
266 racemanCur = racemanCur->
next;
267 }
while (racemanCur != racemanList);
271 racemanCur = racemanList;
273 void *params = racemanCur->
userData;
277 [params] { reSelectRaceman(params); });
278 racemanCur = racemanCur->
next;
279 }
while (racemanCur != racemanList);
289 }
while (rl != racemanList);
320 void *trHdle =
ReInfo->track->params;
321 void *params =
ReInfo->params;
322 const int BUFSIZE = 1024;
328 curseg =
ReInfo->track->seg->next;
331 curseg = curseg->
next;
342 if (strcmp(pole,
"left") == 0) {
366 for (i = 0; i <
ReInfo->s->_ncars; i++) {
367 car = &(
ReInfo->carList[i]);
368 car->_speed_x = speedInit;
369 car->_commitBestLapTime =
true;
370 startpos =
ReInfo->track->length - (d1 + (i / rows) * d2 + (i % rows) *
d3);
371 tr = a + b * ((i % rows) + 1) / (rows + 1);
372 curseg =
ReInfo->track->seg;
373 while (startpos < curseg->lgfromstart) {
374 curseg = curseg->
prev;
377 car->_trkPos.seg = curseg;
378 car->_trkPos.toRight = tr;
379 switch (curseg->
type) {
381 car->_trkPos.toStart =
ts;
386 car->_trkPos.toStart =
ts / curseg->
radius;
388 car->_yaw = curseg->
angle[
TR_ZS] - car->_trkPos.toStart;
391 car->_trkPos.toStart =
ts / curseg->
radius;
393 car->_yaw = curseg->
angle[
TR_ZS] + car->_trkPos.toStart;
429 if (carsPerPit < 1) {
434 GfOut(
"Cars per pit: %d\n", carsPerPit);
436 switch (
ReInfo->track->pits.type) {
438 pits = &(
ReInfo->track->pits);
444 for (i = 0; i < pits->
nMaxPits; i++) {
455 for (i = 0; i <
ReInfo->s->_ncars; i++) {
458 for (j = 0; j < pits->
nMaxPits; j++) {
463 (strcmp(pit->
car[0]->_teamname, car->_teamname) == 0 && pit->
freeCarIndex < carsPerPit))
482 ReInfo->carList[i]._pit = pit;
490 for (i = 0; i < pits->
nMaxPits; i++) {
494 GfOut(
"Pit %d, Team: %s, ", i, pit->
car[j]->_teamname);
496 GfOut(
"%d: %s ", j, pit->
car[j]->_name);
516 if (modInfo->
index == robotIdx) {
523 if (modInfo->
name != NULL && driverName != NULL && strcmp(modInfo->
name, driverName) == 0) {
525 const int BUFSIZE = 1024;
529 GfError(
"Driver list in results is empty");
533 if (resultDriverName != NULL && strcmp(resultDriverName, modInfo->
name) == 0) {
560 void *params =
ReInfo->params;
561 const int BUFSIZE = 1024;
562 char buf[BUFSIZE], path[BUFSIZE];
566 GfOut(
"loading %d cars\n", nCars);
575 int defaultSkillLevel = 2;
577 for(k = 0; k < (int)(
sizeof(
level_str)/
sizeof(
char*)); k++) {
578 if (strcmp(
level_str[k], defaultSkillLevelStr) == 0) {
579 defaultSkillLevel = k;
584 for (i = 1; i < nCars + 1; i++) {
588 snprintf(path, BUFSIZE,
"%sdrivers/%s/%s.%s",
GetLibDir (), cardllname, cardllname, DLLEXT);
592 GfTrace(
"Pb with loading %s driver\n", path);
602 int robotIdx = curModInfo->
index;
603 GfOut(
"Driver's name: %s\n", curModInfo->
name);
606 curModInfo->
fctInit(robotIdx, (
void*)(curRobot));
607 snprintf(buf, BUFSIZE,
"%sdrivers/%s/%s.xml",
GetLocalDir(), cardllname, cardllname);
610 snprintf(buf, BUFSIZE,
"drivers/%s/%s.xml", cardllname, cardllname);
613 if (robhdle != NULL) {
614 elt = &(
ReInfo->carList[index]);
618 elt->
robot = curRobot;
619 elt->_paramsHandle = robhdle;
620 elt->_driverIndex = robotIdx;
636 GfError(
"Human drivers not allowed in console race, fix race setup.\n");
642 elt->_skillLevel = 0;
644 for(k = 0; k < (int)(
sizeof(
level_str)/
sizeof(
char*)); k++) {
646 elt->_skillLevel = k;
650 elt->_startRank = index;
652 elt->_remainingLaps =
ReInfo->s->_totLaps;
656 snprintf(buf, BUFSIZE,
"cars/%s/%s.xml", elt->_carName, elt->_carName);
657 GfOut(
"Car Specification: %s\n", buf);
660 snprintf(buf, BUFSIZE,
"Loading Driver %-20s... Car: %s", curModInfo->
name, elt->_carName);
668 snprintf(buf, BUFSIZE,
"categories/%s.xml", category);
669 GfOut(
"Category Specification: %s\n", buf);
672 GfTrace(
"Car %s not in Category %s (driver %s) !!!\n", elt->_carName, category, elt->_name);
678 if (handle != NULL) {
680 GfTrace(
"Bad Car parameters for driver %s\n", elt->_name);
688 elt->_carHandle = handle;
691 elt->_category[0] =
'\0';
692 GfTrace(
"Bad Car category for driver %s\n", elt->_name);
697 GfTrace(
"Pb No description file for driver %s\n", cardllname);
706 GfTrace(
"No driver for that race...\n");
709 GfOut(
"%d drivers ready to race\n", nCars);
712 ReInfo->s->_ncars = nCars;
715 for (i = 0; i < nCars; i++) {
722 ReInfo->raceRules.fuelFactor,
723 ReInfo->raceRules.damageFactor,
724 ReInfo->raceRules.tireFactor
743 const int BUFSIZE = 1024;
747 const char *stype[4] = {
"",
"RGT",
"LFT",
"STR" };
751 snprintf(buf, BUFSIZE,
">>> Track Name %s",
track->name);
753 snprintf(buf, BUFSIZE,
">>> Track Author %s",
track->author);
755 snprintf(buf, BUFSIZE,
">>> Track Length %.2f m",
track->length);
757 snprintf(buf, BUFSIZE,
">>> Track Width %.2f m",
track->width);
760 GfOut(
"++++++++++++ Track ++++++++++++\n");
771 switch (
track->pits.type) {
773 GfOut(
"Pits = none\n");
776 GfOut(
"Pits = present on track side\n");
779 GfOut(
"Pits = present on separate path\n");
783 for (i = 0, seg =
track->seg->next; i < track->nseg; i++, seg = seg->
next) {
784 GfOut(
" segment %d -------------- \n", seg->
id);
795 GfOut(
" vertices: %-8.8f %-8.8f %-8.8f ++++ ",
799 GfOut(
"%-8.8f %-8.8f %-8.8f\n",
803 GfOut(
" vertices: %-8.8f %-8.8f %-8.8f ++++ ",
807 GfOut(
"%-8.8f %-8.8f %-8.8f\n",
814 GfOut(
"From Last To First\n");
815 GfOut(
"Dx = %-8.8f Dy = %-8.8f Dz = %-8.8f\n",
836 void *params =
ReInfo->params;
837 void *results =
ReInfo->results;
838 const int BUFSIZE = 1024;
840 char trackFile[BUFSIZE];
841 std::vector<tReTrackCandidate> availableTracks;
849 std::string requestedTrackName = trackName;
850 std::string requestedCategoryName = catName;
852 if (
ReTrackFileExists(requestedCategoryName.c_str(), requestedTrackName.c_str(), NULL, 0)) {
853 availableTracks.push_back(
tReTrackCandidate(requestedCategoryName.c_str(), requestedTrackName.c_str()));
859 GfError(
"ReInitTrack: No available track found\n");
864 GfOut(
"Selected track %s/%s is not available, falling back to %s/%s\n",
865 requestedCategoryName.empty() ?
"<none>" : requestedCategoryName.c_str(),
866 requestedTrackName.empty() ?
"<none>" : requestedTrackName.c_str(),
868 trackSelection.
name.c_str());
875 GfError(
"ReInitTrack: Track %s/%s is no longer available\n", trackSelection.
category.c_str(), trackSelection.
name.c_str());
879 snprintf(buf, BUFSIZE,
"Loading Track %s...", trackSelection.
name.c_str());
881 ReInfo->track =
ReInfo->_reTrackItf.trkBuild(trackFile);
883 GfError(
"ReInitTrack: Failed to build track %s\n", trackFile);
895 ReInfo->_reSimItf.shutdown();
897 ReInfo->_reGraphicItf.shutdowncars();
912 nCars =
ReInfo->s->_ncars;
913 for (i = 0; i < nCars; i++) {
914 robot =
ReInfo->s->cars[i]->robot;
942 void *params =
ReInfo->params;
943 void *results =
ReInfo->results;
944 const int BUFSIZE = 1024;
956 void *params =
ReInfo->params;
957 void *results =
ReInfo->results;
958 const int BUFSIZE = 1024;
struct CarElt tCarElt
Car structure (tCarElt).
struct CarPenalty tCarPenalty
One penalty.
static const char * level_str[]
float tdble
Floating point type used in TORCS.
tFList * GfDirGetListFiltered(const char *dir, const char *suffix)
Get the list of files with matching suffix of a given directory.
int GfuiMenuButtonCreateAction(void *scr, const char *text, const char *tip, const tGfuiAction &onpush)
Add a menu button with a focus tip.
int GfModUnloadList(tModList **modlist)
Unload the DLLs of a list.
int GfModLoad(unsigned int gfid, char *dllname, tModList **modlist)
Load the specified DLLs.
const char * GfParmGetStr(void *parmHandle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle.
tdble GfParmGetNum(void *handle, const char *path, const char *key, const char *unit, tdble deflt)
Get a numerical parameter from the parameter set handle.
void GfParmReleaseHandle(void *parmHandle)
Release given parameter set handle parmHandle.
char * GfParmGetFileName(void *handle)
Get the filename property of the parameter set handle.
int GfParmWriteFile(const char *file, void *parmHandle, const char *name)
Write parameter set into file.
int GfParmCheckHandle(void *ref, void *tgt)
Check the values in the parameter set tgt against the min/max/within definitions in the ref parameter...
void * GfParmMergeHandles(void *ref, void *tgt, int mode)
Merge two parameter sets into a new private set.
void * GfParmReadFile(const char *file, int mode)
Read parameter set from file and return handle to parameter set.
int GfParmListSeekNext(void *handle, const char *path)
Advance to the next immediate subsection.
int GfParmListSeekFirst(void *handle, const char *path)
Select the first immediate subsection of a section.
int GfParmGetEltNb(void *handle, const char *path)
Count the number of subsections in a section in the parameter set handle.
int GfParmSetCurNum(void *handle, const char *path, const char *key, const char *unit, tdble val)
Set a numerical parameter in the parameter set handle based on subsection iteration.
const char * GfParmGetCurStr(void *handle, const char *path, const char *key, const char *deflt)
Get a string parameter from the parameter set handle based on subsection iteration.
struct RobotItf tRobotItf
Interface Structure for Robots.
#define GF_TAILQ_INIT(head)
Head initialization (Mandatory)
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
#define GF_TAILQ_FIRST(head)
First element of a TAILQ.
struct trackSeg tTrackSeg
Track segment (tTrackSeg) The segments can be straights (type TR_STR): (the track goes from the right...
static char * strndup(const char *str, int len)
static void reRegisterRaceman(tFList *racemanCur)
const char * ReGetPrevRaceName(void)
void ReAddRacemanListButton(void *menuHandle)
void ReStartNewRace(void *)
void ReRunRaceOnConsole(const char *raceconfig)
const char * ReGetCurrentRaceName(void)
static void reSortRacemanList(tFList **racemanList)
int ReInitTrack(void)
Initialize the current race-manager track.
bool isItThisRobot(tRmInfo *reInfo, const char *path, tModInfo *modInfo)
static void reSelectRaceman(void *params)
int ReInitCars(void)
Initialize the cars for a race.
static void initPits(void)
static void initStartingGrid(void)
void ReRaceCleanDrivers(void)
static tModList * reEventModList
static void reDumpTrack(tTrack *track, int verbose)
Dump the track segments on screen.
#define RM_ATT_CAPTURE_FPS
#define RM_ATTR_CARSPERPIT
struct RmInfo tRmInfo
Race Manager General Info.
#define RM_ATT_CAPTURE_ENABLE
#define RM_SECT_MOVIE_CAPTURE
#define RE_ATTR_CUR_TRACK
struct RmMovieCapture tRmMovieCapture
#define RM_ATTR_INITSPEED
#define RM_SECT_STARTINGGRID
#define RM_ATT_CAPTURE_OUT_DIR
#define RM_ATTR_INITHEIGHT
#define RM_ATTR_COLOFFSET
struct RmCarRules tRmCarRules
#define RE_STATE_EVENT_INIT
#define RM_SECT_DRIVERS_RACING
#define RM_ATTR_SKILL_LEVEL_DEFAULT
#define RM_DISP_MODE_CONSOLE
struct Situation tSituation
cars situation used to inform the GUI and the drivers
#define RM_DISP_MODE_NORMAL
void ReStoreRaceResults(const char *race)
void ReStateApply(int state)
bool ReResolveTrackSelection(void *params, int curTrackIndex, const std::vector< tReTrackCandidate > &availableTracks, tReTrackSelection *selection, bool updateParams)
Resolve the current race-manager track entry to an available track.
std::vector< tReTrackCandidate > ReFindAvailableTracks(void)
Find all available tracks under the current TORCS track search path.
bool ReTrackFileExists(const char *category, const char *trackName, char *trackFile, int trackFileSize)
Check whether a track XML file exists and can be parsed.
Helpers for selecting a valid race-manager track.
struct RobotItf * robot
private
struct FList * next
Next entry.
struct FList * prev
Previous entry.
char * dispName
Name to display on screen.
void * userData
User data.
int index
index if multiple interface in one dll
char * name
name of the module (short) (NULL if no module)
tfModPrivInit fctInit
init function
tTrack * track
Current track.
void * params
Raceman parameters.
void * results
Race results.
tdble lmin
Pitting area length min.
int pitCarIndex
Index of the car in the car array below which occupies the pit.
tTrkLocPos pos
Center of the pit position.
struct CarElt * car[TR_PIT_MAXCARPERPIT]
Car links for pit.
tdble lmax
Pitting area length max.
Track directory pair that can be selected by a race manager.
Result of resolving a race-manager track selection.
std::string name
Selected track directory and XML base name.
std::string category
Selected track category directory name.
bool fallback
true if the configured track was replaced by a fallback
const char * name
Name of the track.
tTrackOwnPit * driversPits
List of pits by driver.
tdble len
Lenght of each pit stop.
int nMaxPits
number max of pits
int driversPitsNb
Number of drivers.
tTrackSeg * seg
Track segment.
tdble toStart
Distance to start of segment (or arc if turn)
int type
Geometrical type:
t3Dd vertex[4]
Coordinates of the 4 corners of the segment.
tdble radius
Radius in meters of the middle of the track (>0)
tdble arc
Arc in rad of the curve (>0)
tdble lgfromstart
Length of beginning of segment from starting line.
tdble length
Length in meters of the middle of the track.
struct trackSeg * next
Next segment.
struct trackSeg * prev
Previous segment.
#define GFPARM_RMODE_CREAT
Allow an empty in-memory set on file-open failure; does not write a file.
#define GFPARM_RMODE_STD
Return a new handle sharing cached data for this filename, if available.
#define GFPARM_MMODE_RELSRC
release ref after the merge
#define GFPARM_MMODE_RELDST
release tgt after the merge
#define GFPARM_MMODE_SRC
Include ref attributes; merge common attributes using ref restrictions and tgt values.
#define MAX_MOD_ITF
Maximum number of interface in one DLL.
struct ModList tModList
list of module interfaces
#define GFPARM_RMODE_REREAD
Clear shared cached data and reread the file.
#define NORM0_2PI(x)
Angle normalization between 0 and 2 * PI.
#define GFPARM_MMODE_DST
Include tgt attributes; merge common attributes using ref restrictions and tgt values.
struct FList tFList
List of (DLL) files for a Directory.
struct ModInfo tModInfo
Module information structure.
#define RAD2DEG(x)
Radian to degree conversion.
struct TrackOwnPit tTrackOwnPit
Driver's pit.
#define TR_CS
Center start angle.
#define TR_PIT_STATE_FREE
#define TR_LFT
Left curve.
#define TR_EL
End-Left corner.
#define TR_ZE
Z End angle.
#define TR_PIT_NONE
No pits for that tracks.
#define TR_PIT_ON_TRACK_SIDE
The pits are on the track side.
#define TR_PIT_ON_SEPARATE_PATH
#define TR_PIT_MAXCARPERPIT
#define TR_ER
End_Right corner.
#define TR_SL
Start-Left corner.
#define TR_RGT
Right curve.
#define TR_ZS
Rotation angles of the track in rad anti-clockwise: Index in:
#define TR_SR
Start-Right corner.
int track(tModInfo *modInfo)