diff --git a/projects/openttd_vs140.vcxproj b/projects/openttd_vs140.vcxproj index 26267f6a03..473dfcda40 100644 --- a/projects/openttd_vs140.vcxproj +++ b/projects/openttd_vs140.vcxproj @@ -1291,8 +1291,6 @@ - - diff --git a/projects/openttd_vs140.vcxproj.filters b/projects/openttd_vs140.vcxproj.filters index 3c4fc43d98..9a468836b0 100644 --- a/projects/openttd_vs140.vcxproj.filters +++ b/projects/openttd_vs140.vcxproj.filters @@ -2961,12 +2961,6 @@ Pathfinder - - Pathfinder - - - Pathfinder - Pathfinder diff --git a/projects/openttd_vs141.vcxproj b/projects/openttd_vs141.vcxproj index 0cd3fe7488..2a963bfa20 100644 --- a/projects/openttd_vs141.vcxproj +++ b/projects/openttd_vs141.vcxproj @@ -1291,8 +1291,6 @@ - - diff --git a/projects/openttd_vs141.vcxproj.filters b/projects/openttd_vs141.vcxproj.filters index 3c4fc43d98..9a468836b0 100644 --- a/projects/openttd_vs141.vcxproj.filters +++ b/projects/openttd_vs141.vcxproj.filters @@ -2961,12 +2961,6 @@ Pathfinder - - Pathfinder - - - Pathfinder - Pathfinder diff --git a/projects/openttd_vs142.vcxproj b/projects/openttd_vs142.vcxproj index 20c3d1b210..f4c76e0978 100644 --- a/projects/openttd_vs142.vcxproj +++ b/projects/openttd_vs142.vcxproj @@ -1291,8 +1291,6 @@ - - diff --git a/projects/openttd_vs142.vcxproj.filters b/projects/openttd_vs142.vcxproj.filters index 3c4fc43d98..9a468836b0 100644 --- a/projects/openttd_vs142.vcxproj.filters +++ b/projects/openttd_vs142.vcxproj.filters @@ -2961,12 +2961,6 @@ Pathfinder - - Pathfinder - - - Pathfinder - Pathfinder diff --git a/source.list b/source.list index b567a0026d..7a6e6661ab 100644 --- a/source.list +++ b/source.list @@ -1049,8 +1049,6 @@ network/core/udp.h # Pathfinder pathfinder/follow_track.hpp -pathfinder/opf/opf_ship.cpp -pathfinder/opf/opf_ship.h pathfinder/pathfinder_func.h pathfinder/pathfinder_type.h pathfinder/pf_performance_timer.hpp diff --git a/src/openttd.cpp b/src/openttd.cpp index c2e7455667..c833583609 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -434,7 +434,6 @@ struct AfterNewGRFScan : NewGRFScanCallback { Game::Uninitialize(true); AI::Uninitialize(true); - CheckConfig(); LoadFromHighScore(); LoadHotkeysFromConfig(); WindowDesc::LoadFromConfig(); diff --git a/src/pathfinder/opf/opf_ship.cpp b/src/pathfinder/opf/opf_ship.cpp deleted file mode 100644 index c993f82033..0000000000 --- a/src/pathfinder/opf/opf_ship.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* $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 . - */ - -/** @file opf_ship.cpp Implementation of the oldest supported ship pathfinder. */ - -#include "../../stdafx.h" -#include "../../tunnelbridge_map.h" -#include "../../tunnelbridge.h" -#include "../../ship.h" -#include "../../core/random_func.hpp" - -#include "../../safeguards.h" - -struct RememberData { - uint16 cur_length; - byte depth; - Track last_choosen_track; -}; - -struct TrackPathFinder { - TileIndex skiptile; - TileIndex dest_coords; - uint best_bird_dist; - uint best_length; - RememberData rd; - TrackdirByte the_dir; -}; - -static bool ShipTrackFollower(TileIndex tile, TrackPathFinder *pfs, uint length) -{ - /* Found dest? */ - if (tile == pfs->dest_coords) { - pfs->best_bird_dist = 0; - - pfs->best_length = minu(pfs->best_length, length); - return true; - } - - /* Skip this tile in the calculation */ - if (tile != pfs->skiptile) { - pfs->best_bird_dist = minu(pfs->best_bird_dist, DistanceMaxPlusManhattan(pfs->dest_coords, tile)); - } - - return false; -} - -static void TPFModeShip(TrackPathFinder *tpf, TileIndex tile, DiagDirection direction) -{ - if (IsTileType(tile, MP_TUNNELBRIDGE)) { - /* wrong track type */ - if (GetTunnelBridgeTransportType(tile) != TRANSPORT_WATER) return; - - DiagDirection dir = GetTunnelBridgeDirection(tile); - /* entering tunnel / bridge? */ - if (dir == direction) { - TileIndex endtile = GetOtherTunnelBridgeEnd(tile); - - tpf->rd.cur_length += GetTunnelBridgeLength(tile, endtile) + 1; - - tile = endtile; - } else { - /* leaving tunnel / bridge? */ - if (ReverseDiagDir(dir) != direction) return; - } - } - - /* This addition will sometimes overflow by a single tile. - * The use of TILE_MASK here makes sure that we still point at a valid - * tile, and then this tile will be in the sentinel row/col, so GetTileTrackStatus will fail. */ - tile = TILE_MASK(tile + TileOffsByDiagDir(direction)); - - if (++tpf->rd.cur_length > 50) return; - - TrackBits bits = TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_WATER, 0)) & DiagdirReachesTracks(direction); - if (bits == TRACK_BIT_NONE) return; - - assert(TileX(tile) != MapMaxX() && TileY(tile) != MapMaxY()); - - bool only_one_track = true; - do { - Track track = RemoveFirstTrack(&bits); - if (bits != TRACK_BIT_NONE) only_one_track = false; - RememberData rd = tpf->rd; - - /* Change direction 4 times only */ - if (!only_one_track && track != tpf->rd.last_choosen_track) { - if (++tpf->rd.depth > 4) { - tpf->rd = rd; - return; - } - tpf->rd.last_choosen_track = track; - } - - tpf->the_dir = TrackEnterdirToTrackdir(track, direction); - - if (!ShipTrackFollower(tile, tpf, tpf->rd.cur_length)) { - TPFModeShip(tpf, tile, TrackdirToExitdir(tpf->the_dir)); - } - - tpf->rd = rd; - } while (bits != TRACK_BIT_NONE); -} - -static void OPFShipFollowTrack(TileIndex tile, DiagDirection direction, TrackPathFinder *tpf) -{ - assert(IsValidDiagDirection(direction)); - - /* initialize path finder variables */ - tpf->rd.cur_length = 0; - tpf->rd.depth = 0; - tpf->rd.last_choosen_track = INVALID_TRACK; - - ShipTrackFollower(tile, tpf, 0); - TPFModeShip(tpf, tile, direction); -} - -/** Directions to search towards given track bits and the ship's enter direction. */ -static const DiagDirection _ship_search_directions[6][4] = { - { DIAGDIR_NE, INVALID_DIAGDIR, DIAGDIR_SW, INVALID_DIAGDIR }, - { INVALID_DIAGDIR, DIAGDIR_SE, INVALID_DIAGDIR, DIAGDIR_NW }, - { INVALID_DIAGDIR, DIAGDIR_NE, DIAGDIR_NW, INVALID_DIAGDIR }, - { DIAGDIR_SE, INVALID_DIAGDIR, INVALID_DIAGDIR, DIAGDIR_SW }, - { DIAGDIR_NW, DIAGDIR_SW, INVALID_DIAGDIR, INVALID_DIAGDIR }, - { INVALID_DIAGDIR, INVALID_DIAGDIR, DIAGDIR_SE, DIAGDIR_NE }, -}; - -/** Track to "direction (& 3)" mapping. */ -static const byte _pick_shiptrack_table[6] = {DIR_NE, DIR_SE, DIR_E, DIR_E, DIR_N, DIR_N}; - -static uint FindShipTrack(const Ship *v, TileIndex tile, DiagDirection dir, TrackBits bits, TileIndex skiptile, Track *track) -{ - TrackPathFinder pfs; - uint best_bird_dist = 0; - uint best_length = 0; - byte ship_dir = v->direction & 3; - - pfs.dest_coords = v->dest_tile; - pfs.skiptile = skiptile; - - Track best_track = INVALID_TRACK; - - assert(bits != TRACK_BIT_NONE); - do { - Track i = RemoveFirstTrack(&bits); - - pfs.best_bird_dist = UINT_MAX; - pfs.best_length = UINT_MAX; - - OPFShipFollowTrack(tile, _ship_search_directions[i][dir], &pfs); - - if (best_track != INVALID_TRACK) { - if (pfs.best_bird_dist != 0) { - /* neither reached the destination, pick the one with the smallest bird dist */ - if (pfs.best_bird_dist > best_bird_dist) goto bad; - if (pfs.best_bird_dist < best_bird_dist) goto good; - } else { - if (pfs.best_length > best_length) goto bad; - if (pfs.best_length < best_length) goto good; - } - - /* if we reach this position, there's two paths of equal value so far. - * pick one randomly. */ - uint r = GB(Random(), 0, 8); - if (_pick_shiptrack_table[i] == ship_dir) r += 80; - if (_pick_shiptrack_table[best_track] == ship_dir) r -= 80; - if (r <= 127) goto bad; - } -good:; - best_track = i; - best_bird_dist = pfs.best_bird_dist; - best_length = pfs.best_length; -bad:; - - } while (bits != TRACK_BIT_NONE); - - *track = best_track; - return best_bird_dist; -} - -/** - * Finds the best track to choose on the next tile and - * returns INVALID_TRACK when it is better to reverse. - * @param v The ship. - * @param tile The tile we are about to enter. - * @param enterdir The direction entering the tile. - * @param tracks The tracks available on new tile. - * @param[out] path_found Whether a path has been found. - * @return Best track on next tile or INVALID_TRACK when better to reverse. - */ -Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found) -{ - assert(IsValidDiagDirection(enterdir)); - - TileIndex tile2 = TILE_ADD(tile, -TileOffsByDiagDir(enterdir)); - Track track; - - /* Let's find out how far it would be if we would reverse first */ - uint rev_dist = UINT_MAX; // distance if we reverse - Track cur_track = TrackdirToTrack(v->GetVehicleTrackdir()); // track on the current tile - DiagDirection rev_enterdir = ReverseDiagDir(enterdir); - TrackBits rev_tracks = TrackStatusToTrackBits(GetTileTrackStatus(tile2, TRANSPORT_WATER, 0)) & - DiagdirReachesTracks(rev_enterdir); - - if (HasTrack(rev_tracks, cur_track)) { - rev_dist = FindShipTrack(v, tile2, rev_enterdir, TrackToTrackBits(cur_track), tile, &track); - if (rev_dist != UINT_MAX) rev_dist++; // penalty for reversing - } - - /* And if we would not reverse? */ - uint dist = FindShipTrack(v, tile, enterdir, tracks, 0, &track); - - /* Due to the way this pathfinder works we cannot determine whether we're lost or not. */ - path_found = true; - if (dist <= rev_dist) return track; - return INVALID_TRACK; // We could better reverse -} diff --git a/src/pathfinder/opf/opf_ship.h b/src/pathfinder/opf/opf_ship.h deleted file mode 100644 index 62668b206a..0000000000 --- a/src/pathfinder/opf/opf_ship.h +++ /dev/null @@ -1,31 +0,0 @@ -/* $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 . - */ - -/** @file opf_ship.h Original pathfinder for ships; very simple. */ - -#ifndef OPF_SHIP_H -#define OPF_SHIP_H - -#include "../../direction_type.h" -#include "../../tile_type.h" -#include "../../track_type.h" -#include "../../vehicle_type.h" - -/** - * Finds the best path for given ship using OPF. - * @param v the ship that needs to find a path - * @param tile the tile to find the path from (should be next tile the ship is about to enter) - * @param enterdir diagonal direction which the ship will enter this new tile from - * @param tracks available tracks on the new tile (to choose from) - * @param path_found [out] Whether a path has been found (true) or has been guessed (false) - * @return the best trackdir for next turn or INVALID_TRACK if the path could not be found - */ -Track OPFShipChooseTrack(const Ship *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found); - -#endif /* OPF_SHIP_H */ diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index ea7882e895..6f32c5506f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1875,7 +1875,7 @@ bool AfterLoadGame() if (_settings_game.pf.yapf.ship_use_yapf) { _settings_game.pf.pathfinder_for_ships = VPF_YAPF; } else { - _settings_game.pf.pathfinder_for_ships = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF); + _settings_game.pf.pathfinder_for_ships = VPF_NPF; } } diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 77cce4c4a4..61d5273401 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -296,6 +296,7 @@ enum SaveLoadVersion : uint16 { SLV_SERVE_NEUTRAL_INDUSTRIES, ///< 210 PR#7234 Company stations can serve industries with attached neutral stations. SLV_ROADVEH_PATH_CACHE, ///< 211 PR#7261 Add path cache for road vehicles. + SLV_REMOVE_OPF, ///< 212 PR#7245 Remove OPF. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/settings.cpp b/src/settings.cpp index 1fc2682cd0..6ea5c081a3 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2275,18 +2275,6 @@ static void Save_PATS() SaveSettings(_settings, &_settings_game); } -void CheckConfig() -{ - /* - * Increase old default values for pf_maxdepth and pf_maxlength - * to support big networks. - */ - if (_settings_newgame.pf.opf.pf_maxdepth == 16 && _settings_newgame.pf.opf.pf_maxlength == 512) { - _settings_newgame.pf.opf.pf_maxdepth = 48; - _settings_newgame.pf.opf.pf_maxlength = 4096; - } -} - extern const ChunkHandler _setting_chunk_handlers[] = { { 'OPTS', NULL, Load_OPTS, NULL, NULL, CH_RIFF}, { 'PATS', Save_PATS, Load_PATS, NULL, Check_PATS, CH_RIFF | CH_LAST}, diff --git a/src/settings_func.h b/src/settings_func.h index 3b3387b5fd..c258cb6404 100644 --- a/src/settings_func.h +++ b/src/settings_func.h @@ -24,7 +24,6 @@ void IConsoleListSettings(const char *prefilter); void LoadFromConfig(bool minimal = false); void SaveToConfig(); -void CheckConfig(); void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc); void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc); diff --git a/src/settings_type.h b/src/settings_type.h index 503342545f..42f8b45170 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -346,12 +346,6 @@ struct ScriptSettings { uint32 script_max_opcode_till_suspend; ///< max opcode calls till scripts will suspend }; -/** Settings related to the old pathfinder. */ -struct OPFSettings { - uint16 pf_maxlength; ///< maximum length when searching for a train route for new pathfinder - byte pf_maxdepth; ///< maximum recursion depth when searching for a train route for new pathfinder -}; - /** Settings related to the new pathfinder. */ struct NPFSettings { /** @@ -440,7 +434,6 @@ struct PathfinderSettings { byte wait_for_pbs_path; ///< how long to wait for a path reservation. byte path_backoff_interval; ///< ticks between checks for a free path. - OPFSettings opf; ///< pathfinder settings for the old pathfinder NPFSettings npf; ///< pathfinder settings for the new pathfinder YAPFSettings yapf; ///< pathfinder settings for the yet another pathfinder }; diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 6d6f8415c8..c04d3e1e2f 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -29,7 +29,6 @@ #include "sound_func.h" #include "ai/ai.hpp" #include "game/game.hpp" -#include "pathfinder/opf/opf_ship.h" #include "engine_base.h" #include "company_base.h" #include "tunnelbridge_map.h" @@ -178,7 +177,6 @@ static void CheckIfShipNeedsService(Vehicle *v) uint max_distance; switch (_settings_game.pf.pathfinder_for_ships) { - case VPF_OPF: max_distance = 12; break; case VPF_NPF: max_distance = _settings_game.pf.npf.maximum_go_to_depot_penalty / NPF_TILE_LENGTH; break; case VPF_YAPF: max_distance = _settings_game.pf.yapf.maximum_go_to_depot_penalty / YAPF_TILE_LENGTH; break; default: NOT_REACHED(); @@ -369,9 +367,7 @@ static bool CheckShipLeaveDepot(Ship *v) if (north_tracks && south_tracks) { /* Ask pathfinder for best direction */ bool reverse = false; - bool path_found; switch (_settings_game.pf.pathfinder_for_ships) { - case VPF_OPF: reverse = OPFShipChooseTrack(v, north_neighbour, north_dir, north_tracks, path_found) == INVALID_TRACK; break; // OPF always allows reversing case VPF_NPF: reverse = NPFShipCheckReverse(v); break; case VPF_YAPF: reverse = YapfShipCheckReverse(v); break; default: NOT_REACHED(); @@ -492,7 +488,6 @@ static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, Tr } switch (_settings_game.pf.pathfinder_for_ships) { - case VPF_OPF: track = OPFShipChooseTrack(v, tile, enterdir, tracks, path_found); break; case VPF_NPF: track = NPFShipChooseTrack(v, path_found); break; case VPF_YAPF: track = YapfShipChooseTrack(v, tile, enterdir, tracks, path_found, v->path); break; default: NOT_REACHED(); @@ -514,8 +509,7 @@ static inline TrackBits GetAvailShipTracks(TileIndex tile, DiagDirection dir, Tr { TrackBits tracks = GetTileShipTrackStatus(tile) & DiagdirReachesTracks(dir); - /* Do not remove 90 degree turns for OPF, as it isn't able to find paths taking it into account. */ - if (_settings_game.pf.forbid_90_deg && _settings_game.pf.pathfinder_for_ships != VPF_OPF) tracks &= ~TrackCrossesTracks(TrackdirToTrack(trackdir)); + if (_settings_game.pf.forbid_90_deg) tracks &= ~TrackCrossesTracks(TrackdirToTrack(trackdir)); return tracks; } diff --git a/src/table/settings.ini b/src/table/settings.ini index 13d8483627..7ab00d5a34 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -953,12 +953,12 @@ type = SLE_UINT8 from = SLV_87 guiflags = SGF_MULTISTRING def = 2 -min = 0 +min = 1 max = 2 interval = 1 str = STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS strhelp = STR_CONFIG_SETTING_PATHFINDER_FOR_SHIPS_HELPTEXT -strval = STR_CONFIG_SETTING_PATHFINDER_OPF +strval = STR_CONFIG_SETTING_PATHFINDER_NPF proc = InvalidateShipPathCache cat = SC_EXPERT @@ -1670,23 +1670,10 @@ max = 255 cat = SC_EXPERT ## -[SDT_VAR] -base = GameSettings -var = pf.opf.pf_maxlength -type = SLE_UINT16 -def = 4096 -min = 64 -max = 65535 -cat = SC_EXPERT - -[SDT_VAR] -base = GameSettings -var = pf.opf.pf_maxdepth -type = SLE_UINT8 -def = 48 -min = 4 -max = 255 -cat = SC_EXPERT +; Used to be pf.opf.pf_maxlength & pf.opf.pf_maxdepth +[SDT_NULL] +length = 3 +to = SLV_REMOVE_OPF ## [SDT_VAR] diff --git a/src/vehicle_type.h b/src/vehicle_type.h index f3e7d535fd..1bc5bcef41 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -60,7 +60,7 @@ static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a n /** Pathfinding option states */ enum VehiclePathFinders { - VPF_OPF = 0, ///< The Original PathFinder (only for ships) + // Original PathFinder (OPF) used to be 0 VPF_NPF = 1, ///< New PathFinder VPF_YAPF = 2, ///< Yet Another PathFinder };