# misc_sl.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #include "../stdafx.h"
    00013 #include "../date_func.h"
    00014 #include "../zoom_func.h"
    00015 #include "../vehicle_func.h"
    00016 #include "../window_gui.h"
    00017 #include "../window_func.h"
    00018 #include "../viewport_func.h"
    00019 #include "../gfx_func.h"
    00020 #include "../core/random_func.hpp"
    00021 #include "../fios.h"
    00022
    00023 #include "saveload.h"
    00024
    00025 extern TileIndex _cur_tileloop_tile;
    00026 extern uint16 _disaster_delay;
    00027 extern byte _trees_tick_ctr;
    00028
    00029 /* Keep track of current game position */
    00030 int _saved_scrollpos_x;
    00031 int _saved_scrollpos_y;
    00032 ZoomLevelByte _saved_scrollpos_zoom;
    00033
    00034 void SaveViewportBeforeSaveGame()
    00035 {
    00036   const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00037
    00038   if (w != NULL) {
    00039     _saved_scrollpos_x = w->viewport->scrollpos_x;
    00040     _saved_scrollpos_y = w->viewport->scrollpos_y;
    00041     _saved_scrollpos_zoom = w->viewport->zoom;
    00042   }
    00043 }
    00044
    00045 void ResetViewportAfterLoadGame()
    00046 {
    00047   Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00048
    00049   w->viewport->scrollpos_x = _saved_scrollpos_x;
    00050   w->viewport->scrollpos_y = _saved_scrollpos_y;
    00051   w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
    00052   w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
    00053
    00054   ViewPort *vp = w->viewport;
    00055   vp->zoom = ZOOM_LVL_NORMAL;
    00056   vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
    00057   vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
    00058
    00059   DoZoomInOutWindow(ZOOM_NONE, w); // update button status
    00060   MarkWholeScreenDirty();
    00061 }
    00062
    00063 static const SaveLoadGlobVarList _date_desc[] = {
    00064   SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
    00065   SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
    00066       SLEG_VAR(_date_fract,             SLE_UINT16),
    00067       SLEG_VAR(_tick_counter,           SLE_UINT16),
    00068   SLE_CONDNULL(2, 0, 156), // _vehicle_id_ctr_day
    00069       SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
    00070   SLE_CONDNULL(1, 0, 45),
    00071   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
    00072   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
    00073       SLEG_VAR(_disaster_delay,         SLE_UINT16),
    00074   SLE_CONDNULL(2, 0, 119),
    00075       SLEG_VAR(_random.state[0],        SLE_UINT32),
    00076       SLEG_VAR(_random.state[1],        SLE_UINT32),
    00077   SLE_CONDNULL(1,  0,   9),
    00078   SLE_CONDNULL(4, 10, 119),
    00079       SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
    00080   SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  0, 108),
    00081   SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                109, SL_MAX_VERSION),
    00082       SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
    00083   SLEG_CONDVAR(_pause_mode,             SLE_UINT8,                   4, SL_MAX_VERSION),
    00084   SLE_CONDNULL(4, 11, 119),
    00085       SLEG_END()
    00086 };
    00087
    00088 static const SaveLoadGlobVarList _date_check_desc[] = {
    00089   SLEG_CONDVAR(_load_check_data.current_date,  SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
    00090   SLEG_CONDVAR(_load_check_data.current_date,  SLE_INT32,                  31, SL_MAX_VERSION),
    00091       SLE_NULL(2),                       // _date_fract
    00092       SLE_NULL(2),                       // _tick_counter
    00093   SLE_CONDNULL(2, 0, 156),               // _vehicle_id_ctr_day
    00094       SLE_NULL(1),                       // _age_cargo_skip_counter
    00095   SLE_CONDNULL(1, 0, 45),
    00096   SLE_CONDNULL(2, 0, 5),                 // _cur_tileloop_tile
    00097   SLE_CONDNULL(4, 6, SL_MAX_VERSION),    // _cur_tileloop_tile
    00098       SLE_NULL(2),                       // _disaster_delay
    00099   SLE_CONDNULL(2, 0, 119),
    00100       SLE_NULL(4),                       // _random.state[0]
    00101       SLE_NULL(4),                       // _random.state[1]
    00102   SLE_CONDNULL(1,  0,   9),
    00103   SLE_CONDNULL(4, 10, 119),
    00104       SLE_NULL(1),                       // _cur_company_tick_index
    00105   SLE_CONDNULL(2, 0, 108),               // _next_competitor_start
    00106   SLE_CONDNULL(4, 109, SL_MAX_VERSION),  // _next_competitor_start
    00107       SLE_NULL(1),                       // _trees_tick_ctr
    00108   SLE_CONDNULL(1, 4, SL_MAX_VERSION),    // _pause_mode
    00109   SLE_CONDNULL(4, 11, 119),
    00110       SLEG_END()
    00111 };
    00112
    00113 /* Save load date related variables as well as persistent tick counters
    00114  * XXX: currently some unrelated stuff is just put here */
    00115 static void SaveLoad_DATE()
    00116 {
    00117   SlGlobList(_date_desc);
    00118 }
    00119
    00120 static void Check_DATE()
    00121 {
    00122   SlGlobList(_date_check_desc);
    00123   if (IsSavegameVersionBefore(31)) {
    00124     _load_check_data.current_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
    00125   }
    00126 }
    00127
    00128
    00129 static const SaveLoadGlobVarList _view_desc[] = {
    00130   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00131   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  6, SL_MAX_VERSION),
    00132   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00133   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  6, SL_MAX_VERSION),
    00134       SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
    00135       SLEG_END()
    00136 };
    00137
    00138 static void SaveLoad_VIEW()
    00139 {
    00140   SlGlobList(_view_desc);
    00141 }
    00142
    00143 extern const ChunkHandler _misc_chunk_handlers[] = {
    00144   { 'DATE', SaveLoad_DATE, SaveLoad_DATE, NULL, Check_DATE, CH_RIFF},
    00145   { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, NULL, NULL,       CH_RIFF | CH_LAST},
    00146 };