diff options
-rw-r--r-- | src/train.h | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 52 |
2 files changed, 33 insertions, 21 deletions
diff --git a/src/train.h b/src/train.h index 40c340328..885130ba7 100644 --- a/src/train.h +++ b/src/train.h @@ -372,6 +372,8 @@ struct Train : public GroundVehicle<Train, VEH_TRAIN> { protected: // These functions should not be called outside acceleration code. + void UpdateVisualEffect(); + /** * Allows to know the power value that this vehicle will use. * @return Power value from the engine in HP, or zero if the vehicle is not powered. diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index c87e8d96e..442c7d680 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -130,6 +130,35 @@ void CheckTrainsLengths() } /** + * Update the cached visual effect. + */ +void Train::UpdateVisualEffect() +{ + const Engine *e = Engine::Get(this->engine_type); + if (e->u.rail.visual_effect != 0) { + this->tcache.cached_vis_effect = e->u.rail.visual_effect; + } else { + if (this->IsWagon() || this->IsArticulatedPart()) { + /* Wagons and articulated parts have no effect by default */ + this->tcache.cached_vis_effect = 0x40; + } else if (e->u.rail.engclass == 0) { + /* Steam is offset by -4 units */ + this->tcache.cached_vis_effect = 4; + } else { + /* Diesel fumes and sparks come from the centre */ + this->tcache.cached_vis_effect = 8; + } + } + + /* Check powered wagon / visual effect callback */ + if (HasBit(e->info.callback_mask, CBM_TRAIN_WAGON_POWER)) { + uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, this->engine_type, this); + + if (callback != CALLBACK_FAILED) this->tcache.cached_vis_effect = GB(callback, 0, 8); + } +} + +/** * Recalculates the cached stuff of a train. Should be called each time a vehicle is added * to/removed from the chain, and when the game is loaded. * Note: this needs to be called too for 'wagon chains' (in the depot, without an engine) @@ -185,27 +214,8 @@ void Train::ConsistChanged(bool same_length) /* Reset colour map */ u->colourmap = PAL_NONE; - if (rvi_u->visual_effect != 0) { - u->tcache.cached_vis_effect = rvi_u->visual_effect; - } else { - if (u->IsWagon() || u->IsArticulatedPart()) { - /* Wagons and articulated parts have no effect by default */ - u->tcache.cached_vis_effect = 0x40; - } else if (rvi_u->engclass == 0) { - /* Steam is offset by -4 units */ - u->tcache.cached_vis_effect = 4; - } else { - /* Diesel fumes and sparks come from the centre */ - u->tcache.cached_vis_effect = 8; - } - } - - /* Check powered wagon / visual effect callback */ - if (HasBit(e_u->info.callback_mask, CBM_TRAIN_WAGON_POWER)) { - uint16 callback = GetVehicleCallback(CBID_TRAIN_WAGON_POWER, 0, 0, u->engine_type, u); - - if (callback != CALLBACK_FAILED) u->tcache.cached_vis_effect = GB(callback, 0, 8); - } + /* Update powered-wagon-status and visual effect */ + u->UpdateVisualEffect(); if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON && UsesWagonOverride(u) && !HasBit(u->tcache.cached_vis_effect, 7)) { |