summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-11-18 14:09:39 +0000
committerrubidium <rubidium@openttd.org>2010-11-18 14:09:39 +0000
commitb9407f7ca07f26a4543d75dd381877467721e796 (patch)
treef76695757e9d7259ea03a6bf795303be343e8ad2 /src/vehicle.cpp
parent797435f05d10a9e4410a3a342080d4f8e3c756c8 (diff)
downloadopenttd-b9407f7ca07f26a4543d75dd381877467721e796.tar.xz
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 75ef97ecd..75ef370f5 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -1855,6 +1855,47 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
}
+void Vehicle::UpdateVisualEffect(bool allow_power_change)
+{
+ bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER);
+ this->vcache.cached_vis_effect = 0;
+
+ const Engine *e = Engine::Get(this->engine_type);
+ if (this->type == VEH_TRAIN) {
+ if (e->u.rail.visual_effect != 0) {
+ this->vcache.cached_vis_effect = e->u.rail.visual_effect;
+ } else {
+ Train *t = Train::From(this);
+ if (t->IsWagon() || t->IsArticulatedPart()) {
+ /* Wagons and articulated parts have no effect by default */
+ SetBit(this->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
+ } else if (e->u.rail.engclass == 0) {
+ /* Steam is offset by -4 units */
+ SB(this->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT, VE_OFFSET_CENTRE - 4);
+ } else {
+ /* Diesel fumes and sparks come from the centre */
+ SB(this->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT, VE_OFFSET_CENTRE);
+ }
+ }
+ } else {
+ /* Non-trains do not have a visual effect by default. */
+ SetBit(this->vcache.cached_vis_effect, VE_DISABLE_EFFECT);
+ }
+
+ /* Check powered wagon / visual effect callback */
+ if (HasBit(e->info.callback_mask, CBM_VEHICLE_VISUAL_EFFECT)) {
+ uint16 callback = GetVehicleCallback(CBID_VEHICLE_VISUAL_EFFECT, 0, 0, this->engine_type, this);
+
+ if (callback != CALLBACK_FAILED) this->vcache.cached_vis_effect = GB(callback, 0, 8);
+ }
+
+ if (!allow_power_change && powered_before != HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) {
+ ToggleBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER);
+ ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GBUG_VEH_POWERED_WAGON, false);
+ }
+}
+
+
void Vehicle::SetNext(Vehicle *next)
{
assert(this != next);