mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
This commit is contained in:
parent
58012c6e6b
commit
29b79e03e8
|
@ -300,7 +300,6 @@ static inline Money RailConvertCost(RailType from, RailType to)
|
|||
}
|
||||
|
||||
void DrawTrainDepotSprite(int x, int y, int image, RailType railtype);
|
||||
Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data);
|
||||
int TicksToLeaveDepot(const Train *v);
|
||||
|
||||
Foundation GetRailFoundation(Slope tileh, TrackBits bits);
|
||||
|
|
|
@ -144,32 +144,18 @@ static const byte _track_sloped_sprites[14] = {
|
|||
* 11uuuudd => rail depot
|
||||
*/
|
||||
|
||||
|
||||
Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
|
||||
{
|
||||
TrackBits rail_bits = *(TrackBits *)data;
|
||||
|
||||
if (v->type != VEH_TRAIN) return NULL;
|
||||
|
||||
Train *t = Train::From(v);
|
||||
if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL;
|
||||
|
||||
_error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a vehicle interacts with the specified track.
|
||||
* All track bits interact except parallel TRACK_BIT_HORZ or TRACK_BIT_VERT.
|
||||
* All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT.
|
||||
*
|
||||
* @param tile The tile.
|
||||
* @param track The track.
|
||||
* @return \c true if no train that interacts, is found. \c false if a train is found.
|
||||
*/
|
||||
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
|
||||
{
|
||||
TrackBits rail_bits = TrackToTrackBits(track);
|
||||
|
||||
return !HasVehicleOnPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc);
|
||||
return EnsureNoTrainOnTrackBits(tile, rail_bits);
|
||||
}
|
||||
|
||||
/** Check that the new track bits may be built.
|
||||
|
|
|
@ -301,7 +301,7 @@ static SigFlags ExploreSegment(Owner owner)
|
|||
|
||||
if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
|
||||
tracks = tracks_masked;
|
||||
if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, &tracks, &EnsureNoTrainOnTrackProc)) flags |= SF_TRAIN;
|
||||
if (!(flags & SF_TRAIN) && !EnsureNoTrainOnTrackBits(tile, tracks)) flags |= SF_TRAIN;
|
||||
} else {
|
||||
if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
|
||||
if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, NULL, &TrainOnTileEnum)) flags |= SF_TRAIN;
|
||||
|
|
|
@ -452,6 +452,31 @@ CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle
|
|||
return CommandCost();
|
||||
}
|
||||
|
||||
static Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
|
||||
{
|
||||
TrackBits rail_bits = *(TrackBits *)data;
|
||||
|
||||
if (v->type != VEH_TRAIN) return NULL;
|
||||
|
||||
Train *t = Train::From(v);
|
||||
if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL;
|
||||
|
||||
_error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a vehicle interacts with the specified track bits.
|
||||
* All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT.
|
||||
*
|
||||
* @param tile The tile.
|
||||
* @param track_bits The track bits.
|
||||
* @return \c true if no train that interacts, is found. \c false if a train is found.
|
||||
*/
|
||||
bool EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
|
||||
{
|
||||
return !HasVehicleOnPos(tile, &track_bits, &EnsureNoTrainOnTrackProc);
|
||||
}
|
||||
|
||||
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove)
|
||||
{
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "transport_type.h"
|
||||
#include "newgrf_config.h"
|
||||
#include "company_type.h"
|
||||
#include "track_type.h"
|
||||
|
||||
#define is_custom_sprite(x) (x >= 0xFD)
|
||||
#define IS_CUSTOM_FIRSTHEAD_SPRITE(x) (x == 0xFD)
|
||||
|
@ -157,6 +158,7 @@ static inline uint32 GetCmdSendToDepot(const BaseVehicle *v)
|
|||
}
|
||||
|
||||
CommandCost EnsureNoVehicleOnGround(TileIndex tile);
|
||||
bool EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits);
|
||||
void StopAllVehicles();
|
||||
|
||||
extern VehicleID _vehicle_id_ctr_day;
|
||||
|
|
Loading…
Reference in New Issue