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