src/ship_cmd.cpp
changeset 8551 f0bcd6753287
parent 8510 1c0456a2feaf
child 8554 81520f852e48
equal deleted inserted replaced
8550:9f90ede990ac 8551:f0bcd6753287
   118 	uint dist;
   118 	uint dist;
   119 	uint best_dist = (uint)-1;
   119 	uint best_dist = (uint)-1;
   120 	TileIndex tile;
   120 	TileIndex tile;
   121 	TileIndex tile2 = v->tile;
   121 	TileIndex tile2 = v->tile;
   122 
   122 
   123 	if (_patches.new_pathfinding_all) {
   123 	if (_patches.pathfinder_for_ships == VPF_NPF) { /* NPF is used */
   124 		NPFFoundTargetData ftd;
   124 		NPFFoundTargetData ftd;
   125 		Trackdir trackdir = GetVehicleTrackdir(v);
   125 		Trackdir trackdir = GetVehicleTrackdir(v);
   126 		ftd = NPFRouteToDepotTrialError(v->tile, trackdir, false, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES);
   126 		ftd = NPFRouteToDepotTrialError(v->tile, trackdir, false, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES);
   127 		if (ftd.best_bird_dist == 0) {
   127 		if (ftd.best_bird_dist == 0) {
   128 			best_depot = GetDepotByTile(ftd.node.tile); /* Found target */
   128 			best_depot = GetDepotByTile(ftd.node.tile); /* Found target */
   129 		} else {
   129 		} else {
   130 			best_depot = NULL; /* Did not find target */
   130 			best_depot = NULL; /* Did not find target */
   131 		}
   131 		}
   132 	} else {
   132 	} else { /* OPF or YAPF */
   133 		FOR_ALL_DEPOTS(depot) {
   133 		FOR_ALL_DEPOTS(depot) {
   134 			tile = depot->xy;
   134 			tile = depot->xy;
   135 			if (IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) {
   135 			if (IsTileDepotType(tile, TRANSPORT_WATER) && IsTileOwner(tile, v->owner)) {
   136 				dist = DistanceManhattan(tile, tile2);
   136 				dist = DistanceManhattan(tile, tile2);
   137 				if (dist < best_dist) {
   137 				if (dist < best_dist) {
   525  * direction in which we are entering the tile */
   525  * direction in which we are entering the tile */
   526 static Track ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
   526 static Track ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
   527 {
   527 {
   528 	assert(enterdir >= 0 && enterdir <= 3);
   528 	assert(enterdir >= 0 && enterdir <= 3);
   529 
   529 
   530 	if (_patches.yapf.ship_use_yapf) {
   530 	if (_patches.pathfinder_for_ships == VPF_YAPF) { /* YAPF */
   531 		Trackdir trackdir = YapfChooseShipTrack(v, tile, enterdir, tracks);
   531 		Trackdir trackdir = YapfChooseShipTrack(v, tile, enterdir, tracks);
   532 		return (trackdir != INVALID_TRACKDIR) ? TrackdirToTrack(trackdir) : INVALID_TRACK;
   532 		return (trackdir != INVALID_TRACKDIR) ? TrackdirToTrack(trackdir) : INVALID_TRACK;
   533 	} else if (_patches.new_pathfinding_all) {
   533 	} else if (_patches.pathfinder_for_ships == VPF_NPF) { /* NPF */
   534 		NPFFindStationOrTileData fstd;
   534 		NPFFindStationOrTileData fstd;
   535 		NPFFoundTargetData ftd;
   535 		NPFFoundTargetData ftd;
   536 		Trackdir trackdir = GetVehicleTrackdir(v);
   536 		Trackdir trackdir = GetVehicleTrackdir(v);
   537 		assert(trackdir != INVALID_TRACKDIR); // Check that we are not in a depot
   537 		assert(trackdir != INVALID_TRACKDIR); // Check that we are not in a depot
   538 
   538 
   547 			to the tile closest to our target. */
   547 			to the tile closest to our target. */
   548 			return TrackdirToTrack(ftd.best_trackdir); /* TODO: Wrapper function? */
   548 			return TrackdirToTrack(ftd.best_trackdir); /* TODO: Wrapper function? */
   549 		} else {
   549 		} else {
   550 			return INVALID_TRACK; /* Already at target, reverse? */
   550 			return INVALID_TRACK; /* Already at target, reverse? */
   551 		}
   551 		}
   552 	} else {
   552 	} else { /* OPF */
   553 		uint tot_dist, dist;
   553 		uint tot_dist, dist;
   554 		Track track;
   554 		Track track;
   555 		TileIndex tile2;
   555 		TileIndex tile2;
   556 
   556 
   557 		tile2 = TILE_ADD(tile, -TileOffsByDiagDir(enterdir));
   557 		tile2 = TILE_ADD(tile, -TileOffsByDiagDir(enterdir));