1
0
Fork 0

(svn r1981) Typedef some structs and enums

release/0.4.5
tron 2005-03-10 07:01:43 +00:00
parent e6feb22411
commit 4bf173e9c1
10 changed files with 185 additions and 172 deletions

View File

@ -205,27 +205,29 @@ uint32 _engine_refit_masks[TOTAL_NUM_ENGINES];
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky // TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
struct WagonOverride { typedef struct WagonOverride {
byte *train_id; byte *train_id;
int trains; int trains;
struct SpriteGroup group; SpriteGroup group;
}; } WagonOverride;
static struct WagonOverrides { typedef struct WagonOverrides {
int overrides_count; int overrides_count;
struct WagonOverride *overrides; WagonOverride *overrides;
} _engine_wagon_overrides[TOTAL_NUM_ENGINES]; } WagonOverrides;
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES];
byte *train_id, int trains)
void SetWagonOverrideSprites(byte engine, SpriteGroup *group, byte *train_id,
int trains)
{ {
struct WagonOverrides *wos; WagonOverrides *wos;
struct WagonOverride *wo; WagonOverride *wo;
wos = &_engine_wagon_overrides[engine]; wos = &_engine_wagon_overrides[engine];
wos->overrides_count++; wos->overrides_count++;
wos->overrides = realloc(wos->overrides, wos->overrides = realloc(wos->overrides,
wos->overrides_count * sizeof(struct WagonOverride)); wos->overrides_count * sizeof(*wos->overrides));
wo = &wos->overrides[wos->overrides_count - 1]; wo = &wos->overrides[wos->overrides_count - 1];
/* FIXME: If we are replacing an override, release original SpriteGroup /* FIXME: If we are replacing an override, release original SpriteGroup
@ -237,9 +239,9 @@ void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group,
memcpy(wo->train_id, train_id, trains); memcpy(wo->train_id, train_id, trains);
} }
static struct SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine) static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine)
{ {
struct WagonOverrides *wos = &_engine_wagon_overrides[engine]; WagonOverrides *wos = &_engine_wagon_overrides[engine];
int i; int i;
// XXX: This could turn out to be a timesink on profiles. We could // XXX: This could turn out to be a timesink on profiles. We could
@ -248,7 +250,7 @@ static struct SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overridin
// that. --pasky // that. --pasky
for (i = 0; i < wos->overrides_count; i++) { for (i = 0; i < wos->overrides_count; i++) {
struct WagonOverride *wo = &wos->overrides[i]; WagonOverride *wo = &wos->overrides[i];
int j; int j;
for (j = 0; j < wo->trains; j++) { for (j = 0; j < wo->trains; j++) {
@ -265,9 +267,9 @@ byte _engine_original_sprites[TOTAL_NUM_ENGINES];
// (It isn't and shouldn't be like this in the GRF files since new cargo types // (It isn't and shouldn't be like this in the GRF files since new cargo types
// may appear in future - however it's more convenient to store it like this in // may appear in future - however it's more convenient to store it like this in
// memory. --pasky) // memory. --pasky)
static struct SpriteGroup _engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_CID]; static SpriteGroup _engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_CID];
void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group) void SetCustomEngineSprites(byte engine, byte cargo, SpriteGroup *group)
{ {
/* FIXME: If we are replacing an override, release original SpriteGroup /* FIXME: If we are replacing an override, release original SpriteGroup
* to prevent leaks. But first we need to refcount the SpriteGroup. * to prevent leaks. But first we need to refcount the SpriteGroup.
@ -275,11 +277,11 @@ void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group)
_engine_custom_sprites[engine][cargo] = *group; _engine_custom_sprites[engine][cargo] = *group;
} }
typedef struct RealSpriteGroup *(*resolve_callback)( typedef RealSpriteGroup *(*resolve_callback)(SpriteGroup *spritegroup,
struct SpriteGroup *spritegroup, const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */ const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */
static struct RealSpriteGroup* ResolveVehicleSpriteGroup( static RealSpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
struct SpriteGroup *spritegroup, const Vehicle *veh, resolve_callback callback) const Vehicle *veh, resolve_callback callback)
{ {
//debug("spgt %d", spritegroup->type); //debug("spgt %d", spritegroup->type);
switch (spritegroup->type) { switch (spritegroup->type) {
@ -287,8 +289,8 @@ static struct RealSpriteGroup* ResolveVehicleSpriteGroup(
return &spritegroup->g.real; return &spritegroup->g.real;
case SGT_DETERMINISTIC: { case SGT_DETERMINISTIC: {
struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ; DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
struct SpriteGroup *target; SpriteGroup *target;
int value = -1; int value = -1;
//debug("[%p] Having fun resolving variable %x", veh, dsg->variable); //debug("[%p] Having fun resolving variable %x", veh, dsg->variable);
@ -296,7 +298,6 @@ static struct RealSpriteGroup* ResolveVehicleSpriteGroup(
if ((dsg->variable >> 6) == 0) { if ((dsg->variable >> 6) == 0) {
/* General property */ /* General property */
value = GetDeterministicSpriteValue(dsg->variable); value = GetDeterministicSpriteValue(dsg->variable);
} else { } else {
/* Vehicle-specific property. */ /* Vehicle-specific property. */
@ -434,7 +435,7 @@ static struct RealSpriteGroup* ResolveVehicleSpriteGroup(
} }
case SGT_RANDOMIZED: { case SGT_RANDOMIZED: {
struct RandomizedSpriteGroup *rsg = &spritegroup->g.random; RandomizedSpriteGroup *rsg = &spritegroup->g.random;
if (veh == NULL) { if (veh == NULL) {
/* Purchase list of something. Show the first one. */ /* Purchase list of something. Show the first one. */
@ -458,9 +459,9 @@ static struct RealSpriteGroup* ResolveVehicleSpriteGroup(
} }
} }
static struct SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v) static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
{ {
struct SpriteGroup *group; SpriteGroup *group;
uint16 overriding_engine = -1; uint16 overriding_engine = -1;
byte cargo = CID_PURCHASE; byte cargo = CID_PURCHASE;
@ -472,10 +473,9 @@ static struct SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
group = &_engine_custom_sprites[engine][cargo]; group = &_engine_custom_sprites[engine][cargo];
if (overriding_engine != 0xffff) { if (overriding_engine != 0xffff) {
struct SpriteGroup *overset; SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
overset = GetWagonOverrideSpriteSet(engine, overriding_engine); if (overset != NULL) group = overset;
if (overset) group = overset;
} }
return group; return group;
@ -483,8 +483,8 @@ static struct SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v)
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction) int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction)
{ {
struct SpriteGroup *group; SpriteGroup *group;
struct RealSpriteGroup *rsg; RealSpriteGroup *rsg;
byte cargo = CID_PURCHASE; byte cargo = CID_PURCHASE;
byte loaded = 0; byte loaded = 0;
bool in_motion = 0; bool in_motion = 0;
@ -548,21 +548,23 @@ static byte _vsg_bits_to_reseed;
extern int _custom_sprites_base; extern int _custom_sprites_base;
static struct RealSpriteGroup * static RealSpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup,
TriggerVehicleSpriteGroup(struct SpriteGroup *spritegroup, struct Vehicle *veh, Vehicle *veh, resolve_callback callback)
resolve_callback callback)
{ {
if (spritegroup->type == SGT_RANDOMIZED) if (spritegroup->type == SGT_RANDOMIZED) {
_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits(&spritegroup->g.random, _vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits(
&spritegroup->g.random,
_vsg_random_triggers, _vsg_random_triggers,
&veh->waiting_triggers); &veh->waiting_triggers
);
}
return ResolveVehicleSpriteGroup(spritegroup, veh, callback); return ResolveVehicleSpriteGroup(spritegroup, veh, callback);
} }
static void DoTriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger, byte base_random_bits, bool first) static void DoTriggerVehicle(Vehicle *veh, VehicleTrigger trigger, byte base_random_bits, bool first)
{ {
struct RealSpriteGroup *rsg; RealSpriteGroup *rsg;
byte new_random_bits; byte new_random_bits;
_vsg_random_triggers = trigger; _vsg_random_triggers = trigger;
@ -615,7 +617,7 @@ static void DoTriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger, byte bas
} }
} }
void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger) void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger)
{ {
DoTriggerVehicle(veh, trigger, 0, true); DoTriggerVehicle(veh, trigger, 0, true);
} }

View File

@ -103,7 +103,7 @@ int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction);
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction) #define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction) #define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
enum VehicleTrigger { typedef enum VehicleTrigger {
VEHICLE_TRIGGER_NEW_CARGO = 1, VEHICLE_TRIGGER_NEW_CARGO = 1,
// Externally triggered only for the first vehicle in chain // Externally triggered only for the first vehicle in chain
VEHICLE_TRIGGER_DEPOT = 2, VEHICLE_TRIGGER_DEPOT = 2,
@ -111,8 +111,8 @@ enum VehicleTrigger {
VEHICLE_TRIGGER_EMPTY = 4, VEHICLE_TRIGGER_EMPTY = 4,
// Not triggered externally (called for the whole chain if we got NEW_CARGO) // Not triggered externally (called for the whole chain if we got NEW_CARGO)
VEHICLE_TRIGGER_ANY_NEW_CARGO = 8, VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
}; } VehicleTrigger;
void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger); void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
void SetCustomEngineName(int engine, const char *name); void SetCustomEngineName(int engine, const char *name);
StringID GetCustomEngineName(int engine); StringID GetCustomEngineName(int engine);

View File

@ -26,7 +26,8 @@ extern int _replace_sprites_count[16];
extern int _replace_sprites_offset[16]; extern int _replace_sprites_offset[16];
extern int _traininfo_vehicle_pitch; extern int _traininfo_vehicle_pitch;
struct GRFFile *_cur_grffile, *_first_grffile; GRFFile *_cur_grffile;
GRFFile *_first_grffile;
int _grffile_count; int _grffile_count;
static int _cur_spriteid; static int _cur_spriteid;
static int _cur_stage; static int _cur_stage;
@ -39,7 +40,7 @@ static int _param_max;
static uint32 _ttdpatch_flags[8]; static uint32 _ttdpatch_flags[8];
enum grfspec_feature { typedef enum grfspec_feature {
GSF_TRAIN, GSF_TRAIN,
GSF_ROAD, GSF_ROAD,
GSF_SHIP, GSF_SHIP,
@ -47,7 +48,7 @@ enum grfspec_feature {
GSF_STATION, GSF_STATION,
GSF_BRIDGE, GSF_BRIDGE,
GSF_TOWNHOUSE, GSF_TOWNHOUSE,
}; } grfspec_feature;
typedef void (*SpecialSpriteHandler)(byte *buf, int len); typedef void (*SpecialSpriteHandler)(byte *buf, int len);
@ -83,22 +84,27 @@ static const int _vehshifts[4] = {
*/ */
enum grfmsg_severity { typedef enum grfmsg_severity {
GMS_NOTICE, GMS_NOTICE,
GMS_WARN, GMS_WARN,
GMS_ERROR, GMS_ERROR,
GMS_FATAL, GMS_FATAL,
}; } grfmsg_severity;
static void CDECL grfmsg(enum grfmsg_severity severity, const char *str, ...) static void CDECL grfmsg(grfmsg_severity severity, const char *str, ...)
{ {
static const char * const severitystr[4] = { "Notice", "Warning", "Error", "Fatal" }; static const char* const severitystr[] = {
"Notice",
"Warning",
"Error",
"Fatal"
};
int export_severity = 0; int export_severity = 0;
char buf[1024]; char buf[1024];
va_list va; va_list va;
va_start(va, str); va_start(va, str);
vsprintf(buf, str, va); vsnprintf(buf, sizeof(buf), str, va);
va_end(va); va_end(va);
export_severity = 2 - (severity == GMS_FATAL ? 2 : severity); export_severity = 2 - (severity == GMS_FATAL ? 2 : severity);
@ -144,25 +150,23 @@ static uint16 grf_load_dword(byte **buf)
} }
static struct GRFFile *GetFileByGRFID(uint32 grfid) static GRFFile *GetFileByGRFID(uint32 grfid)
{ {
struct GRFFile *file; GRFFile *file;
file = _first_grffile;
while ((file != NULL) && (file->grfid != grfid))
file = file->next;
for (file = _first_grffile; file != NULL; file = file->next) {
if (file->grfid == grfid) break;
}
return file; return file;
} }
static struct GRFFile *GetFileByFilename(const char *filename) static GRFFile *GetFileByFilename(const char *filename)
{ {
struct GRFFile *file; GRFFile *file;
file = _first_grffile;
while ((file != NULL) && strcmp(file->filename, filename))
file = file->next;
for (file = _first_grffile; file != NULL; file = file->next) {
if (strcmp(file->filename, filename) == 0) break;
}
return file; return file;
} }
@ -683,7 +687,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x08: case 0x08:
{ /* Class ID */ { /* Class ID */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
uint32 classid; uint32 classid;
/* classid, for a change, is always little-endian */ /* classid, for a change, is always little-endian */
@ -714,7 +718,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x09: case 0x09:
{ /* Define sprite layout */ { /* Define sprite layout */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
int t; int t;
stat->tiles = grf_load_byte(&buf); stat->tiles = grf_load_byte(&buf);
@ -759,9 +763,9 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x0a: case 0x0a:
{ /* Copy sprite layout */ { /* Copy sprite layout */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
byte srcid = grf_load_byte(&buf); byte srcid = grf_load_byte(&buf);
struct StationSpec *srcstat = &_cur_grffile->stations[srcid]; StationSpec *srcstat = &_cur_grffile->stations[srcid];
int t; int t;
stat->tiles = srcstat->tiles; stat->tiles = srcstat->tiles;
@ -805,7 +809,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x0C: case 0x0C:
{ /* Platforms number */ { /* Platforms number */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
stat->allowed_platforms = ~grf_load_byte(&buf); stat->allowed_platforms = ~grf_load_byte(&buf);
} }
@ -814,7 +818,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x0D: case 0x0D:
{ /* Platforms length */ { /* Platforms length */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
stat->allowed_lengths = ~grf_load_byte(&buf); stat->allowed_lengths = ~grf_load_byte(&buf);
} }
@ -823,7 +827,7 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
case 0x0e: case 0x0e:
{ /* Define custom layout */ { /* Define custom layout */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
struct StationSpec *stat = &_cur_grffile->stations[stid + i]; StationSpec *stat = &_cur_grffile->stations[stid + i];
while (buf < *bufp + len) { while (buf < *bufp + len) {
byte length = grf_load_byte(&buf); byte length = grf_load_byte(&buf);
@ -917,8 +921,6 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
return ret; return ret;
} }
#undef shift_buf
/* Action 0x00 */ /* Action 0x00 */
static void VehicleChangeInfo(byte *buf, int len) static void VehicleChangeInfo(byte *buf, int len)
@ -1048,7 +1050,6 @@ ignoring:
} }
} }
} }
#undef shift_buf
} }
#undef FOR_EACH_OBJECT #undef FOR_EACH_OBJECT
@ -1105,8 +1106,8 @@ static void NewSpriteGroup(byte *buf, int len)
/* XXX: For stations, these two are "little cargo" and "lotsa cargo" sets. */ /* XXX: For stations, these two are "little cargo" and "lotsa cargo" sets. */
uint8 numloaded; uint8 numloaded;
uint8 numloading; uint8 numloading;
struct SpriteGroup *group; SpriteGroup *group;
struct RealSpriteGroup *rg; RealSpriteGroup *rg;
byte *loaded_ptr; byte *loaded_ptr;
byte *loading_ptr; byte *loading_ptr;
int i; int i;
@ -1118,7 +1119,7 @@ static void NewSpriteGroup(byte *buf, int len)
numloading = buf[4]; numloading = buf[4];
if (numloaded == 0x81 || numloaded == 0x82) { if (numloaded == 0x81 || numloaded == 0x82) {
struct DeterministicSpriteGroup *dg; DeterministicSpriteGroup *dg;
uint16 groupid; uint16 groupid;
int i; int i;
@ -1132,11 +1133,11 @@ static void NewSpriteGroup(byte *buf, int len)
if (setid >= _cur_grffile->spritegroups_count) { if (setid >= _cur_grffile->spritegroups_count) {
_cur_grffile->spritegroups_count = setid + 1; _cur_grffile->spritegroups_count = setid + 1;
_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(struct SpriteGroup)); _cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
} }
group = &_cur_grffile->spritegroups[setid]; group = &_cur_grffile->spritegroups[setid];
memset(group, 0, sizeof(struct SpriteGroup)); memset(group, 0, sizeof(*group));
group->type = SGT_DETERMINISTIC; group->type = SGT_DETERMINISTIC;
dg = &group->g.determ; dg = &group->g.determ;
@ -1190,7 +1191,7 @@ static void NewSpriteGroup(byte *buf, int len)
return; return;
} else if (numloaded == 0x80 || numloaded == 0x83) { } else if (numloaded == 0x80 || numloaded == 0x83) {
struct RandomizedSpriteGroup *rg; RandomizedSpriteGroup *rg;
int i; int i;
/* This stuff is getting actually evaluated in /* This stuff is getting actually evaluated in
@ -1202,7 +1203,7 @@ static void NewSpriteGroup(byte *buf, int len)
if (setid >= _cur_grffile->spritegroups_count) { if (setid >= _cur_grffile->spritegroups_count) {
_cur_grffile->spritegroups_count = setid + 1; _cur_grffile->spritegroups_count = setid + 1;
_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(struct SpriteGroup)); _cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
} }
group = &_cur_grffile->spritegroups[setid]; group = &_cur_grffile->spritegroups[setid];
@ -1268,10 +1269,10 @@ static void NewSpriteGroup(byte *buf, int len)
if (setid >= _cur_grffile->spritegroups_count) { if (setid >= _cur_grffile->spritegroups_count) {
_cur_grffile->spritegroups_count = setid + 1; _cur_grffile->spritegroups_count = setid + 1;
_cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(struct SpriteGroup)); _cur_grffile->spritegroups = realloc(_cur_grffile->spritegroups, _cur_grffile->spritegroups_count * sizeof(*_cur_grffile->spritegroups));
} }
group = &_cur_grffile->spritegroups[setid]; group = &_cur_grffile->spritegroups[setid];
memset(group, 0, sizeof(struct SpriteGroup)); memset(group, 0, sizeof(*group));
group->type = SGT_REAL; group->type = SGT_REAL;
rg = &group->g.real; rg = &group->g.real;
@ -1347,7 +1348,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
for (i = 0; i < idcount; i++) { for (i = 0; i < idcount; i++) {
uint8 stid = buf[3 + i]; uint8 stid = buf[3 + i];
struct StationSpec *stat = &_cur_grffile->stations[stid]; StationSpec *stat = &_cur_grffile->stations[stid];
byte *bp = &buf[4 + idcount]; byte *bp = &buf[4 + idcount];
for (c = 0; c < cidcount; c++) { for (c = 0; c < cidcount; c++) {
@ -1381,7 +1382,7 @@ static void NewVehicle_SpriteGroupMapping(byte *buf, int len)
for (i = 0; i < idcount; i++) { for (i = 0; i < idcount; i++) {
uint8 stid = buf[3 + i]; uint8 stid = buf[3 + i];
struct StationSpec *stat = &_cur_grffile->stations[stid]; StationSpec *stat = &_cur_grffile->stations[stid];
stat->spritegroup[0] = _cur_grffile->spritegroups[groupid]; stat->spritegroup[0] = _cur_grffile->spritegroups[groupid];
stat->grfid = _cur_grffile->grfid; stat->grfid = _cur_grffile->grfid;
@ -1639,7 +1640,7 @@ static void SkipIf(byte *buf, int len)
param_val = _opt.road_side << 4; param_val = _opt.road_side << 4;
break; break;
case 0x88: { /* see if specified GRFID is active */ case 0x88: { /* see if specified GRFID is active */
struct GRFFile *file; GRFFile *file;
file = GetFileByGRFID(cond_val); file = GetFileByGRFID(cond_val);
param_val = (file != NULL); param_val = (file != NULL);
@ -1959,7 +1960,7 @@ static void GRFInhibit(byte *buf, int len)
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
uint32 grfid = grf_load_dword(&buf); uint32 grfid = grf_load_dword(&buf);
struct GRFFile *file = GetFileByGRFID(grfid); GRFFile *file = GetFileByGRFID(grfid);
/* Unset activation flag */ /* Unset activation flag */
if (file != NULL) { if (file != NULL) {
@ -1996,7 +1997,7 @@ static void InitializeGRFSpecial(void)
void InitNewGRFFile(const char *filename, int sprite_offset) void InitNewGRFFile(const char *filename, int sprite_offset)
{ {
struct GRFFile *newfile; GRFFile *newfile;
newfile = GetFileByFilename(filename); newfile = GetFileByFilename(filename);
if (newfile != NULL) { if (newfile != NULL) {
@ -2006,7 +2007,7 @@ void InitNewGRFFile(const char *filename, int sprite_offset)
return; return;
} }
newfile = calloc(1, sizeof(struct GRFFile)); newfile = calloc(1, sizeof(*newfile));
if (newfile == NULL) if (newfile == NULL)
error ("Out of memory"); error ("Out of memory");

View File

@ -4,12 +4,13 @@
#include "sprite.h" #include "sprite.h"
#include "station.h" #include "station.h"
typedef struct GRFFile GRFFile;
struct GRFFile { struct GRFFile {
char *filename; char *filename;
uint32 grfid; uint32 grfid;
uint16 flags; uint16 flags;
uint16 sprite_offset; uint16 sprite_offset;
struct GRFFile *next; GRFFile *next;
/* A sprite group contains all sprites of a given vehicle (or multiple /* A sprite group contains all sprites of a given vehicle (or multiple
* vehicles) when carrying given cargo. It consists of several sprite * vehicles) when carrying given cargo. It consists of several sprite
@ -28,13 +29,13 @@ struct GRFFile {
int spriteset_feature; int spriteset_feature;
int spritegroups_count; int spritegroups_count;
struct SpriteGroup *spritegroups; SpriteGroup *spritegroups;
struct StationSpec stations[256]; StationSpec stations[256];
}; };
extern int _grffile_count; extern int _grffile_count;
extern struct GRFFile *_first_grffile; extern GRFFile *_first_grffile;
void InitNewGRFFile(const char *filename, int sprite_offset); void InitNewGRFFile(const char *filename, int sprite_offset);
void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage); void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage);

View File

@ -1630,7 +1630,7 @@ static void DrawTile_Track(TileInfo *ti)
if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) { if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) {
// look for customization // look for customization
struct StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _map3_hi[ti->tile]); StationSpec *stat = GetCustomStation(STAT_CLASS_WAYP, _map3_hi[ti->tile]);
if (stat) { if (stat) {
DrawTileSeqStruct const *seq; DrawTileSeqStruct const *seq;
@ -1718,7 +1718,7 @@ void DrawTrainDepotSprite(int x, int y, int image, int railtype)
void DrawWaypointSprite(int x, int y, int stat_id, int railtype) void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
{ {
struct StationSpec *stat; StationSpec *stat;
uint32 relocation; uint32 relocation;
DrawTileSprites *cust; DrawTileSprites *cust;
DrawTileSeqStruct const *seq; DrawTileSeqStruct const *seq;

View File

@ -1194,7 +1194,7 @@ void ShowPatchesSelection(void)
AllocateWindowDesc(&_patches_selection_desc); AllocateWindowDesc(&_patches_selection_desc);
} }
struct GRFFile *_sel_grffile; GRFFile *_sel_grffile;
enum { enum {
NEWGRF_WND_PROC_OFFSET_TOP_WIDGET = 14, NEWGRF_WND_PROC_OFFSET_TOP_WIDGET = 14,
@ -1207,7 +1207,7 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
case WE_PAINT: { case WE_PAINT: {
int x, y = NEWGRF_WND_PROC_OFFSET_TOP_WIDGET; int x, y = NEWGRF_WND_PROC_OFFSET_TOP_WIDGET;
uint16 i = 0; uint16 i = 0;
struct GRFFile *c = _first_grffile; GRFFile *c = _first_grffile;
DrawWindowWidgets(w); DrawWindowWidgets(w);
@ -1323,7 +1323,8 @@ void ShowNewgrf(void)
{ // little helper function to calculate _grffile_count { // little helper function to calculate _grffile_count
// should be REMOVED once _grffile_count is calculated at loading // should be REMOVED once _grffile_count is calculated at loading
struct GRFFile *c = _first_grffile; GRFFile *c = _first_grffile;
_grffile_count = 0; _grffile_count = 0;
while (c != NULL) { while (c != NULL) {
_grffile_count++; _grffile_count++;

View File

@ -6,7 +6,7 @@
#include "sprite.h" #include "sprite.h"
struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value) SpriteGroup *EvalDeterministicSpriteGroup(DeterministicSpriteGroup *dsg, int value)
{ {
int i; int i;
@ -28,7 +28,7 @@ struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup
} }
for (i = 0; i < dsg->num_ranges; i++) { for (i = 0; i < dsg->num_ranges; i++) {
struct DeterministicSpriteGroupRange *range = &dsg->ranges[i]; DeterministicSpriteGroupRange *range = &dsg->ranges[i];
if (range->low <= value && value <= range->high) if (range->low <= value && value <= range->high)
return &range->group; return &range->group;
@ -61,8 +61,7 @@ int GetDeterministicSpriteValue(byte var)
} }
} }
struct SpriteGroup * SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits)
EvalRandomizedSpriteGroup(struct RandomizedSpriteGroup *rsg, byte random_bits)
{ {
byte mask; byte mask;
byte index; byte index;
@ -76,8 +75,8 @@ EvalRandomizedSpriteGroup(struct RandomizedSpriteGroup *rsg, byte random_bits)
return &rsg->groups[index]; return &rsg->groups[index];
} }
byte RandomizedSpriteGroupTriggeredBits(struct RandomizedSpriteGroup *rsg, byte triggers, byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg,
byte *waiting_triggers) byte triggers, byte *waiting_triggers)
{ {
byte match = rsg->triggers & (*waiting_triggers | triggers); byte match = rsg->triggers & (*waiting_triggers | triggers);
bool res; bool res;

View File

@ -27,9 +27,9 @@ typedef struct DrawTileSprites {
/* This is for custom sprites: */ /* This is for custom sprites: */
struct SpriteGroup; typedef struct SpriteGroup SpriteGroup;
struct RealSpriteGroup { typedef struct RealSpriteGroup {
// XXX: Would anyone ever need more than 16 spritesets? Maybe we should // XXX: Would anyone ever need more than 16 spritesets? Maybe we should
// use even less, now we take whole 8kb for custom sprites table, oh my! // use even less, now we take whole 8kb for custom sprites table, oh my!
byte sprites_per_set; // means number of directions - 4 or 8 byte sprites_per_set; // means number of directions - 4 or 8
@ -45,20 +45,28 @@ struct RealSpriteGroup {
uint16 loaded[16]; // sprite ids uint16 loaded[16]; // sprite ids
byte loading_count; byte loading_count;
uint16 loading[16]; // sprite ids uint16 loading[16]; // sprite ids
}; } RealSpriteGroup;
/* Shared by deterministic and random groups. */ /* Shared by deterministic and random groups. */
enum VarSpriteGroupScope { typedef enum VarSpriteGroupScope {
VSG_SCOPE_SELF, VSG_SCOPE_SELF,
// Engine of consists for vehicles, city for stations. // Engine of consists for vehicles, city for stations.
VSG_SCOPE_PARENT, VSG_SCOPE_PARENT,
}; } VarSpriteGroupScope;
struct DeterministicSpriteGroupRanges; typedef struct DeterministicSpriteGroupRanges DeterministicSpriteGroupRanges;
struct DeterministicSpriteGroup { typedef enum DeterministicSpriteGroupOperation {
DSG_OP_NONE,
DSG_OP_DIV,
DSG_OP_MOD,
} DeterministicSpriteGroupOperation;
typedef struct DeterministicSpriteGroupRange DeterministicSpriteGroupRange;
typedef struct DeterministicSpriteGroup {
// Take this variable: // Take this variable:
enum VarSpriteGroupScope var_scope; VarSpriteGroupScope var_scope;
byte variable; byte variable;
// Do this with it: // Do this with it:
@ -66,31 +74,29 @@ struct DeterministicSpriteGroup {
byte and_mask; byte and_mask;
// Then do this with it: // Then do this with it:
enum DeterministicSpriteGroupOperation { DeterministicSpriteGroupOperation operation;
DSG_OP_NONE,
DSG_OP_DIV,
DSG_OP_MOD,
} operation;
byte add_val; byte add_val;
byte divmod_val; byte divmod_val;
// And apply it to this: // And apply it to this:
byte num_ranges; byte num_ranges;
struct DeterministicSpriteGroupRange *ranges; // Dynamically allocated DeterministicSpriteGroupRange *ranges; // Dynamically allocated
// Dynamically allocated, this is the sole owner // Dynamically allocated, this is the sole owner
struct SpriteGroup *default_group; SpriteGroup *default_group;
}; } DeterministicSpriteGroup;
struct RandomizedSpriteGroup { typedef enum RandomizedSpriteGroupCompareMode {
// Take this object:
enum VarSpriteGroupScope var_scope;
// Check for these triggers:
enum RandomizedSpriteGroupCompareMode {
RSG_CMP_ANY, RSG_CMP_ANY,
RSG_CMP_ALL, RSG_CMP_ALL,
} cmp_mode; } RandomizedSpriteGroupCompareMode;
typedef struct RandomizedSpriteGroup {
// Take this object:
VarSpriteGroupScope var_scope;
// Check for these triggers:
RandomizedSpriteGroupCompareMode cmp_mode;
byte triggers; byte triggers;
// Look for this in the per-object randomized bitmask: // Look for this in the per-object randomized bitmask:
@ -98,25 +104,27 @@ struct RandomizedSpriteGroup {
byte num_groups; // must be power of 2 byte num_groups; // must be power of 2
// Take the group with appropriate index: // Take the group with appropriate index:
struct SpriteGroup *groups; SpriteGroup *groups;
}; } RandomizedSpriteGroup;
struct SpriteGroup { typedef enum SpriteGroupType {
enum SpriteGroupType {
SGT_REAL, SGT_REAL,
SGT_DETERMINISTIC, SGT_DETERMINISTIC,
SGT_RANDOMIZED, SGT_RANDOMIZED,
} type; } SpriteGroupType;
struct SpriteGroup {
SpriteGroupType type;
union { union {
struct RealSpriteGroup real; RealSpriteGroup real;
struct DeterministicSpriteGroup determ; DeterministicSpriteGroup determ;
struct RandomizedSpriteGroup random; RandomizedSpriteGroup random;
} g; } g;
}; };
struct DeterministicSpriteGroupRange { struct DeterministicSpriteGroupRange {
struct SpriteGroup group; SpriteGroup group;
byte low; byte low;
byte high; byte high;
}; };
@ -131,10 +139,10 @@ int GetDeterministicSpriteValue(byte var);
/* This takes randomized bitmask (probably associated with /* This takes randomized bitmask (probably associated with
* vehicle/station/whatever) and chooses corresponding SpriteGroup * vehicle/station/whatever) and chooses corresponding SpriteGroup
* accordingly to the given RandomizedSpriteGroup. */ * accordingly to the given RandomizedSpriteGroup. */
struct SpriteGroup *EvalRandomizedSpriteGroup(struct RandomizedSpriteGroup *rsg, byte random_bits); SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits);
/* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask /* Triggers given RandomizedSpriteGroup with given bitmask and returns and-mask
* of random bits to be reseeded, or zero if there were no triggers matched * of random bits to be reseeded, or zero if there were no triggers matched
* (then they are |ed to @waiting_triggers instead). */ * (then they are |ed to @waiting_triggers instead). */
byte RandomizedSpriteGroupTriggeredBits(struct RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers); byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg, byte triggers, byte *waiting_triggers);
#endif #endif

View File

@ -187,11 +187,7 @@ uint GetStationPlatforms(Station *st, uint tile);
* where index is computed as (x * platforms) + platform. */ * where index is computed as (x * platforms) + platform. */
typedef byte *StationLayout; typedef byte *StationLayout;
struct StationSpec { typedef enum StationClass {
uint32 grfid;
int localidx; // per-GRFFile station index + 1; SetCustomStation() takes care of this
enum StationClass {
STAT_CLASS_NONE, // unused station slot or so STAT_CLASS_NONE, // unused station slot or so
STAT_CLASS_DFLT, // default station class STAT_CLASS_DFLT, // default station class
STAT_CLASS_WAYP, // waypoints STAT_CLASS_WAYP, // waypoints
@ -202,7 +198,13 @@ struct StationSpec {
* the whole game at the same time) with base at * the whole game at the same time) with base at
* STAT_CLASS_CUSTOM. --pasky */ * STAT_CLASS_CUSTOM. --pasky */
STAT_CLASS_CUSTOM, // some custom class STAT_CLASS_CUSTOM, // some custom class
} sclass; } StationClass;
typedef struct StationSpec {
uint32 grfid;
int localidx; // per-GRFFile station index + 1; SetCustomStation() takes care of this
StationClass sclass;
/* Bitmask of platform numbers/lengths available for the station. Bits /* Bitmask of platform numbers/lengths available for the station. Bits
* 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms or * 0..6 correspond to 1..7, while bit 7 corresponds to >7 platforms or
@ -241,22 +243,22 @@ struct StationSpec {
/* Sprite offsets for renderdata->seq->image. spritegroup[0] is default /* Sprite offsets for renderdata->seq->image. spritegroup[0] is default
* whilst spritegroup[1] is "CID_PURCHASE". */ * whilst spritegroup[1] is "CID_PURCHASE". */
struct SpriteGroup spritegroup[2]; SpriteGroup spritegroup[2];
}; } StationSpec;
/* Here, @stid is local per-GRFFile station index. If spec->localidx is not yet /* Here, @stid is local per-GRFFile station index. If spec->localidx is not yet
* set, it gets new dynamically allocated global index and spec->localidx is * set, it gets new dynamically allocated global index and spec->localidx is
* set to @stid, otherwise we take it as that we are replacing it and try to * set to @stid, otherwise we take it as that we are replacing it and try to
* search for it first (that isn't much fast but we do it only very seldom). */ * search for it first (that isn't much fast but we do it only very seldom). */
void SetCustomStation(byte stid, struct StationSpec *spec); void SetCustomStation(byte stid, StationSpec *spec);
/* Here, @stid is global station index (in continous range 0..GetCustomStationsCount()) /* Here, @stid is global station index (in continous range 0..GetCustomStationsCount())
* (lookup is therefore very fast as we do this very frequently). */ * (lookup is therefore very fast as we do this very frequently). */
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid); StationSpec *GetCustomStation(StationClass sclass, byte stid);
/* Get sprite offset for a given custom station and station structure (may be /* Get sprite offset for a given custom station and station structure (may be
* NULL if ctype is set - that means we are in a build dialog). The station * NULL if ctype is set - that means we are in a build dialog). The station
* structure is used for variational sprite groups. */ * structure is used for variational sprite groups. */
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype); uint32 GetCustomStationRelocation(StationSpec *spec, Station *stat, byte ctype);
int GetCustomStationsCount(enum StationClass sclass); int GetCustomStationsCount(StationClass sclass);
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type); RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
static inline int GetRoadStopType(TileIndex tile) static inline int GetRoadStopType(TileIndex tile)

View File

@ -889,7 +889,7 @@ static inline byte *CreateMulti(byte *layout, int n, byte b)
} }
// stolen from TTDPatch // stolen from TTDPatch
static void GetStationLayout(byte *layout, int numtracks, int plat_len, struct StationSpec *spec) static void GetStationLayout(byte *layout, int numtracks, int plat_len, StationSpec *spec)
{ {
if (spec != NULL && spec->lengths >= plat_len && if (spec != NULL && spec->lengths >= plat_len &&
spec->platforms[plat_len - 1] >= numtracks && spec->platforms[plat_len - 1] >= numtracks &&
@ -1018,7 +1018,7 @@ int32 CmdBuildRailroadStation(int x_org, int y_org, uint32 flags, uint32 p1, uin
int tile_delta; int tile_delta;
byte *layout_ptr; byte *layout_ptr;
uint station_index = st->index; uint station_index = st->index;
struct StationSpec *statspec; StationSpec *statspec;
// Now really clear the land below the station // Now really clear the land below the station
// It should never return CMD_ERROR.. but you never know ;) // It should never return CMD_ERROR.. but you never know ;)
@ -1169,11 +1169,11 @@ uint GetStationPlatforms(Station *st, uint tile)
/* TODO: Custom classes! */ /* TODO: Custom classes! */
/* Indexed by class, just STAT_CLASS_DFLT and STAT_CLASS_WAYP supported. */ /* Indexed by class, just STAT_CLASS_DFLT and STAT_CLASS_WAYP supported. */
static int _statspec_highest_id[2] = {-1, -1}; static int _statspec_highest_id[2] = {-1, -1};
static struct StationSpec _station_spec[2][256]; static StationSpec _station_spec[2][256];
void SetCustomStation(byte local_stid, struct StationSpec *spec) void SetCustomStation(byte local_stid, StationSpec *spec)
{ {
enum StationClass sclass; StationClass sclass;
int stid = -1; int stid = -1;
assert(spec->sclass == STAT_CLASS_DFLT || spec->sclass == STAT_CLASS_WAYP); assert(spec->sclass == STAT_CLASS_DFLT || spec->sclass == STAT_CLASS_WAYP);
@ -1209,7 +1209,7 @@ void SetCustomStation(byte local_stid, struct StationSpec *spec)
memcpy(&_station_spec[sclass][stid], spec, sizeof(*spec)); memcpy(&_station_spec[sclass][stid], spec, sizeof(*spec));
} }
struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid) StationSpec *GetCustomStation(StationClass sclass, byte stid)
{ {
assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP); assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP);
sclass--; sclass--;
@ -1219,16 +1219,15 @@ struct StationSpec *GetCustomStation(enum StationClass sclass, byte stid)
return &_station_spec[sclass][stid]; return &_station_spec[sclass][stid];
} }
static struct RealSpriteGroup * static RealSpriteGroup *ResolveStationSpriteGroup(SpriteGroup *spritegroup, Station *stat)
ResolveStationSpriteGroup(struct SpriteGroup *spritegroup, struct Station *stat)
{ {
switch (spritegroup->type) { switch (spritegroup->type) {
case SGT_REAL: case SGT_REAL:
return &spritegroup->g.real; return &spritegroup->g.real;
case SGT_DETERMINISTIC: { case SGT_DETERMINISTIC: {
struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ; DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
struct SpriteGroup *target; SpriteGroup *target;
int value = -1; int value = -1;
if ((dsg->variable >> 6) == 0) { if ((dsg->variable >> 6) == 0) {
@ -1300,9 +1299,9 @@ ResolveStationSpriteGroup(struct SpriteGroup *spritegroup, struct Station *stat)
} }
} }
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype) uint32 GetCustomStationRelocation(StationSpec *spec, Station *stat, byte ctype)
{ {
struct RealSpriteGroup *rsg; RealSpriteGroup *rsg;
rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat); rsg = ResolveStationSpriteGroup(&spec->spritegroup[ctype], stat);
@ -1322,7 +1321,7 @@ uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat
return 0x42D; return 0x42D;
} }
int GetCustomStationsCount(enum StationClass sclass) int GetCustomStationsCount(StationClass sclass)
{ {
assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP); assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP);
sclass--; sclass--;
@ -2102,7 +2101,7 @@ static void DrawTile_Station(TileInfo *ti)
if (_map3_lo[ti->tile] & 0x10) { if (_map3_lo[ti->tile] & 0x10) {
// look for customization // look for customization
struct StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _map3_hi[ti->tile]); StationSpec *statspec = GetCustomStation(STAT_CLASS_DFLT, _map3_hi[ti->tile]);
//debug("Cust-o-mized %p", statspec); //debug("Cust-o-mized %p", statspec);