From 236737b2f29cc9ddd129a963d6a312a5c4ffe78b Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 15 Aug 2010 19:59:48 +0000 Subject: (svn r20505) -Feature [FS#3978]: Allow changing visual effect when changing railtype. --- src/train_cmd.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'src/train_cmd.cpp') diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 442c7d680..70c275925 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -129,11 +129,28 @@ void CheckTrainsLengths() } } +/** + * Update visual effect, power and acceleration caches. + * Called when a vehicle in the consist enters a different railtype. + */ +void Train::RailtypeChanged() +{ + for (Train *u = this; u != NULL; u = u->Next()) { + /* The wagon-is-powered-state should not change, so the weight does not change. */ + u->UpdateVisualEffect(false); + } + this->PowerChanged(); + if (this->IsFrontEngine()) this->UpdateAcceleration(); +} + /** * Update the cached visual effect. + * @param allow_power_change true if the wagon-is-powered-state may change. */ -void Train::UpdateVisualEffect() +void Train::UpdateVisualEffect(bool allow_power_change) { + byte powered_before = this->tcache.cached_vis_effect & 0x80; + 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; @@ -156,6 +173,11 @@ void Train::UpdateVisualEffect() if (callback != CALLBACK_FAILED) this->tcache.cached_vis_effect = GB(callback, 0, 8); } + + if (!allow_power_change && powered_before != (this->tcache.cached_vis_effect & 0x80)) { + this->tcache.cached_vis_effect ^= 0x80; + ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GBUG_VEH_POWERED_WAGON, false); + } } /** @@ -215,7 +237,7 @@ void Train::ConsistChanged(bool same_length) u->colourmap = PAL_NONE; /* Update powered-wagon-status and visual effect */ - u->UpdateVisualEffect(); + u->UpdateVisualEffect(true); if (rvi_v->pow_wag_power != 0 && rvi_u->railveh_type == RAILVEH_WAGON && UsesWagonOverride(u) && !HasBit(u->tcache.cached_vis_effect, 7)) { @@ -1566,7 +1588,7 @@ static void ReverseTrainSwapVeh(Train *v, int l, int r) } /* Update power of the train in case tiles were different rail type. */ - v->PowerChanged(); + v->RailtypeChanged(); } @@ -3367,8 +3389,7 @@ static void TrainController(Train *v, Vehicle *nomove) v->tile = gp.new_tile; if (GetTileRailType(gp.new_tile) != GetTileRailType(gp.old_tile)) { - v->First()->PowerChanged(); - v->First()->UpdateAcceleration(); + v->First()->RailtypeChanged(); } v->track = chosen_track; -- cgit v1.2.3-54-g00ecf