Ensure that extended mode is always used for humans. This way, we can use normal indices for the human drivers (human and networkhuman).

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

Former-commit-id: c01e10e89a9c71df0694b0652e431e9b3f492568
Former-commit-id: a60c1a52d466aea92138175a1215e8a90bbd1154
This commit is contained in:
martkelder 2010-08-08 19:09:10 +00:00
parent 699e9131a6
commit 49fd9645be
3 changed files with 27 additions and 89 deletions

View file

@ -122,10 +122,6 @@ shutdown(const int index)
VecNames.erase(VecNames.begin() + idx); VecNames.erase(VecNames.begin() + idx);
// ??????? Why this ???????????
if (index > NbDrivers)
idx -= NbDrivers + 1;
free (HCtx[idx]); free (HCtx[idx]);
HCtx[idx] = 0; HCtx[idx] = 0;
@ -151,10 +147,6 @@ shutdown(const int index)
static int static int
InitFuncPt(int index, void *pt) InitFuncPt(int index, void *pt)
{ {
// ??????? Why this ???????????
if (index > NbDrivers)
index -= NbDrivers + 1;
tRobotItf *itf = (tRobotItf *)pt; tRobotItf *itf = (tRobotItf *)pt;
const int idx = index - 1; const int idx = index - 1;
@ -318,13 +310,7 @@ static void
initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s) initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s)
{ {
char trackname[256]; char trackname[256];
bool otherCar = false;
// ??????? Why this ???????????
if (index > NbDrivers) {
index -= NbDrivers + 1;
otherCar = true;
}
const int idx = index - 1; const int idx = index - 1;
curTrack = track; curTrack = track;
@ -340,14 +326,12 @@ initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSitu
? GfParmGetStrNC(drvInfo, sstring, "car name", NULL) ? GfParmGetStrNC(drvInfo, sstring, "car name", NULL)
: ""; : "";
if (otherCar) {
sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir());
void *curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); void *curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD);
if (curCars) { if (curCars) {
sprintf(sstring, "drivers/human/%d", index + NbDrivers + 1); sprintf(sstring, "drivers/human/%d", index + NbDrivers + 1);
carname = GfParmGetStr(curCars, sstring, "car name", carname.c_str()); carname = GfParmGetStr(curCars, sstring, "car name", carname.c_str());
}//if curCars }//if curCars
}//if otherCar
sprintf(sstring, "%sdrivers/human/cars/%s/default.xml", GetLocalDir(), carname.c_str()); sprintf(sstring, "%sdrivers/human/cars/%s/default.xml", GetLocalDir(), carname.c_str());
*carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); *carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD);
@ -408,9 +392,6 @@ initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSitu
void void
newrace(int index, tCarElt* car, tSituation *s) newrace(int index, tCarElt* car, tSituation *s)
{ {
// ??????? Why this ???????????
if (index > NbDrivers)
index -= NbDrivers + 1;
const int idx = index - 1; const int idx = index - 1;
// Initialize engine RPM shifting threshold table for automatic shifting mode. // Initialize engine RPM shifting threshold table for automatic shifting mode.
@ -1111,9 +1092,6 @@ getAutoClutch(const int idx, int gear, int newGear, tCarElt *car)
static void static void
drive_mt(int index, tCarElt* car, tSituation *s) drive_mt(int index, tCarElt* car, tSituation *s)
{ {
// ??????? Why this ???????????
if (index > NbDrivers)
index -= NbDrivers + 1;
const int idx = index - 1; const int idx = index - 1;
tControlCmd *cmd = HCtx[idx]->cmdControl; tControlCmd *cmd = HCtx[idx]->cmdControl;
@ -1203,9 +1181,6 @@ drive_mt(int index, tCarElt* car, tSituation *s)
static void static void
drive_at(int index, tCarElt* car, tSituation *s) drive_at(int index, tCarElt* car, tSituation *s)
{ {
// ??????? Why this ???????????
if (index > NbDrivers)
index -= NbDrivers + 1;
const int idx = index - 1; const int idx = index - 1;
tControlCmd *cmd = HCtx[idx]->cmdControl; tControlCmd *cmd = HCtx[idx]->cmdControl;
@ -1298,9 +1273,6 @@ drive_at(int index, tCarElt* car, tSituation *s)
static int static int
pitcmd(int index, tCarElt* car, tSituation *s) pitcmd(int index, tCarElt* car, tSituation *s)
{ {
// ??????? Why this ???????????
if (index > NbDrivers)
index -= NbDrivers + 1;
const int idx = index - 1; const int idx = index - 1;
HCtx[idx]->nbPitStops++; HCtx[idx]->nbPitStops++;

View file

@ -160,11 +160,6 @@ InitFuncPt(int index, void *pt)
tRobotItf *itf = (tRobotItf *)pt; tRobotItf *itf = (tRobotItf *)pt;
int idx = index - 1; int idx = index - 1;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
}
if (masterPlayer == -1) { if (masterPlayer == -1) {
masterPlayer = index; masterPlayer = index;
} }
@ -374,15 +369,8 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH
char trackname[256]; char trackname[256];
tdble fuel; tdble fuel;
int idx = index - 1; int idx = index - 1;
char otherCar = FALSE;
void *curCars; void *curCars;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
otherCar = TRUE;
}
curTrack = track; curTrack = track;
s1 = strrchr(track->filename, '/') + 1; s1 = strrchr(track->filename, '/') + 1;
s2 = strchr(s1, '.'); s2 = strchr(s1, '.');
@ -396,7 +384,6 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH
if (DrvInfo != NULL) { if (DrvInfo != NULL) {
carname = strdup(GfParmGetStr(DrvInfo, sstring, "car name", "")); carname = strdup(GfParmGetStr(DrvInfo, sstring, "car name", ""));
} }
if (otherCar) {
sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir());
curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD);
if (curCars) { if (curCars) {
@ -406,7 +393,6 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH
if( oldcarname ) if( oldcarname )
free (oldcarname); free (oldcarname);
} }
}
sprintf(sstring, "%sdrivers/networkhuman/tracks/%s/car-%s-%d.xml", GetLocalDir(), trackname, carname, index); sprintf(sstring, "%sdrivers/networkhuman/tracks/%s/car-%s-%d.xml", GetLocalDir(), trackname, carname, index);
*carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); *carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD);
@ -474,10 +460,6 @@ void newrace(int index, tCarElt* car, tSituation *s)
{ {
int i; int i;
int idx = index - 1; int idx = index - 1;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
}
for (i = 0; i < MAX_GEARS; i++) { for (i = 0; i < MAX_GEARS; i++) {
if (car->_gearRatio[i] != 0) { if (car->_gearRatio[i] != 0) {
@ -1102,11 +1084,6 @@ static void drive_mt(int index, tCarElt* car, tSituation *s)
int idx = index - 1; int idx = index - 1;
tControlCmd *cmd; tControlCmd *cmd;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
}
cmd = HCtx[idx]->CmdControl; cmd = HCtx[idx]->CmdControl;
common_drive(index, car, s); common_drive(index, car, s);
@ -1175,11 +1152,6 @@ static void drive_at(int index, tCarElt* car, tSituation *s)
int idx = index - 1; int idx = index - 1;
tControlCmd *cmd; tControlCmd *cmd;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
}
if (GetNetwork()) if (GetNetwork())
{ {
if (g_activeDriver!=idx) if (g_activeDriver!=idx)
@ -1280,10 +1252,6 @@ static int pitcmd(int index, tCarElt* car, tSituation *s)
tdble f1, f2; tdble f1, f2;
tdble ns; tdble ns;
int idx = index - 1; int idx = index - 1;
if (index > NbDrivers) {
index -= NbDrivers + 1;
idx -= NbDrivers + 1;
}
HCtx[idx]->NbPitStops++; HCtx[idx]->NbPitStops++;
f1 = car->_tank - car->_fuel; f1 = car->_tank - car->_fuel;

View file

@ -509,7 +509,7 @@ initPits(void)
* @param cardllname The dllname of the driver * @param cardllname The dllname of the driver
* @return A pointer to the newly created car if successfull; NULL otherwise * @return A pointer to the newly created car if successfull; NULL otherwise
*/ */
static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int robotIdx, char normal_carname, char const *cardllname ) static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int relativeRobotIdx, char normal_carname, char const *cardllname )
{ {
tCarElt *elt; tCarElt *elt;
tMemoryPool oldPool; tMemoryPool oldPool;
@ -527,15 +527,16 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
int k; int k;
int xx; int xx;
char isHuman; char isHuman;
int robotIdx = relativeRobotIdx;
/* good robot found */ /* good robot found */
curModInfo = &((*(ReInfo->modList))->modInfo[modindex]); curModInfo = &((*(ReInfo->modList))->modInfo[modindex]);
GfOut("Driver's name: %s\n", curModInfo->name); GfOut("Driver's name: %s\n", curModInfo->name);
if (!normal_carname) {
robotIdx += curModInfo->index;
}
isHuman = strcmp( cardllname, "human" ) == 0; isHuman = strcmp( cardllname, "human" ) == 0 || strcmp( cardllname, "networkhuman" ) == 0;
if (!normal_carname && !isHuman) /*Extended is forced for humans, so no need to increase robotIdx*/
robotIdx += curModInfo->index;
/* Retrieve the driver interface (function pointers) */ /* Retrieve the driver interface (function pointers) */
curRobot = (tRobotItf*)calloc(1, sizeof(tRobotItf)); curRobot = (tRobotItf*)calloc(1, sizeof(tRobotItf));
@ -561,10 +562,8 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD); robhdle = GfParmReadFile(buf, GFPARM_RMODE_STD);
} }
if (normal_carname) if (normal_carname || isHuman)
sprintf(path, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, robotIdx); sprintf(path, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, robotIdx);
else if (isHuman)
sprintf(path, "%s/%s/%d", ROB_SECT_ROBOTS, ROB_LIST_INDEX, robotIdx - curModInfo->index);
else else
sprintf(path, "%s", ROB_SECT_ARBITRARY); sprintf(path, "%s", ROB_SECT_ARBITRARY);
@ -590,10 +589,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
elt->robot = curRobot; elt->robot = curRobot;
elt->_paramsHandle = robhdle; elt->_paramsHandle = robhdle;
elt->_driverIndex = robotIdx; elt->_driverIndex = robotIdx;
if (normal_carname) elt->_moduleIndex = relativeRobotIdx;
elt->_moduleIndex = robotIdx;
else
elt->_moduleIndex = robotIdx - curModInfo->index;
strncpy(elt->_modName, cardllname, MAX_NAME_LEN - 1); strncpy(elt->_modName, cardllname, MAX_NAME_LEN - 1);
elt->_modName[MAX_NAME_LEN - 1] = 0; elt->_modName[MAX_NAME_LEN - 1] = 0;
@ -609,7 +605,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
elt->_driveSkill = GfParmGetNum(ReInfo->params, path2, RM_ATTR_SKILLLEVEL, NULL, 0.0f); elt->_driveSkill = GfParmGetNum(ReInfo->params, path2, RM_ATTR_SKILLLEVEL, NULL, 0.0f);
// TODO (D30) : Get human _carName from race info in any case (no more from human.xml). // TODO (D30) : Get human _carName from race info in any case (no more from human.xml).
if (normal_carname) if (normal_carname) /* Even if we get a normal_carname for humans we use it despite of forced extended mode*/
strncpy(elt->_carName, GfParmGetStr(robhdle, path, ROB_ATTR_CAR, ""), MAX_NAME_LEN - 1); strncpy(elt->_carName, GfParmGetStr(robhdle, path, ROB_ATTR_CAR, ""), MAX_NAME_LEN - 1);
else else
strncpy(elt->_carName, GfParmGetStr(ReInfo->params, path2, RM_ATTR_CARNAME, ""), MAX_NAME_LEN - 1); strncpy(elt->_carName, GfParmGetStr(ReInfo->params, path2, RM_ATTR_CARNAME, ""), MAX_NAME_LEN - 1);
@ -626,7 +622,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
} }
elt->_raceNumber = (int)GfParmGetNum(robhdle, path, ROB_ATTR_RACENUM, (char*)NULL, 0); elt->_raceNumber = (int)GfParmGetNum(robhdle, path, ROB_ATTR_RACENUM, (char*)NULL, 0);
if (!normal_carname) if (!normal_carname && elt->_driverType != RM_DRV_HUMAN) /* Increase racenumber if neccesairy */
elt->_raceNumber += elt->_moduleIndex; elt->_raceNumber += elt->_moduleIndex;
elt->_skillLevel = 0; elt->_skillLevel = 0;
str = GfParmGetStr(robhdle, path, ROB_ATTR_LEVEL, ROB_VAL_SEMI_PRO); str = GfParmGetStr(robhdle, path, ROB_ATTR_LEVEL, ROB_VAL_SEMI_PRO);
@ -667,6 +663,8 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
} }
carhdle = GfParmMergeHandles(cathdle, carhdle, carhdle = GfParmMergeHandles(cathdle, carhdle,
GFPARM_MMODE_SRC | GFPARM_MMODE_DST | GFPARM_MMODE_RELSRC | GFPARM_MMODE_RELDST); GFPARM_MMODE_SRC | GFPARM_MMODE_DST | GFPARM_MMODE_RELSRC | GFPARM_MMODE_RELDST);
/* The code below stores the carnames to a separate xml-file such that at newTrack it is known which car is used.
* TODO: find a better method for this */
sprintf (buf, "%sdrivers/curcarnames.xml", GetLocalDir()); sprintf (buf, "%sdrivers/curcarnames.xml", GetLocalDir());
handle = GfParmReadFile(buf, GFPARM_RMODE_CREAT); handle = GfParmReadFile(buf, GFPARM_RMODE_CREAT);
if (handle) { if (handle) {
@ -794,7 +792,7 @@ ReInitCars(void)
} }
if (robhdle && ( strcmp( GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "foo" ), if (robhdle && ( strcmp( GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "foo" ),
GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "bar" ) ) == 0 || GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "bar" ) ) == 0 ||
strcmp( robotModuleName, "human" ) == 0 ) ) /* It does have a field named car in ARBITRARY */ strcmp( robotModuleName, "human" ) == 0 || strcmp( robotModuleName, "networkhuman" ) == 0 ) ) /* It does have a field named car in ARBITRARY */
elt = reLoadSingleCar( index, i, (*(ReInfo->modList))->modInfoSize, robotIdx, FALSE, robotModuleName ); elt = reLoadSingleCar( index, i, (*(ReInfo->modList))->modInfoSize, robotIdx, FALSE, robotModuleName );
else else
GfError("Pb: No description for driver %s (2)\n", robotModuleName ); GfError("Pb: No description for driver %s (2)\n", robotModuleName );