diff --git a/src/drivers/human/human.cpp b/src/drivers/human/human.cpp index f3fa008e..2dd5094f 100644 --- a/src/drivers/human/human.cpp +++ b/src/drivers/human/human.cpp @@ -122,10 +122,6 @@ shutdown(const int index) VecNames.erase(VecNames.begin() + idx); - // ??????? Why this ??????????? - if (index > NbDrivers) - idx -= NbDrivers + 1; - free (HCtx[idx]); HCtx[idx] = 0; @@ -151,10 +147,6 @@ shutdown(const int index) static int InitFuncPt(int index, void *pt) { - // ??????? Why this ??????????? - if (index > NbDrivers) - index -= NbDrivers + 1; - tRobotItf *itf = (tRobotItf *)pt; const int idx = index - 1; @@ -318,13 +310,7 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSituation *s) { char trackname[256]; - bool otherCar = false; - // ??????? Why this ??????????? - if (index > NbDrivers) { - index -= NbDrivers + 1; - otherCar = true; - } const int idx = index - 1; curTrack = track; @@ -340,14 +326,12 @@ initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSitu ? GfParmGetStrNC(drvInfo, sstring, "car name", NULL) : ""; - if (otherCar) { - sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); - void *curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); - if (curCars) { - sprintf(sstring, "drivers/human/%d", index + NbDrivers + 1); - carname = GfParmGetStr(curCars, sstring, "car name", carname.c_str()); - }//if curCars - }//if otherCar + sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); + void *curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); + if (curCars) { + sprintf(sstring, "drivers/human/%d", index + NbDrivers + 1); + carname = GfParmGetStr(curCars, sstring, "car name", carname.c_str()); + }//if curCars sprintf(sstring, "%sdrivers/human/cars/%s/default.xml", GetLocalDir(), carname.c_str()); *carParmHandle = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); @@ -408,9 +392,6 @@ initTrack(int index, tTrack* track, void *carHandle, void **carParmHandle, tSitu void newrace(int index, tCarElt* car, tSituation *s) { - // ??????? Why this ??????????? - if (index > NbDrivers) - index -= NbDrivers + 1; const int idx = index - 1; // 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 drive_mt(int index, tCarElt* car, tSituation *s) { - // ??????? Why this ??????????? - if (index > NbDrivers) - index -= NbDrivers + 1; const int idx = index - 1; tControlCmd *cmd = HCtx[idx]->cmdControl; @@ -1203,9 +1181,6 @@ drive_mt(int index, tCarElt* car, tSituation *s) static void drive_at(int index, tCarElt* car, tSituation *s) { - // ??????? Why this ??????????? - if (index > NbDrivers) - index -= NbDrivers + 1; const int idx = index - 1; tControlCmd *cmd = HCtx[idx]->cmdControl; @@ -1298,9 +1273,6 @@ drive_at(int index, tCarElt* car, tSituation *s) static int pitcmd(int index, tCarElt* car, tSituation *s) { - // ??????? Why this ??????????? - if (index > NbDrivers) - index -= NbDrivers + 1; const int idx = index - 1; HCtx[idx]->nbPitStops++; diff --git a/src/drivers/networkhuman/networkhuman.cpp b/src/drivers/networkhuman/networkhuman.cpp index 6244add6..ec95da7e 100644 --- a/src/drivers/networkhuman/networkhuman.cpp +++ b/src/drivers/networkhuman/networkhuman.cpp @@ -160,11 +160,6 @@ InitFuncPt(int index, void *pt) tRobotItf *itf = (tRobotItf *)pt; int idx = index - 1; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - } - if (masterPlayer == -1) { masterPlayer = index; } @@ -374,15 +369,8 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH char trackname[256]; tdble fuel; int idx = index - 1; - char otherCar = FALSE; void *curCars; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - otherCar = TRUE; - } - curTrack = track; s1 = strrchr(track->filename, '/') + 1; s2 = strchr(s1, '.'); @@ -396,16 +384,14 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH if (DrvInfo != NULL) { carname = strdup(GfParmGetStr(DrvInfo, sstring, "car name", "")); } - if (otherCar) { - sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); - curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); - if (curCars) { - sprintf(sstring, "drivers/networkhuman/%d", index + NbDrivers + 1); - oldcarname = carname; - carname = strdup(GfParmGetStr(curCars, sstring, "car name", oldcarname )); - if( oldcarname ) - free (oldcarname); - } + sprintf(sstring, "%sdrivers/curcarnames.xml", GetLocalDir()); + curCars = GfParmReadFile(sstring, GFPARM_RMODE_REREAD); + if (curCars) { + sprintf(sstring, "drivers/networkhuman/%d", index + NbDrivers + 1); + oldcarname = carname; + carname = strdup(GfParmGetStr(curCars, sstring, "car name", oldcarname )); + if( oldcarname ) + free (oldcarname); } sprintf(sstring, "%sdrivers/networkhuman/tracks/%s/car-%s-%d.xml", GetLocalDir(), trackname, carname, index); @@ -474,10 +460,6 @@ void newrace(int index, tCarElt* car, tSituation *s) { int i; int idx = index - 1; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - } for (i = 0; i < MAX_GEARS; i++) { if (car->_gearRatio[i] != 0) { @@ -1102,11 +1084,6 @@ static void drive_mt(int index, tCarElt* car, tSituation *s) int idx = index - 1; tControlCmd *cmd; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - } - cmd = HCtx[idx]->CmdControl; common_drive(index, car, s); @@ -1175,11 +1152,6 @@ static void drive_at(int index, tCarElt* car, tSituation *s) int idx = index - 1; tControlCmd *cmd; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - } - if (GetNetwork()) { if (g_activeDriver!=idx) @@ -1280,10 +1252,6 @@ static int pitcmd(int index, tCarElt* car, tSituation *s) tdble f1, f2; tdble ns; int idx = index - 1; - if (index > NbDrivers) { - index -= NbDrivers + 1; - idx -= NbDrivers + 1; - } HCtx[idx]->NbPitStops++; f1 = car->_tank - car->_fuel; diff --git a/src/libs/raceengineclient/raceinit.cpp b/src/libs/raceengineclient/raceinit.cpp index 4015ad73..7205e05a 100644 --- a/src/libs/raceengineclient/raceinit.cpp +++ b/src/libs/raceengineclient/raceinit.cpp @@ -509,7 +509,7 @@ initPits(void) * @param cardllname The dllname of the driver * @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; tMemoryPool oldPool; @@ -527,15 +527,16 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int int k; int xx; char isHuman; + int robotIdx = relativeRobotIdx; /* good robot found */ curModInfo = &((*(ReInfo->modList))->modInfo[modindex]); GfOut("Driver's name: %s\n", curModInfo->name); - if (!normal_carname) { + + 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; - } - - isHuman = strcmp( cardllname, "human" ) == 0; /* Retrieve the driver interface (function pointers) */ 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); } - if (normal_carname) + if (normal_carname || isHuman) 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 sprintf(path, "%s", ROB_SECT_ARBITRARY); @@ -590,10 +589,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int elt->robot = curRobot; elt->_paramsHandle = robhdle; elt->_driverIndex = robotIdx; - if (normal_carname) - elt->_moduleIndex = robotIdx; - else - elt->_moduleIndex = robotIdx - curModInfo->index; + elt->_moduleIndex = relativeRobotIdx; strncpy(elt->_modName, cardllname, MAX_NAME_LEN - 1); 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); // 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); else 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); - if (!normal_carname) + if (!normal_carname && elt->_driverType != RM_DRV_HUMAN) /* Increase racenumber if neccesairy */ elt->_raceNumber += elt->_moduleIndex; elt->_skillLevel = 0; 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, 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()); handle = GfParmReadFile(buf, GFPARM_RMODE_CREAT); if (handle) { @@ -794,7 +792,7 @@ ReInitCars(void) } if (robhdle && ( strcmp( GfParmGetStr( robhdle, ROB_SECT_ARBITRARY, ROB_ATTR_TEAM, "foo" ), 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 ); else GfError("Pb: No description for driver %s (2)\n", robotModuleName );