mirror of https://github.com/OpenTTD/OpenTTD
(svn r545) -newgrf: repaired indendation (pasky & octo)
parent
aac4fbc220
commit
acaff32984
132
grfspecial.c
132
grfspecial.c
|
@ -50,11 +50,20 @@ static void CDECL grfmsg(enum grfmsg_severity severity, const char *str, ...)
|
|||
DEBUG(grf, 2) ("[%s][%s] %s", _cur_grffile, severitystr[severity], buf);
|
||||
}
|
||||
|
||||
|
||||
#define check_length(real, wanted, where) \
|
||||
do { \
|
||||
if (real < wanted) { \
|
||||
grfmsg(GMS_ERROR, "%s: Invalid special sprite length %d (expected %d)!", where, real, wanted); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
static byte INLINE grf_load_byte(byte **buf) {
|
||||
return *(*buf)++;
|
||||
}
|
||||
|
||||
|
||||
static uint16 grf_load_word(byte **buf)
|
||||
{
|
||||
uint16 val;
|
||||
|
@ -77,6 +86,7 @@ static uint16 grf_load_dword(byte **buf)
|
|||
return val;
|
||||
}
|
||||
|
||||
|
||||
typedef int (*VCI_Handler)(uint engine, int numinfo, int prop, byte **buf, int len);
|
||||
|
||||
#define foreach_engine for (i = 0; i < numinfo; i++)
|
||||
|
@ -447,14 +457,18 @@ static void VehicleChangeInfo(byte *buf, int len)
|
|||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
if (len > 5) {
|
||||
uint8 feature = buf[1];
|
||||
uint8 numprops = buf[2];
|
||||
uint8 numinfo = buf[3];
|
||||
byte engine = buf[4];
|
||||
uint8 feature;
|
||||
uint8 numprops;
|
||||
uint8 numinfo;
|
||||
byte engine;
|
||||
EngineInfo *ei;
|
||||
|
||||
check_length(len, 6, "VehicleChangeInfo");
|
||||
feature = buf[1];
|
||||
numprops = buf[2];
|
||||
numinfo = buf[3];
|
||||
engine = buf[4];
|
||||
|
||||
if (feature != 0 && feature != 2) {
|
||||
grfmsg(GMS_WARN, "VehicleChangeInfo: Unsupported vehicle type %x, skipping.", feature);
|
||||
return;
|
||||
|
@ -537,7 +551,6 @@ ignoring:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef shift_buf
|
||||
}
|
||||
|
||||
|
@ -577,9 +590,10 @@ static void SpriteNewSet(byte *buf, int len)
|
|||
* For stations, must be 12 (hex) for the eighteen
|
||||
* different sprites that make up a station */
|
||||
/* TODO: No stations support. */
|
||||
uint8 feature;
|
||||
|
||||
if (len == 4) {
|
||||
uint8 feature = buf[1];
|
||||
check_length(len, 4, "SpriteNewSet");
|
||||
feature = buf[1];
|
||||
|
||||
if (feature == 4) {
|
||||
_spriteset_start = 0;
|
||||
|
@ -592,7 +606,6 @@ static void SpriteNewSet(byte *buf, int len)
|
|||
_spriteset_numsets = buf[2];
|
||||
_spriteset_numents = buf[3];
|
||||
}
|
||||
}
|
||||
|
||||
/* Action 0x02 */
|
||||
static void SpriteNewSuperset(byte *buf, int len)
|
||||
|
@ -613,15 +626,19 @@ static void SpriteNewSuperset(byte *buf, int len)
|
|||
/* TODO: Also, empty sprites aren't handled for now. Need to investigate
|
||||
* the "opacity" rules for these, that is which sprite to fall back to
|
||||
* when. --pasky */
|
||||
|
||||
if (bufend - buf > 4) {
|
||||
uint8 feature = buf[1];
|
||||
uint8 setid = buf[2];
|
||||
uint8 numloaded = buf[3];
|
||||
uint8 numloading = buf[4];
|
||||
uint8 feature;
|
||||
uint8 setid;
|
||||
uint8 numloaded;
|
||||
uint8 numloading;
|
||||
struct SpriteSuperSet *superset;
|
||||
int i;
|
||||
|
||||
check_length(len, 5, "SpriteNewSuperset");
|
||||
feature = buf[1];
|
||||
setid = buf[2];
|
||||
numloaded = buf[3];
|
||||
numloading = buf[4];
|
||||
|
||||
if (feature == 4) {
|
||||
grfmsg(GMS_WARN, "SpriteNewSuperset: Stations unsupported, skipping.");
|
||||
return;
|
||||
|
@ -702,7 +719,6 @@ static void SpriteNewSuperset(byte *buf, int len)
|
|||
superset->loading[superset->loading_count++] = _spriteset_start + spriteset_id * _spriteset_numents;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Action 0x03 */
|
||||
static void VehicleMapSpriteSuperset(byte *buf, int len)
|
||||
|
@ -727,14 +743,18 @@ static void VehicleMapSpriteSuperset(byte *buf, int len)
|
|||
|
||||
static byte *last_engines;
|
||||
static int last_engines_count;
|
||||
|
||||
if (bufend - buf > 6) {
|
||||
uint8 feature = buf[1];
|
||||
uint8 idcount = buf[2] & 0x7f;
|
||||
int wagover = buf[2] & 0x80;
|
||||
uint8 cidcount = buf[3 + idcount];
|
||||
uint8 feature;
|
||||
uint8 idcount;
|
||||
int wagover;
|
||||
uint8 cidcount;
|
||||
int c, i;
|
||||
|
||||
check_length(len, 7, "VehicleMapSpriteSuperset");
|
||||
feature = buf[1];
|
||||
idcount = buf[2] & 0x7f;
|
||||
wagover = buf[2] & 0x80;
|
||||
cidcount = buf[3 + idcount];
|
||||
|
||||
if (feature == 4) {
|
||||
grfmsg(GMS_WARN, "VehicleMapSpriteSuperset: Stations unsupported, skipping.");
|
||||
return;
|
||||
|
@ -803,7 +823,6 @@ static void VehicleMapSpriteSuperset(byte *buf, int len)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Action 0x04 */
|
||||
static void VehicleNewName(byte *buf, int len)
|
||||
|
@ -822,11 +841,16 @@ static void VehicleNewName(byte *buf, int len)
|
|||
* factory names etc). We should then also support all languages (by
|
||||
* name), not only the original four ones. --pasky */
|
||||
|
||||
if (len > 5) {
|
||||
uint8 feature = buf[1];
|
||||
uint8 lang = buf[2];
|
||||
uint8 id = buf[4] + _vehshifts[feature];
|
||||
uint8 endid = id + buf[3];
|
||||
uint8 feature;
|
||||
uint8 lang;
|
||||
uint8 id;
|
||||
uint8 endid;
|
||||
|
||||
check_length(len, 6, "VehicleNewName");
|
||||
feature = buf[1];
|
||||
lang = buf[2];
|
||||
id = buf[4] + _vehshifts[feature];
|
||||
endid = id + buf[3];
|
||||
|
||||
if (lang & 0x80) {
|
||||
grfmsg(GMS_WARN, "VehicleNewName: No support for changing in-game texts. Skipping.");
|
||||
|
@ -847,7 +871,6 @@ static void VehicleNewName(byte *buf, int len)
|
|||
buf += ofs, len -= ofs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Action 0x05 */
|
||||
static void GraphicsNew(byte *buf, int len)
|
||||
|
@ -862,9 +885,7 @@ static void GraphicsNew(byte *buf, int len)
|
|||
uint8 type;
|
||||
uint8 num;
|
||||
|
||||
if (len != 2)
|
||||
return;
|
||||
|
||||
check_length(len, 2, "GraphicsNew");
|
||||
type = buf[0];
|
||||
num = buf[1];
|
||||
|
||||
|
@ -902,14 +923,18 @@ static void SkipIf(byte *buf, int len)
|
|||
* B num-sprites */
|
||||
/* TODO: We only support few tests. */
|
||||
/* TODO: More params. More condition types. */
|
||||
|
||||
if (len > 5) {
|
||||
uint8 param = buf[1];
|
||||
uint8 paramsize = buf[2];
|
||||
uint8 condtype = buf[3];
|
||||
uint8 numsprites = buf[4 + paramsize];
|
||||
uint8 param;
|
||||
uint8 paramsize;
|
||||
uint8 condtype;
|
||||
uint8 numsprites;
|
||||
int val, result;
|
||||
|
||||
check_length(len, 6, "SkipIf");
|
||||
param = buf[1];
|
||||
paramsize = buf[2];
|
||||
condtype = buf[3];
|
||||
numsprites = buf[4 + paramsize];
|
||||
|
||||
if (param == 0x83) {
|
||||
val = _opt.landscape;
|
||||
} else {
|
||||
|
@ -938,7 +963,6 @@ static void SkipIf(byte *buf, int len)
|
|||
_skip_sprites = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void GRFInfo(byte *buf, int len)
|
||||
{
|
||||
|
@ -949,18 +973,19 @@ static void GRFInfo(byte *buf, int len)
|
|||
* S name name of this .grf set
|
||||
* S info string describing the set, and e.g. author and copyright */
|
||||
/* TODO: Check version. (We should have own versioning done somehow.) */
|
||||
uint8 version;
|
||||
uint32 grfid; /* this is de facto big endian - grf_load_dword() unsuitable */
|
||||
char *name;
|
||||
char *info;
|
||||
|
||||
if (len > 8) {
|
||||
uint8 version = buf[1];
|
||||
// this is de facto big endian - grf_load_dword() unsuitable
|
||||
uint32 grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
|
||||
char *name = buf + 6;
|
||||
char *info = name + strlen(name) + 1;
|
||||
|
||||
check_length(len, 9, "GRFInfo");
|
||||
version = buf[1];
|
||||
grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
|
||||
name = buf + 6;
|
||||
info = name + strlen(name) + 1;
|
||||
DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s\n",
|
||||
_cur_grffile, version, grfid, name, info);
|
||||
}
|
||||
}
|
||||
|
||||
static void SpriteReplace(byte *buf, int len)
|
||||
{
|
||||
|
@ -998,10 +1023,12 @@ static void GRFError(byte *buf, int len)
|
|||
"Designed to be used with %s.",
|
||||
"Invalid parameter %s.",
|
||||
};
|
||||
uint8 severity;
|
||||
uint8 msgid;
|
||||
|
||||
if (len > 5) {
|
||||
uint8 severity = buf[1];
|
||||
uint8 msgid = buf[3];
|
||||
check_length(len, 6, "GRFError");
|
||||
severity = buf[1];
|
||||
msgid = buf[3];
|
||||
|
||||
if (msgid == 0xff) {
|
||||
grfmsg(severity, "%s", buf+4);
|
||||
|
@ -1009,7 +1036,6 @@ static void GRFError(byte *buf, int len)
|
|||
grfmsg(severity, msgstr[msgid], buf+4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void GRFComment(byte *buf, int len)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue