diff options
author | rubidium <rubidium@openttd.org> | 2009-12-01 23:56:04 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-12-01 23:56:04 +0000 |
commit | 76fe20cdccd68679f4681e3f378b7695d161e8a8 (patch) | |
tree | 2bc31ade4605acc0304669e3bc3353d7beca0d3f /src/pathfinder/npf | |
parent | 291f6490c65bd88067db472a915b4ea29cc5741a (diff) | |
download | openttd-76fe20cdccd68679f4681e3f378b7695d161e8a8.tar.xz |
(svn r18367) -Codechange: unify the ship pathfinder 'calls'
Diffstat (limited to 'src/pathfinder/npf')
-rw-r--r-- | src/pathfinder/npf/npf.cpp | 21 | ||||
-rw-r--r-- | src/pathfinder/npf/npf_func.h | 17 |
2 files changed, 38 insertions, 0 deletions
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index f4211c298..50795d0ed 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -19,6 +19,7 @@ #include "../../tunnelbridge.h" #include "../../pbs.h" #include "../../train.h" +#include "../../ship.h" #include "../pathfinder_func.h" #include "npf.h" @@ -1118,3 +1119,23 @@ void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, Vehicle *v, bool reser fstd->reserve_path = reserve_path; fstd->v = v; } + +/*** Ships ***/ + +Track NPFShipChooseTrack(Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) +{ + NPFFindStationOrTileData fstd; + Trackdir trackdir = v->GetVehicleTrackdir(); + assert(trackdir != INVALID_TRACKDIR); // Check that we are not in a depot + + NPFFillWithOrderData(&fstd, v); + + NPFFoundTargetData ftd = NPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, TRANSPORT_WATER, 0, v->owner, INVALID_RAILTYPES); + + /* If ftd.best_bird_dist is 0, we found our target and ftd.best_trackdir contains + * the direction we need to take to get there, if ftd.best_bird_dist is not 0, + * we did not find our target, but ftd.best_trackdir contains the direction leading + * to the tile closest to our target. */ + if (ftd.best_trackdir == 0xff) return INVALID_TRACK; + return TrackdirToTrack(ftd.best_trackdir); +} diff --git a/src/pathfinder/npf/npf_func.h b/src/pathfinder/npf/npf_func.h new file mode 100644 index 000000000..7121ba065 --- /dev/null +++ b/src/pathfinder/npf/npf_func.h @@ -0,0 +1,17 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file npf_func.h Functions to access the new pathfinder. */ + +#ifndef NPF_FUNC_H +#define NPF_FUNC_H + +Track NPFShipChooseTrack(class Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks); + +#endif /* NPF_FUNC_H */ |