From 127b4fbddabb7269b61ca1a19a8b50d6c52811f7 Mon Sep 17 00:00:00 2001 From: Gerard Krol Date: Thu, 16 Apr 2009 11:53:29 +0200 Subject: [PATCH] Give power back when canceling the production of a droid. Also make the code that determines production speed more independent of the framerate. --- src/structure.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/structure.c b/src/structure.c index f76405a14..d44a27f12 100644 --- a/src/structure.c +++ b/src/structure.c @@ -2821,7 +2821,8 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool mission) DROID_TEMPLATE *psNextTemplate; #endif UDWORD i; - float secondsElapsed,secondsToBuild, powerNeeded; + float secondsToBuild, powerNeeded; + int secondsElapsed; CHECK_STRUCTURE(psStructure); @@ -3297,11 +3298,11 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool mission) secondsElapsed = (gameTime - psFactory->timeStarted) / (float)GAME_TICKS_PER_SEC; secondsToBuild = ((DROID_TEMPLATE*)pSubject)->buildPoints/(float)psFactory->productionOutput; powerNeeded = ((DROID_TEMPLATE *)pSubject)->powerPoints*(secondsElapsed/secondsToBuild); - if (secondsElapsed > 1) + if (secondsElapsed > 0) { progress = requestPowerFor(psStructure->player, powerNeeded, secondsElapsed); psFactory->timeToBuild -= progress; - psFactory->timeStarted = gameTime; + psFactory->timeStarted = psFactory->timeStarted + secondsElapsed*1000; } } @@ -6653,11 +6654,16 @@ void cancelProduction(STRUCTURE *psBuilding) //check its the correct factory if (psBuilding->player == productionPlayer && psFactory->psSubject) { + // give the power back that was used until now + int secondsToBuild = ((DROID_TEMPLATE*)psFactory->psSubject)->buildPoints/psFactory->productionOutput; + int secondsElapsed = secondsToBuild - psFactory->timeToBuild; + int powerUsed = (((DROID_TEMPLATE *)psFactory->psSubject)->powerPoints*secondsElapsed)/secondsToBuild; + addPower(psBuilding->player, powerUsed); + //clear the production run for this factory memset(asProductionRun[psFactory->psAssemblyPoint->factoryType][ psFactory->psAssemblyPoint->factoryInc], 0, sizeof(PRODUCTION_RUN) * MAX_PROD_RUN); - // FIXME: give any power back that was not yet used //clear the factories subject and quantity psFactory->psSubject = NULL; psFactory->quantity = 0;