npf.c
changeset 1313 f1013ec3d318
parent 1299 39c06aba09aa
child 1330 5d76a0522a11
equal deleted inserted replaced
1312:594340ca5b87 1313:f1013ec3d318
     5 #include "aystar.h"
     5 #include "aystar.h"
     6 #include "macros.h"
     6 #include "macros.h"
     7 #include "pathfind.h"
     7 #include "pathfind.h"
     8 #include "station.h"
     8 #include "station.h"
     9 #include "tile.h"
     9 #include "tile.h"
       
    10 #include "depot.h"
    10 
    11 
    11 AyStar _train_find_station;
    12 AyStar _train_find_station;
    12 AyStar _train_find_depot;
    13 AyStar _train_find_depot;
    13 AyStar _road_find_station;
    14 AyStar _road_find_station;
    14 AyStar _road_find_depot;
    15 AyStar _road_find_depot;
   603 	 * far, is shorter than the manhattan distance. This will obviously
   604 	 * far, is shorter than the manhattan distance. This will obviously
   604 	 * always find the closest depot. It will probably be most efficient
   605 	 * always find the closest depot. It will probably be most efficient
   605 	 * for ships, since the heuristic will not be to far off then. I hope.
   606 	 * for ships, since the heuristic will not be to far off then. I hope.
   606 	 */
   607 	 */
   607 	Queue depots;
   608 	Queue depots;
   608 	uint i;
       
   609 	TileType tiletype = 0;
   609 	TileType tiletype = 0;
   610 	int r;
   610 	int r;
   611 	NPFFoundTargetData best_result;
   611 	NPFFoundTargetData best_result;
   612 	NPFFoundTargetData result;
   612 	NPFFoundTargetData result;
   613 	NPFFindStationOrTileData target;
   613 	NPFFindStationOrTileData target;
   614 	AyStarNode start;
   614 	AyStarNode start;
   615 	Depot* current;
   615 	Depot* current;
       
   616 	Depot *depot;
   616 
   617 
   617 
   618 
   618 	/* This is a little ugly, but it works :-S */
   619 	/* This is a little ugly, but it works :-S */
   619 	if (type == TRANSPORT_ROAD)
   620 	if (type == TRANSPORT_ROAD)
   620 		tiletype = MP_STREET;
   621 		tiletype = MP_STREET;
   625 	else
   626 	else
   626 		assert(0);
   627 		assert(0);
   627 
   628 
   628 	init_InsSort(&depots);
   629 	init_InsSort(&depots);
   629 	/* Okay, let's find all depots that we can use first */
   630 	/* Okay, let's find all depots that we can use first */
   630 	for (i=0;i<lengthof(_depots);i++) {
   631 	FOR_ALL_DEPOTS(depot) {
   631 		int depot_tile = _depots[i].xy;
   632 		if (IsTileType(depot->xy, tiletype))
   632 		if (IsTileType(depot_tile, tiletype))
   633 			depots.push(&depots, depot, DistanceManhattan(tile, depot->xy));
   633 			depots.push(&depots, &_depots[i], DistanceManhattan(tile, depot_tile));
       
   634 
       
   635 	}
   634 	}
   636 
   635 
   637 	/* Now, let's initialise the aystar */
   636 	/* Now, let's initialise the aystar */
   638 
   637 
   639 	/* Initialize procs */
   638 	/* Initialize procs */