(svn r6159) -Fix: FindClosestTrainDepot hardly ever found a depot with NPF off due to absence of distance-normalization (Rojer)
authorDarkvater
Sat, 26 Aug 2006 21:54:04 +0000
changeset 4406 4ff711f834b9
parent 4405 262b9ef8ab8f
child 4407 d639dd97eff0
(svn r6159) -Fix: FindClosestTrainDepot hardly ever found a depot with NPF off due to absence of distance-normalization (Rojer)
pathfind.c
pathfind.h
train_cmd.c
--- a/pathfind.c	Sat Aug 26 20:54:30 2006 +0000
+++ b/pathfind.c	Sat Aug 26 21:54:04 2006 +0000
@@ -637,11 +637,6 @@
 	0, //14
 };
 
-
-#define DIAG_FACTOR 3
-#define STR_FACTOR 2
-
-
 static uint DistanceMoo(TileIndex t0, TileIndex t1)
 {
 	const uint dx = abs(TileX(t0) - TileX(t1));
--- a/pathfind.h	Sat Aug 26 20:54:30 2006 +0000
+++ b/pathfind.h	Sat Aug 26 21:54:04 2006 +0000
@@ -5,6 +5,11 @@
 
 #include "direction.h"
 
+enum {
+	STR_FACTOR  = 2,
+	DIAG_FACTOR = 3
+};
+
 //#define PF_BENCH // perform simple benchmarks on the train pathfinder (not
 //supported on all archs)
 
--- a/train_cmd.c	Sat Aug 26 20:54:30 2006 +0000
+++ b/train_cmd.c	Sat Aug 26 21:54:04 2006 +0000
@@ -1847,7 +1847,8 @@
 	if (IsTileType(tile, MP_RAILWAY) &&
 			IsTileOwner(tile, tfdd->owner) &&
 			IsRailDepot(tile)) {
-		tfdd->best_length = length;
+		/* approximate number of tiles by dividing by DIAG_FACTOR */
+		tfdd->best_length = length / DIAG_FACTOR;
 		tfdd->tile = tile;
 		return true;
 	}