diff --git a/src/droid.cpp b/src/droid.cpp index 5d60e1adf..11a75104d 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -1137,7 +1137,7 @@ bool droidUpdateBuild(DROID *psDroid) pointsToAdd = constructPoints * (gameTime - psDroid->actionStarted) / GAME_TICKS_PER_SEC; - structureBuild(psStruct, psDroid, pointsToAdd - psDroid->actionPoints); + structureBuild(psStruct, psDroid, pointsToAdd - psDroid->actionPoints, constructPoints); //store the amount just added psDroid->actionPoints = pointsToAdd; diff --git a/src/intdisplay.cpp b/src/intdisplay.cpp index bfcac90d5..8dc2be05a 100644 --- a/src/intdisplay.cpp +++ b/src/intdisplay.cpp @@ -227,7 +227,12 @@ void intUpdateProgressBar(WIDGET *psWidget, W_CONTEXT *psContext) } else { - BarGraph->text.clear(); // TODO Hard to estimate time remaining, since number of trucks can vary. + BarGraph->text.clear(); + if (Structure->lastBuildRate > 0) + { + int timeToBuild = (Structure->pStructureType->buildPoints - Structure->currentBuildPts) / Structure->lastBuildRate; + BarGraph->text = formatTime(timeToBuild); + } } if (BuildPoints > Range) diff --git a/src/structure.cpp b/src/structure.cpp index 5c0ec8c19..527f7aad7 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -866,7 +866,7 @@ int32_t getStructureDamage(const STRUCTURE *psStructure) /// Add buildPoints to the structures currentBuildPts, due to construction work by the droid /// Also can deconstruct (demolish) a building if passed negative buildpoints -void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints) +void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints, int buildRate) { if (psDroid && !aiCheckAlliances(psStruct->player,psDroid->player)) { @@ -888,7 +888,7 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints) } } } - psStruct->builtThisTick = true; + psStruct->buildRate += buildRate; // buildRate = buildPoints/GAME_UPDATES_PER_SEC, but might be rounded up or down each tick, so can't use buildPoints to get a stable number. if (psStruct->currentBuildPts <= 0 && buildPoints > 0) { // Just starting to build structure, need power for it. @@ -1845,7 +1845,7 @@ STRUCTURE* buildStructureDir(STRUCTURE_STATS *pStructureType, UDWORD x, UDWORD y psBuilding->currentBuildPts = 0; //start building again psBuilding->status = SS_BEING_BUILT; - psBuilding->builtThisTick = true; // Don't abandon the structure first tick. + psBuilding->buildRate = 1; // Don't abandon the structure first tick, so set to nonzero. if (psBuilding->player == selectedPlayer && !FromSave) { intRefreshScreen(); @@ -3737,11 +3737,12 @@ void structureUpdate(STRUCTURE *psBuilding, bool mission) } } - if (psBuilding->status == SS_BEING_BUILT && psBuilding->currentBuildPts == 0 && !psBuilding->builtThisTick && !structureHasModules(psBuilding)) + if (psBuilding->status == SS_BEING_BUILT && psBuilding->currentBuildPts == 0 && psBuilding->buildRate == 0 && !structureHasModules(psBuilding)) { removeStruct(psBuilding, true); // If giving up on building something, remove the structure (and remove it from the power queue). } - psBuilding->builtThisTick = false; + psBuilding->lastBuildRate = psBuilding->buildRate; + psBuilding->buildRate = 0; // Reset to 0, each truck building us will add to our buildRate. /* Only add smoke if they're visible and they can 'burn' */ if (!mission && psBuilding->visible[selectedPlayer] && canSmoke(psBuilding)) @@ -3874,7 +3875,8 @@ void structureUpdate(STRUCTURE *psBuilding, bool mission) STRUCTURE::STRUCTURE(uint32_t id, unsigned player) : BASE_OBJECT(OBJ_STRUCTURE, id, player) , pFunctionality(NULL) - , builtThisTick(true) + , buildRate(1) // Initialise to 1 instead of 0, to make sure we don't get destroyed first tick due to inactivity. + , lastBuildRate(0) , psCurAnim(NULL) {} diff --git a/src/structure.h b/src/structure.h index e2762dbdd..9563c91a0 100644 --- a/src/structure.h +++ b/src/structure.h @@ -113,7 +113,7 @@ extern bool structureStatsShutDown(void); int requestOpenGate(STRUCTURE *psStructure); int32_t structureDamage(STRUCTURE *psStructure, UDWORD damage, WEAPON_CLASS weaponClass, WEAPON_SUBCLASS weaponSubClass, HIT_SIDE impactSide); -extern void structureBuild(STRUCTURE *psStructure, DROID *psDroid, int buildPoints); +extern void structureBuild(STRUCTURE *psStructure, DROID *psDroid, int buildPoints, int buildRate = 1); extern void structureDemolish(STRUCTURE *psStructure, DROID *psDroid, int buildPoints); extern bool structureRepair(STRUCTURE *psStruct, DROID *psDroid, int buildPoints); /* Set the type of droid for a factory to build */ diff --git a/src/structuredef.h b/src/structuredef.h index 029e96dcd..a13c6f420 100644 --- a/src/structuredef.h +++ b/src/structuredef.h @@ -253,7 +253,8 @@ struct STRUCTURE : public BASE_OBJECT SWORD resistance; /* current resistance points, 0 = cannot be attacked electrically */ UDWORD lastResistance; /* time the resistance was last increased*/ FUNCTIONALITY *pFunctionality; /* pointer to structure that contains fields necessary for functionality */ - bool builtThisTick; ///< True iff someone tried building the structure this tick. If construction hasn't started, remove the structure. + int buildRate; ///< Rate that this structure is being built, calculated each tick. Only meaningful if status == SS_BEING_BUILT. If construction hasn't started and build rate is 0, remove the structure. + int lastBuildRate; ///< Needed if wanting the buildRate between buildRate being reset to 0 each tick and the trucks calculating it. /* The weapons on the structure */ UWORD numWeaps;