From 4b9d5a437f9c787425fae55c95330ff916691179 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 5 Sep 2022 18:49:22 +0100 Subject: [PATCH] Add GS methods to set inflation factors See: #415 --- docs/script-additions.html | 10 ++++++++++ src/script/api/script_inflation.cpp | 17 +++++++++++++++++ src/script/api/script_inflation.hpp | 16 ++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/docs/script-additions.html b/docs/script-additions.html index 46d0661a4a..5c4fd62945 100644 --- a/docs/script-additions.html +++ b/docs/script-additions.html @@ -109,6 +109,16 @@
Get the inflation factor for payments.
Returns the inflation factor as a fixed point value (16 bits).
+
+
static bool SetPriceFactor (int64 factor)
+
Set the inflation factor for prices (GS only).
+
The inflation factor is a fixed point value (16 bits).
+
+
+
static bool SetPaymentFactor (int64 factor)
+
Set the inflation factor for payments (GS only).
+
The inflation factor is a fixed point value (16 bits).
+
diff --git a/src/script/api/script_inflation.cpp b/src/script/api/script_inflation.cpp index 6b813f2b10..c565d89be0 100644 --- a/src/script/api/script_inflation.cpp +++ b/src/script/api/script_inflation.cpp @@ -9,7 +9,10 @@ #include "../../stdafx.h" #include "script_inflation.hpp" +#include "script_error.hpp" #include "../../economy_func.h" +#include "../../cheat_type.h" +#include "../../command_type.h" #include "../../safeguards.h" @@ -22,3 +25,17 @@ { return _economy.inflation_payment; } + +/* static */ bool ScriptInflation::SetPriceFactor(int64 factor) +{ + EnforcePrecondition(false, factor >= 1 << 16 && factor <= (int64)MAX_INFLATION); + if ((uint64)factor == _economy.inflation_prices) return true; + return ScriptObject::DoCommand(0, CHT_INFLATION_COST, (uint32)factor, CMD_CHEAT_SETTING); +} + +/* static */ bool ScriptInflation::SetPaymentFactor(int64 factor) +{ + EnforcePrecondition(false, factor >= 1 << 16 && factor <= (int64)MAX_INFLATION); + if ((uint64)factor == _economy.inflation_payment) return true; + return ScriptObject::DoCommand(0, CHT_INFLATION_INCOME, (uint32)factor, CMD_CHEAT_SETTING); +} diff --git a/src/script/api/script_inflation.hpp b/src/script/api/script_inflation.hpp index a61fe4e595..9cc969378a 100644 --- a/src/script/api/script_inflation.hpp +++ b/src/script/api/script_inflation.hpp @@ -30,6 +30,22 @@ public: * @return Inflation factor, 16 bit fixed point. */ static int64 GetPaymentFactor(); + + /** + * Set the inflation factor for prices. + * @param factor Inflation factor, 16 bit fixed point. + * @return True, if the inflation factor was changed. + * @api -ai + */ + static bool SetPriceFactor(int64 factor); + + /** + * Set the inflation factor for payments. + * @param factor Inflation factor, 16 bit fixed point. + * @return True, if the inflation factor was changed. + * @api -ai + */ + static bool SetPaymentFactor(int64 factor); }; #endif /* SCRIPT_INFLATION_HPP */