From 5e7638a6d03bb274dc9b7f9d9f62cf866c6cf7ac Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 Jul 2015 00:32:55 +0100 Subject: [PATCH] Port of old vehicles visible in tunnels patch from http://dev.openttdcoop.org/projects/clientpatches/repository/changes/VehicelsInTunnels.diffhttp://dev.openttdcoop.org/projects/clientpatches/repository/changes/VehicelsInTunnels.diff --- src/lang/english.txt | 1 + src/roadveh_cmd.cpp | 4 ++-- src/table/misc_settings.ini | 4 ++-- src/train_cmd.cpp | 4 ++-- src/transparency.h | 1 + src/transparency_gui.cpp | 6 ++++-- src/vehicle.cpp | 19 +++++++++++++++---- src/vehicle_base.h | 2 ++ src/widgets/transparency_widget.h | 1 + 9 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index ad29b3d596..510f401794 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2275,6 +2275,7 @@ STR_TRANSPARENT_BRIDGES_TOOLTIP :{BLACK}Toggle t STR_TRANSPARENT_STRUCTURES_TOOLTIP :{BLACK}Toggle transparency for structures like lighthouses and antennas. Ctrl+Click to lock STR_TRANSPARENT_CATENARY_TOOLTIP :{BLACK}Toggle transparency for catenary. Ctrl+Click to lock STR_TRANSPARENT_LOADING_TOOLTIP :{BLACK}Toggle transparency for loading indicators. Ctrl+Click to lock +STR_TRANSPARENT_TUNNELS_TOOLTIP :{BLACK}Toggle transparency for vehicles in tunnels. Ctrl+Click to lock. STR_TRANSPARENT_INVISIBLE_TOOLTIP :{BLACK}Set objects invisible instead of transparent # Linkgraph legend window diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 35c671d355..fe37ded414 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1160,7 +1160,7 @@ bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev) v->x_pos = gp.x; v->y_pos = gp.y; v->UpdatePosition(); - if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true); + if (v->IsDrawn()) v->Vehicle::UpdateViewport(true); return true; } @@ -1568,7 +1568,7 @@ static bool RoadVehController(RoadVehicle *v) v->SetLastSpeed(); for (RoadVehicle *u = v; u != NULL; u = u->Next()) { - if ((u->vehstatus & VS_HIDDEN) != 0) continue; + if (!(u->IsDrawn())) continue; u->UpdateViewport(false, false); } diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 52ca2d16ef..fda2f29aae 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -255,7 +255,7 @@ type = SLE_UINT var = _transparency_opt def = 0 min = 0 -max = 0x1FF +max = 0x3FF cat = SC_BASIC [SDTG_VAR] @@ -264,7 +264,7 @@ type = SLE_UINT var = _transparency_lock def = 0 min = 0 -max = 0x1FF +max = 0x3FF cat = SC_BASIC [SDTG_VAR] diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 8f20973b35..6194f6bf42 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3343,7 +3343,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse) v->x_pos = gp.x; v->y_pos = gp.y; v->UpdatePosition(); - if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true); + if (v->IsDrawn()) v->Vehicle::UpdateViewport(true); continue; } } @@ -3870,7 +3870,7 @@ static bool TrainLocoHandler(Train *v, bool mode) } for (Train *u = v; u != NULL; u = u->Next()) { - if ((u->vehstatus & VS_HIDDEN) != 0) continue; + if (!(u->IsDrawn())) continue; u->UpdateViewport(false, false); } diff --git a/src/transparency.h b/src/transparency.h index ab6f9a6f33..773a633e3b 100644 --- a/src/transparency.h +++ b/src/transparency.h @@ -31,6 +31,7 @@ enum TransparencyOption { TO_STRUCTURES, ///< other objects such as transmitters and lighthouses TO_CATENARY, ///< catenary TO_LOADING, ///< loading indicators + TO_TUNNELS, ///< vehicles in tunnels TO_END, TO_INVALID, ///< Invalid transparency option }; diff --git a/src/transparency_gui.cpp b/src/transparency_gui.cpp index 4bad2b0561..0d8d535744 100644 --- a/src/transparency_gui.cpp +++ b/src/transparency_gui.cpp @@ -52,14 +52,15 @@ public: case WID_TT_BRIDGES: case WID_TT_STRUCTURES: case WID_TT_CATENARY: - case WID_TT_LOADING: { + case WID_TT_LOADING: + case WIT_TT_TUNNELS: { uint i = widget - WID_TT_BEGIN; if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, r.left + 1, r.top + 1); break; } case WID_TT_BUTTONS: for (uint i = WID_TT_BEGIN; i < WID_TT_END; i++) { - if (i == WID_TT_LOADING) continue; // Do not draw button for invisible loading indicators. + if (i == WID_TT_LOADING || i == WIT_TT_TUNNELS) continue; // Do not draw button for invisible loading indicators. const NWidgetBase *wi = this->GetWidget(i); DrawFrameRect(wi->pos_x + 1, r.top + 2, wi->pos_x + wi->current_x - 2, r.bottom - 2, COLOUR_PALE_GREEN, @@ -141,6 +142,7 @@ static const NWidgetPart _nested_transparency_widgets[] = { NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_STRUCTURES), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_TOOLTIP), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_CATENARY), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_TOOLTIP), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LOADING), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_TOOLTIP), + NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WIT_TT_TUNNELS), SetMinimalSize(22, 22), SetFill(0, 1), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_TRANSPARENT_TUNNELS_TOOLTIP), NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(), EndContainer(), /* Panel with 'invisibility' buttons. */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 46f98fe63b..e72a0a552f 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -221,6 +221,17 @@ uint Vehicle::Crash(bool flooded) return RandomRange(pass + 1); // Randomise deceased passengers. } +/** + * Get whether a the vehicle should be drawn (i.e. if it isn't hidden, or it is in a tunnel but being shown transparently) + * @return whether to show vehicle + */ +bool Vehicle::IsDrawn() const +{ + return !(this->vehstatus & VS_HIDDEN) || + (IsTransparencySet(TO_TUNNELS) && + ((this->type == VEH_TRAIN && Train::From(this)->track == TRACK_BIT_WORMHOLE) || + (this->type == VEH_ROAD && RoadVehicle::From(this)->state == RVSB_WORMHOLE))); +} /** * Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking. @@ -809,7 +820,7 @@ Vehicle::~Vehicle() /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, * it may happen that vehicle chain is deleted when visible */ - if (!(this->vehstatus & VS_HIDDEN)) this->MarkAllViewportsDirty(); + if (this->IsDrawn()) this->MarkAllViewportsDirty(); Vehicle *v = this->Next(); this->SetNext(NULL); @@ -1013,7 +1024,7 @@ static void DoDrawVehicle(const Vehicle *v) if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); /* Check whether the vehicle shall be transparent due to the game state */ - bool shadowed = (v->vehstatus & VS_SHADOW) != 0; + bool shadowed = (v->vehstatus & (VS_SHADOW | VS_HIDDEN)) != 0; if (v->type == VEH_EFFECT) { /* Check whether the vehicle shall be transparent/invisible due to GUI settings. @@ -1064,7 +1075,7 @@ void ViewportAddVehicles(DrawPixelInfo *dpi) const Vehicle *v = _vehicle_viewport_hash[x + y]; // already masked & 0xFFF while (v != NULL) { - if (!(v->vehstatus & VS_HIDDEN) && + if (v->IsDrawn() && l <= v->coord.right && t <= v->coord.bottom && r >= v->coord.left && @@ -1099,7 +1110,7 @@ Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; FOR_ALL_VEHICLES(v) { - if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0 && + if (((v->vehstatus & VS_UNCLICKABLE) == 0) && v->IsDrawn() && x >= v->coord.left && x <= v->coord.right && y >= v->coord.top && y <= v->coord.bottom) { diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 59584da788..9599efe99b 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -911,6 +911,8 @@ public: return v; } + + bool IsDrawn() const; }; /** diff --git a/src/widgets/transparency_widget.h b/src/widgets/transparency_widget.h index 87618fcb6e..86777ea319 100644 --- a/src/widgets/transparency_widget.h +++ b/src/widgets/transparency_widget.h @@ -25,6 +25,7 @@ enum TransparencyToolbarWidgets { WID_TT_STRUCTURES, ///< Object structure transparency toggle button. WID_TT_CATENARY, ///< Catenary transparency toggle button. WID_TT_LOADING, ///< Loading indicators transparency toggle button. + WIT_TT_TUNNELS, ///< Vehicles in tunnels toggle button. WID_TT_END, ///< End of toggle buttons. /* Panel with buttons for invisibility */