forked from teamnwah/openmw-tes3coop
Refactor weather transitions to act more like MW
Fixed several issues: * Waiting/jail time/training all now properly skip remaining transitions * ChangeWeather no longer permanently sets the region's weather * ChangeWeather being called during a transition now correctly queues up another transition * Corrected transition delta and factor calculations * ModRegion settings are now savedsceneinput
parent
e76401d5ea
commit
54fa5273dc
File diff suppressed because it is too large
Load Diff
@ -1,59 +1,72 @@
|
||||
#include "weatherstate.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
const char* hourRecord = "HOUR";
|
||||
const char* windSpeedRecord = "WNSP";
|
||||
const char* currentWeatherRecord = "CWTH";
|
||||
const char* nextWeatherRecord = "NWTH";
|
||||
const char* currentRegionRecord = "CREG";
|
||||
const char* firstUpdateRecord = "FUPD";
|
||||
const char* remainingTransitionTimeRecord = "RTTM";
|
||||
const char* timePassedRecord = "TMPS";
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
void WeatherState::load(ESMReader& esm)
|
||||
{
|
||||
// store values locally so that a failed load can't leave the state half set
|
||||
float newHour = 0.0;
|
||||
esm.getHNT(newHour, hourRecord);
|
||||
float newWindSpeed = 0.0;
|
||||
esm.getHNT(newWindSpeed, windSpeedRecord);
|
||||
std::string newCurrentWeather = esm.getHNString(currentWeatherRecord);
|
||||
std::string newNextWeather = esm.getHNString(nextWeatherRecord);
|
||||
std::string newCurrentRegion = esm.getHNString(currentRegionRecord);
|
||||
bool newFirstUpdate = false;
|
||||
esm.getHNT(newFirstUpdate, firstUpdateRecord);
|
||||
float newRemainingTransitionTime = 0.0;
|
||||
esm.getHNT(newRemainingTransitionTime, remainingTransitionTimeRecord);
|
||||
double newTimePassed = 0.0;
|
||||
esm.getHNT(newTimePassed, timePassedRecord);
|
||||
|
||||
// swap values now that it is safe to do so
|
||||
mHour = newHour;
|
||||
mWindSpeed = newWindSpeed;
|
||||
mCurrentWeather.swap(newCurrentWeather);
|
||||
mNextWeather.swap(newNextWeather);
|
||||
mCurrentRegion.swap(newCurrentRegion);
|
||||
mFirstUpdate = newFirstUpdate;
|
||||
mRemainingTransitionTime = newRemainingTransitionTime;
|
||||
mTimePassed = newTimePassed;
|
||||
}
|
||||
|
||||
void WeatherState::save(ESMWriter& esm) const
|
||||
{
|
||||
esm.writeHNT(hourRecord, mHour);
|
||||
esm.writeHNT(windSpeedRecord, mWindSpeed);
|
||||
esm.writeHNCString(currentWeatherRecord, mCurrentWeather.c_str());
|
||||
esm.writeHNCString(nextWeatherRecord, mNextWeather.c_str());
|
||||
esm.writeHNCString(currentRegionRecord, mCurrentRegion.c_str());
|
||||
esm.writeHNT(firstUpdateRecord, mFirstUpdate);
|
||||
esm.writeHNT(remainingTransitionTimeRecord, mRemainingTransitionTime);
|
||||
esm.writeHNT(timePassedRecord, mTimePassed);
|
||||
}
|
||||
}
|
||||
#include "weatherstate.hpp"
|
||||
|
||||
#include "esmreader.hpp"
|
||||
#include "esmwriter.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
const char* currentRegionRecord = "CREG";
|
||||
const char* timePassedRecord = "TMPS";
|
||||
const char* fastForwardRecord = "FAST";
|
||||
const char* weatherUpdateTimeRecord = "WUPD";
|
||||
const char* transitionFactorRecord = "TRFC";
|
||||
const char* currentWeatherRecord = "CWTH";
|
||||
const char* nextWeatherRecord = "NWTH";
|
||||
const char* queuedWeatherRecord = "QWTH";
|
||||
const char* regionNameRecord = "RGNN";
|
||||
const char* regionWeatherRecord = "RGNW";
|
||||
const char* regionChanceRecord = "RGNC";
|
||||
}
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
void WeatherState::load(ESMReader& esm)
|
||||
{
|
||||
mCurrentRegion = esm.getHNString(currentRegionRecord);
|
||||
esm.getHNT(mTimePassed, timePassedRecord);
|
||||
esm.getHNT(mFastForward, fastForwardRecord);
|
||||
esm.getHNT(mWeatherUpdateTime, weatherUpdateTimeRecord);
|
||||
esm.getHNT(mTransitionFactor, transitionFactorRecord);
|
||||
esm.getHNT(mCurrentWeather, currentWeatherRecord);
|
||||
esm.getHNT(mNextWeather, nextWeatherRecord);
|
||||
esm.getHNT(mQueuedWeather, queuedWeatherRecord);
|
||||
|
||||
while(esm.peekNextSub(regionNameRecord))
|
||||
{
|
||||
std::string regionID = esm.getHNString(regionNameRecord);
|
||||
RegionWeatherState region;
|
||||
esm.getHNT(region.mWeather, regionWeatherRecord);
|
||||
while(esm.peekNextSub(regionChanceRecord))
|
||||
{
|
||||
char chance;
|
||||
esm.getHNT(chance, regionChanceRecord);
|
||||
region.mChances.push_back(chance);
|
||||
}
|
||||
|
||||
mRegions.insert(std::make_pair(regionID, region));
|
||||
}
|
||||
}
|
||||
|
||||
void WeatherState::save(ESMWriter& esm) const
|
||||
{
|
||||
esm.writeHNCString(currentRegionRecord, mCurrentRegion.c_str());
|
||||
esm.writeHNT(timePassedRecord, mTimePassed);
|
||||
esm.writeHNT(fastForwardRecord, mFastForward);
|
||||
esm.writeHNT(weatherUpdateTimeRecord, mWeatherUpdateTime);
|
||||
esm.writeHNT(transitionFactorRecord, mTransitionFactor);
|
||||
esm.writeHNT(currentWeatherRecord, mCurrentWeather);
|
||||
esm.writeHNT(nextWeatherRecord, mNextWeather);
|
||||
esm.writeHNT(queuedWeatherRecord, mQueuedWeather);
|
||||
|
||||
std::map<std::string, RegionWeatherState>::const_iterator it = mRegions.begin();
|
||||
for(; it != mRegions.end(); ++it)
|
||||
{
|
||||
esm.writeHNCString(regionNameRecord, it->first.c_str());
|
||||
esm.writeHNT(regionWeatherRecord, it->second.mWeather);
|
||||
for(size_t i = 0; i < it->second.mChances.size(); ++i)
|
||||
{
|
||||
esm.writeHNT(regionChanceRecord, it->second.mChances[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,36 @@
|
||||
#ifndef OPENMW_ESM_WEATHERSTATE_H
|
||||
#define OPENMW_ESM_WEATHERSTATE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
struct WeatherState
|
||||
{
|
||||
float mHour;
|
||||
float mWindSpeed;
|
||||
std::string mCurrentWeather;
|
||||
std::string mNextWeather;
|
||||
std::string mCurrentRegion;
|
||||
bool mFirstUpdate;
|
||||
float mRemainingTransitionTime;
|
||||
double mTimePassed;
|
||||
|
||||
void load(ESMReader& esm);
|
||||
void save(ESMWriter& esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef OPENMW_ESM_WEATHERSTATE_H
|
||||
#define OPENMW_ESM_WEATHERSTATE_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
class ESMReader;
|
||||
class ESMWriter;
|
||||
|
||||
struct RegionWeatherState
|
||||
{
|
||||
int mWeather;
|
||||
std::vector<char> mChances;
|
||||
};
|
||||
|
||||
struct WeatherState
|
||||
{
|
||||
std::string mCurrentRegion;
|
||||
float mTimePassed;
|
||||
bool mFastForward;
|
||||
float mWeatherUpdateTime;
|
||||
float mTransitionFactor;
|
||||
int mCurrentWeather;
|
||||
int mNextWeather;
|
||||
int mQueuedWeather;
|
||||
std::map<std::string, RegionWeatherState> mRegions;
|
||||
|
||||
void load(ESMReader& esm);
|
||||
void save(ESMWriter& esm) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue