# misc_sl.cpp

Go to the documentation of this file.

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