Merge branch 'master' into jgrpp

# Conflicts:
#	regression/regression/result.txt
#	src/autoreplace_cmd.cpp
#	src/industry_gui.cpp
#	src/landscape.cpp
#	src/network/network_content.cpp
#	src/newgrf_roadstop.cpp
#	src/pathfinder/yapf/yapf_ship.cpp
#	src/road_gui.cpp
#	src/saveload/ai_sl.cpp
#	src/saveload/saveload.h
#	src/saveload/vehicle_sl.cpp
#	src/station.cpp
#	src/station_gui.cpp
#	src/video/cocoa/cocoa_ogl.h
#	src/video/sdl2_opengl_v.h
#	src/video/video_driver.hpp
#	src/video/win32_v.h
#	src/widget_type.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2024-02-19 18:50:33 +00:00
119 changed files with 4346 additions and 2129 deletions

View File

@@ -304,7 +304,7 @@ static int32_t NPFWaterPathCost(AyStar *as, AyStarNode *current, OpenListNode *p
cost += _settings_game.pf.npf.npf_buoy_penalty; // A small penalty for going over buoys
}
if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) {
if (current->direction != NextTrackdir(parent->path.node.direction)) {
cost += _settings_game.pf.npf.npf_water_curve_penalty;
}
@@ -513,7 +513,7 @@ static int32_t NPFRailPathCost(AyStar *as, AyStarNode *current, OpenListNode *pa
cost += NPFSlopeCost(current);
/* Check for turns */
if (current->direction != NextTrackdir((Trackdir)parent->path.node.direction)) {
if (current->direction != NextTrackdir(parent->path.node.direction)) {
cost += _settings_game.pf.npf.npf_rail_curve_penalty;
}
/* TODO, with realistic acceleration, also the amount of straight track between
@@ -1319,7 +1319,7 @@ Track NPFTrainChooseTrack(const Train *v, bool &path_found, bool reserve_track,
if (target != nullptr) {
target->tile = ftd.node.tile;
target->trackdir = (Trackdir)ftd.node.direction;
target->trackdir = ftd.node.direction;
target->okay = ftd.res_okay;
}

View File

@@ -172,20 +172,28 @@ public:
return 'w';
}
/** Returns a random trackdir that can be reached from the current tile/trackdir, or INVALID_TRACK if none is available. */
static Trackdir GetRandomFollowUpTrackdir(const Ship *v, TileIndex tile, Trackdir dir, bool include_90_degree_turns)
{
TrackFollower follower(v);
if (follower.Follow(tile, dir)) {
tile = follower.m_new_tile;
TrackdirBits dirs = follower.m_new_td_bits;
if (!include_90_degree_turns) dirs &= ~TrackdirCrossesTrackdirs(dir);
const int strip_amount = _random.Next(CountBits(dirs));
for (int s = 0; s < strip_amount; ++s) RemoveFirstTrackdir(&dirs);
return FindFirstTrackdir(dirs);
}
return INVALID_TRACKDIR;
}
/** Creates a random path, avoids 90 degree turns. */
static Trackdir CreateRandomPath(const Ship *v, TileIndex tile, Trackdir dir, ShipPathCache &path_cache, int path_length)
{
for (int i = 0; i < path_length; ++i) {
TrackFollower F(v);
if (F.Follow(tile, dir)) {
tile = F.m_new_tile;
TrackdirBits dirs = F.m_new_td_bits & ~TrackdirCrossesTrackdirs(dir);
const int strip_amount = _random.Next(CountBits(dirs));
for (int s = 0; s < strip_amount; ++s) RemoveFirstTrackdir(&dirs);
dir = FindFirstTrackdir(dirs);
if (dir == INVALID_TRACKDIR) break;
path_cache.push_back(dir);
}
const Trackdir random_dir = GetRandomFollowUpTrackdir(v, tile, dir, false);
if (random_dir == INVALID_TRACKDIR) break;
path_cache.push_back(random_dir);
}
if (path_cache.empty()) return INVALID_TRACKDIR;
@@ -210,12 +218,12 @@ public:
}
/* Move back to the old tile/trackdir (where ship is coming from). */
TileIndex src_tile = TileAddByDiagDir(tile, ReverseDiagDir(enterdir));
Trackdir trackdir = v->GetVehicleTrackdir();
const TileIndex src_tile = TileAddByDiagDir(tile, ReverseDiagDir(enterdir));
const Trackdir trackdir = v->GetVehicleTrackdir();
dbg_assert(IsValidTrackdir(trackdir));
/* Convert origin trackdir to TrackdirBits. */
TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
const TrackdirBits trackdirs = TrackdirToTrackdirBits(trackdir);
const std::vector<WaterRegionPatchDesc> high_level_path = YapfShipFindWaterRegionPath(v, tile, NUMBER_OR_WATER_REGIONS_LOOKAHEAD + 1);
if (high_level_path.empty()) {
@@ -244,7 +252,7 @@ public:
path_found = pf.FindPath(v);
Node *node = pf.GetBestNode();
if (attempt == 0 && !path_found) continue; // Try again with restricted search area.
if (!path_found || !node) return INVALID_TRACKDIR;
if (!path_found || node == nullptr) GetRandomFollowUpTrackdir(v, src_tile, trackdir, true);
/* Return only the path within the current water region if an intermediate destination was returned. If not, cache the entire path
* to the final destination tile. The low-level pathfinder might actually prefer a different docking tile in a nearby region. Without