Skip to content

Commit 1f53a93

Browse files
committed
Initial dynamic weather support
1 parent e20356b commit 1f53a93

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

rwengine/src/data/Weather.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class Weather {
4040
float a, float tod);
4141

4242
std::vector<Entry> entries;
43+
44+
// Taken from: https://www.gtamodding.com/wiki/Time_cycle#Weather_lists
45+
// TODO: This weather list applies only for GTA III
46+
const uint16_t WeatherList[64] = {
47+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 0,
48+
0, 0, 1, 3, 3, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2,
49+
2, 1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 2, 1
50+
};
4351
};
4452

4553
#endif

rwengine/src/engine/GameState.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ struct BasicState {
6464
uint8_t _align3[2]{0};
6565
uint16_t nextWeather{0};
6666
uint8_t _align4[2]{0};
67-
uint16_t forcedWeather{0};
67+
uint16_t forcedWeather{0xFFFF};
6868
uint8_t _align5[2]{0};
6969
float weatherInterpolation{1.f};
7070
uint8_t dateTime[24]{0}; // Unused

rwengine/src/script/modules/GTA3ModuleImpl.inl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4870,8 +4870,7 @@ void opcode_01b6(const ScriptArguments& args, const ScriptWeather weatherID) {
48704870
opcode 01b7
48714871
*/
48724872
void opcode_01b7(const ScriptArguments& args) {
4873-
RW_UNUSED(args);
4874-
args.getState()->basic.forcedWeather = -1;
4873+
args.getState()->basic.forcedWeather = UINT16_MAX;
48754874
}
48764875

48774876
/**

rwgame/RWGame.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ void RWGame::tick(float dt) {
533533
static float clockAccumulator = 0.f;
534534
static float scriptTimerAccumulator = 0.f;
535535
static ScriptInt beepTime = std::numeric_limits<ScriptInt>::max();
536+
static uint8_t prevGameHour = state.basic.gameHour;
536537
if (currState->shouldWorldUpdate()) {
537538
world->chase.update(dt);
538539

@@ -554,6 +555,22 @@ void RWGame::tick(float dt) {
554555
clockAccumulator -= 1.f;
555556
}
556557

558+
if (prevGameHour != state.basic.gameHour) {
559+
prevGameHour = state.basic.gameHour;
560+
state.basic.lastWeather = state.basic.nextWeather;
561+
562+
// TODO: VC and SA has more than 4 weather conditions
563+
if (state.basic.forcedWeather > 3) {
564+
if (state.basic.weatherType < 63) {
565+
++state.basic.weatherType;
566+
} else {
567+
state.basic.weatherType = 0;
568+
}
569+
state.basic.nextWeather = data.weather.WeatherList[state.basic.weatherType];
570+
}
571+
}
572+
state.basic.weatherInterpolation = state.basic.gameMinute / 60.f;
573+
557574
constexpr float timerClockRate = 1.f / 30.f;
558575

559576
if (state.scriptTimerVariable && !state.scriptTimerPaused) {

0 commit comments

Comments
 (0)