diff --git a/apps/openmw/mwlua/regionbindings.cpp b/apps/openmw/mwlua/regionbindings.cpp index ebdce90b28..46ff0eb3c2 100644 --- a/apps/openmw/mwlua/regionbindings.cpp +++ b/apps/openmw/mwlua/regionbindings.cpp @@ -6,6 +6,8 @@ #include #include +#include "../mwworld/weather.hpp" + namespace sol { template <> @@ -47,14 +49,12 @@ namespace MWLua = sol::readonly_property([](const ESM::Region& rec) { return LuaUtil::serializeRefId(rec.mSleepList); }); regionT["weatherProbabilities"] = sol::readonly_property([lua = lua.lua_state()](const ESM::Region& rec) { - constexpr std::array WeatherNames - = { "clear", "cloudy", "foggy", "overcast", "rain", "thunder", "ash", "blight", "snow", "blizzard" }; sol::table res(lua, sol::create); for (size_t i = 0; i < rec.mData.mProbabilities.size(); ++i) { - res[LuaUtil::toLuaIndex(i)] = rec.mData.mProbabilities[i]; - res[WeatherNames[i]] = rec.mData.mProbabilities[i]; + const MWWorld::Weather* weather = MWBase::Environment::get().getWorld()->getWeather(i); + res[weather->mId.serializeText()] = rec.mData.mProbabilities[i]; } return res; }); diff --git a/files/lua_api/openmw/core.lua b/files/lua_api/openmw/core.lua index 8a0285d3fc..c01f92eebe 100644 --- a/files/lua_api/openmw/core.lua +++ b/files/lua_api/openmw/core.lua @@ -1176,11 +1176,11 @@ -- @field #string sleepList A leveled creature list used when sleeping outdoors in this region -- @field #list<#RegionSoundRef> sounds A read-only list of ambient sound references for this region. -- Each reference includes a chance and a resolved link to the full sound record. --- @field #table weatherProbabilities A table mapping weather types to their probability (0–100), should sum to 100. --- Supports both numeric indices (1–10) and string keys: +-- @field #table weatherProbabilities A table mapping weather ids to their probability (0–100), should sum to 100. +-- Supports both numeric indices (1–10) and ids, for example: -- `"clear"`, `"cloudy"`, `"foggy"`, `"overcast"`, `"rain"`, `"thunder"`, `"ash"`, `"blight"`, `"snow"`, `"blizzard"` -- @usage print(region.weatherProbabilities[1]) -- access by index --- @usage print(region.weatherProbabilities["rain"]) -- access by name +-- @usage print(region.weatherProbabilities["rain"]) -- access by id --- -- Region sound reference