Changeset - r1477:d0fe35adb3c4
[Not reviewed]
master
0 10 0
tron - 19 years ago 2005-03-10 07:01:43
tron@openttd.org
(svn r1981) Typedef some structs and enums
10 files changed with 186 insertions and 173 deletions:
0 comments (0 inline, 0 general)
engine.c
Show inline comments
 
@@ -205,27 +205,29 @@ uint32 _engine_refit_masks[TOTAL_NUM_ENG
 

	
 
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky
 

	
 
struct WagonOverride {
 
typedef struct WagonOverride {
 
	byte *train_id;
 
	int trains;
 
	struct SpriteGroup group;
 
};
 
	SpriteGroup group;
 
} WagonOverride;
 

	
 
static struct WagonOverrides {
 
typedef struct WagonOverrides {
 
	int overrides_count;
 
	struct WagonOverride *overrides;
 
} _engine_wagon_overrides[TOTAL_NUM_ENGINES];
 
	WagonOverride *overrides;
 
} WagonOverrides;
 

	
 
static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES];
 

	
 
void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group,
 
                             byte *train_id, int trains)
 
void SetWagonOverrideSprites(byte engine, SpriteGroup *group, byte *train_id,
 
	int trains)
 
{
 
	struct WagonOverrides *wos;
 
	struct WagonOverride *wo;
 
	WagonOverrides *wos;
 
	WagonOverride *wo;
 

	
 
	wos = &_engine_wagon_overrides[engine];
 
	wos->overrides_count++;
 
	wos->overrides = realloc(wos->overrides,
 
	                         wos->overrides_count * sizeof(struct WagonOverride));
 
		wos->overrides_count * sizeof(*wos->overrides));
 

	
 
	wo = &wos->overrides[wos->overrides_count - 1];
 
	/* FIXME: If we are replacing an override, release original SpriteGroup
 
@@ -237,9 +239,9 @@ void SetWagonOverrideSprites(byte engine
 
	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;
 

	
 
	// XXX: This could turn out to be a timesink on profiles. We could
 
@@ -248,7 +250,7 @@ static struct SpriteGroup *GetWagonOverr
 
	// that. --pasky
 

	
 
	for (i = 0; i < wos->overrides_count; i++) {
 
		struct WagonOverride *wo = &wos->overrides[i];
 
		WagonOverride *wo = &wos->overrides[i];
 
		int j;
 

	
 
		for (j = 0; j < wo->trains; j++) {
 
@@ -265,9 +267,9 @@ byte _engine_original_sprites[TOTAL_NUM_
 
// (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
 
// 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
 
	 * to prevent leaks. But first we need to refcount the SpriteGroup.
 
@@ -275,11 +277,11 @@ void SetCustomEngineSprites(byte engine,
 
	_engine_custom_sprites[engine][cargo] = *group;
 
}
 

	
 
typedef struct RealSpriteGroup *(*resolve_callback)(
 
	struct SpriteGroup *spritegroup, const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */
 
typedef RealSpriteGroup *(*resolve_callback)(SpriteGroup *spritegroup,
 
	const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */
 

	
 
static struct RealSpriteGroup* ResolveVehicleSpriteGroup(
 
	struct SpriteGroup *spritegroup, const Vehicle *veh, resolve_callback callback)
 
static RealSpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup,
 
	const Vehicle *veh, resolve_callback callback)
 
{
 
	//debug("spgt %d", spritegroup->type);
 
	switch (spritegroup->type) {
 
@@ -287,8 +289,8 @@ static struct RealSpriteGroup* ResolveVe
 
			return &spritegroup->g.real;
 

	
 
		case SGT_DETERMINISTIC: {
 
			struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
 
			struct SpriteGroup *target;
 
			DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
 
			SpriteGroup *target;
 
			int value = -1;
 

	
 
			//debug("[%p] Having fun resolving variable %x", veh, dsg->variable);
 
@@ -296,7 +298,6 @@ static struct RealSpriteGroup* ResolveVe
 
			if ((dsg->variable >> 6) == 0) {
 
				/* General property */
 
				value = GetDeterministicSpriteValue(dsg->variable);
 

	
 
			} else {
 
				/* Vehicle-specific property. */
 

	
 
@@ -434,7 +435,7 @@ static struct RealSpriteGroup* ResolveVe
 
		}
 

	
 
		case SGT_RANDOMIZED: {
 
			struct RandomizedSpriteGroup *rsg = &spritegroup->g.random;
 
			RandomizedSpriteGroup *rsg = &spritegroup->g.random;
 

	
 
			if (veh == NULL) {
 
				/* Purchase list of something. Show the first one. */
 
@@ -458,9 +459,9 @@ static struct RealSpriteGroup* ResolveVe
 
	}
 
}
 

	
 
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;
 
	byte cargo = CID_PURCHASE;
 

	
 
@@ -472,10 +473,9 @@ static struct SpriteGroup *GetVehicleSpr
 
	group = &_engine_custom_sprites[engine][cargo];
 

	
 
	if (overriding_engine != 0xffff) {
 
		struct SpriteGroup *overset;
 
		SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
 

	
 
		overset = GetWagonOverrideSpriteSet(engine, overriding_engine);
 
		if (overset) group = overset;
 
		if (overset != NULL) group = overset;
 
	}
 

	
 
	return group;
 
@@ -483,8 +483,8 @@ static struct SpriteGroup *GetVehicleSpr
 

	
 
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction)
 
{
 
	struct SpriteGroup *group;
 
	struct RealSpriteGroup *rsg;
 
	SpriteGroup *group;
 
	RealSpriteGroup *rsg;
 
	byte cargo = CID_PURCHASE;
 
	byte loaded = 0;
 
	bool in_motion = 0;
 
@@ -548,21 +548,23 @@ static byte _vsg_bits_to_reseed;
 

	
 
extern int _custom_sprites_base;
 

	
 
static struct RealSpriteGroup *
 
TriggerVehicleSpriteGroup(struct SpriteGroup *spritegroup, struct Vehicle *veh,
 
			  resolve_callback callback)
 
static RealSpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup,
 
	Vehicle *veh, resolve_callback callback)
 
{
 
	if (spritegroup->type == SGT_RANDOMIZED)
 
		_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits(&spritegroup->g.random,
 
		                                                         _vsg_random_triggers,
 
		                                                         &veh->waiting_triggers);
 
	if (spritegroup->type == SGT_RANDOMIZED) {
 
		_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits(
 
			&spritegroup->g.random,
 
			_vsg_random_triggers,
 
			&veh->waiting_triggers
 
		);
 
	}
 

	
 
	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;
 

	
 
	_vsg_random_triggers = trigger;
 
@@ -615,7 +617,7 @@ static void DoTriggerVehicle(Vehicle *ve
 
	}
 
}
 

	
 
void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger)
 
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger)
 
{
 
	DoTriggerVehicle(veh, trigger, 0, true);
 
}
engine.h
Show inline comments
 
@@ -103,7 +103,7 @@ int GetCustomEngineSprite(byte engine, c
 
#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
 
#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
 

	
 
enum VehicleTrigger {
 
typedef enum VehicleTrigger {
 
	VEHICLE_TRIGGER_NEW_CARGO = 1,
 
	// Externally triggered only for the first vehicle in chain
 
	VEHICLE_TRIGGER_DEPOT = 2,
 
@@ -111,8 +111,8 @@ enum VehicleTrigger {
 
	VEHICLE_TRIGGER_EMPTY = 4,
 
	// Not triggered externally (called for the whole chain if we got NEW_CARGO)
 
	VEHICLE_TRIGGER_ANY_NEW_CARGO = 8,
 
};
 
void TriggerVehicle(Vehicle *veh, enum VehicleTrigger trigger);
 
} VehicleTrigger;
 
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger);
 

	
 
void SetCustomEngineName(int engine, const char *name);
 
StringID GetCustomEngineName(int engine);
newgrf.c
Show inline comments
 
@@ -26,7 +26,8 @@ extern int _replace_sprites_count[16];
 
extern int _replace_sprites_offset[16];
 
extern int _traininfo_vehicle_pitch;
 

	
 
struct GRFFile *_cur_grffile, *_first_grffile;
 
GRFFile *_cur_grffile;
 
GRFFile *_first_grffile;
 
int _grffile_count;
 
static int _cur_spriteid;
 
static int _cur_stage;
 
@@ -39,7 +40,7 @@ static int _param_max;
 
static uint32 _ttdpatch_flags[8];
 

	
 

	
 
enum grfspec_feature {
 
typedef enum grfspec_feature {
 
	GSF_TRAIN,
 
	GSF_ROAD,
 
	GSF_SHIP,
 
@@ -47,7 +48,7 @@ enum grfspec_feature {
 
	GSF_STATION,
 
	GSF_BRIDGE,
 
	GSF_TOWNHOUSE,
 
};
 
} grfspec_feature;
 

	
 

	
 
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_WARN,
 
	GMS_ERROR,
 
	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;
 
	char buf[1024];
 
	va_list va;
 

	
 
	va_start(va, str);
 
	vsprintf(buf, str, va);
 
	vsnprintf(buf, sizeof(buf), str, va);
 
	va_end(va);
 

	
 
	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;
 
}
 

	
 
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;
 
}
 

	
 
@@ -683,7 +687,7 @@ static bool StationChangeInfo(uint stid,
 
		case 0x08:
 
		{	/* Class ID */
 
			FOR_EACH_OBJECT {
 
				struct StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				uint32 classid;
 

	
 
				/* classid, for a change, is always little-endian */
 
@@ -714,7 +718,7 @@ static bool StationChangeInfo(uint stid,
 
		case 0x09:
 
		{	/* Define sprite layout */
 
			FOR_EACH_OBJECT {
 
				struct StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				int t;
 

	
 
				stat->tiles = grf_load_byte(&buf);
 
@@ -759,9 +763,9 @@ static bool StationChangeInfo(uint stid,
 
		case 0x0a:
 
		{	/* Copy sprite layout */
 
			FOR_EACH_OBJECT {
 
				struct StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				byte srcid = grf_load_byte(&buf);
 
				struct StationSpec *srcstat = &_cur_grffile->stations[srcid];
 
				StationSpec *srcstat = &_cur_grffile->stations[srcid];
 
				int t;
 

	
 
				stat->tiles = srcstat->tiles;
 
@@ -805,7 +809,7 @@ static bool StationChangeInfo(uint stid,
 
		case 0x0C:
 
		{	/* Platforms number */
 
			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);
 
			}
 
@@ -814,7 +818,7 @@ static bool StationChangeInfo(uint stid,
 
		case 0x0D:
 
		{	/* Platforms length */
 
			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);
 
			}
 
@@ -823,7 +827,7 @@ static bool StationChangeInfo(uint stid,
 
		case 0x0e:
 
		{	/* Define custom layout */
 
			FOR_EACH_OBJECT {
 
				struct StationSpec *stat = &_cur_grffile->stations[stid + i];
 
				StationSpec *stat = &_cur_grffile->stations[stid + i];
 

	
 
				while (buf < *bufp + len) {
 
					byte length = grf_load_byte(&buf);
 
@@ -917,8 +921,6 @@ static bool StationChangeInfo(uint stid,
 
	return ret;
 
}
 

	
 
#undef shift_buf
 

	
 

	
 
/* Action 0x00 */
 
static void VehicleChangeInfo(byte *buf, int len)
 
@@ -1048,7 +1050,6 @@ ignoring:
 
		}
 
		}
 
	}
 
#undef shift_buf
 
}
 

	
 
#undef FOR_EACH_OBJECT
 
@@ -1105,8 +1106,8 @@ static void NewSpriteGroup(byte *buf, in
 
	/* XXX: For stations, these two are "little cargo" and "lotsa cargo" sets. */
 
	uint8 numloaded;
 
	uint8 numloading;
 
	struct SpriteGroup *group;
 
	struct RealSpriteGroup *rg;
 
	SpriteGroup *group;
 
	RealSpriteGroup *rg;
 
	byte *loaded_ptr;
 
	byte *loading_ptr;
 
	int i;
 
@@ -1118,7 +1119,7 @@ static void NewSpriteGroup(byte *buf, in
 
	numloading = buf[4];
 

	
 
	if (numloaded == 0x81 || numloaded == 0x82) {
 
		struct DeterministicSpriteGroup *dg;
 
		DeterministicSpriteGroup *dg;
 
		uint16 groupid;
 
		int i;
 

	
 
@@ -1132,11 +1133,11 @@ static void NewSpriteGroup(byte *buf, in
 

	
 
		if (setid >= _cur_grffile->spritegroups_count) {
 
			_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];
 
		memset(group, 0, sizeof(struct SpriteGroup));
 
		memset(group, 0, sizeof(*group));
 
		group->type = SGT_DETERMINISTIC;
 
		dg = &group->g.determ;
 

	
 
@@ -1190,7 +1191,7 @@ static void NewSpriteGroup(byte *buf, in
 
		return;
 

	
 
	} else if (numloaded == 0x80 || numloaded == 0x83) {
 
		struct RandomizedSpriteGroup *rg;
 
		RandomizedSpriteGroup *rg;
 
		int i;
 

	
 
		/* This stuff is getting actually evaluated in
 
@@ -1202,7 +1203,7 @@ static void NewSpriteGroup(byte *buf, in
 

	
 
		if (setid >= _cur_grffile->spritegroups_count) {
 
			_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];
 
@@ -1268,10 +1269,10 @@ static void NewSpriteGroup(byte *buf, in
 

	
 
	if (setid >= _cur_grffile->spritegroups_count) {
 
		_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];
 
	memset(group, 0, sizeof(struct SpriteGroup));
 
	memset(group, 0, sizeof(*group));
 
	group->type = SGT_REAL;
 
	rg = &group->g.real;
 

	
 
@@ -1347,7 +1348,7 @@ static void NewVehicle_SpriteGroupMappin
 

	
 
		for (i = 0; i < idcount; i++) {
 
			uint8 stid = buf[3 + i];
 
			struct StationSpec *stat = &_cur_grffile->stations[stid];
 
			StationSpec *stat = &_cur_grffile->stations[stid];
 
			byte *bp = &buf[4 + idcount];
 

	
 
			for (c = 0; c < cidcount; c++) {
 
@@ -1381,7 +1382,7 @@ static void NewVehicle_SpriteGroupMappin
 

	
 
			for (i = 0; i < idcount; 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->grfid = _cur_grffile->grfid;
 
@@ -1639,7 +1640,7 @@ static void SkipIf(byte *buf, int len)
 
			param_val = _opt.road_side << 4;
 
			break;
 
		case 0x88: {  /* see if specified GRFID is active */
 
			struct GRFFile *file;
 
			GRFFile *file;
 

	
 
			file = GetFileByGRFID(cond_val);
 
			param_val = (file != NULL);
 
@@ -1959,7 +1960,7 @@ static void GRFInhibit(byte *buf, int le
 

	
 
	for (i = 0; i < num; i++) {
 
		uint32 grfid = grf_load_dword(&buf);
 
		struct GRFFile *file = GetFileByGRFID(grfid);
 
		GRFFile *file = GetFileByGRFID(grfid);
 

	
 
		/* Unset activation flag */
 
		if (file != NULL) {
 
@@ -1996,7 +1997,7 @@ static void InitializeGRFSpecial(void)
 

	
 
void InitNewGRFFile(const char *filename, int sprite_offset)
 
{
 
	struct GRFFile *newfile;
 
	GRFFile *newfile;
 

	
 
	newfile = GetFileByFilename(filename);
 
	if (newfile != NULL) {
 
@@ -2006,7 +2007,7 @@ void InitNewGRFFile(const char *filename
 
		return;
 
	}
 

	
 
	newfile = calloc(1, sizeof(struct GRFFile));
 
	newfile = calloc(1, sizeof(*newfile));
 

	
 
	if (newfile == NULL)
 
		error ("Out of memory");
newgrf.h
Show inline comments
 
@@ -4,12 +4,13 @@
 
#include "sprite.h"
 
#include "station.h"
 

	
 
typedef struct GRFFile GRFFile;
 
struct GRFFile {
 
	char *filename;
 
	uint32 grfid;
 
	uint16 flags;
 
	uint16 sprite_offset;
 
	struct GRFFile *next;
 
	GRFFile *next;
 

	
 
	/* A sprite group contains all sprites of a given vehicle (or multiple
 
	 * vehicles) when carrying given cargo. It consists of several sprite
 
@@ -28,13 +29,13 @@ struct GRFFile {
 
	int spriteset_feature;
 

	
 
	int spritegroups_count;
 
	struct SpriteGroup *spritegroups;
 
	SpriteGroup *spritegroups;
 

	
 
	struct StationSpec stations[256];
 
	StationSpec stations[256];
 
};
 

	
 
extern int _grffile_count;
 
extern struct GRFFile *_first_grffile;
 
extern GRFFile *_first_grffile;
 

	
 
void InitNewGRFFile(const char *filename, int sprite_offset);
 
void DecodeSpecialSprite(const char *filename, int num, int spriteid, int stage);
rail_cmd.c
Show inline comments
 
@@ -1630,7 +1630,7 @@ static void DrawTile_Track(TileInfo *ti)
 

	
 
		if (!IS_RAIL_DEPOT(m5) && IS_RAIL_WAYPOINT(m5) && _map3_lo[ti->tile]&16) {
 
			// 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) {
 
				DrawTileSeqStruct const *seq;
 
@@ -1718,7 +1718,7 @@ void DrawTrainDepotSprite(int x, int y, 
 

	
 
void DrawWaypointSprite(int x, int y, int stat_id, int railtype)
 
{
 
	struct StationSpec *stat;
 
	StationSpec *stat;
 
	uint32 relocation;
 
	DrawTileSprites *cust;
 
	DrawTileSeqStruct const *seq;
settings_gui.c
Show inline comments
 
@@ -1194,7 +1194,7 @@ void ShowPatchesSelection(void)
 
	AllocateWindowDesc(&_patches_selection_desc);
 
}
 

	
 
struct GRFFile *_sel_grffile;
 
GRFFile *_sel_grffile;
 

	
 
enum {
 
	NEWGRF_WND_PROC_OFFSET_TOP_WIDGET = 14,
 
@@ -1207,7 +1207,7 @@ static void NewgrfWndProc(Window *w, Win
 
	case WE_PAINT: {
 
		int x, y = NEWGRF_WND_PROC_OFFSET_TOP_WIDGET;
 
		uint16 i = 0;
 
		struct GRFFile *c = _first_grffile;
 
		GRFFile *c = _first_grffile;
 

	
 
		DrawWindowWidgets(w);
 

	
 
@@ -1323,7 +1323,8 @@ void ShowNewgrf(void)
 

	
 
	{ // little helper function to calculate _grffile_count
 
	  // should be REMOVED once _grffile_count is calculated at loading
 
		struct GRFFile *c = _first_grffile;
 
		GRFFile *c = _first_grffile;
 

	
 
		_grffile_count = 0;
 
		while (c != NULL) {
 
			_grffile_count++;
sprite.c
Show inline comments
 
@@ -6,7 +6,7 @@
 
#include "sprite.h"
 

	
 

	
 
struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value)
 
SpriteGroup *EvalDeterministicSpriteGroup(DeterministicSpriteGroup *dsg, int value)
 
{
 
	int i;
 

	
 
@@ -28,7 +28,7 @@ struct SpriteGroup *EvalDeterministicSpr
 
	}
 

	
 
	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)
 
			return &range->group;
 
@@ -61,8 +61,7 @@ int GetDeterministicSpriteValue(byte var
 
	}
 
}
 

	
 
struct SpriteGroup *
 
EvalRandomizedSpriteGroup(struct RandomizedSpriteGroup *rsg, byte random_bits)
 
SpriteGroup *EvalRandomizedSpriteGroup(RandomizedSpriteGroup *rsg, byte random_bits)
 
{
 
	byte mask;
 
	byte index;
 
@@ -76,8 +75,8 @@ EvalRandomizedSpriteGroup(struct Randomi
 
	return &rsg->groups[index];
 
}
 

	
 
byte RandomizedSpriteGroupTriggeredBits(struct RandomizedSpriteGroup *rsg, byte triggers,
 
                                        byte *waiting_triggers)
 
byte RandomizedSpriteGroupTriggeredBits(RandomizedSpriteGroup *rsg,
 
	byte triggers, byte *waiting_triggers)
 
{
 
	byte match = rsg->triggers & (*waiting_triggers | triggers);
 
	bool res;
sprite.h
Show inline comments
 
@@ -27,9 +27,9 @@ typedef struct DrawTileSprites {
 
/* 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
 
	// 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
 
@@ -45,20 +45,28 @@ struct RealSpriteGroup {
 
	uint16 loaded[16]; // sprite ids
 
	byte loading_count;
 
	uint16 loading[16]; // sprite ids
 
};
 
} RealSpriteGroup;
 

	
 
/* Shared by deterministic and random groups. */
 
enum VarSpriteGroupScope {
 
typedef enum VarSpriteGroupScope {
 
	VSG_SCOPE_SELF,
 
	// Engine of consists for vehicles, city for stations.
 
	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:
 
	enum VarSpriteGroupScope var_scope;
 
	VarSpriteGroupScope var_scope;
 
	byte variable;
 

	
 
	// Do this with it:
 
@@ -66,31 +74,29 @@ struct DeterministicSpriteGroup {
 
	byte and_mask;
 

	
 
	// Then do this with it:
 
	enum DeterministicSpriteGroupOperation {
 
		DSG_OP_NONE,
 
		DSG_OP_DIV,
 
		DSG_OP_MOD,
 
	} operation;
 
	DeterministicSpriteGroupOperation operation;
 
	byte add_val;
 
	byte divmod_val;
 

	
 
	// And apply it to this:
 
	byte num_ranges;
 
	struct DeterministicSpriteGroupRange *ranges; // Dynamically allocated
 
	DeterministicSpriteGroupRange *ranges; // Dynamically allocated
 

	
 
	// Dynamically allocated, this is the sole owner
 
	struct SpriteGroup *default_group;
 
};
 
	SpriteGroup *default_group;
 
} DeterministicSpriteGroup;
 

	
 
struct RandomizedSpriteGroup {
 
typedef enum RandomizedSpriteGroupCompareMode {
 
	RSG_CMP_ANY,
 
	RSG_CMP_ALL,
 
} RandomizedSpriteGroupCompareMode;
 

	
 
typedef struct RandomizedSpriteGroup {
 
	// Take this object:
 
	enum VarSpriteGroupScope var_scope;
 
	VarSpriteGroupScope var_scope;
 

	
 
	// Check for these triggers:
 
	enum RandomizedSpriteGroupCompareMode {
 
		RSG_CMP_ANY,
 
		RSG_CMP_ALL,
 
	} cmp_mode;
 
	RandomizedSpriteGroupCompareMode cmp_mode;
 
	byte triggers;
 

	
 
	// Look for this in the per-object randomized bitmask:
 
@@ -98,25 +104,27 @@ struct RandomizedSpriteGroup {
 
	byte num_groups; // must be power of 2
 

	
 
	// Take the group with appropriate index:
 
	struct SpriteGroup *groups;
 
};
 
	SpriteGroup *groups;
 
} RandomizedSpriteGroup;
 

	
 
typedef enum SpriteGroupType {
 
	SGT_REAL,
 
	SGT_DETERMINISTIC,
 
	SGT_RANDOMIZED,
 
} SpriteGroupType;
 

	
 
struct SpriteGroup {
 
	enum SpriteGroupType {
 
		SGT_REAL,
 
		SGT_DETERMINISTIC,
 
		SGT_RANDOMIZED,
 
	} type;
 
	SpriteGroupType type;
 

	
 
	union {
 
		struct RealSpriteGroup real;
 
		struct DeterministicSpriteGroup determ;
 
		struct RandomizedSpriteGroup random;
 
		RealSpriteGroup real;
 
		DeterministicSpriteGroup determ;
 
		RandomizedSpriteGroup random;
 
	} g;
 
};
 

	
 
struct DeterministicSpriteGroupRange {
 
	struct SpriteGroup group;
 
	SpriteGroup group;
 
	byte low;
 
	byte high;
 
};
 
@@ -131,10 +139,10 @@ int GetDeterministicSpriteValue(byte var
 
/* This takes randomized bitmask (probably associated with
 
 * vehicle/station/whatever) and chooses corresponding SpriteGroup
 
 * 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
 
 * of random bits to be reseeded, or zero if there were no triggers matched
 
 * (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
station.h
Show inline comments
 
@@ -187,22 +187,24 @@ uint GetStationPlatforms(Station *st, ui
 
 * where index is computed as (x * platforms) + platform. */
 
typedef byte *StationLayout;
 

	
 
struct StationSpec {
 
typedef enum StationClass {
 
	STAT_CLASS_NONE, // unused station slot or so
 
	STAT_CLASS_DFLT, // default station class
 
	STAT_CLASS_WAYP, // waypoints
 

	
 
	/* TODO: When we actually support custom classes, they are
 
	 * going to be allocated dynamically (with some classid->sclass
 
	 * mapping, there's a TTDPatch limit on 16 custom classes in
 
	 * the whole game at the same time) with base at
 
	 * STAT_CLASS_CUSTOM. --pasky */
 
	STAT_CLASS_CUSTOM, // some custom class
 
} StationClass;
 

	
 
typedef struct StationSpec {
 
	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_DFLT, // default station class
 
		STAT_CLASS_WAYP, // waypoints
 

	
 
		/* TODO: When we actually support custom classes, they are
 
		 * going to be allocated dynamically (with some classid->sclass
 
		 * mapping, there's a TTDPatch limit on 16 custom classes in
 
		 * the whole game at the same time) with base at
 
		 * STAT_CLASS_CUSTOM. --pasky */
 
		STAT_CLASS_CUSTOM, // some custom class
 
	} sclass;
 
	StationClass sclass;
 

	
 
	/* Bitmask of platform numbers/lengths available for the station.  Bits
 
	 * 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
 
	 * 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
 
 * 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
 
 * 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())
 
 * (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
 
 * NULL if ctype is set - that means we are in a build dialog). The station
 
 * structure is used for variational sprite groups. */
 
uint32 GetCustomStationRelocation(struct StationSpec *spec, struct Station *stat, byte ctype);
 
int GetCustomStationsCount(enum StationClass sclass);
 
uint32 GetCustomStationRelocation(StationSpec *spec, Station *stat, byte ctype);
 
int GetCustomStationsCount(StationClass sclass);
 

	
 
RoadStop * GetRoadStopByTile(TileIndex tile, RoadStopType type);
 
static inline int GetRoadStopType(TileIndex tile)
station_cmd.c
Show inline comments
 
@@ -889,7 +889,7 @@ static inline byte *CreateMulti(byte *la
 
}
 

	
 
// 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 &&
 
			spec->platforms[plat_len - 1] >= numtracks &&
 
@@ -1018,7 +1018,7 @@ int32 CmdBuildRailroadStation(int x_org,
 
		int tile_delta;
 
		byte *layout_ptr;
 
		uint station_index = st->index;
 
		struct StationSpec *statspec;
 
		StationSpec *statspec;
 

	
 
		// Now really clear the land below the station
 
		// It should never return CMD_ERROR.. but you never know ;)
 
@@ -1169,11 +1169,11 @@ uint GetStationPlatforms(Station *st, ui
 
/* TODO: Custom classes! */
 
/* Indexed by class, just STAT_CLASS_DFLT and STAT_CLASS_WAYP supported. */
 
static int _statspec_highest_id[2] = {-1, -1};
 
static struct StationSpec _station_spec[2][256];
 

	
 
void SetCustomStation(byte local_stid, struct StationSpec *spec)
 
static StationSpec _station_spec[2][256];
 

	
 
void SetCustomStation(byte local_stid, StationSpec *spec)
 
{
 
	enum StationClass sclass;
 
	StationClass sclass;
 
	int stid = -1;
 

	
 
	assert(spec->sclass == STAT_CLASS_DFLT || spec->sclass == STAT_CLASS_WAYP);
 
@@ -1209,7 +1209,7 @@ void SetCustomStation(byte local_stid, s
 
	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);
 
	sclass--;
 
@@ -1219,16 +1219,15 @@ struct StationSpec *GetCustomStation(enu
 
	return &_station_spec[sclass][stid];
 
}
 

	
 
static struct RealSpriteGroup *
 
ResolveStationSpriteGroup(struct SpriteGroup *spritegroup, struct Station *stat)
 
static RealSpriteGroup *ResolveStationSpriteGroup(SpriteGroup *spritegroup, Station *stat)
 
{
 
	switch (spritegroup->type) {
 
		case SGT_REAL:
 
			return &spritegroup->g.real;
 

	
 
		case SGT_DETERMINISTIC: {
 
			struct DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
 
			struct SpriteGroup *target;
 
			DeterministicSpriteGroup *dsg = &spritegroup->g.determ;
 
			SpriteGroup *target;
 
			int value = -1;
 

	
 
			if ((dsg->variable >> 6) == 0) {
 
@@ -1300,9 +1299,9 @@ ResolveStationSpriteGroup(struct SpriteG
 
	}
 
}
 

	
 
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);
 

	
 
@@ -1322,7 +1321,7 @@ uint32 GetCustomStationRelocation(struct
 
	return 0x42D;
 
}
 

	
 
int GetCustomStationsCount(enum StationClass sclass)
 
int GetCustomStationsCount(StationClass sclass)
 
{
 
	assert(sclass == STAT_CLASS_DFLT || sclass == STAT_CLASS_WAYP);
 
	sclass--;
 
@@ -2102,7 +2101,7 @@ static void DrawTile_Station(TileInfo *t
 

	
 
	if (_map3_lo[ti->tile] & 0x10) {
 
		// 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);
 

	
0 comments (0 inline, 0 general)