npf.c
author tron
Sun, 06 Feb 2005 22:25:27 +0000
changeset 1329 a8a0d60b0a8e
parent 1313 bba6afb8a995
child 1330 8a67d04016ce
permissions -rw-r--r--
(svn r1833) byte -> char transition: the rest
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     1
#include "stdafx.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     2
#include "ttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1248
diff changeset
     3
#include "debug.h"
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     4
#include "npf.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     5
#include "aystar.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     6
#include "macros.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     7
#include "pathfind.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     8
#include "station.h"
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
     9
#include "tile.h"
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
    10
#include "depot.h"
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    11
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    12
AyStar _train_find_station;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    13
AyStar _train_find_depot;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    14
AyStar _road_find_station;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    15
AyStar _road_find_depot;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    16
AyStar _npf_aystar;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    17
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    18
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    19
 * direction along with the trackdir */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    20
const byte _signal_along_trackdir[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    21
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10, 0, 0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    22
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    23
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    24
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    25
/* Maps a trackdir to the bit that stores its status in the map arrays, in the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    26
 * direction against the trackdir */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    27
const byte _signal_against_trackdir[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    28
	0x40, 0x40, 0x40, 0x10, 0x80, 0x20, 0, 0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    29
	0x80, 0x80, 0x80, 0x20, 0x40, 0x10
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    30
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    31
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    32
/* Maps a trackdir to the trackdirs that can be reached from it (ie, when
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    33
 * entering the next tile */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    34
const uint16 _trackdir_reaches_trackdirs[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    35
0x1009, 0x0016, 0x1009, 0x0016, 0x0520, 0x0016, 0, 0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    36
0x0520, 0x2A00, 0x2A00, 0x0520, 0x2A00, 0x1009
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    37
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    38
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    39
/* Maps a trackdir to all trackdirs that make 90 deg turns with it. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    40
const uint16 _trackdir_crosses_trackdirs[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    41
0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C, 0, 0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    42
0x0202, 0x0101, 0x3030, 0x3030, 0x0C0C, 0x0C0C
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    43
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    44
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    45
/* Maps a track to all tracks that make 90 deg turns with it. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    46
const byte _track_crosses_tracks[6] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    47
	0x2, /* Track 1 -> Track 2 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    48
	0x1, /* Track 2 -> Track 1 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    49
	0x30, /* Upper -> Left | Right */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    50
	0x30, /* Lower -> Left | Right */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    51
	0x0C, /* Left -> Upper | Lower */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    52
	0x0C, /* Right -> Upper | Lower */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    53
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    54
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    55
/* Maps a trackdir to the (4-way) direction the tile is exited when following
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    56
 * that trackdir */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    57
const byte _trackdir_to_exitdir[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    58
	0,1,0,1,2,1, 0,0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    59
	2,3,3,2,3,0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    60
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    61
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    62
const byte _track_exitdir_to_trackdir[6][4] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    63
	{0,    0xff, 8,    0xff},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    64
	{0xff, 1,    0xff, 9},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    65
	{2,    0xff, 0xff, 10},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    66
	{0xff, 3,    11,   0xf},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    67
	{0xff, 0xff, 4,    12},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    68
	{13,   5,    0xff, 0xff}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    69
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    70
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    71
const byte _track_direction_to_trackdir[6][8] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    72
	{0xff, 0,    0xff, 0xff, 0xff, 8,    0xff, 0xff},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    73
	{0xff, 0xff, 0xff, 1,    0xff, 0xff, 0xff, 9},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    74
	{0xff, 0xff, 2,    0xff, 0xff, 0xff, 10,   0xff},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    75
	{0xff, 0xff, 3,    0xff, 0xff, 0xff, 11,   0xff},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    76
	{12,   0xff, 0xff, 0xff, 4,    0xff, 0xff, 0xff},
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    77
	{13,   0xff, 0xff, 0xff, 5,    0xff, 0xff, 0xff}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    78
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    79
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    80
const byte _dir_to_diag_trackdir[4] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    81
	0, 1, 8, 9,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    82
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    83
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    84
const byte _reverse_dir[4] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    85
	2, 3, 0, 1
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    86
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    87
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    88
const byte _reverse_trackdir[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    89
	8, 9, 10, 11, 12, 13, 0xFF, 0xFF,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    90
	0, 1, 2,  3,  4,  5
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    91
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    92
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    93
/* The cost of each trackdir. A diagonal piece is the full NPF_TILE_LENGTH,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    94
 * the shorter piece is sqrt(2)/2*NPF_TILE_LENGTH =~ 0.7071
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    95
 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    96
#define NPF_STRAIGHT_LENGTH (uint)(NPF_TILE_LENGTH * 0.7071)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    97
static const uint _trackdir_length[14] = {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    98
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, 0, 0,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
    99
NPF_TILE_LENGTH, NPF_TILE_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH, NPF_STRAIGHT_LENGTH
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   100
};
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   101
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   102
uint NTPHash(uint key1, uint key2)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   103
{
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   104
	return PATHFIND_HASH_TILE(key1);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   105
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   106
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   107
int32 NPFCalcZero(AyStar* as, AyStarNode* current, OpenListNode* parent) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   108
	return 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   109
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   110
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   111
/* Calcs the heuristic to the target station (using NPFFindStationOrTileData). After
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   112
 * will save the heuristic into NPFFoundTargetData if it is the smallest until
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   113
 * now. It will then also save AyStarNode.user_data[NPF_TRACKDIR_CHOICE] in
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   114
 * best_trackdir
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   115
 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   116
int32 NPFCalcStationOrTileHeuristic(AyStar* as, AyStarNode* current, OpenListNode* parent) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   117
	NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   118
	NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   119
	TileIndex from = current->tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   120
	TileIndex to = fstd->dest_coords;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   121
	uint dist = DistanceManhattan(from, to) * NPF_TILE_LENGTH;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   122
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   123
	if (dist < ftd->best_bird_dist) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   124
		ftd->best_bird_dist = dist;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   125
		ftd->best_trackdir = current->user_data[NPF_TRACKDIR_CHOICE];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   126
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   127
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   128
	debug("Calculating H for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), dist);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   129
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   130
	return dist;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   131
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   132
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   133
/* Fills AyStarNode.user_data[NPF_TRACKDIRCHOICE] with the chosen direction to
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   134
 * get here, either getting it from the current choice or from the parent's
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   135
 * choice */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   136
void NPFFillTrackdirChoice(AyStarNode* current, OpenListNode* parent)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   137
{
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   138
	if (parent->path.parent == NULL) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   139
		byte trackdir = current->direction;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   140
		/* This is a first order decision, so we'd better save the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   141
		 * direction we chose */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   142
		current->user_data[NPF_TRACKDIR_CHOICE] = trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   143
		#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   144
		debug("Saving trackdir: %#x", trackdir);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   145
		#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   146
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   147
		/* We've already made the decision, so just save our parent's
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   148
		 * decision */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   149
		current->user_data[NPF_TRACKDIR_CHOICE] = parent->path.node.user_data[NPF_TRACKDIR_CHOICE];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   150
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   151
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   152
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   153
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   154
/* Will return the cost of the tunnel. If it is an entry, it will return the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   155
 * cost of that tile. If the tile is an exit, it will return the tunnel length
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   156
 * including the exit tile. Requires that this is a Tunnel tile */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   157
uint NPFTunnelCost(AyStarNode* current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   158
	byte exitdir = _trackdir_to_exitdir[current->direction];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   159
	TileIndex tile = current->tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   160
	if ( (uint)(_map5[tile] & 3) == _reverse_dir[exitdir]) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   161
		/* We just popped out if this tunnel, since were
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   162
		 * facing the tunnel exit */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   163
		FindLengthOfTunnelResult flotr;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   164
		flotr = FindLengthOfTunnel(tile, _reverse_dir[exitdir]);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   165
		return flotr.length * NPF_TILE_LENGTH;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   166
		//TODO: Penalty for tunnels?
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   167
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   168
		/* We are entering the tunnel, the enter tile is just a
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   169
		 * straight track */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   170
		return NPF_TILE_LENGTH;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   171
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   172
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   173
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   174
uint NPFSlopeCost(AyStarNode* current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   175
	TileIndex next = current->tile + TileOffsByDir(_trackdir_to_exitdir[current->direction]);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   176
	if (GetTileZ(next) > GetTileZ(current->tile)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   177
		/* Slope up */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   178
		return _patches.npf_rail_slope_penalty;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   179
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   180
	return 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   181
	/* Should we give a bonus for slope down? Probably not, we
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   182
	 * could just substract that bonus from the penalty, because
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   183
	 * there is only one level of steepness... */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   184
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   185
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   186
void NPFMarkTile(TileIndex tile) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   187
	switch(GetTileType(tile)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   188
		case MP_RAILWAY:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   189
		case MP_STREET:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   190
			/* DEBUG: mark visited tiles by mowing the grass under them
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   191
			 * ;-) */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   192
			_map2[tile] &= ~15;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   193
			MarkTileDirtyByTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   194
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   195
		default:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   196
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   197
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   198
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   199
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   200
int32 NPFWaterPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   201
	//TileIndex tile = current->tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   202
	int32 cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   203
	byte trackdir = current->direction;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   204
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   205
	cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   206
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   207
	/* TODO Penalties? */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   208
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   209
	return cost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   210
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   211
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   212
/* Determine the cost of this node, for road tracks */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   213
int32 NPFRoadPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   214
	TileIndex tile = current->tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   215
	int32 cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   216
	/* Determine base length */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   217
	switch (GetTileType(tile)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   218
		case MP_TUNNELBRIDGE:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   219
			if ((_map5[tile] & 0xF0)==0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   220
				cost = NPFTunnelCost(current);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   221
				break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   222
			}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   223
			/* Fall through if above if is false, it is a bridge
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   224
			 * then. We treat that as ordinary rail */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   225
		case MP_STREET:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   226
			cost = NPF_TILE_LENGTH;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   227
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   228
		default:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   229
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   230
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   231
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   232
	/* Determine extra costs */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   233
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   234
	/* Check for slope */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   235
	cost += NPFSlopeCost(current);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   236
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   237
	/* Check for turns */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   238
	//TODO
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   239
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   240
	#ifdef NPF_MARKROUTE
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   241
	NPFMarkTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   242
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   243
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   244
	debug("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   245
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   246
	return cost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   247
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   248
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   249
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   250
/* Determine the cost of this node, for railway tracks */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   251
int32 NPFRailPathCost(AyStar* as, AyStarNode* current, OpenListNode* parent) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   252
	TileIndex tile = current->tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   253
	byte trackdir = current->direction;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   254
	int32 cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   255
	/* Determine base length */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   256
	switch (GetTileType(tile)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   257
		case MP_TUNNELBRIDGE:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   258
			if ((_map5[tile] & 0xF0)==0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   259
				cost = NPFTunnelCost(current);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   260
				break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   261
			}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   262
			/* Fall through if above if is false, it is a bridge
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   263
			 * then. We treat that as ordinary rail */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   264
		case MP_RAILWAY:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   265
			cost = _trackdir_length[trackdir]; /* Should be different for diagonal tracks */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   266
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   267
		case MP_STREET: /* Railway crossing */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   268
			cost = NPF_TILE_LENGTH;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   269
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   270
		default:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   271
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   272
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   273
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   274
	/* Determine extra costs */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   275
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   276
	/* Ordinary track with signals */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   277
	if (IsTileType(tile, MP_RAILWAY) && (_map5[tile] & 0xC0) == 0x40) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   278
		if ((_map2[tile] & _signal_along_trackdir[trackdir]) == 0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   279
			/* Signal facing us is red */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   280
			if (!(current->user_data[NPF_NODE_FLAGS] & NPF_FLAG_SEEN_SIGNAL)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   281
				/* Penalize the first signal we
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   282
				 * encounter, if it is red */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   283
				cost += _patches.npf_rail_firstred_penalty;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   284
			}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   285
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   286
		current->user_data[NPF_NODE_FLAGS] |= NPF_FLAG_SEEN_SIGNAL;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   287
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   288
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   289
	/* Check for slope */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   290
	cost += NPFSlopeCost(current);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   291
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   292
	/* Check for turns */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   293
	//TODO
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   294
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   295
	/* Check for occupied track */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   296
	//TODO
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   297
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   298
	/* Check for station tiles */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   299
	if (IsTileType(tile, MP_STATION)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   300
		/* We give a station tile a penalty. Logically we would only
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   301
		 * want to give station tiles that are not our destination
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   302
		 * this penalty. This would discourage trains to drive through
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   303
		 * busy stations. But, we can just give any station tile a
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   304
		 * penalty, because every possible route will get this penalty
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   305
		 * exactly once, on its end tile (if it's a station) and it
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   306
		 * will therefore not make a difference. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   307
		cost += _patches.npf_rail_station_penalty;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   308
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   309
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   310
	#ifdef NPF_MARKROUTE
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   311
	NPFMarkTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   312
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   313
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   314
	debug("Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   315
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   316
	return cost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   317
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   318
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   319
/* Will find any depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   320
int32 NPFFindDepot(AyStar* as, OpenListNode *current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   321
	TileIndex tile = current->path.node.tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   322
	bool isDepot;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   323
	switch(GetTileType(tile)) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   324
		case MP_RAILWAY:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   325
			/* Check if this is a rail depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   326
			isDepot = IsTrainDepotTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   327
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   328
		case MP_STREET:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   329
			/* Check if this is a road depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   330
			isDepot = IsRoadDepotTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   331
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   332
		case MP_WATER:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   333
			isDepot = IsShipDepotTile(tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   334
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   335
		default:
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   336
			isDepot = false;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   337
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   338
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   339
	if (isDepot)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   340
		return AYSTAR_FOUND_END_NODE;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   341
	else
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   342
		return AYSTAR_DONE;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   343
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   344
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   345
/* Will find a station identified using the NPFFindStationOrTileData */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   346
int32 NPFFindStationOrTile(AyStar* as, OpenListNode *current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   347
	/* If GetNeighbours said we could get here, we assume the station type
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   348
	 * is correct */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   349
	NPFFindStationOrTileData* fstd = (NPFFindStationOrTileData*)as->user_target;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   350
	TileIndex tile = current->path.node.tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   351
	if (	(fstd->station_index == -1 && tile == fstd->dest_coords) || /* We've found the tile, or */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   352
		(IsTileType(tile, MP_STATION) && _map2[tile] == fstd->station_index) /* the station */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   353
	   )
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   354
			return AYSTAR_FOUND_END_NODE;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   355
	else
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   356
		return AYSTAR_DONE;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   357
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   358
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   359
/* To be called when current contains the (shortest route to) the target node.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   360
 * Will fill the contents of the NPFFoundTargetData using
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   361
 * AyStarNode[NPF_TRACKDIR_CHOICE].
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   362
 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   363
void NPFSaveTargetData(AyStar* as, OpenListNode* current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   364
	NPFFoundTargetData* ftd = (NPFFoundTargetData*)as->user_path;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   365
	ftd->best_trackdir = current->path.node.user_data[NPF_TRACKDIR_CHOICE];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   366
	ftd->best_path_dist = current->g;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   367
	ftd->best_bird_dist = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   368
	ftd->node = current->path.node;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   369
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   370
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   371
/* Will just follow the results of GetTileTrackStatus concerning where we can
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   372
 * go and where not. Uses AyStar.user_data[NPF_TYPE] as the transport type and
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   373
 * an argument to GetTileTrackStatus. Will skip tunnels, meaning that the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   374
 * entry and exit are neighbours. Will fill AyStarNode.user_data[NPF_TRACKDIR_CHOICE] with an
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   375
 * appropriate value, and copy AyStarNode.user_data[NPF_NODE_FLAGS] from the
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   376
 * parent */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   377
void NPFFollowTrack(AyStar* aystar, OpenListNode* current) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   378
	byte src_trackdir = current->path.node.direction;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   379
	TileIndex src_tile = current->path.node.tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   380
	byte src_exitdir = _trackdir_to_exitdir[src_trackdir];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   381
	FindLengthOfTunnelResult flotr;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   382
	TileIndex dst_tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   383
	int i = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   384
	uint trackdirs, ts;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   385
	TransportType type = aystar->user_data[NPF_TYPE];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   386
	/* Initialize to 0, so we can jump out (return) somewhere an have no neighbours */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   387
	aystar->num_neighbours = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   388
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   389
	debug("Expanding: (%d, %d, %d) [%d]", TileX(src_tile), TileY(src_tile), src_trackdir, src_tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   390
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   391
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   392
	/* Find dest tile */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   393
	if (IsTileType(src_tile, MP_TUNNELBRIDGE) && (_map5[src_tile] & 0xF0)==0 && (_map5[src_tile] & 3) == src_exitdir) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   394
		/* This is a tunnel. We know this tunnel is our type,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   395
		 * otherwise we wouldn't have got here. It is also facing us,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   396
		 * so we should skip it's body */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   397
		flotr = FindLengthOfTunnel(src_tile, src_exitdir);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   398
		dst_tile = flotr.tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   399
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   400
		if (
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   401
			(type == TRANSPORT_ROAD && IsRoadStationTile(src_tile))
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   402
			|| (type == TRANSPORT_ROAD && IsRoadDepotTile(src_tile))
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   403
			|| (type == TRANSPORT_RAIL && IsTrainDepotTile(src_tile))
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   404
			){
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   405
			/* This is a road station or a train or road depot. We can enter and exit
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   406
			 * those from one side only. Trackdirs don't support that (yet), so we'll
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   407
			 * do this here. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   408
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   409
			byte exitdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   410
			/* Find out the exit direction first */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   411
			if (IsRoadStationTile(src_tile))
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   412
				exitdir = GetRoadStationDir(src_tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   413
			else /* Train or road depot. Direction is stored the same for both, in map5 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   414
				exitdir = _map5[src_tile] & 3; /* Extract the direction from the map */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   415
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   416
			/* Let's see if were headed the right way */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   417
			if (src_trackdir != _dir_to_diag_trackdir[exitdir])
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   418
				/* Not going out of the station/depot through the exit, but the back. No
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   419
				 * neighbours then. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   420
				return;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   421
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   422
		/* This a normal tile, a bridge, a tunnel exit, etc. */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   423
		dst_tile = AddTileIndexDiffCWrap(src_tile, TileIndexDiffCByDir(_trackdir_to_exitdir[src_trackdir]));
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   424
		if (dst_tile == INVALID_TILE) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   425
			/* We reached the border of the map */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   426
			/* TODO Nicer control flow for this */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   427
			return;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   428
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   429
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   430
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   431
	// TODO: check correct rail type (mono, maglev, etc)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   432
	// TODO: check tile owner
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   433
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   434
	/* Determine available tracks */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   435
	if (type == TRANSPORT_ROAD && (IsRoadStationTile(dst_tile) || IsRoadDepotTile(dst_tile))){
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   436
		byte exitdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   437
		/* Road stations and depots return 0 on GTTS, so we have to do this by hand... */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   438
			if (IsRoadStationTile(dst_tile))
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   439
				exitdir = GetRoadStationDir(dst_tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   440
			else /* Road depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   441
				exitdir = _map5[dst_tile] & 3; /* Extract the direction from the map */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   442
			ts = (1 << _dir_to_diag_trackdir[exitdir]) |
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   443
					(1 << _dir_to_diag_trackdir[_reverse_dir[exitdir]]);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   444
					/* Find the trackdirs that are available for a station with this orientation. They are in both directions */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   445
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   446
		ts = GetTileTrackStatus(dst_tile, type);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   447
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   448
	trackdirs = ts & 0x3F3F; /* Filter out signal status and the unused bits */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   449
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   450
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   451
	debug("Next node: (%d, %d) [%d], possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), dst_tile, trackdirs);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   452
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   453
	/* Select only trackdirs we can reach from our current trackdir */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   454
	trackdirs &= _trackdir_reaches_trackdirs[src_trackdir];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   455
	if (_patches.forbid_90_deg && (type == TRANSPORT_RAIL || type == TRANSPORT_WATER)) /* Filter out trackdirs that would make 90 deg turns for trains */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   456
		trackdirs &= ~_trackdir_crosses_trackdirs[src_trackdir];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   457
	#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   458
	debug("After filtering: (%d, %d), possible trackdirs: %#x", TileX(dst_tile), TileY(dst_tile), trackdirs);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   459
	#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   460
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   461
	/* Enumerate possible track */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   462
	while (trackdirs != 0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   463
		byte dst_trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   464
		dst_trackdir =  FindFirstBit2x64(trackdirs);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   465
		trackdirs = KillFirstBit2x64(trackdirs);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   466
		#ifdef NPF_DEBUG
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   467
		debug("Expanded into trackdir: %d, remaining trackdirs: %#x", dst_trackdir, trackdirs);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   468
		#endif
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   469
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   470
		/* Check for oneway signal against us */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   471
		if (IsTileType(dst_tile, MP_RAILWAY) && (_map5[dst_tile]&0xC0) == 0x40) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   472
			// the tile has a signal
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   473
			byte signal_present = _map3_lo[dst_tile];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   474
			if (!(signal_present & _signal_along_trackdir[dst_trackdir])) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   475
				// if one way signal not pointing towards us, stop going in this direction.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   476
				if (signal_present & _signal_against_trackdir[dst_trackdir])
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   477
					break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   478
			}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   479
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   480
		{
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   481
			/* We've found ourselves a neighbour :-) */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   482
			AyStarNode* neighbour = &aystar->neighbours[i];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   483
			neighbour->tile = dst_tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   484
			neighbour->direction = dst_trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   485
			/* Save user data */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   486
			neighbour->user_data[NPF_NODE_FLAGS] = current->path.node.user_data[NPF_NODE_FLAGS];
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   487
			NPFFillTrackdirChoice(neighbour, current);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   488
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   489
		i++;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   490
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   491
	aystar->num_neighbours = i;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   492
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   493
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   494
/*
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   495
 * Plan a route to the specified target (which is checked by target_proc),
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   496
 * from start1 and if not NULL, from start2 as well. The type of transport we
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   497
 * are checking is in type.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   498
 * When we are looking for one specific target (optionally multiple tiles), we
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   499
 * should use a good heuristic to perform aystar search. When we search for
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   500
 * multiple targets that are spread around, we should perform a breadth first
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   501
 * search by specifiying CalcZero as our heuristic.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   502
 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   503
NPFFoundTargetData NPFRouteInternal(AyStarNode* start1, AyStarNode* start2, NPFFindStationOrTileData* target, AyStar_EndNodeCheck target_proc, AyStar_CalculateH heuristic_proc, TransportType type) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   504
	int r;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   505
	NPFFoundTargetData result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   506
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   507
	/* Initialize procs */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   508
	_npf_aystar.CalculateH = heuristic_proc;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   509
	_npf_aystar.EndNodeCheck = target_proc;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   510
	_npf_aystar.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   511
	_npf_aystar.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   512
	if (type == TRANSPORT_RAIL)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   513
		_npf_aystar.CalculateG = NPFRailPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   514
	else if (type == TRANSPORT_ROAD)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   515
		_npf_aystar.CalculateG = NPFRoadPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   516
	else if (type == TRANSPORT_WATER)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   517
		_npf_aystar.CalculateG = NPFWaterPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   518
	else
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   519
		assert(0);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   520
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   521
	/* Initialize Start Node(s) */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   522
	start1->user_data[NPF_TRACKDIR_CHOICE] = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   523
	start1->user_data[NPF_NODE_FLAGS] = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   524
	_npf_aystar.addstart(&_npf_aystar, start1);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   525
	if (start2) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   526
		start2->user_data[NPF_TRACKDIR_CHOICE] = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   527
		start2->user_data[NPF_NODE_FLAGS] = NPF_FLAG_REVERSE;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   528
		_npf_aystar.addstart(&_npf_aystar, start2);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   529
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   530
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   531
	/* Initialize result */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   532
	result.best_bird_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   533
	result.best_path_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   534
	result.best_trackdir = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   535
	_npf_aystar.user_path = &result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   536
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   537
	/* Initialize target */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   538
	_npf_aystar.user_target = target;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   539
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   540
	/* Initialize user_data */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   541
	_npf_aystar.user_data[NPF_TYPE] = type;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   542
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   543
	/* GO! */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   544
	r = AyStarMain_Main(&_npf_aystar);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   545
	assert(r != AYSTAR_STILL_BUSY);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   546
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   547
	if (result.best_bird_dist != 0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   548
		if (target) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   549
			DEBUG(misc, 1) ("NPF: Could not find route to 0x%x from 0x%x.", target->dest_coords, start1->tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   550
		} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   551
			/* Assumption: target == NULL, so we are looking for a depot */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   552
			DEBUG(misc, 1) ("NPF: Could not find route to a depot from 0x%x.", start1->tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   553
		}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   554
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   555
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   556
	return result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   557
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   558
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   559
NPFFoundTargetData NPFRouteToStationOrTileTwoWay(TileIndex tile1, byte trackdir1, TileIndex tile2, byte trackdir2, NPFFindStationOrTileData* target, TransportType type) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   560
	AyStarNode start1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   561
	AyStarNode start2;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   562
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   563
	start1.tile = tile1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   564
	start2.tile = tile2;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   565
	start1.direction = trackdir1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   566
	start2.direction = trackdir2;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   567
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   568
	return NPFRouteInternal(&start1, &start2, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, type);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   569
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   570
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   571
NPFFoundTargetData NPFRouteToStationOrTile(TileIndex tile, byte trackdir, NPFFindStationOrTileData* target, TransportType type) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   572
	AyStarNode start;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   573
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   574
	assert(tile != 0);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   575
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   576
	start.tile = tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   577
	start.direction = trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   578
	/* We set this in case the target is also the start tile, we will just
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   579
	 * return a not found then */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   580
	start.user_data[NPF_TRACKDIR_CHOICE] = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   581
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   582
	return NPFRouteInternal(&start, NULL, target, NPFFindStationOrTile, NPFCalcStationOrTileHeuristic, type);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   583
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   584
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   585
NPFFoundTargetData NPFRouteToDepotBreadthFirst(TileIndex tile, byte trackdir, TransportType type) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   586
	AyStarNode start;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   587
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   588
	start.tile = tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   589
	start.direction = trackdir;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   590
	/* We set this in case the target is also the start tile, we will just
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   591
	 * return a not found then */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   592
	start.user_data[NPF_TRACKDIR_CHOICE] = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   593
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   594
	/* perform a breadth first search. Target is NULL,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   595
	 * since we are just looking for any depot...*/
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   596
	return NPFRouteInternal(&start, NULL, NULL, NPFFindDepot, NPFCalcZero, type);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   597
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   598
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   599
NPFFoundTargetData NPFRouteToDepotTrialError(TileIndex tile, byte trackdir, TransportType type) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   600
	/* Okay, what we're gonna do. First, we look at all depots, calculate
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   601
	 * the manhatten distance to get to each depot. We then sort them by
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   602
	 * distance. We start by trying to plan a route to the closest, then
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   603
	 * the next closest, etc. We stop when the best route we have found so
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   604
	 * far, is shorter than the manhattan distance. This will obviously
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   605
	 * always find the closest depot. It will probably be most efficient
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   606
	 * for ships, since the heuristic will not be to far off then. I hope.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   607
	 */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   608
	Queue depots;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   609
	TileType tiletype = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   610
	int r;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   611
	NPFFoundTargetData best_result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   612
	NPFFoundTargetData result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   613
	NPFFindStationOrTileData target;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   614
	AyStarNode start;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   615
	Depot* current;
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   616
	Depot *depot;
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   617
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   618
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   619
	/* This is a little ugly, but it works :-S */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   620
	if (type == TRANSPORT_ROAD)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   621
		tiletype = MP_STREET;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   622
	else if (type == TRANSPORT_RAIL)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   623
		tiletype = MP_RAILWAY;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   624
	else if (type == TRANSPORT_WATER)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   625
		tiletype = MP_WATER;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   626
	else
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   627
		assert(0);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   628
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   629
	init_InsSort(&depots);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   630
	/* Okay, let's find all depots that we can use first */
1313
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   631
	FOR_ALL_DEPOTS(depot) {
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   632
		if (IsTileType(depot->xy, tiletype))
bba6afb8a995 (svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents: 1299
diff changeset
   633
			depots.push(&depots, depot, DistanceManhattan(tile, depot->xy));
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   634
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   635
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   636
	/* Now, let's initialise the aystar */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   637
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   638
	/* Initialize procs */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   639
	_npf_aystar.CalculateH = NPFCalcStationOrTileHeuristic;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   640
	_npf_aystar.EndNodeCheck = NPFFindStationOrTile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   641
	_npf_aystar.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   642
	_npf_aystar.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   643
	if (type == TRANSPORT_RAIL)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   644
		_npf_aystar.CalculateG = NPFRailPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   645
	else if (type == TRANSPORT_ROAD)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   646
		_npf_aystar.CalculateG = NPFRoadPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   647
	else if (type == TRANSPORT_WATER)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   648
		_npf_aystar.CalculateG = NPFWaterPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   649
	else
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   650
		assert(0);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   651
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   652
	/* Initialize target */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   653
	target.station_index = -1; /* We will initialize dest_coords inside the loop below */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   654
	_npf_aystar.user_target = &target;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   655
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   656
	/* Initialize user_data */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   657
	_npf_aystar.user_data[NPF_TYPE] = type;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   658
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   659
	/* Initialize Start Node */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   660
	start.tile = tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   661
	start.direction = trackdir; /* We will initialize user_data inside the loop below */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   662
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   663
	/* Initialize Result */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   664
	_npf_aystar.user_path = &result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   665
	best_result.best_path_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   666
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   667
	/* Just iterate the depots in order of increasing distance */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   668
	while ((current = depots.pop(&depots))) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   669
		/* Check to see if we already have a path shorter than this
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   670
		 * depot's manhattan distance. Hack: We call DistanceManhattan
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   671
		 * again, we should probably modify the queue to give us that
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   672
		 * value... */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   673
		if ( DistanceManhattan(tile, current->xy * NPF_TILE_LENGTH) > best_result.best_path_dist)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   674
			break;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   675
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   676
		/* Initialize Start Node */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   677
		/* We set this in case the target is also the start tile, we will just
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   678
		 * return a not found then */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   679
		start.user_data[NPF_TRACKDIR_CHOICE] = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   680
		start.user_data[NPF_NODE_FLAGS] = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   681
		_npf_aystar.addstart(&_npf_aystar, &start);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   682
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   683
		/* Initialize result */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   684
		result.best_bird_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   685
		result.best_path_dist = (uint)-1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   686
		result.best_trackdir = 0xff;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   687
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   688
		/* Initialize target */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   689
		target.dest_coords = current->xy;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   690
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   691
		/* GO! */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   692
		r = AyStarMain_Main(&_npf_aystar);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   693
		assert(r != AYSTAR_STILL_BUSY);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   694
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   695
		/* This depot is closer */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   696
		if (result.best_path_dist < best_result.best_path_dist)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   697
			best_result = result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   698
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   699
	if (result.best_bird_dist != 0) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   700
		DEBUG(misc, 1) ("NPF: Could not find route to any depot from 0x%x.", tile);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   701
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   702
	return best_result;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   703
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   704
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   705
void InitializeNPF(void)
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   706
{
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   707
		init_AyStar(&_npf_aystar, NTPHash, 1024);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   708
		_npf_aystar.loops_per_tick = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   709
		_npf_aystar.max_path_cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   710
		_npf_aystar.max_search_nodes = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   711
		/*
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   712
		init_AyStar(&_train_find_station, NTPHash, 1024);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   713
		init_AyStar(&_train_find_depot, NTPHash, 1024);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   714
		init_AyStar(&_road_find_station, NTPHash, 1024);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   715
		init_AyStar(&_road_find_depot, NTPHash, 1024);
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   716
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   717
		_train_find_station.loops_per_tick = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   718
		_train_find_depot.loops_per_tick = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   719
		_road_find_station.loops_per_tick = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   720
		_road_find_depot.loops_per_tick = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   721
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   722
		_train_find_station.max_path_cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   723
		_train_find_depot.max_path_cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   724
		_road_find_station.max_path_cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   725
		_road_find_depot.max_path_cost = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   726
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   727
		_train_find_station.max_search_nodes = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   728
		_train_find_depot.max_search_nodes = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   729
		_road_find_station.max_search_nodes = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   730
		_road_find_depot.max_search_nodes = 0;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   731
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   732
		_train_find_station.CalculateG = NPFRailPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   733
		_train_find_depot.CalculateG = NPFRailPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   734
		_road_find_station.CalculateG = NPFRoadPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   735
		_road_find_depot.CalculateG = NPFRoadPathCost;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   736
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   737
		_train_find_station.CalculateH = NPFCalcStationHeuristic;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   738
		_train_find_depot.CalculateH = NPFCalcStationHeuristic;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   739
		_road_find_station.CalculateH = NPFCalcStationHeuristic;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   740
		_road_find_depot.CalculateH = NPFCalcStationHeuristic;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   741
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   742
		_train_find_station.EndNodeCheck = NPFFindStationOrTile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   743
		_train_find_depot.EndNodeCheck = NPFFindStationOrTile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   744
		_road_find_station.EndNodeCheck = NPFFindStationOrTile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   745
		_road_find_depot.EndNodeCheck = NPFFindStationOrTile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   746
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   747
		_train_find_station.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   748
		_train_find_depot.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   749
		_road_find_station.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   750
		_road_find_depot.FoundEndNode = NPFSaveTargetData;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   751
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   752
		_train_find_station.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   753
		_train_find_depot.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   754
		_road_find_station.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   755
		_road_find_depot.GetNeighbours = NPFFollowTrack;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   756
		*/
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   757
}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   758
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   759
void NPFFillWithOrderData(NPFFindStationOrTileData* fstd, Vehicle* v) {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   760
	/* Ships don't really reach their stations, but the tile in front. So don't
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   761
	 * save the station id for ships. For roadvehs we don't store it either,
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   762
	 * because multistop depends on vehicles actually reaching the exact
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   763
	 * dest_tile, not just any stop of that station.
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   764
	 * So only for train orders to stations we fill fstd->station_index, for all
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   765
	 * others only dest_coords */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   766
	if ((v->current_order.type) == OT_GOTO_STATION && v->type == VEH_Train) {
1248
d217e7124dee (svn r1752) - Fix: MSVC acting up once again, as well as project file updates for the missing files.
darkvater
parents: 1247
diff changeset
   767
		const Station* st = GetStation(v->current_order.station);
d217e7124dee (svn r1752) - Fix: MSVC acting up once again, as well as project file updates for the missing files.
darkvater
parents: 1247
diff changeset
   768
		TileIndexDiffC center = {st->trainst_w/2, st->trainst_h/2};
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   769
		fstd->station_index = v->current_order.station;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   770
		/* Let's take the center of the station as our target tile for trains */
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   771
		fstd->dest_coords = TILE_ADD(st->train_tile, ToTileIndexDiff(center));
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   772
	} else {
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   773
		fstd->dest_coords = v->dest_tile;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   774
		fstd->station_index = -1;
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   775
	}
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents:
diff changeset
   776
}