diff options
author | peter1138 <peter1138@openttd.org> | 2006-10-17 14:52:55 +0000 |
---|---|---|
committer | peter1138 <peter1138@openttd.org> | 2006-10-17 14:52:55 +0000 |
commit | da639420411af786afb8935b3ffa8ae5b7a2bf02 (patch) | |
tree | 65561802c9a3ba08aa86919f9a87fa96adc65492 | |
parent | 8072c6fe17fceb454171bc1837be4c6f1bdde4bb (diff) | |
download | openttd-da639420411af786afb8935b3ffa8ae5b7a2bf02.tar.xz |
(svn r6795) - NewGRF: Add support for cargo-specific wagon overrides.
-rw-r--r-- | newgrf.c | 5 | ||||
-rw-r--r-- | newgrf_engine.c | 20 | ||||
-rw-r--r-- | newgrf_engine.h | 2 |
3 files changed, 13 insertions, 14 deletions
@@ -1870,8 +1870,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len) if (ctype == GC_INVALID) ctype = GC_PURCHASE; if (wagover) { - // TODO: No multiple cargo types per vehicle yet. --pasky - SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); + SetWagonOverrideSprites(engine, ctype, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); } else { SetCustomEngineSprites(engine, ctype, _cur_grffile->spritegroups[groupid]); last_engines[i] = engine; @@ -1901,7 +1900,7 @@ static void FeatureMapSpriteGroup(byte *buf, int len) SetRotorOverrideSprites(engine, _cur_grffile->spritegroups[groupid]); } else { // TODO: No multiple cargo types per vehicle yet. --pasky - SetWagonOverrideSprites(engine, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); + SetWagonOverrideSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid], last_engines, last_engines_count); } } else { SetCustomEngineSprites(engine, GC_DEFAULT, _cur_grffile->spritegroups[groupid]); diff --git a/newgrf_engine.c b/newgrf_engine.c index 45a8af476..3d6d5bf76 100644 --- a/newgrf_engine.c +++ b/newgrf_engine.c @@ -58,11 +58,10 @@ static const uint16 _cargo_classes[NUM_GLOBAL_CID] = { int _traininfo_vehicle_pitch = 0; int _traininfo_vehicle_width = 29; -// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky - typedef struct WagonOverride { byte *train_id; int trains; + CargoID cargo; const SpriteGroup *group; } WagonOverride; @@ -73,7 +72,7 @@ typedef struct WagonOverrides { static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES]; -void SetWagonOverrideSprites(EngineID engine, const SpriteGroup *group, byte *train_id, int trains) +void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup *group, byte *train_id, int trains) { WagonOverrides *wos; WagonOverride *wo; @@ -88,12 +87,13 @@ void SetWagonOverrideSprites(EngineID engine, const SpriteGroup *group, byte *tr * to prevent leaks. But first we need to refcount the SpriteGroup. * --pasky */ wo->group = group; + wo->cargo = cargo; wo->trains = trains; wo->train_id = malloc(trains); memcpy(wo->train_id, train_id, trains); } -static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, byte overriding_engine) +static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine) { const WagonOverrides *wos = &_engine_wagon_overrides[engine]; int i; @@ -108,7 +108,7 @@ static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, byte overri int j; for (j = 0; j < wo->trains; j++) { - if (wo->train_id[j] == overriding_engine) return wo->group; + if (wo->train_id[j] == overriding_engine && (wo->cargo == cargo || wo->cargo == GC_DEFAULT)) return wo->group; } } return NULL; @@ -872,7 +872,7 @@ SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle *v, Direction dire group = engine_custom_sprites[engine][cargo]; if (v != NULL && v->type == VEH_Train) { - const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); + const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine); if (overset != NULL) group = overset; } @@ -919,7 +919,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_vie bool UsesWagonOverride(const Vehicle* v) { assert(v->type == VEH_Train); - return GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine) != NULL; + return GetWagonOverrideSpriteSet(v->engine_type, _global_cargo_id[_opt.landscape][v->cargo_type], v->u.rail.first_engine) != NULL; } /** @@ -949,7 +949,7 @@ uint16 GetVehicleCallback(uint16 callback, uint32 param1, uint32 param2, EngineI group = engine_custom_sprites[engine][cargo]; if (v != NULL && v->type == VEH_Train) { - const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); + const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine); if (overset != NULL) group = overset; } @@ -991,7 +991,7 @@ uint16 GetVehicleCallbackParent(uint16 callback, uint32 param1, uint32 param2, E group = engine_custom_sprites[engine][cargo]; if (v != NULL && v->type == VEH_Train) { - const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); + const SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine); if (overset != NULL) group = overset; } @@ -1023,7 +1023,7 @@ static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, byte base_rando group = engine_custom_sprites[v->engine_type][cargo]; if (v->type == VEH_Train) { - const SpriteGroup *overset = GetWagonOverrideSpriteSet(v->engine_type, v->u.rail.first_engine); + const SpriteGroup *overset = GetWagonOverrideSpriteSet(v->engine_type, cargo, v->u.rail.first_engine); if (overset != NULL) group = overset; } diff --git a/newgrf_engine.h b/newgrf_engine.h index cad79eb3c..252a1ad1c 100644 --- a/newgrf_engine.h +++ b/newgrf_engine.h @@ -19,7 +19,7 @@ extern const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE]; extern const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID]; extern const uint32 cargo_classes[16]; -void SetWagonOverrideSprites(EngineID engine, const struct SpriteGroup *group, byte *train_id, int trains); +void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, byte *train_id, int trains); void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group); void SetRotorOverrideSprites(EngineID engine, const struct SpriteGroup *group); SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction); |