# misc_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: misc_sl.cpp 15903 2009-03-30 23:15:05Z rubidium $ */
    00002
    00005 #include "../stdafx.h"
    00006 #include "../date_func.h"
    00007 #include "../variables.h"
    00008 #include "../core/random_func.hpp"
    00009 #include "../openttd.h"
    00010 #include "../zoom_func.h"
    00011 #include "../vehicle_func.h"
    00012 #include "../window_gui.h"
    00013 #include "../window_func.h"
    00014 #include "../viewport_func.h"
    00015 #include "../gfx_func.h"
    00016 #include "../company_base.h"
    00017 #include "../town.h"
    00018
    00019 #include "saveload.h"
    00020
    00021 extern TileIndex _cur_tileloop_tile;
    00022
    00023 /* Keep track of current game position */
    00024 int _saved_scrollpos_x;
    00025 int _saved_scrollpos_y;
    00026
    00027 void SaveViewportBeforeSaveGame()
    00028 {
    00029   const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00030
    00031   if (w != NULL) {
    00032     _saved_scrollpos_x = w->viewport->scrollpos_x;
    00033     _saved_scrollpos_y = w->viewport->scrollpos_y;
    00034     _saved_scrollpos_zoom = w->viewport->zoom;
    00035   }
    00036 }
    00037
    00038 void ResetViewportAfterLoadGame()
    00039 {
    00040   Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00041
    00042   w->viewport->scrollpos_x = _saved_scrollpos_x;
    00043   w->viewport->scrollpos_y = _saved_scrollpos_y;
    00044   w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
    00045   w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
    00046
    00047   ViewPort *vp = w->viewport;
    00048   vp->zoom = min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
    00049   vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
    00050   vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
    00051
    00052   DoZoomInOutWindow(ZOOM_NONE, w); // update button status
    00053   MarkWholeScreenDirty();
    00054 }
    00055
    00056
    00057 static const SaveLoadGlobVarList _date_desc[] = {
    00058   SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
    00059   SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
    00060       SLEG_VAR(_date_fract,             SLE_UINT16),
    00061       SLEG_VAR(_tick_counter,           SLE_UINT16),
    00062       SLEG_VAR(_vehicle_id_ctr_day,     SLE_UINT16),
    00063       SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
    00064   SLE_CONDNULL(1, 0, 45),
    00065   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
    00066   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
    00067       SLEG_VAR(_disaster_delay,         SLE_UINT16),
    00068       SLEG_VAR(_station_tick_ctr,       SLE_UINT16),
    00069       SLEG_VAR(_random.state[0],        SLE_UINT32),
    00070       SLEG_VAR(_random.state[1],        SLE_UINT32),
    00071   SLEG_CONDVAR(_cur_town_ctr,           SLE_FILE_U8  | SLE_VAR_U32,  0, 9),
    00072   SLEG_CONDVAR(_cur_town_ctr,           SLE_UINT32,                 10, SL_MAX_VERSION),
    00073       SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
    00074   SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  0, 108),
    00075   SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                109, SL_MAX_VERSION),
    00076       SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
    00077   SLEG_CONDVAR(_pause_game,             SLE_UINT8,                   4, SL_MAX_VERSION),
    00078   SLEG_CONDVAR(_cur_town_iter,          SLE_UINT32,                 11, SL_MAX_VERSION),
    00079       SLEG_END()
    00080 };
    00081
    00082 /* Save load date related variables as well as persistent tick counters
    00083  * XXX: currently some unrelated stuff is just put here */
    00084 static void SaveLoad_DATE()
    00085 {
    00086   SlGlobList(_date_desc);
    00087 }
    00088
    00089
    00090 static const SaveLoadGlobVarList _view_desc[] = {
    00091   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00092   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  6, SL_MAX_VERSION),
    00093   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00094   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  6, SL_MAX_VERSION),
    00095       SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
    00096       SLEG_END()
    00097 };
    00098
    00099 static void SaveLoad_VIEW()
    00100 {
    00101   SlGlobList(_view_desc);
    00102 }
    00103
    00104 extern const ChunkHandler _misc_chunk_handlers[] = {
    00105   { 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
    00106   { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF | CH_LAST},
    00107 };