From b6653683169cab026aafb732500a98c96f8fc6d0 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Sun, 24 Mar 2024 05:18:14 +0200 Subject: [PATCH 1/3] Buffed repair speed for wheels, hover and cyborgs --- data/mp/stats/propulsion.json | 9 ++++++--- src/droid.cpp | 2 ++ src/stats.cpp | 1 + src/statsdef.h | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/data/mp/stats/propulsion.json b/data/mp/stats/propulsion.json index ba0944f0056..9ae8c4f7108 100644 --- a/data/mp/stats/propulsion.json +++ b/data/mp/stats/propulsion.json @@ -32,7 +32,8 @@ "turnSpeed": 225, "type": "Legged", "usageClass": "Cyborg", - "weight": 50 + "weight": 50, + "repairFactor": 1.25 }, "HalfTrack": { "buildPoints": 75, @@ -106,7 +107,8 @@ "skidDeceleration": 120, "speed": 300, "type": "Hover", - "weight": 200 + "weight": 200, + "repairFactor": 1.5 }, "tracked01": { "buildPoints": 125, @@ -132,6 +134,7 @@ "skidDeceleration": 350, "speed": 175, "type": "Wheeled", - "weight": 300 + "weight": 300, + "repairFactor": 2 } } diff --git a/src/droid.cpp b/src/droid.cpp index c0e3f64269a..31c755d925b 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -1292,6 +1292,8 @@ static bool droidUpdateDroidRepairBase(DROID *psRepairDroid, DROID *psDroidToRep int iPointsToAdd = gameTimeAdjustedAverage(iRepairRateNumerator, iRepairRateDenominator); + iPointsToAdd = static_cast(std::round(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor)); + 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 32eba101284..b7e7bda40d7 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -822,6 +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->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..3b185a2f9ff 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; + float repairFactor = 0; struct UPGRADE : COMPONENT_STATS::UPGRADE { From 90fff547561d7e666cbb6bed69d1415352723b33 Mon Sep 17 00:00:00 2001 From: Nikolay Borodin Date: Mon, 28 Oct 2024 15:54:10 +0200 Subject: [PATCH 2/3] Removed floating point math from calculation --- data/mp/stats/propulsion.json | 6 +++--- lib/framework/math_ext.h | 7 +++++++ src/droid.cpp | 2 +- src/stats.cpp | 2 +- src/statsdef.h | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/data/mp/stats/propulsion.json b/data/mp/stats/propulsion.json index 9ae8c4f7108..d2f63a0de52 100644 --- a/data/mp/stats/propulsion.json +++ b/data/mp/stats/propulsion.json @@ -33,7 +33,7 @@ "type": "Legged", "usageClass": "Cyborg", "weight": 50, - "repairFactor": 1.25 + "repairFactor": 125 }, "HalfTrack": { "buildPoints": 75, @@ -108,7 +108,7 @@ "speed": 300, "type": "Hover", "weight": 200, - "repairFactor": 1.5 + "repairFactor": 150 }, "tracked01": { "buildPoints": 125, @@ -135,6 +135,6 @@ "speed": 175, "type": "Wheeled", "weight": 300, - "repairFactor": 2 + "repairFactor": 200 } } diff --git a/lib/framework/math_ext.h b/lib/framework/math_ext.h index a5b5dc00072..f88d65b66cf 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 31c755d925b..ccaf0292178 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -1292,7 +1292,7 @@ static bool droidUpdateDroidRepairBase(DROID *psRepairDroid, DROID *psDroidToRep int iPointsToAdd = gameTimeAdjustedAverage(iRepairRateNumerator, iRepairRateDenominator); - iPointsToAdd = static_cast(std::round(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor)); + iPointsToAdd = idiv_round(iPointsToAdd * psDroidToRepair->getPropulsionStats()->repairFactor, 100); psDroidToRepair->body = clip(psDroidToRepair->body + iPointsToAdd, 0, psDroidToRepair->originalBody); diff --git a/src/stats.cpp b/src/stats.cpp index b7e7bda40d7..bc8f7011f9a 100644 --- a/src/stats.cpp +++ b/src/stats.cpp @@ -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"); diff --git a/src/statsdef.h b/src/statsdef.h index 3b185a2f9ff..dc1ba207ef3 100644 --- a/src/statsdef.h +++ b/src/statsdef.h @@ -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 { From c84bb8218c077151f7b22539ac6347c263609783 Mon Sep 17 00:00:00 2001 From: Nikolay Borodin Date: Mon, 28 Oct 2024 19:34:59 +0200 Subject: [PATCH 3/3] Removed trailing whitespaces --- lib/framework/math_ext.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/framework/math_ext.h b/lib/framework/math_ext.h index f88d65b66cf..a21310e0444 100644 --- a/lib/framework/math_ext.h +++ b/lib/framework/math_ext.h @@ -114,8 +114,8 @@ static inline WZ_DECL_CONST T clip(T x, T min, T max) template static inline WZ_DECL_CONST T idiv_round(T numerator, T denominator) { - return ((numerator < 0) == (denominator < 0)) - ? ((numerator + denominator / 2) / denominator) + return ((numerator < 0) == (denominator < 0)) + ? ((numerator + denominator / 2) / denominator) : ((numerator - denominator / 2) / denominator); }