Fix an issue where demolishing a building would result in a negative amount of power.

master
Gerard Krol 2009-04-13 23:21:07 +02:00
parent 4185b66bfb
commit d4b9ff2232
2 changed files with 6 additions and 3 deletions

View File

@ -181,7 +181,7 @@ void usePower(int player, float quantity)
void addPower(int player, float quantity)
{
ASSERT(player < MAX_PLAYERS, "addPower: Bad player (%u)", player);
ASSERT(asPower[player].currentPower + quantity >= 0, "not enough power");
asPower[player].currentPower += quantity;
}
@ -233,6 +233,7 @@ float updateExtractedPower(STRUCTURE *psBuilding)
pResExtractor->timeLastUpdated = gameTime;
extractedPoints += pointsToAdd;
}
ASSERT(extractedPoints > 0, "extracted negative amount of power");
return extractedPoints;
}
@ -297,6 +298,7 @@ void updateCurrentPower(POWER_GEN *psPowerGen, UDWORD player)
}
asPower[player].currentPower += (extractedPower * psPowerGen->multiplier) / 100;
ASSERT(asPower[player].currentPower >= 0, "negative power");
}
// only used in multiplayer games.
@ -305,6 +307,7 @@ void setPower(int player, float power)
ASSERT(player < MAX_PLAYERS, "setPower: Bad player (%u)", player);
asPower[player].currentPower = power;
ASSERT(asPower[player].currentPower >= 0, "negative power");
}
float getPower(int player)

View File

@ -1156,8 +1156,8 @@ void structureBuild(STRUCTURE *psStruct, DROID *psDroid, int buildPoints)
}
else
{
// get half the power back for repairing
powerNeeded = ((psStruct->currentBuildPts + buildPoints) * structureTotalReturn(psStruct))/(psStruct->pStructureType->buildPoints) -
// get half the power back for demolishing
powerNeeded = (((int)psStruct->currentBuildPts + buildPoints) * structureTotalReturn(psStruct))/(psStruct->pStructureType->buildPoints) -
(psStruct->currentBuildPts * structureTotalReturn(psStruct))/(psStruct->pStructureType->buildPoints);
buildPointsToAdd = buildPoints;
addPower(psDroid->player, -powerNeeded);