Changeset - r8832:6c9ef37d3595
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2008-04-05 15:30:15
rubidium@openttd.org
(svn r12580) -Codechange: merge some logical related to non-stop orders.
4 files changed with 41 insertions and 46 deletions:
0 comments (0 inline, 0 general)
src/order_base.h
Show inline comments
 
@@ -6,12 +6,14 @@
 
#define ORDER_BASE_H
 

	
 
#include "order_type.h"
 
#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)
 

	
 
/* If you change this, keep in mind that it is saved on 3 places:
 
 * - Load_ORDR, all the global orders
 
 * - Vehicle -> current_order
 
@@ -37,12 +39,14 @@ struct Order : PoolItem<Order, OrderID, 
 
	 * Check if a Order really exists.
 
	 */
 
	inline bool IsValid() const { return this->type != OT_NOTHING; }
 

	
 
	void Free();
 
	void FreeChain();
 

	
 
	bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
 
};
 

	
 
static inline VehicleOrderID GetMaxOrderIndex()
 
{
 
	/* TODO - This isn't the real content of the function, but
 
	 *  with the new pool-system this will be replaced with one that
src/order_cmd.cpp
Show inline comments
 
@@ -1340,12 +1340,13 @@ bool ProcessOrders(Vehicle *v)
 

	
 
	/* Check if we've reached a non-stop station while TTDPatch nonstop is enabled.. */
 
	if (_patches.new_nonstop &&
 
			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++;
 
	}
 

	
 
	/* Get the current order */
 
	if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
 
@@ -1411,12 +1412,29 @@ bool ProcessOrders(Vehicle *v)
 
			return false;
 
	}
 

	
 
	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();
 
	_Order_pool.AddBlockToPool();
 

	
 
	_backup_orders_tile = 0;
src/station_cmd.cpp
Show inline comments
 
@@ -2396,39 +2396,33 @@ static void ClickTile_Station(TileIndex 
 
static const byte _enter_station_speedtable[12] = {
 
	215, 195, 175, 155, 135, 115, 95, 75, 55, 35, 15, 0
 
};
 

	
 
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;
 
				}
 
			}
 
		}
 
	} else if (v->type == VEH_ROAD) {
 
		if (v->u.road.state < RVSB_IN_ROAD_STOP && !IsReversingRoadTrackdir((Trackdir)v->u.road.state) && v->u.road.frame == 0) {
 
			if (IsRoadStop(tile) && IsRoadVehFront(v)) {
src/train_cmd.cpp
Show inline comments
 
@@ -299,33 +299,12 @@ void TrainConsistChanged(Vehicle* v)
 

	
 
enum AccelType {
 
	AM_ACCEL,
 
	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)
 
{
 
	static const int absolute_max_speed = 2000;
 
	int max_speed = absolute_max_speed;
 
	int speed = v->cur_speed * 10 / 16; // km-ish/h -> mp/h
 
@@ -382,13 +361,13 @@ static int GetTrainAcceleration(Vehicle 
 
			/* Apply max_speed bonus of 20% for a tilting train */
 
			max_speed += max_speed / 5;
 
		}
 
	}
 

	
 
	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;
 

	
 
			int delta_v = v->cur_speed / (station_length + 1);
 
			if (v->max_speed > (v->cur_speed - delta_v)) {
0 comments (0 inline, 0 general)