mirror of https://github.com/OpenTTD/OpenTTD
(svn r3767) Move all direction related enums and functions to a separate header
parent
f007ad282c
commit
586388c9f1
1
depot.h
1
depot.h
|
@ -6,6 +6,7 @@
|
||||||
/** @file depot.h Header files for depots (not hangars)
|
/** @file depot.h Header files for depots (not hangars)
|
||||||
* @see depot.c */
|
* @see depot.c */
|
||||||
|
|
||||||
|
#include "direction.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
|
#ifndef DIRECTION_H
|
||||||
|
#define DIRECTION_H
|
||||||
|
|
||||||
|
/* Direction as commonly used in v->direction, 8 way. */
|
||||||
|
typedef enum Direction {
|
||||||
|
DIR_N = 0,
|
||||||
|
DIR_NE = 1, /* Northeast, upper right on your monitor */
|
||||||
|
DIR_E = 2,
|
||||||
|
DIR_SE = 3,
|
||||||
|
DIR_S = 4,
|
||||||
|
DIR_SW = 5,
|
||||||
|
DIR_W = 6,
|
||||||
|
DIR_NW = 7,
|
||||||
|
DIR_END,
|
||||||
|
INVALID_DIR = 0xFF,
|
||||||
|
} Direction;
|
||||||
|
|
||||||
|
|
||||||
|
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */
|
||||||
|
typedef enum DiagDirection {
|
||||||
|
DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */
|
||||||
|
DIAGDIR_SE = 1,
|
||||||
|
DIAGDIR_SW = 2,
|
||||||
|
DIAGDIR_NW = 3,
|
||||||
|
DIAGDIR_END,
|
||||||
|
INVALID_DIAGDIR = 0xFF,
|
||||||
|
} DiagDirection;
|
||||||
|
|
||||||
|
static inline DiagDirection ReverseDiagDir(DiagDirection d)
|
||||||
|
{
|
||||||
|
return 2 ^ d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline DiagDirection DirToDiagdir(Direction dir)
|
||||||
|
{
|
||||||
|
return (DiagDirection)(dir >> 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* the 2 axis */
|
||||||
|
typedef enum Axis {
|
||||||
|
AXIS_X = 0,
|
||||||
|
AXIS_Y = 1
|
||||||
|
} Axis;
|
||||||
|
|
||||||
|
#endif
|
8
npf.c
8
npf.c
|
@ -162,11 +162,11 @@ static uint NPFTunnelCost(AyStarNode* current)
|
||||||
{
|
{
|
||||||
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
|
DiagDirection exitdir = TrackdirToExitdir((Trackdir)current->direction);
|
||||||
TileIndex tile = current->tile;
|
TileIndex tile = current->tile;
|
||||||
if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagdir(exitdir)) {
|
if ((DiagDirection)GB(_m[tile].m5, 0, 2) == ReverseDiagDir(exitdir)) {
|
||||||
/* We just popped out if this tunnel, since were
|
/* We just popped out if this tunnel, since were
|
||||||
* facing the tunnel exit */
|
* facing the tunnel exit */
|
||||||
FindLengthOfTunnelResult flotr;
|
FindLengthOfTunnelResult flotr;
|
||||||
flotr = FindLengthOfTunnel(tile, ReverseDiagdir(exitdir));
|
flotr = FindLengthOfTunnel(tile, ReverseDiagDir(exitdir));
|
||||||
return flotr.length * NPF_TILE_LENGTH;
|
return flotr.length * NPF_TILE_LENGTH;
|
||||||
//TODO: Penalty for tunnels?
|
//TODO: Penalty for tunnels?
|
||||||
} else {
|
} else {
|
||||||
|
@ -543,7 +543,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
* otherwise (only for trains, since only with trains you can
|
* otherwise (only for trains, since only with trains you can
|
||||||
* (sometimes) reach tiles after reversing that you couldn't reach
|
* (sometimes) reach tiles after reversing that you couldn't reach
|
||||||
* without reversing. */
|
* without reversing. */
|
||||||
if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)) && type == TRANSPORT_RAIL) {
|
if (src_trackdir == DiagdirToDiagTrackdir(ReverseDiagDir(exitdir)) && type == TRANSPORT_RAIL) {
|
||||||
/* We are headed inwards. We can only reverse here, so we'll not
|
/* We are headed inwards. We can only reverse here, so we'll not
|
||||||
* consider this direction, but jump ahead to the reverse direction.
|
* consider this direction, but jump ahead to the reverse direction.
|
||||||
* It would be nicer to return one neighbour here (the reverse
|
* It would be nicer to return one neighbour here (the reverse
|
||||||
|
@ -596,7 +596,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
|
||||||
* orientation. They are only "inwards", since we are reaching this tile
|
* orientation. They are only "inwards", since we are reaching this tile
|
||||||
* from some other tile. This prevents vehicles driving into depots from
|
* from some other tile. This prevents vehicles driving into depots from
|
||||||
* the back */
|
* the back */
|
||||||
ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagdir(exitdir)));
|
ts = TrackdirToTrackdirBits(DiagdirToDiagTrackdir(ReverseDiagDir(exitdir)));
|
||||||
} else {
|
} else {
|
||||||
ts = GetTileTrackStatus(dst_tile, type);
|
ts = GetTileTrackStatus(dst_tile, type);
|
||||||
}
|
}
|
||||||
|
|
4
rail.c
4
rail.c
|
@ -99,10 +99,6 @@ const Trackdir _dir_to_diag_trackdir[] = {
|
||||||
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
|
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_X_SW, TRACKDIR_Y_NW,
|
||||||
};
|
};
|
||||||
|
|
||||||
const DiagDirection _reverse_diagdir[] = {
|
|
||||||
DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE, DIAGDIR_SE
|
|
||||||
};
|
|
||||||
|
|
||||||
const Trackdir _reverse_trackdir[] = {
|
const Trackdir _reverse_trackdir[] = {
|
||||||
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_UPPER_W, TRACKDIR_LOWER_W, TRACKDIR_LEFT_N, TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR,
|
TRACKDIR_X_SW, TRACKDIR_Y_NW, TRACKDIR_UPPER_W, TRACKDIR_LOWER_W, TRACKDIR_LEFT_N, TRACKDIR_RIGHT_N, INVALID_TRACKDIR, INVALID_TRACKDIR,
|
||||||
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_UPPER_E, TRACKDIR_LOWER_E, TRACKDIR_LEFT_S, TRACKDIR_RIGHT_S
|
TRACKDIR_X_NE, TRACKDIR_Y_SE, TRACKDIR_UPPER_E, TRACKDIR_LOWER_E, TRACKDIR_LEFT_S, TRACKDIR_RIGHT_S
|
||||||
|
|
16
rail.h
16
rail.h
|
@ -5,6 +5,7 @@
|
||||||
#ifndef RAIL_H
|
#ifndef RAIL_H
|
||||||
#define RAIL_H
|
#define RAIL_H
|
||||||
|
|
||||||
|
#include "direction.h"
|
||||||
#include "tile.h"
|
#include "tile.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -464,21 +465,6 @@ static inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir) {
|
||||||
return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
|
return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a (4-way) direction to the reverse.
|
|
||||||
*/
|
|
||||||
static inline DiagDirection ReverseDiagdir(DiagDirection diagdir) {
|
|
||||||
extern const DiagDirection _reverse_diagdir[DIAGDIR_END];
|
|
||||||
return _reverse_diagdir[diagdir];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Maps a (8-way) direction to a (4-way) DiagDirection
|
|
||||||
*/
|
|
||||||
static inline DiagDirection DirToDiagdir(Direction dir) {
|
|
||||||
assert(dir < DIR_END);
|
|
||||||
return (DiagDirection)(dir >> 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Checks if a given Track is diagonal */
|
/* Checks if a given Track is diagonal */
|
||||||
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); }
|
static inline bool IsDiagonalTrack(Track track) { return (track == TRACK_X) || (track == TRACK_Y); }
|
||||||
|
|
|
@ -537,7 +537,7 @@ static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks
|
||||||
if (_patches.new_pathfinding_all) {
|
if (_patches.new_pathfinding_all) {
|
||||||
NPFFindStationOrTileData fstd;
|
NPFFindStationOrTileData fstd;
|
||||||
NPFFoundTargetData ftd;
|
NPFFoundTargetData ftd;
|
||||||
TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagdir(enterdir)));
|
TileIndex src_tile = TILE_ADD(tile, TileOffsByDir(ReverseDiagDir(enterdir)));
|
||||||
byte trackdir = GetVehicleTrackdir(v);
|
byte trackdir = GetVehicleTrackdir(v);
|
||||||
assert (trackdir != 0xFF); /* Check that we are not in a depot */
|
assert (trackdir != 0xFF); /* Check that we are not in a depot */
|
||||||
|
|
||||||
|
@ -564,9 +564,9 @@ static int ChooseShipTrack(Vehicle *v, TileIndex tile, int enterdir, uint tracks
|
||||||
tot_dist = (uint)-1;
|
tot_dist = (uint)-1;
|
||||||
|
|
||||||
/* Let's find out how far it would be if we would reverse first */
|
/* Let's find out how far it would be if we would reverse first */
|
||||||
b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagdir(enterdir)] & v->u.ship.state;
|
b = GetTileShipTrackStatus(tile2) & _ship_sometracks[ReverseDiagDir(enterdir)] & v->u.ship.state;
|
||||||
if (b != 0) {
|
if (b != 0) {
|
||||||
dist = FindShipTrack(v, tile2, ReverseDiagdir(enterdir), b, tile, &track);
|
dist = FindShipTrack(v, tile2, ReverseDiagDir(enterdir), b, tile, &track);
|
||||||
if (dist != (uint)-1)
|
if (dist != (uint)-1)
|
||||||
tot_dist = dist + 1;
|
tot_dist = dist + 1;
|
||||||
}
|
}
|
||||||
|
|
35
tile.h
35
tile.h
|
@ -20,41 +20,6 @@ typedef enum TileTypes {
|
||||||
MP_UNMOVABLE,
|
MP_UNMOVABLE,
|
||||||
} TileType;
|
} TileType;
|
||||||
|
|
||||||
/* Direction as commonly used in v->direction, 8 way. */
|
|
||||||
typedef enum Directions {
|
|
||||||
DIR_N = 0,
|
|
||||||
DIR_NE = 1, /* Northeast, upper right on your monitor */
|
|
||||||
DIR_E = 2,
|
|
||||||
DIR_SE = 3,
|
|
||||||
DIR_S = 4,
|
|
||||||
DIR_SW = 5,
|
|
||||||
DIR_W = 6,
|
|
||||||
DIR_NW = 7,
|
|
||||||
DIR_END,
|
|
||||||
INVALID_DIR = 0xFF,
|
|
||||||
} Direction;
|
|
||||||
|
|
||||||
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */
|
|
||||||
typedef enum DiagonalDirections {
|
|
||||||
DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */
|
|
||||||
DIAGDIR_SE = 1,
|
|
||||||
DIAGDIR_SW = 2,
|
|
||||||
DIAGDIR_NW = 3,
|
|
||||||
DIAGDIR_END,
|
|
||||||
INVALID_DIAGDIR = 0xFF,
|
|
||||||
} DiagDirection;
|
|
||||||
|
|
||||||
static inline DiagDirection ReverseDiagDir(DiagDirection d)
|
|
||||||
{
|
|
||||||
return 2 ^ d;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* the 2 axis */
|
|
||||||
typedef enum Axis {
|
|
||||||
AXIS_X = 0,
|
|
||||||
AXIS_Y = 1
|
|
||||||
} Axis;
|
|
||||||
|
|
||||||
void SetMapExtraBits(TileIndex tile, byte flags);
|
void SetMapExtraBits(TileIndex tile, byte flags);
|
||||||
uint GetMapExtraBits(TileIndex tile);
|
uint GetMapExtraBits(TileIndex tile);
|
||||||
|
|
Loading…
Reference in New Issue