summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-05 15:30:15 +0000
committerrubidium <rubidium@openttd.org>2008-04-05 15:30:15 +0000
commited2acd6f3da6572839e57423f95625093f245aa1 (patch)
tree57bb3ebb25557e1d6fcad5c15f3dac0e731a4475 /src
parentf8b2e84537fce4c436e6c2db74f967d7e9347e95 (diff)
downloadopenttd-ed2acd6f3da6572839e57423f95625093f245aa1.tar.xz
(svn r12580) -Codechange: merge some logical related to non-stop orders.
Diffstat (limited to 'src')
-rw-r--r--src/order_base.h4
-rw-r--r--src/order_cmd.cpp18
-rw-r--r--src/station_cmd.cpp42
-rw-r--r--src/train_cmd.cpp23
4 files changed, 41 insertions, 46 deletions
diff --git a/src/order_base.h b/src/order_base.h
index 8cc3a29f4..12663b3c9 100644
--- 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 : PoolItem<Order, OrderID, &_Order_pool> {
void Free();
void FreeChain();
+
+ bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
};
static inline VehicleOrderID GetMaxOrderIndex()
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 871124959..775e08f0f 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -1343,6 +1343,7 @@ bool ProcessOrders(Vehicle *v)
v->current_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
index 4c633cd50..76ac8802a 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2399,33 +2399,27 @@ static const byte _enter_station_speedtable[12] = {
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
index 314af0090..87099c28d 100644
--- 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 *v, bool mode)
}
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;