Skip to content

Commit

Permalink
Removed floating point math from calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Oct 28, 2024
1 parent b665368 commit 8db220d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions data/mp/stats/propulsion.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"type": "Legged",
"usageClass": "Cyborg",
"weight": 50,
"repairFactor": 1.25
"repairFactor": 125
},
"HalfTrack": {
"buildPoints": 75,
Expand Down Expand Up @@ -108,7 +108,7 @@
"speed": 300,
"type": "Hover",
"weight": 200,
"repairFactor": 1.5
"repairFactor": 150
},
"tracked01": {
"buildPoints": 125,
Expand All @@ -135,6 +135,6 @@
"speed": 175,
"type": "Wheeled",
"weight": 300,
"repairFactor": 2
"repairFactor": 200
}
}
7 changes: 7 additions & 0 deletions lib/framework/math_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ static inline WZ_DECL_CONST T clip(T x, T min, T max)
return x < min ? min : x > max ? max : x;
}

template <typename T>
static inline WZ_DECL_CONST T idiv_round(T numerator, T denominator)
{
return ((numerator < 0) == (denominator < 0))
? ((numerator + denominator /2 ) / denominator)
: ((numerator - denominator / 2) / denominator);
}

/*!
* Clips x to boundaries
Expand Down
2 changes: 1 addition & 1 deletion src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ static bool droidUpdateDroidRepairBase(DROID *psRepairDroid, DROID *psDroidToRep

int iPointsToAdd = gameTimeAdjustedAverage(iRepairRateNumerator, iRepairRateDenominator);

iPointsToAdd = static_cast<int>(std::round(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor));
iPointsToAdd = idiv_round<int>(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor, 100);

psDroidToRepair->body = clip<UDWORD>(psDroidToRepair->body + iPointsToAdd, 0, psDroidToRepair->originalBody);

Expand Down
2 changes: 1 addition & 1 deletion src/stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ bool loadPropulsionStats(WzConfig &ini)
psStats->acceleration = ini.value("acceleration", 250).toInt();
ASSERT(psStats->acceleration != 0, "\"%s\".\"acceleration\" is 0", psStats->id.toUtf8().c_str());
psStats->deceleration = ini.value("deceleration", 800).toInt();
psStats->repairFactor = ini.value("repairFactor", 1.0f).toFloat();
psStats->repairFactor = ini.value("repairFactor", 100).toInt();
psStats->skidDeceleration = ini.value("skidDeceleration", 600).toInt();
psStats->pIMD = nullptr;
psStats->pIMD = statsGetIMD(ini, psStats, "model");
Expand Down
2 changes: 1 addition & 1 deletion src/statsdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ struct PROPULSION_STATS : public COMPONENT_STATS
unsigned skidDeceleration = 0;
unsigned deceleration = 0;
unsigned acceleration = 0;
float repairFactor = 0;
unsigned repairFactor = 0;

struct UPGRADE : COMPONENT_STATS::UPGRADE
{
Expand Down

0 comments on commit 8db220d

Please sign in to comment.