(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
authordarkvater
Sun, 14 Nov 2004 20:53:34 +0000
changeset 414 4629d4bf7f14
parent 413 36f14a6d63d7
child 415 20f981988266
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
engine.c
engine.h
sprite.c
--- a/engine.c	Sun Nov 14 20:50:38 2004 +0000
+++ b/engine.c	Sun Nov 14 20:53:34 2004 +0000
@@ -243,14 +243,26 @@
 	_engine_custom_sprites[engine][cargo] = *group;
 }
 
-int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo,
-                          byte loaded, byte in_motion, byte direction)
+int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction)
 {
-	struct SpriteGroup *group = &_engine_custom_sprites[engine][cargo];
+	struct SpriteGroup *group;
 	struct RealSpriteGroup *rsg;
+	uint16 overriding_engine = -1;
+	byte cargo = CID_PURCHASE;
+	byte loaded = 0;
+	byte in_motion = 0;
 	int totalsets, spriteset;
 	int r;
 
+	if (v != NULL) {
+		overriding_engine = v->type == VEH_Train ? v->u.rail.first_engine : -1;
+		cargo = _global_cargo_id[_opt.landscape][v->cargo_type];
+		loaded = ((v->cargo_count + 1) * 100) / (v->cargo_cap + 1);
+		in_motion = !!v->cur_speed;
+	}
+
+	group = &_engine_custom_sprites[engine][cargo];
+
 	if (overriding_engine != 0xffff) {
 		struct SpriteGroup *overset;
 
--- a/engine.h	Sun Nov 14 20:50:38 2004 +0000
+++ b/engine.h	Sun Nov 14 20:53:34 2004 +0000
@@ -97,14 +97,9 @@
 void SetWagonOverrideSprites(byte engine, struct SpriteGroup *group, byte *train_id, int trains);
 void SetCustomEngineSprites(byte engine, byte cargo, struct SpriteGroup *group);
 // loaded is in percents, overriding_engine 0xffff is none
-int GetCustomEngineSprite(byte engine, uint16 overriding_engine, byte cargo, byte loaded, byte in_motion, byte direction);
-#define GetCustomVehicleSprite(v, direction) \
-	GetCustomEngineSprite(v->engine_type, v->type == VEH_Train ? v->u.rail.first_engine : -1, \
-	                      _global_cargo_id[_opt.landscape][v->cargo_type], \
-	                      ((v->cargo_count + 1) * 100) / (v->cargo_cap + 1), \
-	                      !!v->cur_speed, direction)
-#define GetCustomVehicleIcon(v, direction) \
-	GetCustomEngineSprite(v, -1, CID_PURCHASE, 0, 0, direction)
+int GetCustomEngineSprite(byte engine, Vehicle *v, byte direction);
+#define GetCustomVehicleSprite(v, direction) GetCustomEngineSprite(v->engine_type, v, direction)
+#define GetCustomVehicleIcon(et, direction) GetCustomEngineSprite(et, NULL, direction)
 
 void SetCustomEngineName(int engine, char *name);
 StringID GetCustomEngineName(int engine);
--- a/sprite.c	Sun Nov 14 20:50:38 2004 +0000
+++ b/sprite.c	Sun Nov 14 20:53:34 2004 +0000
@@ -1,62 +1,62 @@
-#include "stdafx.h"
-
-#include <stdarg.h>
-
-#include "ttd.h"
-#include "sprite.h"
-
-
-struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value)
-{
-	int i;
-
-	value >>= dsg->shift_num; // This should bring us to the byte range.
-	value &= dsg->and_mask;
-
-	if (dsg->operation != DSG_OP_NONE)
-		value += (signed char) dsg->add_val;
-
-	switch (dsg->operation) {
-		case DSG_OP_DIV:
-			value /= (signed char) dsg->divmod_val;
-			break;
-		case DSG_OP_MOD:
-			value %= (signed char) dsg->divmod_val;
-			break;
-		case DSG_OP_NONE:
-			break;
-	}
-
-	for (i = 0; i < dsg->num_ranges; i++) {
-		struct DeterministicSpriteGroupRange *range = &dsg->ranges[i];
-
-		if (range->low <= value && value <= range->high)
-			return &range->group;
-	}
-
-	return dsg->default_group;
-}
-
-int GetDeterministicSpriteValue(byte var)
-{
-	switch (var) {
-		case 0x00:
-			return _date;
-		case 0x01:
-			return _cur_year;
-		case 0x02:
-			return _cur_month;
-		case 0x03:
-			return _opt.landscape;
-		case 0x09:
-			return _date_fract;
-		case 0x0A:
-			return _tick_counter;
-		case 0x0C:
-			/* If we got here, it means there was no callback or
-			 * callbacks aren't supported on our callpath. */
-			return 0;
-		default:
-			return -1;
-	}
-}
+#include "stdafx.h"
+
+#include <stdarg.h>
+
+#include "ttd.h"
+#include "sprite.h"
+
+
+struct SpriteGroup *EvalDeterministicSpriteGroup(struct DeterministicSpriteGroup *dsg, int value)
+{
+	int i;
+
+	value >>= dsg->shift_num; // This should bring us to the byte range.
+	value &= dsg->and_mask;
+
+	if (dsg->operation != DSG_OP_NONE)
+		value += (signed char) dsg->add_val;
+
+	switch (dsg->operation) {
+		case DSG_OP_DIV:
+			value /= (signed char) dsg->divmod_val;
+			break;
+		case DSG_OP_MOD:
+			value %= (signed char) dsg->divmod_val;
+			break;
+		case DSG_OP_NONE:
+			break;
+	}
+
+	for (i = 0; i < dsg->num_ranges; i++) {
+		struct DeterministicSpriteGroupRange *range = &dsg->ranges[i];
+
+		if (range->low <= value && value <= range->high)
+			return &range->group;
+	}
+
+	return dsg->default_group;
+}
+
+int GetDeterministicSpriteValue(byte var)
+{
+	switch (var) {
+		case 0x00:
+			return _date;
+		case 0x01:
+			return _cur_year;
+		case 0x02:
+			return _cur_month;
+		case 0x03:
+			return _opt.landscape;
+		case 0x09:
+			return _date_fract;
+		case 0x0A:
+			return _tick_counter;
+		case 0x0C:
+			/* If we got here, it means there was no callback or
+			 * callbacks aren't supported on our callpath. */
+			return 0;
+		default:
+			return -1;
+	}
+}