Expose item manager random seed (synchronized in online too) in scripting

This commit is contained in:
Benau 2019-12-06 14:10:45 +08:00
parent 06b11056c8
commit b29a42719c
3 changed files with 20 additions and 0 deletions

View File

@ -50,6 +50,7 @@ std::vector<video::SColorf> ItemManager::m_glow_color;
bool ItemManager::m_disable_item_collection = false;
std::shared_ptr<ItemManager> ItemManager::m_item_manager;
std::mt19937 ItemManager::m_random_engine;
uint32_t ItemManager::m_random_seed = 0;
//-----------------------------------------------------------------------------
/** Creates one instance of the item manager. */

View File

@ -54,6 +54,8 @@ private:
static bool m_disable_item_collection;
static std::mt19937 m_random_engine;
static uint32_t m_random_seed;
protected:
/** The instance of ItemManager while a race is on. */
static std::shared_ptr<ItemManager> m_item_manager;
@ -66,7 +68,14 @@ public:
static void updateRandomSeed(uint32_t seed_number)
{
m_random_engine.seed(seed_number);
m_random_seed = seed_number;
} // updateRandomSeed
// ------------------------------------------------------------------------
static uint32_t getRandomSeed()
{
return m_random_seed;
} // getRandomSeed
// ------------------------------------------------------------------------
/** Disable item collection, useful to test client mispreditions or

View File

@ -28,6 +28,7 @@
#include "input/device_manager.hpp"
#include "input/input_device.hpp"
#include "input/input_manager.hpp"
#include "items/item_manager.hpp"
#include "modes/world.hpp"
#include "scriptengine/property_animator.hpp"
#include "scriptengine/aswrappedcall.hpp"
@ -185,6 +186,11 @@ namespace Scripting
return ::Track::getCurrentTrack()->getIsDuringDay();
}
uint32_t getItemManagerRandomSeed()
{
return ItemManager::getRandomSeed();
}
void setFog(float maxDensity, float start, float end, int r, int g, int b, float duration)
{
PropertyAnimator* animator = PropertyAnimator::get();
@ -557,6 +563,10 @@ namespace Scripting
mp ? WRAP_FN(getMajorRaceMode) : asFUNCTION(getMajorRaceMode),
call_conv); assert(r >= 0);
r = engine->RegisterGlobalFunction("uint getItemManagerRandomSeed()",
mp ? WRAP_FN(getItemManagerRandomSeed) : asFUNCTION(getItemManagerRandomSeed),
call_conv); assert(r >= 0);
r = engine->RegisterGlobalFunction("int getMinorRaceMode()",
mp ? WRAP_FN(getMinorRaceMode) : asFUNCTION(getMinorRaceMode),
call_conv); assert(r >= 0);