diff --git a/data/mp/stats/propulsion.json b/data/mp/stats/propulsion.json index 0ff83c7f58d..d593dee270e 100644 --- a/data/mp/stats/propulsion.json +++ b/data/mp/stats/propulsion.json @@ -33,7 +33,8 @@ "turnSpeed": 225, "type": "Legged", "usageClass": "Cyborg", - "weight": 50 + "weight": 50, + "repairFactor": 125 }, "HalfTrack": { "buildPoints": 75, @@ -107,7 +108,8 @@ "skidDeceleration": 120, "speed": 300, "type": "Hover", - "weight": 200 + "weight": 200, + "repairFactor": 150 }, "tracked01": { "buildPoints": 125, @@ -133,6 +135,7 @@ "skidDeceleration": 350, "speed": 175, "type": "Wheeled", - "weight": 300 + "weight": 300, + "repairFactor": 200 } } diff --git a/lib/framework/math_ext.h b/lib/framework/math_ext.h index a5b5dc00072..a21310e0444 100644 --- a/lib/framework/math_ext.h +++ b/lib/framework/math_ext.h @@ -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 +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 diff --git a/src/droid.cpp b/src/droid.cpp index e3e0ed75179..6dc3d849a9a 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -1343,6 +1343,8 @@ static bool droidUpdateDroidRepairBase(DROID *psRepairDroid, DROID *psDroidToRep int iPointsToAdd = gameTimeAdjustedAverage(iRepairRateNumerator, iRepairRateDenominator); + iPointsToAdd = idiv_round(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor, 100); + psDroidToRepair->body = clip(psDroidToRepair->body + iPointsToAdd, 0, psDroidToRepair->originalBody); /* add plasma repair effect whilst being repaired */ diff --git a/src/stats.cpp b/src/stats.cpp index d74e53532a1..95a0731dd24 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -833,6 +833,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", 100).toInt(); psStats->skidDeceleration = ini.value("skidDeceleration", 600).toInt(); psStats->pIMD = nullptr; psStats->pIMD = statsGetIMD(ini, psStats, "model"); diff --git a/src/statsdef.h b/src/statsdef.h index e47fc2bc40b..dc1ba207ef3 100644 --- a/src/statsdef.h +++ b/src/statsdef.h @@ -338,6 +338,7 @@ struct PROPULSION_STATS : public COMPONENT_STATS unsigned skidDeceleration = 0; unsigned deceleration = 0; unsigned acceleration = 0; + unsigned repairFactor = 0; struct UPGRADE : COMPONENT_STATS::UPGRADE {