From 8855f40dea8e3a7aaee6943c9d94f0f4129170da Mon Sep 17 00:00:00 2001 From: mungewell Date: Thu, 9 Aug 2012 04:19:48 +0000 Subject: [PATCH] Bug #737 - allows hillclimb (laps=0/duration=00:00:01) => race last until s/f line crossed. git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4839 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 92c12ceeca0782ca2e3b2c9434f4548b7f998b5f Former-commit-id: edb70fbdbe1268b23c0733e8eaf3b23dcb1d3cf9 --- src/libs/raceengine/racecars.cpp | 50 +++++++++++------------------ src/libs/raceengine/raceresults.cpp | 10 ++++-- 2 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/libs/raceengine/racecars.cpp b/src/libs/raceengine/racecars.cpp index 1be86457b..36a4c1615 100644 --- a/src/libs/raceengine/racecars.cpp +++ b/src/libs/raceengine/racecars.cpp @@ -545,7 +545,6 @@ ReCarsManageCar(tCarElt *car, bool& bestLapChanged) car->_currentSector = 0; if (car->_laps > 1) { car->_lastLapTime = s->currentTime - info->sTime; - car->_curTime += car->_lastLapTime; if (car->_bestLapTime != 0) { car->_deltaBestLapTime = car->_lastLapTime - car->_bestLapTime; } @@ -576,6 +575,9 @@ ReCarsManageCar(tCarElt *car, bool& bestLapChanged) car->_timeBeforeNext = 0; } } + } + if (car->_laps > 0) { + car->_curTime += s->currentTime - info->sTime; if (car->_pos != 1 && s->_raceType == RM_TYPE_RACE) { car->_timeBehindLeader = car->_curTime - s->cars[0]->_curTime; @@ -589,43 +591,29 @@ ReCarsManageCar(tCarElt *car, bool& bestLapChanged) } info->sTime = (tdble)s->currentTime; - switch (ReInfo->s->_raceType) { + + if (ReInfo->s->_raceType == RM_TYPE_PRACTICE && + (car->_laps > 1 || s->_totLaps == 0)) + ReSavePracticeLap(car); + } + + if (ReInfo->_displayMode == RM_DISP_MODE_NONE) + { + switch(s->_raceType) + { case RM_TYPE_PRACTICE: - if (ReInfo->_displayMode == RM_DISP_MODE_NONE && s->_ncars <= 1) - ReUpdatePracticeCurRes(car, /*forceNew=*/true); - /* save the lap result */ - if (s->_ncars == 1) - ReSavePracticeLap(car); + ReUpdatePracticeCurRes(car); break; - case RM_TYPE_QUALIF: - if (ReInfo->_displayMode == RM_DISP_MODE_NONE && s->_ncars <= 1) - ReUpdateQualifCurRes(car); + ReUpdateQualifCurRes(car); break; case RM_TYPE_RACE: - if (ReInfo->_displayMode == RM_DISP_MODE_NONE) - ReUpdateRaceCurRes(); + ReUpdateRaceCurRes(); + break; + default: break; } - } else { - if (ReInfo->_displayMode == RM_DISP_MODE_NONE) - { - switch(s->_raceType) - { - case RM_TYPE_PRACTICE: - ReUpdatePracticeCurRes(car); - break; - case RM_TYPE_QUALIF: - ReUpdateQualifCurRes(car); - break; - case RM_TYPE_RACE: - ReUpdateRaceCurRes(); - break; - default: - break; - } - } - } + } info->topSpd = car->_speed_x; info->botSpd = car->_speed_x; diff --git a/src/libs/raceengine/raceresults.cpp b/src/libs/raceengine/raceresults.cpp index f0e9f1bc1..fec5ac616 100644 --- a/src/libs/raceengine/raceresults.cpp +++ b/src/libs/raceengine/raceresults.cpp @@ -703,8 +703,14 @@ ReSavePracticeLap(tCarElt *car) void *results = ReInfo->results; tReCarInfo *info = &(ReInfo->_reCarInfo[car->index]); - snprintf(path, sizeof(path), "%s/%s/%s/%d", ReInfo->track->name, RE_SECT_RESULTS, ReInfo->_reRaceName, car->_laps - 1); - GfParmSetNum(results, path, RE_ATTR_TIME, NULL, (tdble)car->_lastLapTime); + if (car->_laps == 1) { + /* hack to allow results from practice hillclimb to be recorded (as lap1) */ + snprintf(path, sizeof(path), "%s/%s/%s/%d", ReInfo->track->name, RE_SECT_RESULTS, ReInfo->_reRaceName, 1); + GfParmSetNum(results, path, RE_ATTR_TIME, NULL, (tdble)car->_curTime); + } else { + snprintf(path, sizeof(path), "%s/%s/%s/%d", ReInfo->track->name, RE_SECT_RESULTS, ReInfo->_reRaceName, car->_laps - 1); + GfParmSetNum(results, path, RE_ATTR_TIME, NULL, (tdble)car->_lastLapTime); + } GfParmSetNum(results, path, RE_ATTR_BEST_LAP_TIME, NULL, (tdble)car->_bestLapTime); GfParmSetNum(results, path, RE_ATTR_TOP_SPEED, NULL, info->topSpd); GfParmSetNum(results, path, RE_ATTR_BOT_SPEED, NULL, info->botSpd);