# HG changeset patch # User rubidium # Date 2008-04-05 15:30:15 # Node ID 6c9ef37d3595efb1d87f2fcae90fcd70ab9f8528 # Parent 00e04a1734cedb0d054bbeec62b8e14d6c435e71 (svn r12580) -Codechange: merge some logical related to non-stop orders. diff --git a/src/order_base.h b/src/order_base.h --- a/src/order_base.h +++ b/src/order_base.h @@ -9,6 +9,8 @@ #include "oldpool.h" #include "core/bitmath_func.hpp" #include "cargo_type.h" +#include "station_type.h" +#include "vehicle_type.h" DECLARE_OLD_POOL(Order, Order, 6, 1000) @@ -40,6 +42,8 @@ struct Order : PoolItemcurrent_order.flags & OFB_NON_STOP && IsTileType(v->tile, MP_STATION) && v->current_order.dest == GetStationIndex(v->tile)) { + v->last_station_visited = v->current_order.dest; UpdateVehicleTimetable(v, true); v->cur_order_index++; } @@ -1414,6 +1415,23 @@ bool ProcessOrders(Vehicle *v) return may_reverse; } +/** + * Check whether the given vehicle should stop at the given station + * based on this order and the non-stop settings. + * @param v the vehicle that might be stopping. + * @param station the station to stop at. + * @return true if the vehicle should stop. + */ +bool Order::ShouldStopAtStation(const Vehicle *v, StationID station) const +{ + return + v->last_station_visited != station && // Do stop only when we've not just been there + type == OT_GOTO_STATION && // Do stop only when going to a station + /* Finally do stop when the non-stop flag is not set, or when we should stop at + * this station according to the new_nonstop setting. */ + (!this->flags & OFB_NON_STOP || ((this->dest != station) == _patches.new_nonstop)); +} + void InitializeOrders() { _Order_pool.CleanPool(); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -2399,33 +2399,27 @@ static const byte _enter_station_speedta static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y) { + StationID station_id = GetStationIndex(tile); + if (!v->current_order.ShouldStopAtStation(v, station_id)) return VETSB_CONTINUE; + if (v->type == VEH_TRAIN) { if (IsRailwayStation(tile) && IsFrontEngine(v) && !IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) { - StationID station_id = GetStationIndex(tile); - - if ((!(v->current_order.flags & OFB_NON_STOP) && !_patches.new_nonstop) || - (v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) { - if (!(_patches.new_nonstop && v->current_order.flags & OFB_NON_STOP) && - v->current_order.type != OT_LEAVESTATION && - v->last_station_visited != station_id) { - DiagDirection dir = DirToDiagDir(v->direction); - - x &= 0xF; - y &= 0xF; - - if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); - if (y == TILE_SIZE / 2) { - if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; - if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */ - if (x < 12) { - uint16 spd; - - v->vehstatus |= VS_TRAIN_SLOWING; - spd = _enter_station_speedtable[x]; - if (spd < v->cur_speed) v->cur_speed = spd; - } - } + DiagDirection dir = DirToDiagDir(v->direction); + + x &= 0xF; + y &= 0xF; + + if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y); + if (y == TILE_SIZE / 2) { + if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x; + if (x == 12) return VETSB_ENTERED_STATION | (VehicleEnterTileStatus)(station_id << VETS_STATION_ID_OFFSET); /* enter station */ + if (x < 12) { + uint16 spd; + + v->vehstatus |= VS_TRAIN_SLOWING; + spd = _enter_station_speedtable[x]; + if (spd < v->cur_speed) v->cur_speed = spd; } } } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -302,27 +302,6 @@ enum AccelType { AM_BRAKE }; -static bool TrainShouldStop(const Vehicle* v, TileIndex tile) -{ - const Order* o = &v->current_order; - StationID sid = GetStationIndex(tile); - - assert(v->type == VEH_TRAIN); - /* When does a train drive through a station - * first we deal with the "new nonstop handling" */ - if (_patches.new_nonstop && o->flags & OFB_NON_STOP && sid == o->dest) { - return false; - } - - if (v->last_station_visited == sid) return false; - - if (sid != o->dest && (o->flags & OFB_NON_STOP || _patches.new_nonstop)) { - return false; - } - - return true; -} - /** new acceleration*/ static int GetTrainAcceleration(Vehicle *v, bool mode) { @@ -385,7 +364,7 @@ static int GetTrainAcceleration(Vehicle } if (IsTileType(v->tile, MP_STATION) && IsFrontEngine(v)) { - if (TrainShouldStop(v, v->tile)) { + if (v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) { int station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction)); int st_max_speed = 120;