(svn r12580) -Codechange: merge some logical related to non-stop orders.
authorrubidium
Sat, 05 Apr 2008 15:30:15 +0000
changeset 9328 a7ad10a9b0cb
parent 9327 4520e2d84651
child 9329 928920d21bc1
(svn r12580) -Codechange: merge some logical related to non-stop orders.
src/order_base.h
src/order_cmd.cpp
src/station_cmd.cpp
src/train_cmd.cpp
--- a/src/order_base.h	Sat Apr 05 12:30:48 2008 +0000
+++ b/src/order_base.h	Sat Apr 05 15:30:15 2008 +0000
@@ -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 @@
 
 	void Free();
 	void FreeChain();
+
+	bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
 };
 
 static inline VehicleOrderID GetMaxOrderIndex()
--- a/src/order_cmd.cpp	Sat Apr 05 12:30:48 2008 +0000
+++ b/src/order_cmd.cpp	Sat Apr 05 15:30:15 2008 +0000
@@ -1343,6 +1343,7 @@
 			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 @@
 	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();
--- a/src/station_cmd.cpp	Sat Apr 05 12:30:48 2008 +0000
+++ b/src/station_cmd.cpp	Sat Apr 05 15:30:15 2008 +0000
@@ -2399,33 +2399,27 @@
 
 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;
 				}
 			}
 		}
--- a/src/train_cmd.cpp	Sat Apr 05 12:30:48 2008 +0000
+++ b/src/train_cmd.cpp	Sat Apr 05 15:30:15 2008 +0000
@@ -302,27 +302,6 @@
 	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 @@
 	}
 
 	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;