Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
3.4 kB · 90 lines
C++
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#include "weatherstate.hpp"
#include "esmreader.hpp"#include "esmwriter.hpp"#include "loadregn.hpp"
namespace ESM{ namespace { constexpr NAME currentRegionRecord = "CREG"; constexpr NAME timePassedRecord = "TMPS"; constexpr NAME fastForwardRecord = "FAST"; constexpr NAME weatherUpdateTimeRecord = "WUPD"; constexpr NAME transitionFactorRecord = "TRFC"; constexpr NAME currentWeatherRecord = "CWTH"; constexpr NAME nextWeatherRecord = "NWTH"; constexpr NAME queuedWeatherRecord = "QWTH"; constexpr NAME regionNameRecord = "RGNN"; constexpr NAME regionWeatherRecord = "RGNW"; constexpr NAME regionChanceRecord = "RGNC"; }}
namespace ESM{ void WeatherState::load(ESMReader& esm) { mCurrentRegion = esm.getHNRefId(currentRegionRecord); esm.getHNT(mTimePassed, timePassedRecord); esm.getHNT(mFastForward, fastForwardRecord); esm.getHNT(mWeatherUpdateTime, weatherUpdateTimeRecord); esm.getHNT(mTransitionFactor, transitionFactorRecord); int currentWeather; esm.getHNT(currentWeather, currentWeatherRecord); mCurrentWeather = ESM::Weather::indexToRefId(currentWeather); int nextWeather; esm.getHNT(nextWeather, nextWeatherRecord); mNextWeather = ESM::Weather::indexToRefId(nextWeather); int queuedWeather; esm.getHNT(queuedWeather, queuedWeatherRecord); mQueuedWeather = ESM::Weather::indexToRefId(queuedWeather);
while (esm.isNextSub(regionNameRecord)) { ESM::RefId regionID = esm.getRefId(); RegionWeatherState region; int weatherId; esm.getHNT(weatherId, regionWeatherRecord); region.mWeather = Weather::indexToRefId(weatherId); int index = 0; while (esm.isNextSub(regionChanceRecord)) { uint8_t chance; esm.getHT(chance); ESM::RefId id = Weather::indexToRefId(index++); region.mChances.emplace(id, chance); }
mRegions.insert(std::make_pair(regionID, region)); } }
void WeatherState::save(ESMWriter& esm) const { esm.writeHNCRefId(currentRegionRecord, mCurrentRegion); esm.writeHNT(timePassedRecord, mTimePassed); esm.writeHNT(fastForwardRecord, mFastForward); esm.writeHNT(weatherUpdateTimeRecord, mWeatherUpdateTime); esm.writeHNT(transitionFactorRecord, mTransitionFactor); esm.writeHNT(currentWeatherRecord, Weather::refIdToIndex(mCurrentWeather)); esm.writeHNT(nextWeatherRecord, Weather::refIdToIndex(mNextWeather)); esm.writeHNT(queuedWeatherRecord, Weather::refIdToIndex(mQueuedWeather));
for (const auto& [region, weather] : mRegions) { esm.writeHNCRefId(regionNameRecord, region); esm.writeHNT(regionWeatherRecord, Weather::refIdToIndex(weather.mWeather)); for (int i = 0; i < Weather::Length; ++i) { ESM::RefId id = Weather::indexToRefId(i); uint8_t chance = 0; const auto found = weather.mChances.find(id); if (found != weather.mChances.end()) chance = found->second; esm.writeHNT(regionChanceRecord, chance); } } }}