summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-10-12 15:05:25 +0000
committerpeter1138 <peter1138@openttd.org>2006-10-12 15:05:25 +0000
commitd9a1578cf44ec4788dfc9ff1fb99a6b7fccbbc73 (patch)
treeb4c00efeffa403c0b59c9b6e007533edfd82dce4
parentfd3fd176e50fdacf5b48ff024b7f182dbb88782d (diff)
downloadopenttd-d9a1578cf44ec4788dfc9ff1fb99a6b7fccbbc73.tar.xz
(svn r6756) - Fix: When resolving vehicle groups, only fall back to the default group if the group chosen is undefined, not if it returns a bad result. This fixes some issues with UKRS.
-rw-r--r--newgrf_engine.c41
1 files changed, 11 insertions, 30 deletions
diff --git a/newgrf_engine.c b/newgrf_engine.c
index cbc8844db..45a8af476 100644
--- a/newgrf_engine.c
+++ b/newgrf_engine.c
@@ -862,14 +862,12 @@ SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction dire
{
const SpriteGroup *group;
ResolverObject object;
- CargoID cargo = GC_PURCHASE;
+ CargoID cargo;
NewVehicleResolver(&object, engine, v);
- if (v != NULL) {
- cargo = _global_cargo_id[_opt.landscape][v->cargo_type];
- assert(cargo != GC_INVALID);
- }
+ cargo = (v == NULL) ? GC_PURCHASE : _global_cargo_id[_opt.landscape][v->cargo_type];
+ assert(cargo != GC_INVALID);
group = engine_custom_sprites[engine][cargo];
@@ -879,13 +877,8 @@ SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction dire
if (overset != NULL) group = overset;
}
+ if (group == NULL) group = engine_custom_sprites[engine][GC_DEFAULT];
group = Resolve(group, &object);
-
- if ((group == NULL || group->type != SGT_RESULT) && cargo != GC_DEFAULT) {
- // This group is empty but perhaps there'll be a default one.
- group = Resolve(engine_custom_sprites[engine][GC_DEFAULT], &object);
- }
-
if (group == NULL || group->type != SGT_RESULT) return 0;
return group->g.result.sprite + (direction % group->g.result.num_sprites);
@@ -951,6 +944,7 @@ uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineI
object.callback_param2 = param2;
cargo = (v == NULL) ? GC_PURCHASE : _global_cargo_id[_opt.landscape][v->cargo_type];
+ assert(cargo != GC_INVALID);
group = engine_custom_sprites[engine][cargo];
@@ -960,13 +954,8 @@ uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineI
if (overset != NULL) group = overset;
}
+ if (group == NULL) group = engine_custom_sprites[engine][GC_DEFAULT];
group = Resolve(group, &object);
-
- if ((group == NULL || group->type != SGT_CALLBACK) && cargo != GC_DEFAULT) {
- // This group is empty but perhaps there'll be a default one.
- group = Resolve(engine_custom_sprites[engine][GC_DEFAULT], &object);
- }
-
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
return group->g.callback.result;
@@ -997,6 +986,7 @@ uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, E
object.u.vehicle.parent = parent;
cargo = (v == NULL) ? GC_PURCHASE : _global_cargo_id[_opt.landscape][v->cargo_type];
+ assert(cargo != GC_INVALID);
group = engine_custom_sprites[engine][cargo];
@@ -1006,13 +996,8 @@ uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, E
if (overset != NULL) group = overset;
}
+ if (group == NULL) group = engine_custom_sprites[engine][GC_DEFAULT];
group = Resolve(group, &object);
-
- if ((group == NULL || group->type != SGT_CALLBACK) && cargo != GC_DEFAULT) {
- // This group is empty but perhaps there'll be a default one.
- group = Resolve(engine_custom_sprites[engine][GC_DEFAULT], &object);
- }
-
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
return group->g.callback.result;
@@ -1033,6 +1018,8 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
object.trigger = trigger;
cargo = _global_cargo_id[_opt.landscape][v->cargo_type];
+ assert(cargo != GC_INVALID);
+
group = engine_custom_sprites[v->engine_type][cargo];
if (v->type == VEH_Train) {
@@ -1040,14 +1027,8 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando
if (overset != NULL) group = overset;
}
+ if (group == NULL) group = engine_custom_sprites[v->engine_type][GC_DEFAULT];
group = Resolve(group, &object);
- if (group == NULL && v->cargo_type != GC_DEFAULT) {
- // This group is empty but perhaps there'll be a default one.
- group = Resolve(engine_custom_sprites[v->engine_type][GC_DEFAULT], &object);
- }
-
- /* Really return? */
- if (group == NULL) return;
new_random_bits = Random();
v->random_bits &= ~object.reseed;