(svn r20504) -Codechange: Move updating of train's visual effect to separate function.

pull/155/head
frosch 14 years ago
parent fe3c70624e
commit c4f630e5ba

@ -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…
Cancel
Save