CleverRaven/Cataclysm-DDA — pull request #7434 by BevapDin (2014-04-26 22:57:12+00:00)
Title: Fix loading the wrong weather.

Weather is a bit disturbed.

`weather_segment::deadline` is supposed to be the time when this weather segment ends. In `game::update_weather` this deadline is used as the key in the `weather_log` map.

So `weather_log` looks like this:
```
[20] => [RAIN, deadline=20, ... ]
[40] => [SUNNY, deadline=40, ... ]
[90] => [CLEAR, deadline=90, ... ]
...
```

Assume `nextweather` is 20, the first weather segment is finished, the new weather type is this:
```
weather_segment new_weather = weather_log.lower_bound((int)nextweather)->second;
```
which returns the first weather segment (RAIN) again - because `lower_bound` returns the first entry whose key is >= (in this case the segment with key >= 20).

The new deadline is not taken from this weather segment, but from the next one:
```
nextweather = weather_log.upper_bound(int(new_weather.deadline))->second.deadline;
```
`upper_bound` returns the first entry whose key is > (in this case > 20) and this is the second entry (SUNNY). Its deadline (40) is used now.

On turn 40, the same happens, but `lower_bound` returns now the second entry (SUNNY) and `upper_bound` returns the third (CLEAR) and now the weather changes to SUNNY.

So basically the game sets the weather deadline to the end of the next weather segment, but the weather type to the current segment.

Loading a save sets the weather (type and *deadline*) to this:
```
weather_log.lower_bound(int(calendar::turn))
```

If saved on turn 21 (weather is RAIN, `nextweather` is 40) and loaded, the weather is set tot SUNNY and `nextweather` to 40, because `lower_bound(21)` returns the second entry.

If saved on turn 20 (weather is RAIN, `nextweather` is 40) and loaded, the weather is set tot RAIN and `nextweather` to 40, because `lower_bound(20)` returns the first entry.

I changed `lower_bound` to `upper_bound` in `game::update_weather` and in `game::load_weather`, because we need a weather segment whose deadline is in the future. Now loading on turn 20 gets the second weather segment (SUNNY).

Same as it gets when normally reaching turn 20 in `game::update_weather`.

This might fix the problem mentioned there: https://github.com/CleverRaven/Cataclysm-DDA/pull/7427#issuecomment-41480115