Changeset - r15874:dfd0ea646f2d
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-08-19 19:23:38
rubidium@openttd.org
(svn r20566) -Feature: happy smiles on the faces of Ammler and planetmaker
4 files changed with 81 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -2428,48 +2428,49 @@ STR_SPRITE_ALIGNER_PICKER_TOOLTIP       
 
STR_SPRITE_ALIGNER_GOTO_CAPTION                                 :{WHITE}Go to sprite
 

	
 
# NewGRF (self) generated warnings/errors
 
STR_NEWGRF_ERROR_MSG_INFO                                       :{SILVER}{RAW_STRING}
 
STR_NEWGRF_ERROR_MSG_WARNING                                    :{RED}Warning: {SILVER}{RAW_STRING}
 
STR_NEWGRF_ERROR_MSG_ERROR                                      :{RED}Error: {SILVER}{RAW_STRING}
 
STR_NEWGRF_ERROR_MSG_FATAL                                      :{RED}Fatal: {SILVER}{RAW_STRING}
 
STR_NEWGRF_ERROR_FATAL_POPUP                                    :{WHITE}A fatal NewGRF error has occurred: {}{STRING5}
 
STR_NEWGRF_ERROR_VERSION_NUMBER                                 :{1:STRING1} will not work with the TTDPatch version reported by OpenTTD.
 
STR_NEWGRF_ERROR_DOS_OR_WINDOWS                                 :{1:STRING1} is for the {STRING1} version of TTD.
 
STR_NEWGRF_ERROR_UNSET_SWITCH                                   :{1:STRING1} is designed to be used with {STRING1}
 
STR_NEWGRF_ERROR_INVALID_PARAMETER                              :Invalid parameter for {1:STRING1}: parameter {STRING1} ({NUM})
 
STR_NEWGRF_ERROR_LOAD_BEFORE                                    :{1:STRING1} must be loaded before {STRING1}.
 
STR_NEWGRF_ERROR_LOAD_AFTER                                     :{1:STRING1} must be loaded after {STRING1}.
 
STR_NEWGRF_ERROR_OTTD_VERSION_NUMBER                            :{1:STRING1} requires OpenTTD version {STRING1} or better.
 
STR_NEWGRF_ERROR_AFTER_TRANSLATED_FILE                          :the GRF file it was designed to translate
 
STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED                        :Too many NewGRFs are loaded.
 
STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC                       :Loading {RAW_STRING} as static NewGRF with {RAW_STRING} could cause desyncs.
 
STR_NEWGRF_ERROR_UNEXPECTED_SPRITE                              :Unexpected sprite.
 
STR_NEWGRF_ERROR_UNKNOWN_PROPERTY                               :Unknown Action 0 property.
 
STR_NEWGRF_ERROR_INVALID_ID                                     :Attempt to use invalid ID.
 
STR_NEWGRF_ERROR_CORRUPT_SPRITE                                 :{YELLOW}{RAW_STRING} contains a corrupt sprite. All corrupt sprites will be shown as a red question mark (?).
 
STR_NEWGRF_ERROR_MULTIPLE_ACTION_8                              :Contains multiple Action 8 entries.
 
STR_NEWGRF_ERROR_READ_BOUNDS                                    :Read past end of pseudo-sprite.
 
STR_NEWGRF_ERROR_MISSING_SPRITES                                :{WHITE}The currently used base graphics set is missing a number of sprites.{}Please update the base graphics set.
 

	
 
# NewGRF related 'general' warnings
 
STR_NEWGRF_POPUP_CAUTION_CAPTION                                :{WHITE}Caution!
 
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_DUPLICATE_GRFID                                      :{WHITE}Can't add file: duplicate GRF ID
 
STR_NEWGRF_COMPATIBLE_LOADED                                    :{ORANGE}Matching file not found (compatible GRF loaded)
 

	
 
STR_NEWGRF_COMPATIBLE_LOAD_WARNING                              :{WHITE}Compatible GRF(s) loaded for missing files
 
STR_NEWGRF_DISABLED_WARNING                                     :{WHITE}Missing GRF file(s) have been disabled
 
STR_NEWGRF_UNPAUSE_WARNING_TITLE                                :{YELLOW}Missing GRF file(s)
 
STR_NEWGRF_UNPAUSE_WARNING                                      :{WHITE}Unpausing can crash OpenTTD. Do not file bug reports for subsequent crashes.{}Do you really want to unpause?
 

	
 
# NewGRF status
 
STR_NEWGRF_LIST_NONE                                            :None
 
STR_NEWGRF_LIST_ALL_FOUND                                       :All files present
 
STR_NEWGRF_LIST_COMPATIBLE                                      :{YELLOW}Found compatible files
 
STR_NEWGRF_LIST_MISSING                                         :{RED}Missing files
 

	
 
# NewGRF 'it's broken' warnings
 
STR_NEWGRF_BROKEN                                               :{WHITE}Behaviour of NewGRF '{0:RAW_STRING}' is likely to cause desyncs and/or crashes.
 
STR_NEWGRF_BROKEN_POWERED_WAGON                                 :{WHITE}It changed powered-wagon state for '{1:ENGINE}' when not inside a depot.
 
STR_NEWGRF_BROKEN_VEHICLE_LENGTH                                :{WHITE}It changed vehicle length for '{1:ENGINE}' when not inside a depot.
 
STR_BROKEN_VEHICLE_LENGTH                                       :{WHITE}Train '{VEHICLE}' belonging to '{COMPANY}' has invalid length. It is probably caused by problems with NewGRFs. Game may desync or crash.
src/newgrf.cpp
Show inline comments
 
@@ -27,48 +27,49 @@
 
#include "newgrf.h"
 
#include "newgrf_cargo.h"
 
#include "newgrf_house.h"
 
#include "newgrf_sound.h"
 
#include "newgrf_station.h"
 
#include "industry.h"
 
#include "newgrf_canal.h"
 
#include "newgrf_commons.h"
 
#include "newgrf_townname.h"
 
#include "newgrf_industries.h"
 
#include "newgrf_airporttiles.h"
 
#include "newgrf_airport.h"
 
#include "rev.h"
 
#include "fios.h"
 
#include "rail.h"
 
#include "strings_func.h"
 
#include "date_func.h"
 
#include "string_func.h"
 
#include "network/network.h"
 
#include <map>
 
#include "core/alloc_type.hpp"
 
#include "core/mem_func.hpp"
 
#include "smallmap_gui.h"
 
#include "genworld.h"
 
#include "gui.h"
 

	
 
#include "table/strings.h"
 
#include "table/build_industry.h"
 

	
 
/* TTDPatch extended GRF format codec
 
 * (c) Petr Baudis 2004 (GPL'd)
 
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
 
 *
 
 * Contains portions of documentation by TTDPatch team.
 
 * Thanks especially to Josef Drexler for the documentation as well as a lot
 
 * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
 
 * served as subject to the initial testing of this codec. */
 

	
 

	
 
static int _skip_sprites; // XXX
 
static uint _file_index; // XXX
 

	
 
static SmallVector<GRFFile *, 16> _grf_files;
 

	
 
static GRFFile *_cur_grffile;
 
static SpriteID _cur_spriteid;
 
static GrfLoadingStage _cur_stage;
 
static uint32 _nfo_line;
 

	
 
@@ -4328,174 +4329,207 @@ static void FeatureNewName(ByteReader *b
 
 * @param max_sprites the maximum number of sprites that can be loaded in this action 5.
 
 * @param name        used for error warnings.
 
 * @return the number of sprites that is going to be skipped
 
 */
 
static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites, const char *name)
 
{
 

	
 
	if (offset >= max_sprites) {
 
		grfmsg(1, "GraphicsNew: %s sprite offset must be less than %i, skipping", name, max_sprites);
 
		uint orig_num = num;
 
		num = 0;
 
		return orig_num;
 
	}
 

	
 
	if (offset + num > max_sprites) {
 
		grfmsg(4, "GraphicsNew: %s sprite overflow, truncating...", name);
 
		uint orig_num = num;
 
		num = max(max_sprites - offset, 0);
 
		return orig_num - num;
 
	}
 

	
 
	return 0;
 
}
 

	
 

	
 
/** The type of action 5 type. */
 
enum Action5BlockType {
 
	A5BLOCK_FIXED,                ///< Only allow replacing a whole block of sprites. (TTDP compatible)
 
	A5BLOCK_ALLOW_OFFSET,         ///< Allow replacing any subset by specifiing an offset.
 
	A5BLOCK_INVALID,              ///< unknown/not-implemented type
 
};
 
/** Information about a single action 5 type. */
 
struct Action5Type {
 
	Action5BlockType block_type;  ///< How is this Action5 type processed?
 
	SpriteID sprite_base;         ///< Load the sprites starting from this sprite.
 
	uint16 min_sprites;           ///< If the Action5 contains less sprites, the whole block will be ignored.
 
	uint16 max_sprites;           ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used.
 
	const char *name;             ///< Name for error messages.
 
};
 

	
 
/** The information about action 5 types. */
 
static const Action5Type _action5_types[] = {
 
	/* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */
 
	/* 0x00 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x00"             },
 
	/* 0x01 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x01"             },
 
	/* 0x02 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x02"             },
 
	/* 0x03 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x03"             },
 
	/* 0x04 */ { A5BLOCK_FIXED,        SPR_SIGNALS_BASE,            48, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    "Signal graphics"       },
 
	/* 0x05 */ { A5BLOCK_FIXED,        SPR_ELRAIL_BASE,             48, ELRAIL_SPRITE_COUNT,                         "Catenary graphics"     },
 
	/* 0x06 */ { A5BLOCK_FIXED,        SPR_SLOPES_BASE,             74, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics"   },
 
	/* 0x07 */ { A5BLOCK_INVALID,      0,                           75, 0,                                           "TTDP GUI graphics"     }, // Not used by OTTD.
 
	/* 0x08 */ { A5BLOCK_FIXED,        SPR_CANALS_BASE,             65, CANALS_SPRITE_COUNT,                         "Canal graphics"        },
 
	/* 0x09 */ { A5BLOCK_FIXED,        SPR_ONEWAY_BASE,              6, ONEWAY_SPRITE_COUNT,                         "One way road graphics" },
 
	/* 0x0A */ { A5BLOCK_FIXED,        SPR_2CCMAP_BASE,            256, TWOCCMAP_SPRITE_COUNT,                       "2CC colour maps"       },
 
	/* 0x0B */ { A5BLOCK_FIXED,        SPR_TRAMWAY_BASE,           113, TRAMWAY_SPRITE_COUNT,                        "Tramway graphics"      },
 
	/* 0x0C */ { A5BLOCK_INVALID,      0,                          133, 0,                                           "Snowy temperate tree"  }, // Not yet used by OTTD.
 
	/* 0x0D */ { A5BLOCK_FIXED,        SPR_SHORE_BASE,              16, SPR_SHORE_SPRITE_COUNT,                      "Shore graphics"        },
 
	/* 0x0E */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "New Signals graphics"  }, // Not yet used by OTTD.
 
	/* 0x0F */ { A5BLOCK_FIXED,        SPR_TRACKS_FOR_SLOPES_BASE,  12, TRACKS_FOR_SLOPES_SPRITE_COUNT,              "Sloped rail track"     },
 
	/* 0x10 */ { A5BLOCK_FIXED,        SPR_AIRPORTX_BASE,           15, AIRPORTX_SPRITE_COUNT,                       "Airport graphics"      },
 
	/* 0x11 */ { A5BLOCK_FIXED,        SPR_ROADSTOP_BASE,            8, ROADSTOP_SPRITE_COUNT,                       "Road stop graphics"    },
 
	/* 0x12 */ { A5BLOCK_FIXED,        SPR_AQUEDUCT_BASE,            8, AQUEDUCT_SPRITE_COUNT,                       "Aqueduct graphics"     },
 
	/* 0x13 */ { A5BLOCK_FIXED,        SPR_AUTORAIL_BASE,           55, AUTORAIL_SPRITE_COUNT,                       "Autorail graphics"     },
 
	/* 0x14 */ { A5BLOCK_ALLOW_OFFSET, SPR_FLAGS_BASE,               1, FLAGS_SPRITE_COUNT,                          "Flag graphics"         },
 
	/* 0x15 */ { A5BLOCK_ALLOW_OFFSET, SPR_OPENTTD_BASE,             1, OPENTTD_SPRITE_COUNT,                        "OpenTTD GUI graphics"  },
 
	/* 0x16 */ { A5BLOCK_ALLOW_OFFSET, SPR_AIRPORT_PREVIEW_BASE,     1, SPR_AIRPORT_PREVIEW_COUNT,                   "Airport preview graphics" },
 
};
 

	
 
/* Action 0x05 */
 
static void GraphicsNew(ByteReader *buf)
 
{
 
	/* <05> <graphics-type> <num-sprites> <other data...>
 
	 *
 
	 * B graphics-type What set of graphics the sprites define.
 
	 * E num-sprites   How many sprites are in this set?
 
	 * V other data    Graphics type specific data.  Currently unused. */
 
	/* TODO */
 

	
 
	enum Action5BlockType {
 
		A5BLOCK_FIXED,                ///< Only allow replacing a whole block of sprites. (TTDP compatible)
 
		A5BLOCK_ALLOW_OFFSET,         ///< Allow replacing any subset by specifiing an offset.
 
		A5BLOCK_INVALID,              ///< unknown/not-implemented type
 
	};
 
	struct Action5Type {
 
		Action5BlockType block_type;  ///< How is this Action5 type processed?
 
		SpriteID sprite_base;         ///< Load the sprites starting from this sprite.
 
		uint16 min_sprites;           ///< If the Action5 contains less sprites, the whole block will be ignored.
 
		uint16 max_sprites;           ///< If the Action5 contains more sprites, only the first max_sprites sprites will be used.
 
		const char *name;             ///< Name for error messages.
 
	};
 

	
 
	static const Action5Type action5_types[] = {
 
		/* Note: min_sprites should not be changed. Therefore these constants are directly here and not in sprites.h */
 
		/* 0x00 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x00"             },
 
		/* 0x01 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x01"             },
 
		/* 0x02 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x02"             },
 
		/* 0x03 */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "Type 0x03"             },
 
		/* 0x04 */ { A5BLOCK_FIXED,        SPR_SIGNALS_BASE,            48, PRESIGNAL_SEMAPHORE_AND_PBS_SPRITE_COUNT,    "Signal graphics"       },
 
		/* 0x05 */ { A5BLOCK_FIXED,        SPR_ELRAIL_BASE,             48, ELRAIL_SPRITE_COUNT,                         "Catenary graphics"     },
 
		/* 0x06 */ { A5BLOCK_FIXED,        SPR_SLOPES_BASE,             74, NORMAL_AND_HALFTILE_FOUNDATION_SPRITE_COUNT, "Foundation graphics"   },
 
		/* 0x07 */ { A5BLOCK_INVALID,      0,                           75, 0,                                           "TTDP GUI graphics"     }, // Not used by OTTD.
 
		/* 0x08 */ { A5BLOCK_FIXED,        SPR_CANALS_BASE,             65, CANALS_SPRITE_COUNT,                         "Canal graphics"        },
 
		/* 0x09 */ { A5BLOCK_FIXED,        SPR_ONEWAY_BASE,              6, ONEWAY_SPRITE_COUNT,                         "One way road graphics" },
 
		/* 0x0A */ { A5BLOCK_FIXED,        SPR_2CCMAP_BASE,            256, TWOCCMAP_SPRITE_COUNT,                       "2CC colour maps"       },
 
		/* 0x0B */ { A5BLOCK_FIXED,        SPR_TRAMWAY_BASE,           113, TRAMWAY_SPRITE_COUNT,                        "Tramway graphics"      },
 
		/* 0x0C */ { A5BLOCK_INVALID,      0,                          133, 0,                                           "Snowy temperate tree"  }, // Not yet used by OTTD.
 
		/* 0x0D */ { A5BLOCK_FIXED,        SPR_SHORE_BASE,              16, SPR_SHORE_SPRITE_COUNT,                      "Shore graphics"        },
 
		/* 0x0E */ { A5BLOCK_INVALID,      0,                            0, 0,                                           "New Signals graphics"  }, // Not yet used by OTTD.
 
		/* 0x0F */ { A5BLOCK_FIXED,        SPR_TRACKS_FOR_SLOPES_BASE,  12, TRACKS_FOR_SLOPES_SPRITE_COUNT,              "Sloped rail track"     },
 
		/* 0x10 */ { A5BLOCK_FIXED,        SPR_AIRPORTX_BASE,           15, AIRPORTX_SPRITE_COUNT,                       "Airport graphics"      },
 
		/* 0x11 */ { A5BLOCK_FIXED,        SPR_ROADSTOP_BASE,            8, ROADSTOP_SPRITE_COUNT,                       "Road stop graphics"    },
 
		/* 0x12 */ { A5BLOCK_FIXED,        SPR_AQUEDUCT_BASE,            8, AQUEDUCT_SPRITE_COUNT,                       "Aqueduct graphics"     },
 
		/* 0x13 */ { A5BLOCK_FIXED,        SPR_AUTORAIL_BASE,           55, AUTORAIL_SPRITE_COUNT,                       "Autorail graphics"     },
 
		/* 0x14 */ { A5BLOCK_ALLOW_OFFSET, SPR_FLAGS_BASE,               1, FLAGS_SPRITE_COUNT,                          "Flag graphics"         },
 
		/* 0x15 */ { A5BLOCK_ALLOW_OFFSET, SPR_OPENTTD_BASE,             1, OPENTTD_SPRITE_COUNT,                        "OpenTTD GUI graphics"  },
 
		/* 0x16 */ { A5BLOCK_ALLOW_OFFSET, SPR_AIRPORT_PREVIEW_BASE,     1, SPR_AIRPORT_PREVIEW_COUNT,                   "Airport preview graphics" },
 
	};
 

	
 
	uint8 type = buf->ReadByte();
 
	uint16 num = buf->ReadExtendedByte();
 
	uint16 offset = HasBit(type, 7) ? buf->ReadExtendedByte() : 0;
 
	ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
 

	
 
	if ((type == 0x0D) && (num == 10) && _cur_grffile->is_ottdfile) {
 
		/* Special not-TTDP-compatible case used in openttd(d/w).grf
 
		/* Special not-TTDP-compatible case used in openttd.grf
 
		 * Missing shore sprites and initialisation of SPR_SHORE_BASE */
 
		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from openttd(d/w).grf.");
 
		grfmsg(2, "GraphicsNew: Loading 10 missing shore sprites from extra grf.");
 
		LoadNextSprite(SPR_SHORE_BASE +  0, _file_index, _nfo_line++); // SLOPE_STEEP_S
 
		LoadNextSprite(SPR_SHORE_BASE +  5, _file_index, _nfo_line++); // SLOPE_STEEP_W
 
		LoadNextSprite(SPR_SHORE_BASE +  7, _file_index, _nfo_line++); // SLOPE_WSE
 
		LoadNextSprite(SPR_SHORE_BASE + 10, _file_index, _nfo_line++); // SLOPE_STEEP_N
 
		LoadNextSprite(SPR_SHORE_BASE + 11, _file_index, _nfo_line++); // SLOPE_NWS
 
		LoadNextSprite(SPR_SHORE_BASE + 13, _file_index, _nfo_line++); // SLOPE_ENW
 
		LoadNextSprite(SPR_SHORE_BASE + 14, _file_index, _nfo_line++); // SLOPE_SEN
 
		LoadNextSprite(SPR_SHORE_BASE + 15, _file_index, _nfo_line++); // SLOPE_STEEP_E
 
		LoadNextSprite(SPR_SHORE_BASE + 16, _file_index, _nfo_line++); // SLOPE_EW
 
		LoadNextSprite(SPR_SHORE_BASE + 17, _file_index, _nfo_line++); // SLOPE_NS
 
		if (_loaded_newgrf_features.shore == SHORE_REPLACE_NONE) _loaded_newgrf_features.shore = SHORE_REPLACE_ONLY_NEW;
 
		return;
 
	}
 

	
 
	/* Supported type? */
 
	if ((type >= lengthof(action5_types)) || (action5_types[type].block_type == A5BLOCK_INVALID)) {
 
	if ((type >= lengthof(_action5_types)) || (_action5_types[type].block_type == A5BLOCK_INVALID)) {
 
		grfmsg(2, "GraphicsNew: Custom graphics (type 0x%02X) sprite block of length %u (unimplemented, ignoring)", type, num);
 
		_skip_sprites = num;
 
		return;
 
	}
 

	
 
	const Action5Type *action5_type = &action5_types[type];
 
	const Action5Type *action5_type = &_action5_types[type];
 

	
 
	/* Ignore offset if not allowed */
 
	if ((action5_type->block_type != A5BLOCK_ALLOW_OFFSET) && (offset != 0)) {
 
		grfmsg(1, "GraphicsNew: %s (type 0x%02X) do not allow an <offset> field. Ignoring offset.", action5_type->name, type);
 
		offset = 0;
 
	}
 

	
 
	/* Ignore action5 if too few sprites are specified. (for TTDP compatibility)
 
	 * This does not make sense, if <offset> is allowed */
 
	if ((action5_type->block_type == A5BLOCK_FIXED) && (num < action5_type->min_sprites)) {
 
		grfmsg(1, "GraphicsNew: %s (type 0x%02X) count must be at least %d. Only %d were specified. Skipping.", action5_type->name, type, action5_type->min_sprites, num);
 
		_skip_sprites = num;
 
		return;
 
	}
 

	
 
	/* Load at most max_sprites sprites. Skip remaining sprites. (for compatibility with TTDP and future extentions) */
 
	uint16 skip_num = SanitizeSpriteOffset(num, offset, action5_type->max_sprites, action5_type->name);
 
	SpriteID replace = action5_type->sprite_base + offset;
 

	
 
	/* Load <num> sprites starting from <replace>, then skip <skip_num> sprites. */
 
	grfmsg(2, "GraphicsNew: Replacing sprites %d to %d of %s (type 0x%02X) at SpriteID 0x%04X", offset, offset + num - 1, action5_type->name, type, replace);
 

	
 
	for (; num > 0; num--) {
 
		_nfo_line++;
 
		LoadNextSprite(replace == 0 ? _cur_spriteid++ : replace++, _file_index, _nfo_line);
 
	}
 

	
 
	if (type == 0x0D) _loaded_newgrf_features.shore = SHORE_REPLACE_ACTION_5;
 

	
 
	_skip_sprites = skip_num;
 
}
 

	
 
/* Action 0x05 (SKIP) */
 
static void SkipAct5(ByteReader *buf)
 
{
 
	/* Ignore type byte */
 
	buf->ReadByte();
 

	
 
	/* Skip the sprites of this action */
 
	_skip_sprites = buf->ReadExtendedByte();
 

	
 
	grfmsg(3, "SkipAct5: Skipping %d sprites", _skip_sprites);
 
}
 

	
 
/**
 
 * Check whether we are (obviously) missing some of the extra
 
 * (Action 0x05) sprites that we like to use.
 
 * When missing sprites are found a warning will be shown.
 
 */
 
void CheckForMissingSprites()
 
{
 
	/* Don't break out quickly, but allow to check the other
 
	 * sprites as well, so we can give the best information. */
 
	bool missing = false;
 
	for (uint8 i = 0; i < lengthof(_action5_types); i++) {
 
		const Action5Type *type = &_action5_types[i];
 
		if (type->block_type == A5BLOCK_INVALID) continue;
 

	
 
		for (uint j = 0; j < type->max_sprites; j++) {
 
			if (!SpriteExists(type->sprite_base + j)) {
 
				DEBUG(grf, 0, "%s sprites are missing", type->name);
 
				missing = true;
 
				/* No need to log more of the same. */
 
				break;
 
			}
 
		}
 
	}
 

	
 
	if (missing) {
 
		ShowErrorMessage(STR_NEWGRF_ERROR_MISSING_SPRITES, INVALID_STRING_ID, WL_CRITICAL);
 
	}
 
}
 

	
 
/**
 
 * Reads a variable common to VarAction2 and Action7/9/D.
 
 *
 
 * Returns VarAction2 variable 'param' resp. Action7/9/D variable '0x80 + param'.
 
 * If a variable is not accessible from all four actions, it is handled in the action specific functions.
 
 *
 
 * @param param variable number (as for VarAction2, for Action7/9/D you have to subtract 0x80 first).
 
 * @param value returns the value of the variable.
 
 * @return true iff the variable is known and the value is returned in 'value'.
 
 */
 
bool GetGlobalVariable(byte param, uint32 *value)
 
{
 
	switch (param) {
 
		case 0x00: // current date
 
			*value = max(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
 
			return true;
 

	
 
		case 0x01: // current year
 
			*value = Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR;
 
			return true;
 

	
 
		case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
 
			YearMonthDay ymd;
 
			ConvertDateToYMD(_date, &ymd);
 
			Date start_of_year = ConvertYMDToDate(ymd.year, 0, 1);
src/newgrf_config.h
Show inline comments
 
@@ -146,45 +146,46 @@ struct GRFConfig : ZeroedMemoryAllocator
 
	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
 
	uint8 num_valid_params;    ///< NOSAVE: Number of valid parameters (action 0x14)
 
	uint8 palette;             ///< GRFPalette, bitset
 
	SmallVector<GRFParameterInfo *, 4> param_info; ///< NOSAVE: extra information about the parameters
 

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

	
 
	bool IsOpenTTDBaseGRF() const;
 

	
 
	const char *GetName() const;
 
	const char *GetDescription() const;
 

	
 
	void SetSuitablePalette();
 
};
 

	
 
extern GRFConfig *_all_grfs;          ///< First item in list of all scanned NewGRFs
 
extern GRFConfig *_grfconfig;         ///< First item in list of current GRF set up
 
extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set up
 
extern GRFConfig *_grfconfig_static;  ///< First item in list of static GRF set up
 

	
 
void ScanNewGRFFiles();
 
void CheckForMissingSprites();
 
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum = NULL);
 
GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask = 0xFFFFFFFF);
 
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only);
 
void AppendStaticGRFConfigs(GRFConfig **dst);
 
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el);
 
void ClearGRFConfigList(GRFConfig **config);
 
void ResetGRFConfig(bool defaults);
 
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig);
 
bool FillGRFDetails(GRFConfig *config, bool is_static);
 
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last);
 

	
 
/* In newgrf_gui.cpp */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config);
 

	
 
#ifdef ENABLE_NETWORK
 
/* For communication about GRFs over the network */
 
#define UNKNOWN_GRF_NAME_PLACEHOLDER "<Unknown>"
 
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create);
 
#endif /* ENABLE_NETWORK */
 

	
 
#endif /* NEWGRF_CONFIG_H */
src/openttd.cpp
Show inline comments
 
@@ -356,48 +356,49 @@ static void ShutdownGame()
 
}
 

	
 
static void LoadIntroGame()
 
{
 
	_game_mode = GM_MENU;
 

	
 
	ResetGRFConfig(false);
 

	
 
	/* Setup main window */
 
	ResetWindowSystem();
 
	SetupColoursAndInitialWindow();
 

	
 
	/* Load the default opening screen savegame */
 
	if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
 
		GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
 
		WaitTillGeneratedWorld();
 
		SetLocalCompany(COMPANY_SPECTATOR);
 
	} else {
 
		SetLocalCompany(COMPANY_FIRST);
 
	}
 

	
 
	_pause_mode = PM_UNPAUSED;
 
	_cursor.fix_at = false;
 

	
 
	CheckForMissingSprites();
 
	CheckForMissingGlyphsInLoadedLanguagePack();
 

	
 
	/* Play main theme */
 
	if (_music_driver->IsSongPlaying()) ResetMusic();
 
}
 

	
 
void MakeNewgameSettingsLive()
 
{
 
#ifdef ENABLE_AI
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		if (_settings_game.ai_config[c] != NULL) {
 
			delete _settings_game.ai_config[c];
 
		}
 
	}
 
#endif /* ENABLE_AI */
 

	
 
	_settings_game = _settings_newgame;
 

	
 
#ifdef ENABLE_AI
 
	for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
 
		_settings_game.ai_config[c] = NULL;
 
		if (_settings_newgame.ai_config[c] != NULL) {
 
			_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
 
		}
0 comments (0 inline, 0 general)