Files
@ r28520:f9aebe299cae
Branch filter:
Location: cpp/openttd-patchpack/source/src/saveload/misc_sl.cpp - annotation
r28520:f9aebe299cae
7.9 KiB
text/x-c
Codechange: MacOS already has MIN/MAX macros defined
This is caused because we use PreCompile Headers, and one of them
includes a system headers which defines MIN/MAX.
This is caused because we use PreCompile Headers, and one of them
includes a system headers which defines MIN/MAX.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25752:2d6c2238f03d r25752:2d6c2238f03d r25752:2d6c2238f03d r25752:2d6c2238f03d r27148:4e041ae27b9d r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r14248:a9050881acd7 r15326:d5a6f99c5425 r27104:635f8101e375 r27104:635f8101e375 r10571:99cb9a95b4cf r21383:942c32fb8b0e r21383:942c32fb8b0e r10571:99cb9a95b4cf r27737:728d55b97775 r15515:db92a54a178e r27371:b9ad4c1bff08 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r23660:fd38a6a589de r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r28291:4fc68c2c9a36 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r26752:adf33386687c r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r24333:94ef0c6c84e2 r24597:afde5721a3b6 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r18462:a1ba75a7f741 r18462:a1ba75a7f741 r18462:a1ba75a7f741 r18462:a1ba75a7f741 r18462:a1ba75a7f741 r18462:a1ba75a7f741 r18460:1ec843d3a5ae r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r17899:92aaab03ad72 r27104:635f8101e375 r10571:99cb9a95b4cf r25585:53810459092f r27148:4e041ae27b9d r27148:4e041ae27b9d r27148:4e041ae27b9d r27149:50ec6b0c653e r27149:50ec6b0c653e r25751:3154638283de r25751:3154638283de r25751:3154638283de r25752:2d6c2238f03d r25751:3154638283de r25751:3154638283de r25752:2d6c2238f03d r25751:3154638283de r25751:3154638283de r27371:b9ad4c1bff08 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r27104:635f8101e375 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25585:53810459092f r25751:3154638283de r25751:3154638283de r15326:d5a6f99c5425 r15326:d5a6f99c5425 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25773:457e167f3c9e r25774:14ee6e7f4ecc r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25700:e59a6326ffc3 r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25700:e59a6326ffc3 r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r10571:99cb9a95b4cf r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25700:e59a6326ffc3 r25773:457e167f3c9e r27884:803962be0328 r25773:457e167f3c9e r15326:d5a6f99c5425 r25773:457e167f3c9e r10571:99cb9a95b4cf r25585:53810459092f r25751:3154638283de r25751:3154638283de r25751:3154638283de r25751:3154638283de r25751:3154638283de r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25773:457e167f3c9e r25773:457e167f3c9e r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r10571:99cb9a95b4cf r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25700:e59a6326ffc3 r25773:457e167f3c9e r25773:457e167f3c9e r25772:5ba83ce3a853 r25772:5ba83ce3a853 r25772:5ba83ce3a853 r10571:99cb9a95b4cf r25596:7bf7822e5659 r25596:7bf7822e5659 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file misc_sl.cpp Saving and loading of things that didn't fit anywhere else */
#include "../stdafx.h"
#include "saveload.h"
#include "compat/misc_sl_compat.h"
#include "../timer/timer_game_calendar.h"
#include "../zoom_func.h"
#include "../window_gui.h"
#include "../window_func.h"
#include "../viewport_func.h"
#include "../gfx_func.h"
#include "../core/random_func.hpp"
#include "../fios.h"
#include "../timer/timer.h"
#include "../timer/timer_game_tick.h"
#include "../safeguards.h"
extern TileIndex _cur_tileloop_tile;
extern uint16_t _disaster_delay;
extern byte _trees_tick_ctr;
extern std::string _savegame_id;
/* Keep track of current game position */
int _saved_scrollpos_x;
int _saved_scrollpos_y;
ZoomLevel _saved_scrollpos_zoom;
void SaveViewportBeforeSaveGame()
{
/* Don't use GetMainWindow() in case the window does not exist. */
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
if (w == nullptr || w->viewport == nullptr) {
/* Ensure saved position is clearly invalid. */
_saved_scrollpos_x = INT_MAX;
_saved_scrollpos_y = INT_MAX;
_saved_scrollpos_zoom = ZOOM_LVL_END;
} else {
_saved_scrollpos_x = w->viewport->scrollpos_x;
_saved_scrollpos_y = w->viewport->scrollpos_y;
_saved_scrollpos_zoom = w->viewport->zoom;
}
}
void ResetViewportAfterLoadGame()
{
Window *w = GetMainWindow();
w->viewport->scrollpos_x = _saved_scrollpos_x;
w->viewport->scrollpos_y = _saved_scrollpos_y;
w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
Viewport *vp = w->viewport;
vp->zoom = std::min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
/* If zoom_max is ZOOM_LVL_MIN then the setting has not been loaded yet, therefore all levels are allowed. */
if (_settings_client.gui.zoom_max != ZOOM_LVL_MIN) {
/* Ensure zoom level is allowed */
while (vp->zoom < _settings_client.gui.zoom_min) DoZoomInOutWindow(ZOOM_OUT, w);
while (vp->zoom > _settings_client.gui.zoom_max) DoZoomInOutWindow(ZOOM_IN, w);
}
DoZoomInOutWindow(ZOOM_NONE, w); // update button status
MarkWholeScreenDirty();
}
byte _age_cargo_skip_counter; ///< Skip aging of cargo? Used before savegame version 162.
extern TimeoutTimer<TimerGameTick> _new_competitor_timeout;
static const SaveLoad _date_desc[] = {
SLEG_CONDVAR("date", TimerGameCalendar::date, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
SLEG_CONDVAR("date", TimerGameCalendar::date, SLE_INT32, SLV_31, SL_MAX_VERSION),
SLEG_VAR("date_fract", TimerGameCalendar::date_fract, SLE_UINT16),
SLEG_CONDVAR("tick_counter", TimerGameTick::counter, SLE_FILE_U16 | SLE_VAR_U64, SL_MIN_VERSION, SLV_U64_TICK_COUNTER),
SLEG_CONDVAR("tick_counter", TimerGameTick::counter, SLE_UINT64, SLV_U64_TICK_COUNTER, SL_MAX_VERSION),
SLEG_CONDVAR("age_cargo_skip_counter", _age_cargo_skip_counter, SLE_UINT8, SL_MIN_VERSION, SLV_162),
SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
SLEG_CONDVAR("cur_tileloop_tile", _cur_tileloop_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
SLEG_VAR("next_disaster_start", _disaster_delay, SLE_UINT16),
SLEG_VAR("random_state[0]", _random.state[0], SLE_UINT32),
SLEG_VAR("random_state[1]", _random.state[1], SLE_UINT32),
SLEG_VAR("company_tick_counter", _cur_company_tick_index, SLE_FILE_U8 | SLE_VAR_U32),
SLEG_VAR("trees_tick_counter", _trees_tick_ctr, SLE_UINT8),
SLEG_CONDVAR("pause_mode", _pause_mode, SLE_UINT8, SLV_4, SL_MAX_VERSION),
SLEG_CONDSSTR("id", _savegame_id, SLE_STR, SLV_SAVEGAME_ID, SL_MAX_VERSION),
/* For older savegames, we load the current value as the "period"; afterload will set the "fired" and "elapsed". */
SLEG_CONDVAR("next_competitor_start", _new_competitor_timeout.period, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_109),
SLEG_CONDVAR("next_competitor_start", _new_competitor_timeout.period, SLE_UINT32, SLV_109, SLV_AI_START_DATE),
SLEG_CONDVAR("competitors_interval", _new_competitor_timeout.period, SLE_UINT32, SLV_AI_START_DATE, SL_MAX_VERSION),
SLEG_CONDVAR("competitors_interval_elapsed", _new_competitor_timeout.storage.elapsed, SLE_UINT32, SLV_AI_START_DATE, SL_MAX_VERSION),
SLEG_CONDVAR("competitors_interval_fired", _new_competitor_timeout.fired, SLE_BOOL, SLV_AI_START_DATE, SL_MAX_VERSION),
};
static const SaveLoad _date_check_desc[] = {
SLEG_CONDVAR("date", _load_check_data.current_date, SLE_FILE_U16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_31),
SLEG_CONDVAR("date", _load_check_data.current_date, SLE_INT32, SLV_31, SL_MAX_VERSION),
};
/* Save load date related variables as well as persistent tick counters
* XXX: currently some unrelated stuff is just put here */
struct DATEChunkHandler : ChunkHandler {
DATEChunkHandler() : ChunkHandler('DATE', CH_TABLE) {}
void Save() const override
{
SlTableHeader(_date_desc);
SlSetArrayIndex(0);
SlGlobList(_date_desc);
}
void LoadCommon(const SaveLoadTable &slt, const SaveLoadCompatTable &slct) const
{
const std::vector<SaveLoad> oslt = SlCompatTableHeader(slt, slct);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlGlobList(oslt);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many DATE entries");
}
void Load() const override
{
this->LoadCommon(_date_desc, _date_sl_compat);
}
void LoadCheck(size_t) const override
{
this->LoadCommon(_date_check_desc, _date_check_sl_compat);
if (IsSavegameVersionBefore(SLV_31)) {
_load_check_data.current_date += CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR;
}
}
};
static const SaveLoad _view_desc[] = {
SLEG_CONDVAR("x", _saved_scrollpos_x, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
SLEG_CONDVAR("x", _saved_scrollpos_x, SLE_INT32, SLV_6, SL_MAX_VERSION),
SLEG_CONDVAR("y", _saved_scrollpos_y, SLE_FILE_I16 | SLE_VAR_I32, SL_MIN_VERSION, SLV_6),
SLEG_CONDVAR("y", _saved_scrollpos_y, SLE_INT32, SLV_6, SL_MAX_VERSION),
SLEG_VAR("zoom", _saved_scrollpos_zoom, SLE_UINT8),
};
struct VIEWChunkHandler : ChunkHandler {
VIEWChunkHandler() : ChunkHandler('VIEW', CH_TABLE) {}
void Save() const override
{
SlTableHeader(_view_desc);
SlSetArrayIndex(0);
SlGlobList(_view_desc);
}
void Load() const override
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_view_desc, _view_sl_compat);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlGlobList(slt);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many DATE entries");
}
};
static const DATEChunkHandler DATE;
static const VIEWChunkHandler VIEW;
static const ChunkHandlerRef misc_chunk_handlers[] = {
DATE,
VIEW,
};
extern const ChunkHandlerTable _misc_chunk_handlers(misc_chunk_handlers);
|