diff options
-rw-r--r-- | functions.h | 1 | ||||
-rw-r--r-- | misc.c | 2 | ||||
-rw-r--r-- | network_client.c | 38 | ||||
-rw-r--r-- | network_data.h | 1 | ||||
-rw-r--r-- | network_server.c | 47 | ||||
-rw-r--r-- | openttd.c | 2 | ||||
-rw-r--r-- | saveload.c | 2 | ||||
-rw-r--r-- | settings.c | 47 | ||||
-rw-r--r-- | settings_gui.c | 4 |
9 files changed, 49 insertions, 95 deletions
diff --git a/functions.h b/functions.h index f33f0ce2c..a1895cd6e 100644 --- a/functions.h +++ b/functions.h @@ -227,6 +227,7 @@ void ShowEndGameChart(void); TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng); void AfterLoadTown(void); +void UpdatePatches(void); void GenRandomNewGame(uint32 rnd1, uint32 rnd2); void StartScenarioEditor(uint32 rnd1, uint32 rnd2); void AskExitGame(void); @@ -191,6 +191,8 @@ void GenerateWorld(int mode, uint size_x, uint size_y) // Make sure everything is done via OWNER_NONE _current_player = OWNER_NONE; + UpdatePatches(); + _generating_world = true; InitializeGame(mode == GW_RANDOM ? 0 : IG_DATE_RESET, size_x, size_y); SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); diff --git a/network_client.c b/network_client.c index 83a20de5b..f78a7ff17 100644 --- a/network_client.c +++ b/network_client.c @@ -16,7 +16,6 @@ #include "command.h" #include "gfx.h" #include "window.h" -#include "settings.h" #include "console.h" #include "variables.h" #include "ai/ai.h" @@ -32,8 +31,6 @@ extern const char _openttd_revision[]; static uint32 last_ack_frame; -static void NetworkRecvPatchSettings(NetworkClientState* cs, Packet* p); - // ********** // Sending functions // DEF_CLIENT_SEND_COMMAND has no parameters @@ -504,10 +501,6 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); } - if (maptype == MAP_PACKET_PATCH) { - NetworkRecvPatchSettings(MY_CLIENT, p); - } - // Check if this was the last packet if (maptype == MAP_PACKET_END) { fclose(file_pointer); @@ -826,37 +819,6 @@ static NetworkClientPacket* const _network_client_packet[] = { // If this fails, check the array above with network_data.h assert_compile(lengthof(_network_client_packet) == PACKET_END); -extern const SettingDesc _patch_settings[]; - -// This is a TEMPORARY solution to get the patch-settings -// to the client. When the patch-settings are saved in the savegame -// this should be removed!! -static void NetworkRecvPatchSettings(NetworkClientState* cs, Packet* p) -{ - const SettingDesc *item; - - item = _patch_settings; - - for (; item->save.cmd != SL_END; item++) { - void *var = ini_get_variable(&item->save, &_patches); - switch (GetVarMemType(item->save.conv)) { - case SLE_VAR_BL: - case SLE_VAR_I8: - case SLE_VAR_U8: - *(uint8 *)(var) = NetworkRecv_uint8(cs, p); - break; - case SLE_VAR_I16: - case SLE_VAR_U16: - *(uint16 *)(var) = NetworkRecv_uint16(cs, p); - break; - case SLE_VAR_I32: - case SLE_VAR_U32: - *(uint32 *)(var) = NetworkRecv_uint32(cs, p); - break; - } - } -} - // Is called after a client is connected to the server void NetworkClient_Connected(void) { diff --git a/network_data.h b/network_data.h index b8f6a0eef..c2dbdc4b8 100644 --- a/network_data.h +++ b/network_data.h @@ -58,7 +58,6 @@ typedef enum { typedef enum { MAP_PACKET_START, MAP_PACKET_NORMAL, - MAP_PACKET_PATCH, MAP_PACKET_END, } MapPacket; diff --git a/network_server.c b/network_server.c index 2c863587d..bd3a620ad 100644 --- a/network_server.c +++ b/network_server.c @@ -19,14 +19,11 @@ #include "saveload.h" #include "vehicle.h" #include "station.h" -#include "settings.h" #include "variables.h" // This file handles all the server-commands static void NetworkHandleCommandQueue(NetworkClientState* cs); -static void NetworkSendPatchSettings(NetworkClientState* cs); - void NetworkPopulateCompanyInfo(void); // Is the network enabled? @@ -322,12 +319,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MAP) NetworkSend_Packet(p, cs); if (feof(file_pointer)) { // Done reading! - Packet *p; - - // XXX - Delete this when patch-settings are saved in-game - NetworkSendPatchSettings(cs); - - p = NetworkSend_Init(PACKET_SERVER_MAP); + Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); NetworkSend_uint8(p, MAP_PACKET_END); NetworkSend_Packet(p, cs); @@ -1187,43 +1179,6 @@ static NetworkServerPacket* const _network_server_packet[] = { // If this fails, check the array above with network_data.h assert_compile(lengthof(_network_server_packet) == PACKET_END); - -extern const SettingDesc _patch_settings[]; - -// This is a TEMPORARY solution to get the patch-settings -// to the client. When the patch-settings are saved in the savegame -// this should be removed!! -static void NetworkSendPatchSettings(NetworkClientState* cs) -{ - const SettingDesc *item; - Packet *p = NetworkSend_Init(PACKET_SERVER_MAP); - NetworkSend_uint8(p, MAP_PACKET_PATCH); - // Now send all the patch-settings in a pretty order.. - - item = _patch_settings; - - for (; item->save.cmd != SL_END; item++) { - const void *var = ini_get_variable(&item->save, &_patches); - switch (GetVarMemType(item->save.conv)) { - case SLE_VAR_BL: - case SLE_VAR_I8: - case SLE_VAR_U8: - NetworkSend_uint8(p, *(uint8 *)var); - break; - case SLE_VAR_I16: - case SLE_VAR_U16: - NetworkSend_uint16(p, *(uint16 *)var); - break; - case SLE_VAR_I32: - case SLE_VAR_U32: - NetworkSend_uint32(p, *(uint32 *)var); - break; - } - } - - NetworkSend_Packet(p, cs); -} - // This update the company_info-stuff void NetworkPopulateCompanyInfo(void) { @@ -1312,6 +1312,8 @@ bool AfterLoadGame(void) } END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0); } + if (CheckSavegameVersion(22)) UpdatePatches(); + FOR_ALL_PLAYERS(p) p->avail_railtypes = GetPlayerRailtypes(p->index); return true; diff --git a/saveload.c b/saveload.c index 206b6f9c1..1bbd79913 100644 --- a/saveload.c +++ b/saveload.c @@ -29,7 +29,7 @@ #include "variables.h" #include <setjmp.h> -const uint16 SAVEGAME_VERSION = 21; +const uint16 SAVEGAME_VERSION = 22; uint16 _sl_version; /// the major savegame version identifier byte _sl_minor_version; /// the minor savegame version, DO NOT USE! diff --git a/settings.c b/settings.c index e8942abd1..853ba7b9d 100644 --- a/settings.c +++ b/settings.c @@ -15,6 +15,9 @@ #include "console.h" #include "saveload.h" +/** The patch values that are used for new games and/or modified in config file */ +Patches _patches_newgame; + typedef struct IniFile IniFile; typedef struct IniItem IniItem; typedef struct IniGroup IniGroup; @@ -1229,7 +1232,7 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP #endif /* WIN32 */ proc(ini, _gameopt_settings, "gameopt", &_opt_newgame); - proc(ini, _patch_settings, "patches", &_patches); + proc(ini, _patch_settings, "patches", &_patches_newgame); proc(ini, _currency_settings,"currency", &_custom_currency); #ifdef ENABLE_NETWORK @@ -1276,7 +1279,7 @@ int32 CmdChangePatchSetting(int x, int y, uint32 flags, uint32 p1, uint32 p2) if (sd == NULL) return CMD_ERROR; if (flags & DC_EXEC) { - Patches *patches_ptr = &_patches; + Patches *patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches; void *var = ini_get_variable(&sd->save, patches_ptr); Write_ValidateSetting(var, sd, (int32)p2); @@ -1303,6 +1306,11 @@ void SetPatchValue(uint index, const Patches *object, int32 value) if (sd->save.conv & SLF_NETWORK_NO) { void *var = ini_get_variable(&sd->save, object); Write_ValidateSetting(var, sd, value); + + if (_game_mode != GM_MENU) { + void *var2 = ini_get_variable(&sd->save, &_patches_newgame); + Write_ValidateSetting(var2, sd, value); + } } else { DoCommandP(0, index, value, NULL, CMD_CHANGE_PATCH_SETTING); } @@ -1336,7 +1344,7 @@ void IConsoleSetPatchSetting(const char *name, const char *value) } sscanf(value, "%d", &val); - patches_ptr = &_patches; + patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches; ptr = ini_get_variable(&sd->save, patches_ptr); SetPatchValue(index, patches_ptr, val); @@ -1362,7 +1370,7 @@ void IConsoleGetPatchSetting(const char *name) return; } - ptr = ini_get_variable(&sd->save, &_patches); + ptr = ini_get_variable(&sd->save, (_game_mode == GM_MENU) ? &_patches_newgame : &_patches); if (sd->desc.cmd == SDT_BOOLX) { snprintf(value, sizeof(value), (*(bool*)ptr == 1) ? "on" : "off"); @@ -1439,6 +1447,20 @@ static void Save_OPTS(void) SaveSettings(_gameopt_settings, &_opt); } +static void Load_PATS(void) +{ + /* Copy over default setting since some might not get loaded in + * a networking environment. This ensures for example that the local + * signal_side stays when joining a network-server */ + _patches = _patches_newgame; + LoadSettings(_patch_settings, &_patches); +} + +static void Save_PATS(void) +{ + SaveSettings(_patch_settings, &_patches); +} + void CheckConfig(void) { // fix up news_display_opt from old to new @@ -1453,12 +1475,21 @@ void CheckConfig(void) // Increase old default values for pf_maxdepth and pf_maxlength // to support big networks. - if (_patches.pf_maxdepth == 16 && _patches.pf_maxlength == 512) { - _patches.pf_maxdepth = 48; - _patches.pf_maxlength = 4096; + if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) { + _patches_newgame.pf_maxdepth = 48; + _patches_newgame.pf_maxlength = 4096; } } +void UpdatePatches(void) +{ + /* Since old(er) savegames don't have any patches saved, we initialise + * them with the default values just as it was in the old days. + * Also new games need this copying-over */ + _patches = _patches_newgame; /* backwards compatibility */ +} + const ChunkHandler _setting_chunk_handlers[] = { - { 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF | CH_LAST} + { 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF}, + { 'PATS', Save_PATS, Load_PATS, CH_RIFF | CH_LAST}, }; diff --git a/settings_gui.c b/settings_gui.c index 09196ff76..a452c26b4 100644 --- a/settings_gui.c +++ b/settings_gui.c @@ -673,6 +673,8 @@ static const PatchPage _patches_page[] = { {_patches_ai, lengthof(_patches_ai)}, }; +extern Patches _patches_newgame; + /** The main patches window. Shows a number of categories on top and * a selection of patches in that category. * Uses WP(w, def_d) macro - data_1, data_2, data_3 */ @@ -682,7 +684,7 @@ static void PatchesSelectionWndProc(Window *w, WindowEvent *e) switch (e->event) { case WE_CREATE: - patches_ptr = &_patches; + patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches; break; case WE_PAINT: { |