19 lines
851 B
C++
19 lines
851 B
C++
#include "classes.h"
|
|
#include "lua_api.h"
|
|
#include "seeds.h"
|
|
|
|
constexpr RNG LUA_RNG_DEFAULT = {RNG_SEED_DEFAULT, 5, 9, 7};
|
|
|
|
// (008bbcf0) Registers Lua's RNG: a default seeded constructor and the game's RNG methods.
|
|
void lua_api_rng_register(lua_State* state)
|
|
{
|
|
lua_class_begin(state, "RNG", LUA_CLASS_RNG);
|
|
lua_static(state, "__call", [](LuaIgnored) { return LUA_RNG_DEFAULT; });
|
|
lua_method(state, "GetSeed", [](RNG& rng) { return rng._seed; });
|
|
lua_method(state, "SetSeed", [](RNG& rng, uint32_t seed, uint32_t shiftIndex) { rng.SetSeed(seed, shiftIndex); });
|
|
lua_method(state, "RandomInt", [](RNG& rng, uint32_t max) { return rng.RandomInt(max); });
|
|
lua_method(state, "RandomFloat", [](RNG& rng) { return rng.RandomFloat(); });
|
|
lua_method(state, "Next", [](RNG& rng) { return rng.Next(); });
|
|
lua_class_end(state);
|
|
}
|