(svn r20566) -Feature: happy smiles on the faces of Ammler and planetmaker

This commit is contained in:
rubidium 2010-08-19 19:23:38 +00:00
parent 8c5916ffb7
commit 552adca67f
4 changed files with 81 additions and 44 deletions

View File

@ -2449,6 +2449,7 @@ STR_NEWGRF_ERROR_INVALID_ID :Attempt to use
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!

View File

@ -48,6 +48,7 @@
#include "core/mem_func.hpp"
#include "smallmap_gui.h"
#include "genworld.h"
#include "gui.h"
#include "table/strings.h"
#include "table/build_industry.h"
@ -4349,21 +4350,14 @@ static uint16 SanitizeSpriteOffset(uint16& num, uint16 offset, int max_sprites,
return 0;
}
/* 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 */
/** 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.
@ -4372,7 +4366,8 @@ static void GraphicsNew(ByteReader *buf)
const char *name; ///< Name for error messages.
};
static const Action5Type action5_types[] = {
/** 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" },
@ -4399,15 +4394,25 @@ static void GraphicsNew(ByteReader *buf)
/* 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 */
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
@ -4423,13 +4428,13 @@ static void GraphicsNew(ByteReader *buf)
}
/* 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)) {
@ -4474,6 +4479,35 @@ static void SkipAct5(ByteReader *buf)
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.
*

View File

@ -167,6 +167,7 @@ extern GRFConfig *_grfconfig_newgame; ///< First item in list of default GRF set
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);

View File

@ -377,6 +377,7 @@ static void LoadIntroGame()
_pause_mode = PM_UNPAUSED;
_cursor.fix_at = false;
CheckForMissingSprites();
CheckForMissingGlyphsInLoadedLanguagePack();
/* Play main theme */