Add setting to control RV re-routing on road layout change

Default to road removal only
This is due to poor performance with many RVs when town growth is
continually adding to the road layout
pull/167/head
Jonathan G Rennison 4 years ago
parent 903b0fdd39
commit d5ada6a14b

@ -1939,6 +1939,12 @@ STR_CONFIG_SETTING_SHARING :{ORANGE}Infrast
STR_CONFIG_SETTING_PATHFINDER_NPF :NPF
STR_CONFIG_SETTING_PATHFINDER_YAPF_RECOMMENDED :YAPF {BLUE}(Recommended)
STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE :Re-route road vehicles when road layout changes: {STRING2}
STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_HELPTEXT :Whether to re-route all road vehicles on the map when the road layout is changed.{}This can improve road vehicle responsiveness to a changing roa dlayout at the expense of performance.{}Note that if this is set to "Yes", town growth can trigger re-routing of road vehicles which may cause slow-downs on large maps.
STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_NO :No
STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_REMOVE_ONLY :Road removal only
STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_YES :Yes
STR_CONFIG_SETTING_PATHFINDER_FOR_TRAINS :Pathfinder for trains: {STRING2}
STR_CONFIG_SETTING_PATHFINDER_FOR_TRAINS_HELPTEXT :Path finder to use for trains
STR_CONFIG_SETTING_PATHFINDER_FOR_ROAD_VEHICLES :Pathfinder for road vehicles: {STRING2}

@ -467,7 +467,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
DirtyAllCompanyInfrastructureWindows();
/* Todo: Change this to be more fine-grained if necessary */
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(false);
}
} else {
assert_tile(IsDriveThroughStopTile(tile), tile);
@ -477,7 +477,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
SetRoadType(tile, rtt, INVALID_ROADTYPE);
MarkTileDirtyByTile(tile);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(false);
}
}
return cost;
@ -530,7 +530,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
}
}
NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, present | pieces);
if (RoadLayoutChangeNotificationEnabled(false)) NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, present | pieces);
UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -(int)CountBits(pieces));
if (present == ROAD_NONE) {
@ -575,7 +575,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
UpdateCompanyRoadInfrastructure(existing_rt, GetRoadOwner(tile, rtt), -2);
Track railtrack = GetCrossingRailTrack(tile);
NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, GetCrossingRoadBits(tile));
if (RoadLayoutChangeNotificationEnabled(false)) NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, GetCrossingRoadBits(tile));
if (GetRoadType(tile, OtherRoadTramType(rtt)) == INVALID_ROADTYPE) {
TrackBits tracks = GetCrossingRailBits(tile);
bool reserved = HasCrossingReservation(tile);
@ -860,7 +860,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
MakeRoadCrossing(tile, company, company, GetTileOwner(tile), roaddir, GetRailType(tile), rtt == RTT_ROAD ? rt : INVALID_ROADTYPE, (rtt == RTT_TRAM) ? rt : INVALID_ROADTYPE, p2);
SetCrossingReservation(tile, reserved);
UpdateLevelCrossing(tile, false);
NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, GetCrossingRoadBits(tile));
if (RoadLayoutChangeNotificationEnabled(true)) NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, GetCrossingRoadBits(tile));
MarkTileDirtyByTile(tile);
}
return CommandCost(EXPENSES_CONSTRUCTION, 2 * RoadBuildCost(rt));
@ -991,7 +991,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
MarkBridgeDirty(tile);
AddRoadTunnelBridgeInfrastructure(tile, other_end);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(true);
DirtyAllCompanyInfrastructureWindows();
}
@ -1089,7 +1089,7 @@ do_clear:;
if (rtt == RTT_ROAD) SetTownIndex(tile, p2);
}
if (rttype != ROAD_TILE_CROSSING) SetRoadBits(tile, existing | pieces, rtt);
NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, existing | pieces);
if (RoadLayoutChangeNotificationEnabled(true)) NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, existing | pieces);
break;
}
@ -1108,7 +1108,7 @@ do_clear:;
MarkTileDirtyByTile(other_end);
MarkTileDirtyByTile(tile);
}
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(true);
break;
}
@ -1116,13 +1116,13 @@ do_clear:;
assert_tile(IsDriveThroughStopTile(tile), tile);
SetRoadType(tile, rtt, rt);
SetRoadOwner(tile, rtt, company);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(true);
break;
}
default:
MakeRoadNormal(tile, pieces, (rtt == RTT_ROAD) ? rt : INVALID_ROADTYPE, (rtt == RTT_TRAM) ? rt : INVALID_ROADTYPE, p2, company, company);
NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, pieces);
if (RoadLayoutChangeNotificationEnabled(true)) NotifyRoadLayoutChangedIfTileNonLeaf(tile, rtt, pieces);
break;
}
@ -1387,7 +1387,7 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
MarkTileDirtyByTile(tile);
MakeDefaultName(dep);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(true);
}
cost.AddCost(_price[PR_BUILD_DEPOT_ROAD]);
return cost;
@ -1416,7 +1416,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
delete Depot::GetByTile(tile);
DoClearSquare(tile);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(false);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_ROAD]);

@ -14,6 +14,7 @@
#include "road.h"
#include "economy_func.h"
#include "transparency.h"
#include "settings_type.h"
/**
* Whether the given roadtype is valid.
@ -160,11 +161,21 @@ void UpdateCompanyRoadInfrastructure(RoadType rt, Owner o, int count);
struct TileInfo;
void DrawRoadOverlays(const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rit, uint road_offset, uint tram_offset);
inline bool RoadLayoutChangeNotificationEnabled(bool added)
{
return _settings_game.pf.reroute_rv_on_layout_change >= (added ? 2 : 1);
}
inline void NotifyRoadLayoutChanged()
{
_road_layout_change_counter++;
}
inline void NotifyRoadLayoutChanged(bool added)
{
if (RoadLayoutChangeNotificationEnabled(added)) NotifyRoadLayoutChanged();
}
void NotifyRoadLayoutChangedIfTileNonLeaf(TileIndex tile, RoadTramType rtt, RoadBits present_bits);
void NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(TileIndex start, TileIndex end, DiagDirection start_dir, RoadTramType rtt);

@ -1826,6 +1826,7 @@ static SettingsContainer &GetSettingsTree()
routing->Add(new SettingEntry("pf.forbid_90_deg"));
routing->Add(new SettingEntry("pf.pathfinder_for_roadvehs"));
routing->Add(new SettingEntry("pf.pathfinder_for_ships"));
routing->Add(new SettingEntry("pf.reroute_rv_on_layout_change"));
}
vehicles->Add(new SettingEntry("order.no_servicing_if_no_breakdowns"));

@ -495,6 +495,7 @@ struct PathfinderSettings {
bool roadveh_queue; ///< buggy road vehicle queueing
bool forbid_90_deg; ///< forbid trains to make 90 deg turns
uint8 reroute_rv_on_layout_change; ///< whether to re-route road vehicles when the layout changes
bool reverse_at_signals; ///< whether to reverse at signals at all
byte wait_oneway_signal; ///< waitingtime in days before a oneway signal

@ -2078,7 +2078,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
MarkTileDirtyByTile(cur_tile);
}
ZoningMarkDirtyStationCoverageArea(st);
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(true);
}
if (st != nullptr) {
@ -2196,7 +2196,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
for (const RoadStop *rs = st->bus_stops; rs != nullptr; rs = rs->next) st->bus_station.Add(rs->xy);
}
NotifyRoadLayoutChanged();
NotifyRoadLayoutChanged(false);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[is_truck ? PR_CLEAR_STATION_TRUCK : PR_CLEAR_STATION_BUS]);

@ -1293,6 +1293,21 @@ var = pf.roadveh_queue
def = true
cat = SC_EXPERT
[SDT_VAR]
base = GameSettings
var = pf.reroute_rv_on_layout_change
type = SLE_UINT8
guiflags = SGF_MULTISTRING
def = 1
min = 0
max = 2
interval = 1
str = STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE
strhelp = STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_HELPTEXT
strval = STR_CONFIG_SETTING_REROUTE_RV_ON_LAYOUT_CHANGE_NO
cat = SC_ADVANCED
patxname = ""pf.reroute_rv_on_layout_change""
[SDT_BOOL]
base = GameSettings
var = pf.new_pathfinding_all

@ -648,10 +648,12 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
make_bridge_ramp(tile_start, dir);
make_bridge_ramp(tile_end, ReverseDiagDir(dir));
AddRoadTunnelBridgeInfrastructure(tile_start, tile_end);
if (IsRoadCustomBridgeHead(tile_start) || IsRoadCustomBridgeHead(tile_end)) {
NotifyRoadLayoutChanged();
} else {
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile_start, tile_end, dir, GetRoadTramType(roadtype));
if (RoadLayoutChangeNotificationEnabled(true)) {
if (IsRoadCustomBridgeHead(tile_start) || IsRoadCustomBridgeHead(tile_end)) {
NotifyRoadLayoutChanged();
} else {
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile_start, tile_end, dir, GetRoadTramType(roadtype));
}
}
break;
}
@ -1011,7 +1013,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
} else {
if (c != nullptr) c->infrastructure.road[roadtype] += num_pieces * 2; // A full diagonal road has two road bits.
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(start_tile, end_tile, direction, GetRoadTramType(roadtype));
if (RoadLayoutChangeNotificationEnabled(true)) NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(start_tile, end_tile, direction, GetRoadTramType(roadtype));
RoadType road_rt = RoadTypeIsRoad(roadtype) ? roadtype : INVALID_ROADTYPE;
RoadType tram_rt = RoadTypeIsTram(roadtype) ? roadtype : INVALID_ROADTYPE;
MakeRoadTunnel(start_tile, company, t->index, direction, road_rt, tram_rt);
@ -1148,8 +1150,10 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
/* A full diagonal road tile has two road bits. */
UpdateCompanyRoadInfrastructure(GetRoadTypeRoad(tile), GetRoadOwner(tile, RTT_ROAD), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
UpdateCompanyRoadInfrastructure(GetRoadTypeTram(tile), GetRoadOwner(tile, RTT_TRAM), -(int)(len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR));
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, GetTunnelBridgeDirection(tile), RTT_ROAD);
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, GetTunnelBridgeDirection(tile), RTT_TRAM);
if (RoadLayoutChangeNotificationEnabled(false)) {
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, GetTunnelBridgeDirection(tile), RTT_ROAD);
NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, GetTunnelBridgeDirection(tile), RTT_TRAM);
}
delete Tunnel::GetByTile(tile);
@ -1246,11 +1250,13 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
SubtractRailTunnelBridgeInfrastructure(tile, endtile);
} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
SubtractRoadTunnelBridgeInfrastructure(tile, endtile);
if (IsRoadCustomBridgeHead(tile) || IsRoadCustomBridgeHead(endtile)) {
NotifyRoadLayoutChanged();
} else {
if (HasRoadTypeRoad(tile)) NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, direction, RTT_ROAD);
if (HasRoadTypeTram(tile)) NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, direction, RTT_TRAM);
if (RoadLayoutChangeNotificationEnabled(false)) {
if (IsRoadCustomBridgeHead(tile) || IsRoadCustomBridgeHead(endtile)) {
NotifyRoadLayoutChanged();
} else {
if (HasRoadTypeRoad(tile)) NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, direction, RTT_ROAD);
if (HasRoadTypeTram(tile)) NotifyRoadLayoutChangedIfSimpleTunnelBridgeNonLeaf(tile, endtile, direction, RTT_TRAM);
}
}
} else { // Aqueduct
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;

Loading…
Cancel
Save