Changeset - r10066:d73a08a8dd72
[Not reviewed]
master
0 7 0
rubidium - 16 years ago 2008-09-03 07:51:07
rubidium@openttd.org
(svn r14233) -Feature/Fix [FS#2172]: save the palette of the loaded NewGRFs in the savegame, so joining with a server using Windows palette will make a client with the DOS palette do palette conversion and (thus) not cause a desync due to the different palettes disabling different NewGRFs.
7 files changed with 39 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/gfxinit.cpp
Show inline comments
 
@@ -296,17 +296,17 @@ static void LoadSpriteTables()
 
	 * so we have to manually add it, and then remove it later.
 
	 */
 
	GRFConfig *top = _grfconfig;
 
	GRFConfig *master = CallocT<GRFConfig>(1);
 
	master->filename = strdup(_used_graphics_set->files[GFT_EXTRA].filename);
 
	FillGRFDetails(master, false);
 
	master->windows_paletted = (_used_graphics_set->palette == PAL_WINDOWS);
 
	ClrBit(master->flags, GCF_INIT_ONLY);
 
	master->next = top;
 
	_grfconfig = master;
 

	
 
	_palette_remap_grf[i] = (_use_palette != _used_graphics_set->palette);
 
	LoadNewGRF(SPR_NEWGRFS_BASE, i);
 

	
 
	/* Free and remove the top element. */
 
	ClearGRFConfig(&master);
 
	_grfconfig = top;
 
}
src/lang/english.txt
Show inline comments
 
@@ -3191,16 +3191,19 @@ STR_PERFORMANCE_DETAIL_MONEY_TIP        
 
STR_PERFORMANCE_DETAIL_LOAN_TIP                                 :{BLACK}The amount of money this company has taken on loan
 
STR_PERFORMANCE_DETAIL_TOTAL_TIP                                :{BLACK}Total points out of possible points
 

	
 
STR_NEWGRF_SETTINGS_BUTTON                                      :{BLACK}NewGRF Settings
 
STR_NEWGRF_SETTINGS_CAPTION                                     :{WHITE}NewGRF settings
 
STR_NEWGRF_APPLY_CHANGES                                        :{BLACK}Apply changes
 
STR_NEWGRF_TOGGLE_PALETTE                                       :{BLACK}Toggle palette
 
STR_NEWGRF_TOGGLE_PALETTE_TIP                                   :{BLACK}Toggle the palette of the selected NewGRF.{}Do this when the graphics from this NewGRF look pink in-game
 
STR_NEWGRF_SET_PARAMETERS                                       :{BLACK}Set parameters
 
STR_NEWGRF_TIP                                                  :{BLACK}A list of all the Newgrf sets that you have installed. Click a set to change the settings
 
STR_NEWGRF_NO_FILES_INSTALLED                                   :{BLACK}There are currently no newgrf files installed! Please refer to the manual for instructions on installing new graphics
 
STR_NEWGRF_FILENAME                                             :{BLACK}Filename: {SILVER}{RAW_STRING}
 
STR_NEWGRF_PALETTE                                              :{BLACK}Palette: {SILVER}{RAW_STRING}
 
STR_NEWGRF_GRF_ID                                               :{BLACK}GRF ID: {SILVER}{RAW_STRING}
 
STR_NEWGRF_MD5SUM                                               :{BLACK}MD5sum: {SILVER}{RAW_STRING}
 
STR_NEWGRF_CONFIRMATION_TEXT                                    :{YELLOW}You are about to make changes to a running game; this can crash OpenTTD.{}Are you absolutely sure about this?
 

	
 
STR_NEWGRF_ERROR_MSG_INFO                                       :{SILVER}{RAW_STRING}
 
STR_NEWGRF_ERROR_MSG_WARNING                                    :{RED}Warning: {SILVER}{RAW_STRING}
src/newgrf.cpp
Show inline comments
 
@@ -3641,17 +3641,13 @@ bool GetGlobalVariable(byte param, uint3
 
			uint build    = 1382;
 
			*value = (major << 24) | (minor << 20) | (revision << 16) | build;
 
			return true;
 
		}
 

	
 
		case 0x0D: // TTD Version, 00=DOS, 01=Windows
 
			if (_palette_remap_grf[_file_index]) {
 
				*value = !_use_palette;
 
			} else {
 
				*value = _use_palette;
 
			}
 
			*value = _cur_grfconfig->windows_paletted;
 
			return true;
 

	
 
		case 0x0E: // Y-offset for train sprites
 
			*value = _traininfo_vehicle_pitch;
 
			return true;
 

	
 
@@ -4097,13 +4093,13 @@ static void GRFInfo(byte *buf, size_t le
 

	
 
	_cur_grffile->grfid = grfid;
 
	_cur_grffile->grf_version = version;
 
	_cur_grfconfig->status = _cur_stage < GLS_RESERVE ? GCS_INITIALISED : GCS_ACTIVATED;
 

	
 
	/* Do swap the GRFID for displaying purposes since people expect that */
 
	DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name);
 
	DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s (palette: %s)", version, BSWAP32(grfid), name, _cur_grfconfig->windows_paletted ? "Windows" : "DOS");
 
}
 

	
 
/* Action 0x0A */
 
static void SpriteReplace(byte *buf, size_t len)
 
{
 
	/* <0A> <num-sets> <set1> [<set2> ...]
 
@@ -5891,12 +5887,13 @@ void LoadNewGRFFile(GRFConfig *config, u
 
		config->error->message  = STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED;
 
		return;
 
	}
 

	
 
	FioOpenFile(file_index, filename);
 
	_file_index = file_index; // XXX
 
	_palette_remap_grf[_file_index] = (config->windows_paletted != (_use_palette == PAL_WINDOWS));
 

	
 
	_cur_grfconfig = config;
 

	
 
	DEBUG(grf, 2, "LoadNewGRFFile: Reading NewGRF-file '%s'", filename);
 

	
 
	/* Skip the first sprite; we don't care about how many sprites this
src/newgrf_config.cpp
Show inline comments
 
@@ -11,12 +11,13 @@
 
#include "newgrf.h"
 
#include "newgrf_config.h"
 
#include "core/alloc_func.hpp"
 
#include "string_func.h"
 
#include "gamelog.h"
 
#include "network/network_type.h"
 
#include "gfx_func.h"
 

	
 
#include "fileio_func.h"
 
#include "fios.h"
 

	
 

	
 
GRFConfig *_all_grfs;
 
@@ -69,12 +70,14 @@ bool FillGRFDetails(GRFConfig *config, b
 
		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
 

	
 
		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
 
		if (HasBit(config->flags, GCF_UNSAFE)) return false;
 
	}
 

	
 
	config->windows_paletted = (_use_palette == PAL_WINDOWS);
 

	
 
	return CalcGRFMD5Sum(config);
 
}
 

	
 

	
 
void ClearGRFConfig(GRFConfig **config)
 
{
 
@@ -478,17 +481,18 @@ bool GRFConfig::IsOpenTTDBaseGRF() const
 
{
 
	return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
 
}
 

	
 

	
 
static const SaveLoad _grfconfig_desc[] = {
 
	SLE_STR(GRFConfig, filename,   SLE_STR, 0x40),
 
	SLE_VAR(GRFConfig, grfid,      SLE_UINT32),
 
	SLE_ARR(GRFConfig, md5sum,     SLE_UINT8, 16),
 
	SLE_ARR(GRFConfig, param,      SLE_UINT32, 0x80),
 
	SLE_VAR(GRFConfig, num_params, SLE_UINT8),
 
	    SLE_STR(GRFConfig, filename,         SLE_STR,    0x40),
 
	    SLE_VAR(GRFConfig, grfid,            SLE_UINT32),
 
	    SLE_ARR(GRFConfig, md5sum,           SLE_UINT8,  16),
 
	    SLE_ARR(GRFConfig, param,            SLE_UINT32, 0x80),
 
	    SLE_VAR(GRFConfig, num_params,       SLE_UINT8),
 
	SLE_CONDVAR(GRFConfig, windows_paletted, SLE_BOOL,   101, SL_MAX_VERSION),
 
	SLE_END()
 
};
 

	
 

	
 
static void Save_NGRF()
 
{
 
@@ -505,12 +509,13 @@ static void Save_NGRF()
 
static void Load_NGRF()
 
{
 
	ClearGRFConfigList(&_grfconfig);
 
	while (SlIterateArray() != -1) {
 
		GRFConfig *c = CallocT<GRFConfig>(1);
 
		SlObject(c, _grfconfig_desc);
 
		if (CheckSavegameVersion(101)) c->windows_paletted = (_use_palette == PAL_WINDOWS);
 
		AppendToGRFConfigList(&_grfconfig, c);
 
	}
 

	
 
	/* Append static NewGRF configuration */
 
	AppendStaticGRFConfigs(&_grfconfig);
 
}
src/newgrf_config.h
Show inline comments
 
@@ -65,12 +65,13 @@ struct GRFConfig : public GRFIdentifier 
 

	
 
	uint8 flags;        ///< NOSAVE: GCF_Flags, bitset
 
	GRFStatus status;   ///< NOSAVE: GRFStatus, enum
 
	uint32 grf_bugs;    ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
 
	uint32 param[0x80]; ///< GRF parameters
 
	uint8 num_params;   ///< Number of used parameters
 
	bool windows_paletted;  ///< Whether the NewGRF is Windows paletted or not
 

	
 
	struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
 

	
 
	bool IsOpenTTDBaseGRF() const;
 
};
 

	
src/newgrf_gui.cpp
Show inline comments
 
@@ -97,12 +97,16 @@ static void ShowNewGRFInfo(const GRFConf
 
		} else {
 
			SetDParam(0, STR_01A9_NONE);
 
		}
 
		y += DrawStringMultiLine(x, y, STR_NEWGRF_PARAMETER, w, bottom - y);
 
	}
 

	
 
	/* Draw the palette of the NewGRF */
 
	SetDParamStr(0, c->windows_paletted ? "Windows" : "DOS");
 
	y += DrawStringMultiLine(x, y, STR_NEWGRF_PALETTE, w, bottom - y);
 

	
 
	/* Show flags */
 
	if (c->status == GCS_NOT_FOUND)        y += DrawStringMultiLine(x, y, STR_NEWGRF_NOT_FOUND, w, bottom - y);
 
	if (c->status == GCS_DISABLED)         y += DrawStringMultiLine(x, y, STR_NEWGRF_DISABLED, w, bottom - y);
 
	if (HasBit(c->flags, GCF_COMPATIBLE)) y += DrawStringMultiLine(x, y, STR_NEWGRF_COMPATIBLE_LOADED, w, bottom - y);
 

	
 
	/* Draw GRF info if it exists */
 
@@ -298,12 +302,13 @@ struct NewGRFWindow : public Window {
 
		SNGRFS_MOVE_UP,
 
		SNGRFS_MOVE_DOWN,
 
		SNGRFS_FILE_LIST,
 
		SNGRFS_SCROLLBAR,
 
		SNGRFS_NEWGRF_INFO,
 
		SNGRFS_SET_PARAMETERS,
 
		SNGRFS_TOGGLE_PALETTE,
 
		SNGRFS_APPLY_CHANGES,
 
		SNGRFS_RESIZE,
 
	};
 

	
 
	GRFConfig **orig_list; ///< grf list the window is shown with
 
	GRFConfig *list;       ///< temporary grf list to which changes are made
 
@@ -356,12 +361,13 @@ struct NewGRFWindow : public Window {
 
		SetVScrollCount(this, i);
 

	
 
		this->SetWidgetsDisabledState(!this->editable,
 
			SNGRFS_PRESET_LIST,
 
			SNGRFS_ADD,
 
			SNGRFS_APPLY_CHANGES,
 
			SNGRFS_TOGGLE_PALETTE,
 
			WIDGET_LIST_END
 
		);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
@@ -568,12 +574,20 @@ struct NewGRFWindow : public Window {
 
				static char buff[512];
 
				GRFBuildParamList(buff, this->sel, lastof(buff));
 
				SetDParamStr(0, buff);
 
				ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL);
 
				break;
 
			}
 

	
 
			case SNGRFS_TOGGLE_PALETTE: {
 
				if (this->sel != NULL) {
 
					this->sel->windows_paletted ^= true;
 
					this->SetDirty();
 
				}
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		if (index == -1) {
 
@@ -662,22 +676,23 @@ static const Widget _newgrf_widgets[] = 
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW,  10,  79,  32,  43, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW,  80, 149,  32,  43, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  COLOUR_YELLOW, 150, 219,  32,  43, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
 
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  COLOUR_YELLOW, 220, 289,  32,  43, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
 
{     WWT_MATRIX,    RESIZE_RB,  COLOUR_MAUVE,    0, 287,  46, 115, 0x501,                       STR_NEWGRF_FILE_TIP },              // SNGRFS_FILE_LIST
 
{  WWT_SCROLLBAR,   RESIZE_LRB,  COLOUR_MAUVE,  288, 299,  46, 115, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
 
{      WWT_PANEL,   RESIZE_RTB,  COLOUR_MAUVE,    0, 299, 116, 228, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
 
{ WWT_PUSHTXTBTN,    RESIZE_TB,  COLOUR_MAUVE,    0, 143, 229, 240, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
 
{ WWT_PUSHTXTBTN,   RESIZE_RTB,  COLOUR_MAUVE,  144, 287, 229, 240, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
 
{  WWT_RESIZEBOX,  RESIZE_LRTB,  COLOUR_MAUVE,  288, 299, 229, 240, 0x0,                         STR_RESIZE_BUTTON },                // SNGRFS_RESIZE
 
{      WWT_PANEL,   RESIZE_RTB,  COLOUR_MAUVE,    0, 299, 116, 238, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
 
{ WWT_PUSHTXTBTN,    RESIZE_TB,  COLOUR_MAUVE,    0,  95, 239, 250, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
 
{ WWT_PUSHTXTBTN,   RESIZE_RTB,  COLOUR_MAUVE,   96, 191, 239, 250, STR_NEWGRF_TOGGLE_PALETTE,   STR_NEWGRF_TOGGLE_PALETTE_TIP },    // SNGRFS_TOGGLE_PALETTE
 
{ WWT_PUSHTXTBTN,   RESIZE_RTB,  COLOUR_MAUVE,  192, 287, 239, 250, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
 
{  WWT_RESIZEBOX,  RESIZE_LRTB,  COLOUR_MAUVE,  288, 299, 239, 250, 0x0,                         STR_RESIZE_BUTTON },                // SNGRFS_RESIZE
 
{ WIDGETS_END },
 
};
 

	
 
/* Window definition of the manage newgrfs window */
 
static const WindowDesc _newgrf_desc = {
 
	WDP_CENTER, WDP_CENTER, 300, 241, 300, 241,
 
	WDP_CENTER, WDP_CENTER, 300, 251, 300, 251,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	_newgrf_widgets,
 
};
 

	
 
/** Callback function for the newgrf 'apply changes' confirmation window
src/saveload.cpp
Show inline comments
 
@@ -34,13 +34,13 @@
 
#include "fileio_func.h"
 
#include <list>
 
#include "gamelog.h"
 

	
 
#include "table/strings.h"
 

	
 
extern const uint16 SAVEGAME_VERSION = 100;
 
extern const uint16 SAVEGAME_VERSION = 101;
 

	
 
SavegameType _savegame_type; ///< type of savegame we are loading
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
0 comments (0 inline, 0 general)