2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/** @file misc.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-08-07 14:45:50 +00:00
|
|
|
#include "currency.h"
|
2007-04-12 13:07:15 +00:00
|
|
|
#include "landscape.h"
|
2005-10-22 06:39:32 +00:00
|
|
|
#include "news.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "saveload.h"
|
2005-01-02 17:23:04 +00:00
|
|
|
#include "engine.h"
|
2005-05-02 23:59:11 +00:00
|
|
|
#include "vehicle_gui.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-11-30 16:10:19 +00:00
|
|
|
#include "ai/ai.h"
|
2007-03-19 11:27:30 +00:00
|
|
|
#include "newgrf_house.h"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "viewport_func.h"
|
2007-12-21 22:50:51 +00:00
|
|
|
#include "economy_func.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "zoom_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
2007-12-26 11:45:43 +00:00
|
|
|
#include "map_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
|
|
|
#include "texteff.hpp"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-09 09:45:45 +00:00
|
|
|
#include "gfx_func.h"
|
2008-01-22 12:09:12 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2008-01-09 09:45:45 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/sprites.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 20:53:31 +00:00
|
|
|
char _name_array[512][32];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeVehicles();
|
|
|
|
void InitializeWaypoints();
|
|
|
|
void InitializeDepots();
|
|
|
|
void InitializeEngines();
|
|
|
|
void InitializeOrders();
|
|
|
|
void InitializeClearLand();
|
|
|
|
void InitializeRailGui();
|
|
|
|
void InitializeRoadGui();
|
|
|
|
void InitializeAirportGui();
|
|
|
|
void InitializeDockGui();
|
|
|
|
void InitializeIndustries();
|
|
|
|
void InitializeMainGui();
|
|
|
|
void InitializeTowns();
|
|
|
|
void InitializeTrees();
|
|
|
|
void InitializeSigns();
|
|
|
|
void InitializeStations();
|
2007-06-22 11:58:59 +00:00
|
|
|
void InitializeCargoPackets();
|
2007-03-07 11:47:46 +00:00
|
|
|
static void InitializeNameMgr();
|
|
|
|
void InitializePlayers();
|
|
|
|
static void InitializeCheats();
|
|
|
|
void InitializeNPF();
|
2005-01-22 20:23:18 +00:00
|
|
|
|
2006-01-06 21:57:37 +00:00
|
|
|
void InitializeGame(int mode, uint size_x, uint size_y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-13 19:51:31 +00:00
|
|
|
AllocateMap(size_x, size_y);
|
|
|
|
|
2007-11-15 18:28:00 +00:00
|
|
|
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-06 20:59:52 +00:00
|
|
|
_pause_game = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
_fast_forward = 0;
|
|
|
|
_tick_counter = 0;
|
2007-06-22 20:04:21 +00:00
|
|
|
_realtime_tick = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
_date_fract = 0;
|
|
|
|
_cur_tileloop_tile = 0;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2006-01-06 21:57:37 +00:00
|
|
|
if ((mode & IG_DATE_RESET) == IG_DATE_RESET) {
|
2006-08-16 12:07:24 +00:00
|
|
|
SetDate(ConvertYMDToDate(_patches.starting_year, 0, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
InitializeEngines();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeVehicles();
|
2005-03-24 17:03:37 +00:00
|
|
|
InitializeWaypoints();
|
2006-08-22 15:39:22 +00:00
|
|
|
InitializeDepots();
|
2005-01-15 19:06:22 +00:00
|
|
|
InitializeOrders();
|
2007-05-19 09:40:18 +00:00
|
|
|
InitializeGroup();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
InitNewsItemStructs();
|
2005-07-13 19:51:31 +00:00
|
|
|
InitializeLandscape();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeClearLand();
|
|
|
|
InitializeRailGui();
|
|
|
|
InitializeRoadGui();
|
|
|
|
InitializeAirportGui();
|
|
|
|
InitializeDockGui();
|
|
|
|
InitializeTowns();
|
|
|
|
InitializeTrees();
|
2005-01-12 11:21:28 +00:00
|
|
|
InitializeSigns();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeStations();
|
2007-06-22 11:58:59 +00:00
|
|
|
InitializeCargoPackets();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeIndustries();
|
2007-03-19 11:27:30 +00:00
|
|
|
InitializeBuildingCounts();
|
2006-04-22 09:25:36 +00:00
|
|
|
InitializeMainGui();
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeNameMgr();
|
2004-09-06 18:15:13 +00:00
|
|
|
InitializeVehiclesGuiList();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeTrains();
|
2005-01-31 11:23:10 +00:00
|
|
|
InitializeNPF();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-30 16:10:19 +00:00
|
|
|
AI_Initialize();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializePlayers();
|
|
|
|
InitializeCheats();
|
|
|
|
|
|
|
|
InitTextEffects();
|
2007-08-19 09:38:30 +00:00
|
|
|
InitChatMessage();
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeAnimatedTiles();
|
|
|
|
|
|
|
|
InitializeLandscapeVariables(false);
|
|
|
|
|
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
|
2006-10-16 10:26:22 +00:00
|
|
|
bool IsCustomName(StringID id)
|
|
|
|
{
|
|
|
|
return GB(id, 11, 5) == 15;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void InitializeCheats()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-11 09:55:19 +00:00
|
|
|
memset(&_cheats, 0, sizeof(Cheats));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void InitializeNameMgr()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
memset(_name_array, 0, sizeof(_name_array));
|
|
|
|
}
|
|
|
|
|
2008-01-12 19:58:06 +00:00
|
|
|
/* Copy and convert old custom names to UTF-8 */
|
|
|
|
char *CopyFromOldName(StringID id)
|
2006-11-16 22:05:33 +00:00
|
|
|
{
|
2008-01-12 19:58:06 +00:00
|
|
|
if (!IsCustomName(id)) return NULL;
|
2006-11-16 22:05:33 +00:00
|
|
|
|
2008-01-12 19:58:06 +00:00
|
|
|
if (CheckSavegameVersion(37)) {
|
|
|
|
/* Old names were 32 characters long, so 128 characters should be
|
|
|
|
* plenty to allow for expansion when converted to UTF-8. */
|
|
|
|
char tmp[128];
|
|
|
|
const char *strfrom = _name_array[GB(id, 0, 9)];
|
2006-11-16 22:05:33 +00:00
|
|
|
char *strto = tmp;
|
|
|
|
|
|
|
|
for (; *strfrom != '\0'; strfrom++) {
|
|
|
|
WChar c = (byte)*strfrom;
|
2008-01-12 19:58:06 +00:00
|
|
|
|
|
|
|
/* Map from non-ISO8859-15 characters to UTF-8. */
|
2006-11-16 22:05:33 +00:00
|
|
|
switch (c) {
|
|
|
|
case 0xA4: c = 0x20AC; break; // Euro
|
|
|
|
case 0xA6: c = 0x0160; break; // S with caron
|
|
|
|
case 0xA8: c = 0x0161; break; // s with caron
|
|
|
|
case 0xB4: c = 0x017D; break; // Z with caron
|
|
|
|
case 0xB8: c = 0x017E; break; // z with caron
|
|
|
|
case 0xBC: c = 0x0152; break; // OE ligature
|
|
|
|
case 0xBD: c = 0x0153; break; // oe ligature
|
|
|
|
case 0xBE: c = 0x0178; break; // Y with diaresis
|
|
|
|
default: break;
|
|
|
|
}
|
2008-01-12 19:58:06 +00:00
|
|
|
|
|
|
|
/* Check character will fit into our buffer. */
|
2006-11-16 22:05:33 +00:00
|
|
|
if (strto + Utf8CharLen(c) > lastof(tmp)) break;
|
2008-01-12 19:58:06 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
strto += Utf8Encode(strto, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate the new string and copy it back to the name array */
|
|
|
|
*strto = '\0';
|
2008-01-12 19:58:06 +00:00
|
|
|
|
|
|
|
return strdup(tmp);
|
|
|
|
} else {
|
|
|
|
/* Name will already be in UTF-8. */
|
|
|
|
return strdup(_name_array[GB(id, 0, 9)]);
|
2006-11-16 22:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/* Calculate constants that depend on the landscape type. */
|
2004-08-09 17:04:08 +00:00
|
|
|
void InitializeLandscapeVariables(bool only_constants)
|
|
|
|
{
|
2007-02-20 22:09:21 +00:00
|
|
|
if (only_constants) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2007-02-20 22:09:21 +00:00
|
|
|
_cargo_payment_rates[i] = GetCargo(i)->initial_payment;
|
|
|
|
_cargo_payment_rates_frac[i] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_NAME()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int index;
|
2004-09-11 09:55:19 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2007-04-18 22:10:36 +00:00
|
|
|
SlArray(_name_array[index], SlGetFieldLength(), SLE_UINT8);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SaveLoadGlobVarList _date_desc[] = {
|
2006-08-26 11:06:54 +00:00
|
|
|
SLEG_CONDVAR(_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
|
|
|
|
SLEG_CONDVAR(_date, SLE_INT32, 31, SL_MAX_VERSION),
|
2006-08-22 14:38:37 +00:00
|
|
|
SLEG_VAR(_date_fract, SLE_UINT16),
|
|
|
|
SLEG_VAR(_tick_counter, SLE_UINT16),
|
|
|
|
SLEG_VAR(_vehicle_id_ctr_day, SLE_UINT16),
|
|
|
|
SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
|
2007-02-10 08:19:39 +00:00
|
|
|
SLE_CONDNULL(1, 0, 45),
|
2006-08-22 14:38:37 +00:00
|
|
|
SLEG_CONDVAR(_cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5),
|
|
|
|
SLEG_CONDVAR(_cur_tileloop_tile, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLEG_VAR(_disaster_delay, SLE_UINT16),
|
|
|
|
SLEG_VAR(_station_tick_ctr, SLE_UINT16),
|
2008-01-29 00:27:25 +00:00
|
|
|
SLEG_VAR(_random.state[0], SLE_UINT32),
|
|
|
|
SLEG_VAR(_random.state[1], SLE_UINT32),
|
2006-08-22 14:38:37 +00:00
|
|
|
SLEG_CONDVAR(_cur_town_ctr, SLE_FILE_U8 | SLE_VAR_U32, 0, 9),
|
|
|
|
SLEG_CONDVAR(_cur_town_ctr, SLE_UINT32, 10, SL_MAX_VERSION),
|
|
|
|
SLEG_VAR(_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_U32),
|
|
|
|
SLEG_VAR(_next_competitor_start, SLE_FILE_U16 | SLE_VAR_U32),
|
|
|
|
SLEG_VAR(_trees_tick_ctr, SLE_UINT8),
|
2007-03-06 20:59:52 +00:00
|
|
|
SLEG_CONDVAR(_pause_game, SLE_UINT8, 4, SL_MAX_VERSION),
|
2006-08-22 14:38:37 +00:00
|
|
|
SLEG_CONDVAR(_cur_town_iter, SLE_UINT32, 11, SL_MAX_VERSION),
|
2006-02-20 19:42:39 +00:00
|
|
|
SLEG_END()
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-03 04:04:22 +00:00
|
|
|
/* Save load date related variables as well as persistent tick counters
|
|
|
|
* XXX: currently some unrelated stuff is just put here */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SaveLoad_DATE()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SlGlobList(_date_desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const SaveLoadGlobVarList _view_desc[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
SLEG_CONDVAR(_saved_scrollpos_x, SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
|
|
|
|
SLEG_CONDVAR(_saved_scrollpos_x, SLE_INT32, 6, SL_MAX_VERSION),
|
|
|
|
SLEG_CONDVAR(_saved_scrollpos_y, SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
|
|
|
|
SLEG_CONDVAR(_saved_scrollpos_y, SLE_INT32, 6, SL_MAX_VERSION),
|
|
|
|
SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
|
2006-02-20 19:42:39 +00:00
|
|
|
SLEG_END()
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SaveLoad_VIEW()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SlGlobList(_view_desc);
|
|
|
|
}
|
|
|
|
|
2005-01-29 19:45:14 +00:00
|
|
|
static uint32 _map_dim_x;
|
|
|
|
static uint32 _map_dim_y;
|
|
|
|
|
|
|
|
static const SaveLoadGlobVarList _map_dimensions[] = {
|
2006-02-20 19:42:39 +00:00
|
|
|
SLEG_CONDVAR(_map_dim_x, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLEG_CONDVAR(_map_dim_y, SLE_UINT32, 6, SL_MAX_VERSION),
|
|
|
|
SLEG_END()
|
2005-01-29 19:45:14 +00:00
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAPS()
|
2005-01-29 19:45:14 +00:00
|
|
|
{
|
2005-01-29 20:11:19 +00:00
|
|
|
_map_dim_x = MapSizeX();
|
|
|
|
_map_dim_y = MapSizeY();
|
2005-01-29 19:45:14 +00:00
|
|
|
SlGlobList(_map_dimensions);
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAPS()
|
2005-01-29 19:45:14 +00:00
|
|
|
{
|
|
|
|
SlGlobList(_map_dimensions);
|
2005-07-13 19:51:31 +00:00
|
|
|
AllocateMap(_map_dim_x, _map_dim_y);
|
2005-01-29 19:45:14 +00:00
|
|
|
}
|
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
enum {
|
|
|
|
MAP_SL_BUF_SIZE = 4096
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAPT()
|
2005-08-06 17:40:21 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-07-13 18:04:01 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type_height = buf[j];
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAPT()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type_height;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP1()
|
2005-07-13 18:04:01 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j];
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP1()
|
2005-07-13 18:04:01 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m1;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP2()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-07-13 18:04:01 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE,
|
2005-07-13 18:04:01 +00:00
|
|
|
/* In those versions the m2 was 8 bits */
|
2005-11-22 19:33:29 +00:00
|
|
|
CheckSavegameVersion(5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
|
2005-07-13 18:04:01 +00:00
|
|
|
);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m2 = buf[j];
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP2()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-07-13 18:04:01 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
SlSetLength(size * sizeof(uint16));
|
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m2;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP3()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j];
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP3()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m3;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP4()
|
2005-08-06 17:40:21 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j];
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP4()
|
2005-08-06 17:40:21 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m4;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP5()
|
2005-07-13 18:04:01 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j];
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP5()
|
2005-08-06 17:40:21 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-08-06 17:40:21 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m5;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-08-06 17:40:21 +00:00
|
|
|
}
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_MAP6()
|
2005-07-13 18:04:01 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-07-13 18:04:01 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (CheckSavegameVersion(42)) {
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
/* 1024, otherwise we overflow on 64x64 maps! */
|
|
|
|
SlArray(buf, 1024, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != 1024; j++) {
|
2007-01-11 02:05:13 +00:00
|
|
|
_m[i++].m6 = GB(buf[j], 0, 2);
|
|
|
|
_m[i++].m6 = GB(buf[j], 2, 2);
|
|
|
|
_m[i++].m6 = GB(buf[j], 4, 2);
|
|
|
|
_m[i++].m6 = GB(buf[j], 6, 2);
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m6 = buf[j];
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_MAP6()
|
2005-07-13 18:04:01 +00:00
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2005-07-13 18:04:01 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m6;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2005-07-13 18:04:01 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-19 11:27:30 +00:00
|
|
|
static void Load_MAP7()
|
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j];
|
2007-03-19 11:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Save_MAP7()
|
|
|
|
{
|
2008-01-22 12:09:12 +00:00
|
|
|
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
|
|
|
TileIndex size = MapSize();
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
SlSetLength(size);
|
2008-01-22 12:09:12 +00:00
|
|
|
for (TileIndex i = 0; i != size;) {
|
|
|
|
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m7;
|
|
|
|
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
2007-03-19 11:27:30 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_CHTS()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte count = sizeof(_cheats)/sizeof(Cheat);
|
|
|
|
Cheat* cht = (Cheat*) &_cheats;
|
|
|
|
Cheat* cht_last = &cht[count];
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
SlSetLength(count * 2);
|
|
|
|
for (; cht != cht_last; cht++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
SlWriteByte(cht->been_used);
|
|
|
|
SlWriteByte(cht->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_CHTS()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-02-06 09:18:04 +00:00
|
|
|
Cheat* cht = (Cheat*)&_cheats;
|
|
|
|
uint count = SlGetFieldLength() / 2;
|
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-06 09:18:04 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2007-01-10 18:56:51 +00:00
|
|
|
cht[i].been_used = (SlReadByte() != 0);
|
|
|
|
cht[i].value = (SlReadByte() != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern const ChunkHandler _misc_chunk_handlers[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ 'MAPS', Save_MAPS, Load_MAPS, CH_RIFF },
|
|
|
|
{ 'MAPT', Save_MAPT, Load_MAPT, CH_RIFF },
|
|
|
|
{ 'MAPO', Save_MAP1, Load_MAP1, CH_RIFF },
|
|
|
|
{ 'MAP2', Save_MAP2, Load_MAP2, CH_RIFF },
|
|
|
|
{ 'M3LO', Save_MAP3, Load_MAP3, CH_RIFF },
|
|
|
|
{ 'M3HI', Save_MAP4, Load_MAP4, CH_RIFF },
|
|
|
|
{ 'MAP5', Save_MAP5, Load_MAP5, CH_RIFF },
|
2007-01-11 02:05:13 +00:00
|
|
|
{ 'MAPE', Save_MAP6, Load_MAP6, CH_RIFF },
|
2007-03-19 11:27:30 +00:00
|
|
|
{ 'MAP7', Save_MAP7, Load_MAP7, CH_RIFF },
|
2006-08-22 14:38:37 +00:00
|
|
|
|
2008-01-12 19:58:06 +00:00
|
|
|
{ 'NAME', NULL, Load_NAME, CH_ARRAY},
|
2004-08-09 17:04:08 +00:00
|
|
|
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
|
|
|
|
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST}
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|