npf.h
author Darkvater
Sat, 14 May 2005 22:03:25 +0000
changeset 1809 d54f7f8050f6
parent 1777 f703cf05b5b9
child 1857 f07b4fc6c4bf
permissions -rw-r--r--
(svn r2313) - Fix: [ 1202115 ] Clicking shipslist on bouy asserts GetPlayer(). Bouys and oilrigs don't have owners, so it cannot get the vehicle-list of the station-owner. Just use _current_player
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     1
#ifndef NPF_H
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     2
#define NPF_H
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     3
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     4
#include "ttd.h"
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     5
#include "aystar.h"
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     6
#include "vehicle.h"
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     7
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     8
//mowing grass
1661
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
     9
enum {
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    10
	NPF_HASH_BITS = 12, /* The size of the hash used in pathfinding. Just changing this value should be sufficient to change the hash size. Should be an even value. */
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    11
	/* Do no change below values */
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    12
	NPF_HASH_SIZE = 1 << NPF_HASH_BITS,
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    13
	NPF_HASH_HALFBITS = NPF_HASH_BITS / 2,
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    14
	NPF_HASH_HALFMASK = (1 << NPF_HASH_HALFBITS) - 1
f3799f2c84fa (svn r2165) - Codechange: [NPF] Properly enummed NPF hash size, it is easily changable now.
matthijs
parents: 1459
diff changeset
    15
};
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    16
1777
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    17
enum {
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    18
	/** This penalty is the equivalent of "inifite", which means that paths that
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    19
	 * get this penalty will be chosen, but only if there is no other route
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    20
	 * without it. Be careful with not applying this penalty to often, or the
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    21
	 * total path cost might overflow..
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    22
	 * For now, this is just a Very Big Penalty, we might actually implement
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    23
	 * this in a nicer way :-)
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    24
	 */
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    25
	NPF_INFINITE_PENALTY = 1000 * NPF_TILE_LENGTH
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    26
};
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    27
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    28
typedef struct NPFFindStationOrTileData { /* Meant to be stored in AyStar.targetdata */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    29
	TileIndex dest_coords; /* An indication of where the station is, for heuristic purposes, or the target tile */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    30
	int station_index; /* station index we're heading for, or -1 when we're heading for a tile */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    31
} NPFFindStationOrTileData;
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    32
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    33
enum { /* Indices into AyStar.userdata[] */
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    34
	NPF_TYPE = 0, /* Contains a TransportTypes value */
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    35
	NPF_OWNER, /* Contains an Owner value */
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    36
};
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    37
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    38
enum { /* Indices into AyStarNode.userdata[] */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    39
	NPF_TRACKDIR_CHOICE = 0, /* The trackdir chosen to get here */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    40
	NPF_NODE_FLAGS,
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    41
};
1459
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    42
typedef enum { /* Flags for AyStarNode.userdata[NPF_NODE_FLAGS]. Use NPFGetBit() and NPFGetBit() to use them. */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    43
	NPF_FLAG_SEEN_SIGNAL, /* Used to mark that a signal was seen on the way, for rail only */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    44
	NPF_FLAG_REVERSE, /* Used to mark that this node was reached from the second start node, if applicable */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    45
	NPF_FLAG_LAST_SIGNAL_RED, /* Used to mark that the last signal on this path was red */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    46
	NPF_FLAG_TARGET_CHECKED, /* Used by end node checking function of npf to mark
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    47
														 that they have evaluated this node. When this
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    48
														 flag is on, NPF_FLAG_IS_TARGET is on when the
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    49
														 node is a target, and off when it is not. Should
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    50
														 never be used directly, only by the end node
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    51
														 checking functions for caching of results. */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    52
	NPF_FLAG_IS_TARGET, /* See comment for NPF_FLAG_TARGET_CHECKED */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    53
} NPFNodeFlag;
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    54
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    55
typedef struct NPFFoundTargetData { /* Meant to be stored in AyStar.userpath */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    56
	uint best_bird_dist; /* The best heuristic found. Is 0 if the target was found */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    57
	uint best_path_dist; /* The shortest path. Is (uint)-1 if no path is found */
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    58
	byte best_trackdir; /* The trackdir that leads to the shortest path/closest birds dist */
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    59
	AyStarNode node; /* The node within the target the search led us to */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    60
} NPFFoundTargetData;
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    61
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    62
/* These functions below are _not_ re-entrant, in favor of speed! */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    63
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    64
/* Will search from the given tile and direction, for a route to the given
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    65
 * station for the given transport type. See the declaration of
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    66
 * NPFFoundTargetData above for the meaning of the result. */
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    67
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type, Owner owner);
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    68
/* Will search as above, but with two start nodes, the second being the
1459
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    69
 * reverse. Look at the NPF_FLAG_REVERSE flag in the result node to see which
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    70
 * direction was taken (NPFGetBit(result.node, NPF_FLAG_REVERSE)) */
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    71
NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type, Owner owner);
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    72
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    73
/* Will search a route to the closest depot. */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    74
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    75
/* Search using breadth first. Good for little track choice and inaccurate
1777
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    76
 * heuristic, such as railway/road.*/
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    77
NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type, Owner owner);
1777
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    78
/* Same as above but with two start nodes, the second being the reverse. Call
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    79
 * NPFGetBit(result.node, NPF_FLAG_REVERSE) to see from which node the path
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    80
 * orginated. All pathfs from the second node will have the given
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    81
 * reverse_penalty applied (NPF_TILE_LENGTH is the equivalent of one full
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    82
 * tile).
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    83
 */
f703cf05b5b9 (svn r2281) - Fix: [ 1115204 ] [NPF] When pressing the goto depot button, trains will now also look behind it if there is no depot in front. If so, the train reverses immediately. This also work anywhere, not just at stations.
matthijs
parents: 1751
diff changeset
    84
NPFFoundTargetData NPFRouteToDepotBreadthFirstTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, TransportType type, Owner owner, uint reverse_penalty);
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    85
/* Search by trying each depot in order of Manhattan Distance. Good for lots
1330
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    86
 * of choices and accurate heuristics, such as water. */
5d76a0522a11 (svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents: 1247
diff changeset
    87
NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type, Owner owner);
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    88
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    89
void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v);
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    90
1459
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    91
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    92
/*
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    93
 * Functions to manipulate the various NPF related flags on an AyStarNode.
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    94
 */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    95
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    96
/**
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    97
 * Returns the current value of the given flag on the given AyStarNode.
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    98
 */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
    99
static inline bool NPFGetFlag(const AyStarNode* node, NPFNodeFlag flag)
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   100
{
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   101
	return HASBIT(node->user_data[NPF_NODE_FLAGS], flag);
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   102
}
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   103
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   104
/**
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   105
 * Sets the given flag on the given AyStarNode to the given value.
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   106
 */
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   107
static inline void NPFSetFlag(AyStarNode* node, NPFNodeFlag flag, bool value)
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   108
{
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   109
	if (value)
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   110
		SETBIT(node->user_data[NPF_NODE_FLAGS], flag);
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   111
	else
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   112
		CLRBIT(node->user_data[NPF_NODE_FLAGS], flag);
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   113
}
19333d7f99b3 (svn r1963) - Add: [NPF] Penalty for a red signal that is the last signal on the path.
matthijs
parents: 1330
diff changeset
   114
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   115
/*
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   116
 * Some tables considering tracks, directions and signals.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   117
 * XXX: Better place to but these?
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   118
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   119
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   120
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   121
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   122
 * direction along with the trackdir.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   123
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   124
const byte _signal_along_trackdir[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   125
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   126
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   127
 * Maps a trackdir to the bit that stores its status in the map arrays, in the
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   128
 * direction against the trackdir.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   129
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   130
const byte _signal_against_trackdir[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   131
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   132
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   133
 * Maps a trackdir to the trackdirs that can be reached from it (ie, when
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   134
 * entering the next tile.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   135
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   136
const uint16 _trackdir_reaches_trackdirs[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   137
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   138
/**
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   139
 * Maps a trackdir to the trackdir that you will end up on if you go straight
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   140
 * ahead. This will be the same trackdir for diagonal trackdirs, but a
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   141
 * different (alternating) one for straight trackdirs */
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   142
const uint16 _next_trackdir[14];
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   143
/**
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   144
 * Maps a trackdir to all trackdirs that make 90 deg turns with it.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   145
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   146
const uint16 _trackdir_crosses_trackdirs[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   147
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   148
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   149
 * Maps a track to all tracks that make 90 deg turns with it.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   150
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   151
const byte _track_crosses_tracks[6];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   152
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   153
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   154
 * Maps a trackdir to the (4-way) direction the tile is exited when following
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   155
 * that trackdir.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   156
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   157
const byte _trackdir_to_exitdir[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   158
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   159
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   160
 * Maps a track and an (4-way) dir to the trackdir that represents the track
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   161
 * with the exit in the given direction.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   162
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   163
const byte _track_exitdir_to_trackdir[6][4];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   164
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   165
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   166
 * Maps a track and a full (8-way) direction to the trackdir that represents
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   167
 * the track running in the given direction.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   168
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   169
const byte _track_direction_to_trackdir[6][8];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   170
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   171
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   172
 * Maps a (4-way) direction to the diagonal track that runs in that
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   173
 * direction.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   174
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   175
const byte _dir_to_diag_trackdir[4];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   176
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   177
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   178
 * Maps a (4-way) direction to the reverse.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   179
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   180
const byte _reverse_dir[4];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   181
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   182
/**
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   183
 * Maps a trackdir to the reverse trackdir.
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   184
 */
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   185
const byte _reverse_trackdir[14];
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   186
1751
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   187
/* Returns the Track that a given Trackdir represents */
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   188
static inline byte TrackdirToTrack(byte trackdir) { return trackdir & 0x7; }
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   189
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   190
/* Returns a Trackdir for the given Track. Since every Track corresponds to
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   191
 * two Trackdirs, we choose the one which points between N and SE.
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   192
 * Note that the actual implementation is quite futile, but this might change
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   193
 * in the future.
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   194
 */
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   195
static inline byte TrackToTrackdir(byte track) { return track; }
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   196
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   197
/* Checks if a given Track is diagonal */
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   198
static inline bool IsDiagonalTrack(byte track) { return track == 0x0 || track == 0x1; }
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   199
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   200
/* Checks if a given Trackdir is diagonal. */
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   201
static inline bool IsDiagonalTrackdir(byte trackdir) { return IsDiagonalTrack(TrackdirToTrack(trackdir)); }
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   202
009a240d035a (svn r2255) - Fix: [ 9680363 ] [NPF] Broken buoy handling for ships
matthijs
parents: 1678
diff changeset
   203
1247
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   204
#define REVERSE_TRACKDIR(trackdir) (trackdir ^ 0x8)
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   205
3851739bfd09 (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   206
#endif // NPF_H