misc_sl.cpp

Go to the documentation of this file.
00001 /* $Id: misc_sl.cpp 18809 2010-01-15 16:41:15Z rubidium $ */
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 "../variables.h"
00015 #include "../openttd.h"
00016 #include "../zoom_func.h"
00017 #include "../vehicle_func.h"
00018 #include "../window_gui.h"
00019 #include "../window_func.h"
00020 #include "../viewport_func.h"
00021 #include "../gfx_func.h"
00022 #include "../company_base.h"
00023 #include "../core/random_func.hpp"
00024 
00025 #include "saveload.h"
00026 
00027 extern TileIndex _cur_tileloop_tile;
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 = (ZoomLevel)min(_saved_scrollpos_zoom, ZOOM_LVL_MAX);
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 
00064 static const SaveLoadGlobVarList _date_desc[] = {
00065   SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
00066   SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
00067       SLEG_VAR(_date_fract,             SLE_UINT16),
00068       SLEG_VAR(_tick_counter,           SLE_UINT16),
00069       SLEG_VAR(_vehicle_id_ctr_day,     SLE_UINT16),
00070       SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
00071   SLE_CONDNULL(1, 0, 45),
00072   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
00073   SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
00074       SLEG_VAR(_disaster_delay,         SLE_UINT16),
00075   SLE_CONDNULL(2, 0, 119),
00076       SLEG_VAR(_random.state[0],        SLE_UINT32),
00077       SLEG_VAR(_random.state[1],        SLE_UINT32),
00078   SLE_CONDNULL(1,  0,   9),
00079   SLE_CONDNULL(4, 10, 119),
00080       SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
00081   SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  0, 108),
00082   SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                109, SL_MAX_VERSION),
00083       SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
00084   SLEG_CONDVAR(_pause_mode,             SLE_UINT8,                   4, SL_MAX_VERSION),
00085   SLE_CONDNULL(4, 11, 119),
00086       SLEG_END()
00087 };
00088 
00089 /* Save load date related variables as well as persistent tick counters
00090  * XXX: currently some unrelated stuff is just put here */
00091 static void SaveLoad_DATE()
00092 {
00093   SlGlobList(_date_desc);
00094 }
00095 
00096 
00097 static const SaveLoadGlobVarList _view_desc[] = {
00098   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
00099   SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  6, SL_MAX_VERSION),
00100   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
00101   SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  6, SL_MAX_VERSION),
00102       SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
00103       SLEG_END()
00104 };
00105 
00106 static void SaveLoad_VIEW()
00107 {
00108   SlGlobList(_view_desc);
00109 }
00110 
00111 extern const ChunkHandler _misc_chunk_handlers[] = {
00112   { 'DATE', SaveLoad_DATE, SaveLoad_DATE, NULL, CH_RIFF},
00113   { 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, NULL, CH_RIFF | CH_LAST},
00114 };

Generated on Mon Aug 30 19:36:59 2010 for OpenTTD by  doxygen 1.6.1