src/direction_func.h
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8100 6bc08f98ec16
child 9045 2e2f3fc16905
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
     1
/* $Id$ */
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
     2
8100
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 7641
diff changeset
     3
/** @file direction_func.h Different functions related to conversions between directions. */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
     4
8100
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 7641
diff changeset
     5
#ifndef DIRECTION_FUNC_H
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 7641
diff changeset
     6
#define DIRECTION_FUNC_H
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
     7
8100
6bc08f98ec16 (svn r11661) -Codechange: some header reworks in order to try to reduce the compile time of OpenTTD by reduce the amount of circular-ish dependencies.
rubidium
parents: 7641
diff changeset
     8
#include "direction_type.h"
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5475
diff changeset
     9
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    10
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    11
 * Return the reverse of a direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    12
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    13
 * @param d The direction to get the reverse from
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    14
 * @return The reverse Direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    15
 */
3157
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
    16
static inline Direction ReverseDir(Direction d)
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
    17
{
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
    18
	return (Direction)(4 ^ d);
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
    19
}
3f35e2d9c8e3 (svn r3783) Replace further ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3154
diff changeset
    20
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
    21
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    22
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    23
 * Calculate the difference between to directions
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    24
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    25
 * @param d0 The first direction as the base
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    26
 * @param d1 The second direction as the offset from the base
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    27
 * @return The difference how the second directions drifts of the first one.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    28
 */
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    29
static inline DirDiff DirDifference(Direction d0, Direction d1)
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    30
{
3162
5ff241ceadb3 (svn r3788) Fix (harmless) typo in r3784
tron
parents: 3158
diff changeset
    31
	return (DirDiff)((d0 + 8 - d1) % 8);
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    32
}
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    33
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    34
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    35
 * Applies two differences together
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    36
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    37
 * This function adds two differences together and return the resulting
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    38
 * difference. So adding two DIRDIFF_REVERSE together results in the
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    39
 * DIRDIFF_SAME difference.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    40
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    41
 * @param d The first difference
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    42
 * @param delta The second difference to add on
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    43
 * @return The resulting difference
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    44
 */
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    45
static inline DirDiff ChangeDirDiff(DirDiff d, DirDiff delta)
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    46
{
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    47
	return (DirDiff)((d + delta) % 8);
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    48
}
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    49
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    50
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    51
 * Change a direction by a given difference
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    52
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    53
 * This functions returns a new direction of the given direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    54
 * which is rotated by the given difference.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    55
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    56
 * @param d The direction to get a new direction from
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    57
 * @param delta The offset/drift applied to the direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    58
 * @return The new direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    59
 */
3158
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    60
static inline Direction ChangeDir(Direction d, DirDiff delta)
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    61
{
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    62
	return (Direction)((d + delta) % 8);
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    63
}
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    64
696a6ca0bfa9 (svn r3784) Add a type and functions to handle direction changes
tron
parents: 3157
diff changeset
    65
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    66
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    67
 * Returns the reverse direction of the given DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    68
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    69
 * @param d The DiagDirection to get the reverse from
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    70
 * @return The reverse direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    71
 */
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
    72
static inline DiagDirection ReverseDiagDir(DiagDirection d)
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
    73
{
3148
96d6a2fa97df (svn r3769) Add a cast to make KUDr's C++ compiler happy
tron
parents: 3147
diff changeset
    74
	return (DiagDirection)(2 ^ d);
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
    75
}
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
    76
7641
3a75903fd892 (svn r11172) -Codechange: rewrite of town road building and addition of the possibility to clean up unconnected road bits during the local road reconstructions. Based on a patch by skidd13.
rubidium
parents: 7394
diff changeset
    77
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    78
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    79
 * Applies a difference on a DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    80
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    81
 * This function applies a difference on a DiagDirection and returns
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    82
 * the new DiagDirection.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    83
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    84
 * @param d The DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    85
 * @param delta The difference to applie on
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    86
 * @return The new direction which was calculated
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    87
 */
3163
14e1eba3591d (svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents: 3162
diff changeset
    88
static inline DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
14e1eba3591d (svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents: 3162
diff changeset
    89
{
14e1eba3591d (svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents: 3162
diff changeset
    90
	return (DiagDirection)((d + delta) % 4);
14e1eba3591d (svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents: 3162
diff changeset
    91
}
14e1eba3591d (svn r3789) Add an enum and function to handle DiagDirection changes
tron
parents: 3162
diff changeset
    92
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    93
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    94
 * Convert a Direction to a DiagDirection.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    95
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    96
 * This function can be used to convert the 8-way Direction to
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    97
 * the 4-way DiagDirection. If the direction cannot be mapped its
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    98
 * "rounded clockwise". So DIR_N becomes DIAGDIR_NE.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
    99
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   100
 * @param dir The direction to convert
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   101
 * @return The resulting DiagDirection, maybe "rounded clockwise".
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   102
 */
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   103
static inline DiagDirection DirToDiagDir(Direction dir)
3147
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
   104
{
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
   105
	return (DiagDirection)(dir >> 1);
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
   106
}
fc76d566a68e (svn r3767) Move all direction related enums and functions to a separate header
tron
parents:
diff changeset
   107
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   108
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   109
 * Convert a DiagDirection to a Direction.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   110
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   111
 * This function can be used to convert the 4-way DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   112
 * to the 8-way Direction. As 4-way are less than 8-way not all
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   113
 * possible directions can be calculated.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   114
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   115
 * @param dir The direction to convert
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   116
 * @return The resulting Direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   117
 */
3153
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   118
static inline Direction DiagDirToDir(DiagDirection dir)
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   119
{
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   120
	return (Direction)(dir * 2 + 1);
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   121
}
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   122
e83501906eae (svn r3776) Replace many ints and magic numbers by Direction, DiagDirection and friends
tron
parents: 3148
diff changeset
   123
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   124
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   125
 * Select the other axis as provided.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   126
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   127
 * This is basically the not-operator for the axis.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   128
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   129
 * @param a The given axis
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   130
 * @return The other axis
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   131
 */
4158
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   132
static inline Axis OtherAxis(Axis a)
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   133
{
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   134
	return (Axis)(a ^ 1);
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   135
}
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   136
91ff9bb84ced (svn r5582) Add and use AxisToTrack{Bits,}()
tron
parents: 3953
diff changeset
   137
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   138
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   139
 * Convert a DiagDirection to the axis.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   140
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   141
 * This function returns the axis which belongs to the given
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   142
 * DiagDirection. The axis X belongs to the DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   143
 * north-east and south-west.
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   144
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   145
 * @param d The DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   146
 * @return The axis which belongs to the direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   147
 */
3154
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   148
static inline Axis DiagDirToAxis(DiagDirection d)
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   149
{
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   150
	return (Axis)(d & 1);
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   151
}
6ab0cb6b7ab3 (svn r3777) Add some functions to handle tunnels
tron
parents: 3153
diff changeset
   152
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   153
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   154
/**
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   155
 * Converts an Axis to a DiagDirection
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   156
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   157
 * This function returns the DiagDirection which
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   158
 * belongs to the axis. As 2 directions are mapped to an axis
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   159
 * this function returns the one which points to south,
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   160
 * either south-west (on X axis) or south-east (on Y axis)
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   161
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   162
 * @param a The axis
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   163
 * @return The direction pointed to south
3209
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   164
 */
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   165
static inline DiagDirection AxisToDiagDir(Axis a)
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   166
{
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   167
	return (DiagDirection)(2 - a);
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   168
}
98153d2f1ba7 (svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
tron
parents: 3163
diff changeset
   169
3953
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   170
/**
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   171
 * Convert an axis and a flag for north/south into a DiagDirection
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6248
diff changeset
   172
 * @param xy axis to convert
3953
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   173
 * @param ns north -> 0, south -> 1
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6248
diff changeset
   174
 * @return the desired DiagDirection
3953
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   175
 */
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   176
static inline DiagDirection XYNSToDiagDir(Axis xy, uint ns)
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   177
{
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   178
	return (DiagDirection)(xy * 3 ^ ns * 2);
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   179
}
e64bbd8598e2 (svn r5101) Add a function to convert an axis and a flag for north/south into a DiagDirection. Use it for bridge ramps and ship depots
tron
parents: 3744
diff changeset
   180
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   181
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   182
 * Checks if an interger value is a valid DiagDirection
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   183
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   184
 * @param d The value to check
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   185
 * @return True if the value belongs to a DiagDirection, else false
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   186
 */
3699
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   187
static inline bool IsValidDiagDirection(DiagDirection d)
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   188
{
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   189
	return d < DIAGDIR_END;
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   190
}
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   191
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   192
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   193
 * Checks if an integer value is a valid Direction
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   194
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   195
 * @param d The value to check
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   196
 * @return True if the value belongs to a Direction, else false
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   197
 */
3744
6f0d9e0fc2d9 (svn r4732) - Fix: use correct types in IsValid[Direction|Axis]
glx
parents: 3699
diff changeset
   198
static inline bool IsValidDirection(Direction d)
3699
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   199
{
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   200
	return d < DIR_END;
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   201
}
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   202
7394
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   203
/**
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   204
 * Checks if an integer value is a valid Axis
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   205
 *
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   206
 * @param d The value to check
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   207
 * @return True if the value belongs to an Axis, else false
baec3551d2d3 (svn r10763) -Documentation [FS#1098]: document direction.h. Patch by Progman.
rubidium
parents: 6432
diff changeset
   208
 */
3744
6f0d9e0fc2d9 (svn r4732) - Fix: use correct types in IsValid[Direction|Axis]
glx
parents: 3699
diff changeset
   209
static inline bool IsValidAxis(Axis d)
3699
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   210
{
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   211
	return d < AXIS_END;
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   212
}
dfd1e4dec957 (svn r4640) - Add: IsValidDiagDirection, IsValidDirection and IsValidAxis functions.
matthijs
parents: 3209
diff changeset
   213
4666
172a0cdf28a6 (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4158
diff changeset
   214
#endif /* DIRECTION_H */