|
@@ -45,12 +45,13 @@
|
|
|
#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)
|
|
@@ -4346,36 +4347,30 @@ static uint16 SanitizeSpriteOffset(uint1
|
|
|
return orig_num - num;
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
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[] = {
|
|
|
/** 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" },
|
|
@@ -4396,21 +4391,31 @@ static void GraphicsNew(ByteReader *buf)
|
|
|
/* 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 */
|
|
|
|
|
|
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
|
|
@@ -4420,19 +4425,19 @@ static void GraphicsNew(ByteReader *buf)
|
|
|
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;
|
|
|
}
|
|
@@ -4472,12 +4477,41 @@ static void SkipAct5(ByteReader *buf)
|
|
|
_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).
|