Skip to content

Commit

Permalink
stats: Fix inconsistent body points of droids.
Browse files Browse the repository at this point in the history
Body points shown (with a red mark) when hovering now match the body points when choosing the component, which both now
approximately (with slight variations due to rounding differences) match the old body points from 3.1.

Hopefully fixes ticket:4369.
  • Loading branch information
Cyp committed May 14, 2016
1 parent 1ee5fcb commit 11150da
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/design.cpp
Expand Up @@ -2574,6 +2574,7 @@ static void intSetTemplateBodyShadowStats(COMPONENT_STATS *psStats)
COMPONENT_TYPE type = psStats->compType;
UDWORD body;
UDWORD bodyBody = asBodyStats[sCurrDesign.asParts[COMP_BODY]].body;
uint32_t bodyUpgradeBody = asBodyStats[sCurrDesign.asParts[COMP_BODY]].upgrade[selectedPlayer].body;
UDWORD brainBody = asBrainStats[sCurrDesign.asParts[COMP_BRAIN]].body;
UDWORD sensorBody = asSensorStats[sCurrDesign.asParts[COMP_SENSOR]].body;
UDWORD ECMBody = asECMStats[sCurrDesign.asParts[COMP_ECM]].body;
Expand Down Expand Up @@ -2602,6 +2603,7 @@ static void intSetTemplateBodyShadowStats(COMPONENT_STATS *psStats)
{
case COMP_BODY:
bodyBody = newComponentBody;
bodyUpgradeBody = ((BODY_STATS *)psStats)->upgrade[selectedPlayer].body;
break;
case COMP_PROPULSION:
propulsionBody = newComponentBody;
Expand Down Expand Up @@ -2642,11 +2644,11 @@ static void intSetTemplateBodyShadowStats(COMPONENT_STATS *psStats)
body = bodyBody + brainBody + sensorBody + ECMBody + repairBody + constructBody;

/* propulsion HP are a percentage of the body's HP */
body += (propulsionBody * bodyBody) / 100;
body += bodyBody * propulsionBody / 100;

//add weapon HP
body += weaponBody1 + weaponBody2 + weaponBody3;
body += (body * asBodyStats[sCurrDesign.asParts[COMP_BODY]].upgrade[selectedPlayer].body / 100);
body = body * bodyUpgradeBody / std::max(bodyBody, 1u);
widgSetMinorBarSize(psWScreen, IDDES_BODYPOINTS, body);
}

Expand Down
82 changes: 38 additions & 44 deletions src/droid.cpp
Expand Up @@ -1522,63 +1522,57 @@ UDWORD calcDroidWeight(DROID_TEMPLATE *psTemplate)
return weight;
}

/* Calculate the body points of a droid from it's template */
UDWORD calcTemplateBody(DROID_TEMPLATE *psTemplate, UBYTE player)
static uint32_t calcDroidOrTemplateBody(uint8_t (&asParts)[DROID_MAXCOMP], unsigned numWeaps, uint8_t (&asWeaps)[DROID_MAXWEAPS], unsigned player)
{
UDWORD body, i;
auto &bodyStats = asBodyStats[asParts[COMP_BODY]];

if (psTemplate == NULL)
{
ASSERT(false, "null template");
return 0;
}
BODY_STATS *psStats = asBodyStats + psTemplate->asParts[COMP_BODY];
/* Get the basic component body points */
body =
(asBodyStats + psTemplate->asParts[COMP_BODY])->body +
(asBrainStats + psTemplate->asParts[COMP_BRAIN])->body +
(asSensorStats + psTemplate->asParts[COMP_SENSOR])->body +
(asECMStats + psTemplate->asParts[COMP_ECM])->body +
(asRepairStats + psTemplate->asParts[COMP_REPAIRUNIT])->body +
(asConstructStats + psTemplate->asParts[COMP_CONSTRUCT])->body;
// Get the basic component body points
uint32_t body =
bodyStats.body +
asBrainStats[asParts[COMP_BRAIN]].body +
asSensorStats[asParts[COMP_SENSOR]].body +
asECMStats[asParts[COMP_ECM]].body +
asRepairStats[asParts[COMP_REPAIRUNIT]].body +
asConstructStats[asParts[COMP_CONSTRUCT]].body;

/* propulsion body points are a percentage of the bodys' body points */
body += ((asPropulsionStats + psTemplate->asParts[COMP_PROPULSION])->body * psStats->body) / 100;
// propulsion body points are a percentage of the body's body points
body += bodyStats.body * asPropulsionStats[asParts[COMP_PROPULSION]].body / 100;

/* Add the weapon body points */
for (i = 0; i < psTemplate->numWeaps; i++)
// Add the weapon body points
for (unsigned i = 0; i < numWeaps; ++i)
{
body += asWeaponStats[psTemplate->asWeaps[i]].body;
if (asWeaps[i] > 0)
{
body += asWeaponStats[asWeaps[i]].body;
}
}

//add on any upgrade value that may need to be applied
body = body * bodyStats.upgrade[player].body / std::max(bodyStats.body, 1u);

return body;
}

/* Calculate the base body points of a droid without upgrades*/
static UDWORD calcDroidBaseBody(DROID *psDroid)
// Calculate the body points of a droid from its template
UDWORD calcTemplateBody(DROID_TEMPLATE *psTemplate, UBYTE player)
{
/* Get the basic component body points */
int body =
(asBodyStats + psDroid->asBits[COMP_BODY])->upgrade[psDroid->player].body +
(asBrainStats + psDroid->asBits[COMP_BRAIN])->body +
(asSensorStats + psDroid->asBits[COMP_SENSOR])->body +
(asECMStats + psDroid->asBits[COMP_ECM])->body +
(asRepairStats + psDroid->asBits[COMP_REPAIRUNIT])->body +
(asConstructStats + psDroid->asBits[COMP_CONSTRUCT])->body;

/* propulsion body points are a percentage of the bodys' body points */
body += (((asPropulsionStats + psDroid->asBits[COMP_PROPULSION])->body *
(asBodyStats + psDroid->asBits[COMP_BODY])->body) / 100);

/* Add the weapon body points */
for (int i = 0; i < psDroid->numWeaps; i++)
if (psTemplate == nullptr)
{
if (psDroid->asWeaps[i].nStat > 0)
{
body += (asWeaponStats + psDroid->asWeaps[i].nStat)->body;
}
ASSERT(false, "null template");
return 0;
}
return body;

return calcDroidOrTemplateBody(psTemplate->asParts, psTemplate->numWeaps, psTemplate->asWeaps, player);
}

// Calculate the base body points of a droid with upgrades
static UDWORD calcDroidBaseBody(DROID *psDroid)
{
uint8_t asWeaps[DROID_MAXWEAPS];
std::transform(std::begin(psDroid->asWeaps), std::end(psDroid->asWeaps), asWeaps, [](WEAPON &weap) {
return weap.nStat;
});
return calcDroidOrTemplateBody(psDroid->asBits, psDroid->numWeaps, asWeaps, psDroid->player);
}


Expand Down

0 comments on commit 11150da

Please sign in to comment.