# misc_sl.cpp

Go to the documentation of this file.

    00001 /* $Id: misc_sl.cpp 18476 2009-12-13 00:13:06Z 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 ZoomLevelByte _saved_scrollpos_zoom;
    00027
    00028 void SaveViewportBeforeSaveGame()
    00029 {
    00030   const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00031
    00032   if (w != NULL) {
    00033     _saved_scrollpos_x = w->viewport->scrollpos_x;
    00034     _saved_scrollpos_y = w->viewport->scrollpos_y;
    00035     _saved_scrollpos_zoom = w->viewport->zoom;
    00036   }
    00037 }
    00038
    00039 void ResetViewportAfterLoadGame()
    00040 {
    00041   Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
    00042
    00043   w->viewport->scrollpos_x = _saved_scrollpos_x;
    00044   w->viewport->scrollpos_y = _saved_scrollpos_y;
    00045   w->viewport->dest_scrollpos_x = _saved_scrollpos_x;
    00046   w->viewport->dest_scrollpos_y = _saved_scrollpos_y;
    00047
    00048   ViewPort *vp = w->viewport;
    00049   vp->zoom = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
    00050   vp->virtual_width = ScaleByZoom(vp->width, vp->zoom);
    00051   vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
    00052
    00053   DoZoomInOutWindow(ZOOM_NONE, w); // update button status
    00054   MarkWholeScreenDirty();
    00055 }
    00056
    00057
    00058 static const SaveLoadGlobVarList _date_desc[] = {
    00059   SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
    00060   SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
    00061       SLEG_VAR(_date_fract,             SLE_UINT16),
    00062       SLEG_VAR(_tick_counter,           SLE_UINT16),
    00063       SLEG_VAR(_vehicle_id_ctr_day,     SLE_UINT16),
    00064       SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
    00065   SLE_CONDNULL(1, 0, 45),
    00066   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
    00067   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
    00068       SLEG_VAR(_disaster_delay,         SLE_UINT16),
    00069   SLE_CONDNULL(2, 0, 119),
    00070       SLEG_VAR(_random.state[0],        SLE_UINT32),
    00071       SLEG_VAR(_random.state[1],        SLE_UINT32),
    00072   SLE_CONDNULL(1,  0,   9),
    00073   SLE_CONDNULL(4, 10, 119),
    00074       SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
    00075   SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  0, 108),
    00076   SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                109, SL_MAX_VERSION),
    00077       SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
    00078   SLEG_CONDVAR(_pause_game,             SLE_UINT8,                   4, SL_MAX_VERSION),
    00079   SLE_CONDNULL(4, 11, 119),
    00080       SLEG_END()
    00081 };
    00082
    00083 /* Save load date related variables as well as persistent tick counters
    00084  * XXX: currently some unrelated stuff is just put here */
    00085 static void SaveLoad_DATE()
    00086 {
    00087   SlGlobList(_date_desc);
    00088 }
    00089
    00090
    00091 static const SaveLoadGlobVarList _view_desc[] = {
    00092   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00093   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  6, SL_MAX_VERSION),
    00094   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
    00095   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  6, SL_MAX_VERSION),
    00096       SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
    00097       SLEG_END()
    00098 };
    00099
    00100 static void SaveLoad_VIEW()
    00101 {
    00102   SlGlobList(_view_desc);
    00103 }
    00104
    00105 extern const ChunkHandler _misc_chunk_handlers[] = {
    00106   { 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
    00107   { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF | CH_LAST},
    00108 };