mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r20504) -Codechange: Move updating of train's visual effect to separate function.
This commit is contained in:
parent
4ca2609362
commit
57a098bccc
@ -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.
|
||||
|
@ -129,6 +129,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.
|
||||
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user