Do not report incomplete structures as damaged, unless they actually were.

The maximum sizes of incomplete structure health bars are now correspondingly smaller.

Fixes ticket:1911.
master
Cyp 2011-11-16 16:48:30 +01:00
parent 7eb32e9de2
commit 8d7df45d35
3 changed files with 24 additions and 3 deletions

View File

@ -2875,6 +2875,11 @@ static void drawStructureHealth(STRUCTURE *psStruct)
{
//show body points
health = (1. - getStructureDamage(psStruct)/65536.f) * 100;
// If structure is incomplete, make bar correspondingly thinner.
int maxBody = structureBody(psStruct);
int maxBodyBuilt = structureBodyBuilt(psStruct);
width = (uint64_t)width * maxBodyBuilt / maxBody;
}
if (health > REPAIRLEV_HIGH)
{
@ -2893,7 +2898,7 @@ static void drawStructureHealth(STRUCTURE *psStruct)
}
health = (((width*10000)/100)*health)/10000;
health*=2;
pie_BoxFill(scrX-scrR-1, scrY-1, scrX+scrR+1, scrY+3, WZCOL_RELOAD_BACKGROUND);
pie_BoxFill(scrX-scrR-1, scrY-1, scrX-scrR+2*width+1, scrY+3, WZCOL_RELOAD_BACKGROUND);
pie_BoxFill(scrX-scrR, scrY, scrX-scrR+health, scrY+1, powerCol);
pie_BoxFill(scrX-scrR, scrY+1, scrX-scrR+health, scrY+2, powerColShadow);
}

View File

@ -855,10 +855,11 @@ int32_t structureDamage(STRUCTURE *psStructure, UDWORD damage, WEAPON_CLASS weap
int32_t getStructureDamage(const STRUCTURE *psStructure)
{
int32_t health;
CHECK_STRUCTURE(psStructure);
health = (int64_t)65536 * psStructure->body / structureBody(psStructure);
unsigned maxBody = structureBodyBuilt(psStructure);
int64_t health = (int64_t)65536 * psStructure->body / maxBody;
CLIP(health, 0, 65536);
return 65536 - health;
@ -6221,6 +6222,20 @@ bool validStructResistance(STRUCTURE *psStruct)
return bTarget;
}
unsigned structureBodyBuilt(STRUCTURE const *psStructure)
{
unsigned maxBody = structureBody(psStructure);
if (psStructure->status == SS_BEING_BUILT || psStructure->status == SS_BEING_DEMOLISHED)
{
// Calculate the body points the structure would have, if not damaged.
unsigned unbuiltBody = (maxBody + 9) / 10; // See droidStartBuild() in droid.cpp.
unsigned deltaBody = (uint64_t)9 * maxBody * psStructure->currentBuildPts / (10 * psStructure->pStructureType->buildPoints); // See structureBuild() in structure.cpp.
maxBody = unbuiltBody + deltaBody;
}
return maxBody;
}
/*Access functions for the upgradeable stats of a structure*/
UDWORD structureBody(const STRUCTURE *psStructure)

View File

@ -272,6 +272,7 @@ extern bool checkSpecificStructExists(UDWORD structInc, UDWORD player);
extern int32_t getStructureDamage(const STRUCTURE* psStructure);
/*Access functions for the upgradeable stats of a structure*/
unsigned structureBodyBuilt(STRUCTURE const *psStruct); ///< Returns the maximum body points of a structure with the current number of build points.
extern UDWORD structureBody(const STRUCTURE *psStruct);
extern UDWORD structureArmour(STRUCTURE_STATS *psStats, UBYTE player);
extern UDWORD structureResistance(STRUCTURE_STATS *psStats, UBYTE player);