Chunnel: Add a ground veh flag for (maybe) being in a chunnel

Use this to avoid inclination change code in non-chunnel wormholes.
This commit is contained in:
Jonathan G Rennison
2017-03-05 18:37:35 +00:00
parent ec9f0371e8
commit 4c9f7b73b3
2 changed files with 9 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
#include "vehicle_gui.h" #include "vehicle_gui.h"
#include "landscape.h" #include "landscape.h"
#include "window_func.h" #include "window_func.h"
#include "tunnel_map.h"
#include "widgets/vehicle_widget.h" #include "widgets/vehicle_widget.h"
/** What is the status of our acceleration? */ /** What is the status of our acceleration? */
@@ -54,6 +55,7 @@ enum GroundVehicleFlags {
GVF_GOINGUP_BIT = 0, ///< Vehicle is currently going uphill. (Cached track information for acceleration) GVF_GOINGUP_BIT = 0, ///< Vehicle is currently going uphill. (Cached track information for acceleration)
GVF_GOINGDOWN_BIT = 1, ///< Vehicle is currently going downhill. (Cached track information for acceleration) GVF_GOINGDOWN_BIT = 1, ///< Vehicle is currently going downhill. (Cached track information for acceleration)
GVF_SUPPRESS_IMPLICIT_ORDERS = 2, ///< Disable insertion and removal of automatic orders until the vehicle completes the real order. GVF_SUPPRESS_IMPLICIT_ORDERS = 2, ///< Disable insertion and removal of automatic orders until the vehicle completes the real order.
GVF_CHUNNEL_BIT = 3, ///< Vehicle may currently be in a chunnel. (Cached track information for inclination changes)
}; };
/** /**
@@ -225,6 +227,10 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
this->z_pos += HasBit(this->gv_flags, GVF_GOINGUP_BIT) ? d : -d; this->z_pos += HasBit(this->gv_flags, GVF_GOINGUP_BIT) ? d : -d;
} }
if (HasBit(this->gv_flags, GVF_CHUNNEL_BIT) && !IsTunnelTile(this->tile)) {
ClrBit(this->gv_flags, GVF_CHUNNEL_BIT);
}
assert(this->z_pos == GetSlopePixelZ(this->x_pos, this->y_pos)); assert(this->z_pos == GetSlopePixelZ(this->x_pos, this->y_pos));
} }
@@ -241,7 +247,7 @@ struct GroundVehicle : public SpecializedVehicle<T, Type> {
int old_z = this->z_pos; int old_z = this->z_pos;
if (in_wormhole) { if (in_wormhole) {
this->UpdateZPositionInWormhole(); if (HasBit(this->gv_flags, GVF_CHUNNEL_BIT)) this->UpdateZPositionInWormhole();
} else if (new_tile) { } else if (new_tile) {
this->UpdateZPositionAndInclination(); this->UpdateZPositionAndInclination();
} else { } else {

View File

@@ -2108,6 +2108,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
if (frame == _tunnel_visibility_frame[dir]) { if (frame == _tunnel_visibility_frame[dir]) {
t->tile = tile; t->tile = tile;
t->track = TRACK_BIT_WORMHOLE; t->track = TRACK_BIT_WORMHOLE;
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(t->gv_flags, GVF_CHUNNEL_BIT);
t->vehstatus |= VS_HIDDEN; t->vehstatus |= VS_HIDDEN;
return VETSB_ENTERED_WORMHOLE; return VETSB_ENTERED_WORMHOLE;
} }
@@ -2133,6 +2134,7 @@ static VehicleEnterTileStatus VehicleEnter_TunnelBridge(Vehicle *v, TileIndex ti
rv->tile = tile; rv->tile = tile;
rv->cur_image_valid_dir = INVALID_DIR; rv->cur_image_valid_dir = INVALID_DIR;
rv->state = RVSB_WORMHOLE; rv->state = RVSB_WORMHOLE;
if (Tunnel::GetByTile(tile)->is_chunnel) SetBit(rv->gv_flags, GVF_CHUNNEL_BIT);
rv->vehstatus |= VS_HIDDEN; rv->vehstatus |= VS_HIDDEN;
return VETSB_ENTERED_WORMHOLE; return VETSB_ENTERED_WORMHOLE;
} else { } else {