From a672e460468a14d88de2ce9b92fadc4fbf349ba2 Mon Sep 17 00:00:00 2001 From: Peter van der Meer Date: Fri, 6 Dec 2024 19:16:45 +0100 Subject: [PATCH] refactor(mechanics): Move random from ConditionSet to on-demand auto-conditions (#10836) --- source/ConditionSet.cpp | 5 +---- source/PlayerInfo.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/source/ConditionSet.cpp b/source/ConditionSet.cpp index a4af42a07533..c64365405d04 100644 --- a/source/ConditionSet.cpp +++ b/source/ConditionSet.cpp @@ -19,7 +19,6 @@ this program. If not, see . #include "DataNode.h" #include "DataWriter.h" #include "Logger.h" -#include "Random.h" #include #include @@ -160,9 +159,7 @@ namespace { for(const string &str : side) { int64_t value = 0; - if(str == "random") - value = Random::Int(100); - else if(DataNode::IsNumber(str)) + if(DataNode::IsNumber(str)) value = static_cast(DataNode::Value(str)); else { diff --git a/source/PlayerInfo.cpp b/source/PlayerInfo.cpp index d750d4e377e2..395ca2db6238 100644 --- a/source/PlayerInfo.cpp +++ b/source/PlayerInfo.cpp @@ -3952,6 +3952,14 @@ void PlayerInfo::RegisterDerivedConditions() return true; }); + // A condition for returning a random integer in the range [0, 100). + auto &&randomProvider = conditions.GetProviderNamed("random"); + auto randomFun = [](const string &name) -> int64_t + { + return Random::Int(100); + }; + randomProvider.SetGetFunction(randomFun); + // A condition for returning a random integer in the range [0, input). Input may be a number, // or it may be the name of a condition. For example, "roll: 100" would roll a random // integer in the range [0, 100), but if you had a condition "max roll" with a value of 100,