mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-07 06:46:43 +00:00
(svn r12580) -Codechange: merge some logical related to non-stop orders.
This commit is contained in:
parent
d977461d10
commit
aef20ec54d
@ -9,6 +9,8 @@
|
|||||||
#include "oldpool.h"
|
#include "oldpool.h"
|
||||||
#include "core/bitmath_func.hpp"
|
#include "core/bitmath_func.hpp"
|
||||||
#include "cargo_type.h"
|
#include "cargo_type.h"
|
||||||
|
#include "station_type.h"
|
||||||
|
#include "vehicle_type.h"
|
||||||
|
|
||||||
DECLARE_OLD_POOL(Order, Order, 6, 1000)
|
DECLARE_OLD_POOL(Order, Order, 6, 1000)
|
||||||
|
|
||||||
@ -40,6 +42,8 @@ struct Order : PoolItem<Order, OrderID, &_Order_pool> {
|
|||||||
|
|
||||||
void Free();
|
void Free();
|
||||||
void FreeChain();
|
void FreeChain();
|
||||||
|
|
||||||
|
bool ShouldStopAtStation(const Vehicle *v, StationID station) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline VehicleOrderID GetMaxOrderIndex()
|
static inline VehicleOrderID GetMaxOrderIndex()
|
||||||
|
@ -1343,6 +1343,7 @@ bool ProcessOrders(Vehicle *v)
|
|||||||
v->current_order.flags & OFB_NON_STOP &&
|
v->current_order.flags & OFB_NON_STOP &&
|
||||||
IsTileType(v->tile, MP_STATION) &&
|
IsTileType(v->tile, MP_STATION) &&
|
||||||
v->current_order.dest == GetStationIndex(v->tile)) {
|
v->current_order.dest == GetStationIndex(v->tile)) {
|
||||||
|
v->last_station_visited = v->current_order.dest;
|
||||||
UpdateVehicleTimetable(v, true);
|
UpdateVehicleTimetable(v, true);
|
||||||
v->cur_order_index++;
|
v->cur_order_index++;
|
||||||
}
|
}
|
||||||
@ -1414,6 +1415,23 @@ bool ProcessOrders(Vehicle *v)
|
|||||||
return may_reverse;
|
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()
|
void InitializeOrders()
|
||||||
{
|
{
|
||||||
_Order_pool.CleanPool();
|
_Order_pool.CleanPool();
|
||||||
|
@ -2399,33 +2399,27 @@ static const byte _enter_station_speedtable[12] = {
|
|||||||
|
|
||||||
static VehicleEnterTileStatus VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
|
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 (v->type == VEH_TRAIN) {
|
||||||
if (IsRailwayStation(tile) && IsFrontEngine(v) &&
|
if (IsRailwayStation(tile) && IsFrontEngine(v) &&
|
||||||
!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
|
!IsCompatibleTrainStationTile(tile + TileOffsByDiagDir(DirToDiagDir(v->direction)), tile)) {
|
||||||
StationID station_id = GetStationIndex(tile);
|
DiagDirection dir = DirToDiagDir(v->direction);
|
||||||
|
|
||||||
if ((!(v->current_order.flags & OFB_NON_STOP) && !_patches.new_nonstop) ||
|
x &= 0xF;
|
||||||
(v->current_order.type == OT_GOTO_STATION && v->current_order.dest == station_id)) {
|
y &= 0xF;
|
||||||
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;
|
if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
|
||||||
y &= 0xF;
|
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;
|
||||||
|
|
||||||
if (DiagDirToAxis(dir) != AXIS_X) Swap(x, y);
|
v->vehstatus |= VS_TRAIN_SLOWING;
|
||||||
if (y == TILE_SIZE / 2) {
|
spd = _enter_station_speedtable[x];
|
||||||
if (dir != DIAGDIR_SE && dir != DIAGDIR_SW) x = TILE_SIZE - 1 - x;
|
if (spd < v->cur_speed) v->cur_speed = spd;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,27 +302,6 @@ enum AccelType {
|
|||||||
AM_BRAKE
|
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*/
|
/** new acceleration*/
|
||||||
static int GetTrainAcceleration(Vehicle *v, bool mode)
|
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 (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 station_length = GetStationByTile(v->tile)->GetPlatformLength(v->tile, DirToDiagDir(v->direction));
|
||||||
|
|
||||||
int st_max_speed = 120;
|
int st_max_speed = 120;
|
||||||
|
Loading…
Reference in New Issue
Block a user