From c924b90b2b578d75a2007ed6f64d4e9e3525f2b5 Mon Sep 17 00:00:00 2001 From: Lemongrass3110 Date: Mon, 9 Nov 2020 14:12:51 +0100 Subject: [PATCH] Follow up to be9babe Exporting the random option ids back into the script engine, since they might be useful to some custom scripts. --- src/map/itemdb.cpp | 21 +++++++++++++++++++++ src/map/itemdb.hpp | 1 + 2 files changed, 22 insertions(+) diff --git a/src/map/itemdb.cpp b/src/map/itemdb.cpp index d3dfc08f6e..108c7a1045 100644 --- a/src/map/itemdb.cpp +++ b/src/map/itemdb.cpp @@ -2333,6 +2333,27 @@ uint64 RandomOptionDatabase::parseBodyNode(const YAML::Node &node) { return 1; } +void RandomOptionDatabase::loadingFinished(){ + const char* prefix = "RDMOPT_"; + + for( const auto& pair : *this ){ + std::string name = prefix + pair.second->name; + int64 constant; + + // Check if it has already been set + if( script_get_constant( name.c_str(), &constant ) ){ + // It is already the same + if( constant == pair.first ){ + continue; + }else{ + // Export it to the script engine -> will issue a warning + } + } + + script_set_constant( name.c_str(), pair.first, false, false ); + } +} + RandomOptionDatabase random_option_db; /** diff --git a/src/map/itemdb.hpp b/src/map/itemdb.hpp index b010a9e2a6..bfbd29d773 100644 --- a/src/map/itemdb.hpp +++ b/src/map/itemdb.hpp @@ -955,6 +955,7 @@ public: const std::string getDefaultLocation(); uint64 parseBodyNode(const YAML::Node &node); + void loadingFinished(); // Additional bool option_exists(std::string name);