Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/CompileFlags.cmake
#	src/aircraft_cmd.cpp
#	src/blitter/32bpp_anim.cpp
#	src/cargopacket.cpp
#	src/cheat_gui.cpp
#	src/company_cmd.cpp
#	src/company_gui.cpp
#	src/core/pool_func.hpp
#	src/date.cpp
#	src/economy.cpp
#	src/error_gui.cpp
#	src/ground_vehicle.cpp
#	src/ground_vehicle.hpp
#	src/group_gui.cpp
#	src/industry_cmd.cpp
#	src/lang/dutch.txt
#	src/lang/french.txt
#	src/lang/german.txt
#	src/linkgraph/linkgraph_gui.cpp
#	src/linkgraph/mcf.cpp
#	src/network/network_content.cpp
#	src/network/network_server.cpp
#	src/network/network_udp.cpp
#	src/newgrf_engine.cpp
#	src/newgrf_station.cpp
#	src/order_cmd.cpp
#	src/order_gui.cpp
#	src/pathfinder/follow_track.hpp
#	src/pathfinder/yapf/yapf_common.hpp
#	src/saveload/saveload.cpp
#	src/settings_gui.cpp
#	src/station_cmd.cpp
#	src/station_kdtree.h
#	src/string_func.h
#	src/table/settings.ini
#	src/tgp.cpp
#	src/timetable_cmd.cpp
#	src/timetable_gui.cpp
#	src/toolbar_gui.cpp
#	src/town_cmd.cpp
#	src/train_cmd.cpp
#	src/train_gui.cpp
#	src/tree_gui.cpp
#	src/tunnelbridge_cmd.cpp
#	src/vehicle.cpp
#	src/vehicle_gui.cpp
#	src/video/sdl2_v.cpp
#	src/video/sdl_v.cpp
#	src/video/win32_v.cpp
#	src/viewport.cpp
#	src/viewport_sprite_sorter_sse4.cpp
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2021-02-01 17:07:34 +00:00
290 changed files with 2135 additions and 1577 deletions

View File

@@ -952,7 +952,7 @@ static void TownTickHandler(Town *t)
i = t->growth_rate;
} else {
/* If growth failed wait a bit before retrying */
i = min(t->growth_rate, TOWN_GROWTH_TICKS - 1);
i = std::min<uint16>(t->growth_rate, TOWN_GROWTH_TICKS - 1);
}
}
t->grow_counter = i;
@@ -1084,8 +1084,8 @@ static bool IsRoadAllowedHere(Town *t, TileIndex tile, DiagDirection dir)
* If that fails clear the land, and if that fails exit.
* This is to make sure that we can build a road here later. */
RoadType rt = GetTownRoadType(t);
if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, DC_AUTO, CMD_BUILD_ROAD).Failed() &&
DoCommand(tile, 0, 0, DC_AUTO | DC_TOWN, CMD_LANDSCAPE_CLEAR).Failed()) {
if (DoCommand(tile, ((dir == DIAGDIR_NW || dir == DIAGDIR_SE) ? ROAD_Y : ROAD_X) | (rt << 4), 0, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Failed() &&
DoCommand(tile, 0, 0, DC_AUTO | DC_NO_WATER | DC_TOWN, CMD_LANDSCAPE_CLEAR).Failed()) {
return false;
}
}
@@ -1261,44 +1261,45 @@ static bool GrowTownWithRoad(const Town *t, TileIndex tile, RoadBits rcmd)
}
/**
* Checks if a town road can be continued on the other side of a bridge.
* Checks if a town road can be continued into the next tile.
* Road vehicle stations, bridges, and tunnels are fine, as long as they are facing the right direction.
*
* @param end_tile The end tile of the bridge
* @param bridge_dir The direction of the bridge
* @param t The current town
* @param tile The tile where the road would be built
* @param road_dir The direction of the road
* @return true if the road can be continued, else false
*/
static bool CanRoadContinueAfterBridge(const Town* t, const TileIndex end_tile, const DiagDirection bridge_dir)
static bool CanRoadContinueIntoNextTile(const Town* t, const TileIndex tile, const DiagDirection road_dir)
{
const int delta = TileOffsByDiagDir(bridge_dir); // +1 tile in the direction of the bridge
TileIndex next_tile = end_tile + delta; // The tile beyond the bridge
RoadBits rcmd = DiagDirToRoadBits(ReverseDiagDir(bridge_dir));
const int delta = TileOffsByDiagDir(road_dir); // +1 tile in the direction of the road
TileIndex next_tile = tile + delta; // The tile beyond which must be connectable to the target tile
RoadBits rcmd = DiagDirToRoadBits(ReverseDiagDir(road_dir));
RoadType rt = GetTownRoadType(t);
/* Before we try anything, make sure the tile is on the map and not the void. */
if (!IsValidTile(next_tile)) return false;
/* If the next tile is a bridge or tunnel, allow if it's a road bridge/tunnel continuing in the same direction. */
/* If the next tile is a bridge or tunnel, allow if it's continuing in the same direction. */
if (IsTileType(next_tile, MP_TUNNELBRIDGE)) {
return GetTunnelBridgeTransportType(next_tile) == TRANSPORT_ROAD && GetTunnelBridgeDirection(next_tile) == bridge_dir;
return GetTunnelBridgeTransportType(next_tile) == TRANSPORT_ROAD && GetTunnelBridgeDirection(next_tile) == road_dir;
}
/* If the next tile is a station, allow if it's a road station facing the proper direction. Otherwise return false. */
if (IsTileType(next_tile, MP_STATION)) {
/* If the next tile is a road station, allow if it's facing the same direction, otherwise disallow. */
return IsRoadStop(next_tile) && GetRoadStopDir(next_tile) == ReverseDiagDir(bridge_dir);
/* If the next tile is a road station, allow if it can be entered by the new tunnel/bridge, otherwise disallow. */
return IsRoadStop(next_tile) && (GetRoadStopDir(next_tile) == ReverseDiagDir(road_dir) || (IsDriveThroughStopTile(next_tile) && GetRoadStopDir(next_tile) == road_dir));
}
/* If the next tile is a road depot, allow if it's facing the new bridge. */
/* If the next tile is a road depot, allow if it's facing the right way. */
if (IsTileType(next_tile, MP_ROAD)) {
return IsRoadDepot(next_tile) && GetRoadDepotDirection(next_tile) == ReverseDiagDir(bridge_dir);
return IsRoadDepot(next_tile) && GetRoadDepotDirection(next_tile) == ReverseDiagDir(road_dir);
}
/* If the next tile is a railroad track, check if towns are allowed to build level crossings.
* If level crossing are not allowed, reject the bridge. Else allow DoCommand to determine if the rail track is buildable. */
* If level crossing are not allowed, reject the construction. Else allow DoCommand to determine if the rail track is buildable. */
if (IsTileType(next_tile, MP_RAILWAY) && !_settings_game.economy.allow_town_level_crossings) return false;
/* If a road tile can be built, the bridge is allowed.
* If not, the bridge is rejected. */
/* If a road tile can be built, the construction is allowed. */
return DoCommand(next_tile, rcmd | (rt << 4), t->index, DC_AUTO | DC_NO_WATER, CMD_BUILD_ROAD).Succeeded();
}
@@ -1363,7 +1364,7 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
if (IsValidTile(bridge_tile + delta) && !MayTownModifyRoad(bridge_tile + delta)) return false;
/* Make sure the road can be continued past the bridge. At this point, bridge_tile holds the end tile of the bridge. */
if (!CanRoadContinueAfterBridge(t, bridge_tile, bridge_dir)) return false;
if (!CanRoadContinueIntoNextTile(t, bridge_tile, bridge_dir)) return false;
std::bitset <MAX_BRIDGES> tried;
uint n = MAX_BRIDGES;
@@ -1396,6 +1397,75 @@ static bool GrowTownWithBridge(const Town *t, const TileIndex tile, const DiagDi
return false;
}
/**
* Grows the town with a tunnel.
* First we check if a tunnel is reasonable.
* If so we check if we are able to build it.
*
* @param t The current town
* @param tile The current tile
* @param tunnel_dir The valid direction in which to grow a tunnel
* @return true if a tunnel has been built, else false
*/
static bool GrowTownWithTunnel(const Town* t, const TileIndex tile, const DiagDirection tunnel_dir)
{
assert(tunnel_dir < DIAGDIR_END);
Slope slope = GetTileSlope(tile);
/* Only consider building a tunnel if the starting tile is sloped properly. */
if (slope != InclinedSlope(tunnel_dir)) return false;
/* Assure that the tunnel is connectable to the start side */
if (!(GetTownRoadBits(TileAddByDiagDir(tile, ReverseDiagDir(tunnel_dir))) & DiagDirToRoadBits(tunnel_dir))) return false;
const int delta = TileOffsByDiagDir(tunnel_dir);
int max_tunnel_length = 0;
/* There are two conditions for building tunnels: Under a mountain and under an obstruction. */
if (CanRoadContinueIntoNextTile(t, tile, tunnel_dir)) {
/* Only tunnel under a mountain if the slope is continuous for at least 4 tiles. We want tunneling to be a last resort for large hills. */
TileIndex slope_tile = tile;
for (uint8 tiles = 0; tiles < 4; tiles++) {
slope = GetTileSlope(slope_tile);
if (slope != InclinedSlope(tunnel_dir) && !IsSteepSlope(slope) && !IsSlopeWithOneCornerRaised(slope)) return false;
slope_tile += delta;
}
/* More population means longer tunnels, but make sure we can at least cover the smallest mountain which neccesitates tunneling. */
max_tunnel_length = (t->cache.population / 1000) + 7;
} else {
/* When tunneling under an obstruction, the length limit is 5, enough to tunnel under a four-track railway. */
max_tunnel_length = 5;
}
uint8 tunnel_length = 0;
TileIndex tunnel_tile = tile; // Iteratator to store the other end tile of the tunnel.
/* Find the end tile of the tunnel for length and continuation checks. */
do {
if (tunnel_length++ >= max_tunnel_length) return false;
tunnel_tile += delta;
/* The tunnel ends when start and end tiles are the same height. */
} while (IsValidTile(tunnel_tile) && GetTileZ(tile) != GetTileZ(tunnel_tile));
/* Don't allow a tunnel where the start and end tiles are adjacent. */
if (tunnel_length == 1) return false;
/* Make sure the road can be continued past the tunnel. At this point, tunnel_tile holds the end tile of the tunnel. */
if (!CanRoadContinueIntoNextTile(t, tunnel_tile, tunnel_dir)) return false;
/* Attempt to build the tunnel. Return false if it fails to let the town build a road instead. */
RoadType rt = GetTownRoadType(t);
if (DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL).Succeeded()) {
DoCommand(tile, rt | (TRANSPORT_ROAD << 8), 0, DC_EXEC | CommandFlagsToDCFlags(GetCommandFlags(CMD_BUILD_TUNNEL)), CMD_BUILD_TUNNEL);
_grow_town_result = GROWTH_SUCCEED;
return true;
}
return false;
}
/**
* Checks whether at least one surrounding roads allows to build a house here
*
@@ -1654,10 +1724,11 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
rcmd = CleanUpRoadBits(tile, rcmd);
if (rcmd == ROAD_NONE) return;
/* Only use the target direction for bridges to ensure they're connected.
/* Only use the target direction for bridges and tunnels to ensure they're connected.
* The target_dir is as computed previously according to town layout, so
* it will match it perfectly. */
if (GrowTownWithBridge(t1, tile, target_dir)) return;
if (GrowTownWithTunnel(t1, tile, target_dir)) return;
GrowTownWithRoad(t1, tile, rcmd);
}
@@ -2342,7 +2413,7 @@ bool GenerateTowns(TownLayout layout)
uint current_number = 0;
uint difficulty = (_game_mode != GM_EDITOR) ? _settings_game.difficulty.number_towns : 0;
uint total = (difficulty == (uint)CUSTOM_TOWN_NUMBER_DIFFICULTY) ? _settings_game.game_creation.custom_town_number : ScaleByMapSize(_num_initial_towns[difficulty] + (Random() & 7));
total = min(TownPool::MAX_SIZE, total);
total = std::min<uint>(TownPool::MAX_SIZE, total);
uint32 townnameparts;
TownNames town_names;
@@ -3431,7 +3502,7 @@ static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags)
* tick-perfect and gives player some time window where he can
* spam funding with the exact same efficiency.
*/
t->grow_counter = min(t->grow_counter, 2 * TOWN_GROWTH_TICKS - (t->growth_rate - t->grow_counter) % TOWN_GROWTH_TICKS);
t->grow_counter = std::min<uint16>(t->grow_counter, 2 * TOWN_GROWTH_TICKS - (t->growth_rate - t->grow_counter) % TOWN_GROWTH_TICKS);
SetWindowDirty(WC_TOWN_VIEW, t->index);
}
@@ -3610,7 +3681,7 @@ static void UpdateTownRating(Town *t)
/* Increase company ratings if they're low */
for (const Company *c : Company::Iterate()) {
if (t->ratings[c->index] < RATING_GROWTH_MAXIMUM) {
t->ratings[c->index] = min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP);
t->ratings[c->index] = std::min((int)RATING_GROWTH_MAXIMUM, t->ratings[c->index] + RATING_GROWTH_UP_STEP);
}
}
@@ -3618,12 +3689,12 @@ static void UpdateTownRating(Town *t)
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
if (Company::IsValidID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
t->ratings[st->owner] = min(new_rating, INT16_MAX); // do not let it overflow
t->ratings[st->owner] = std::min<int>(new_rating, INT16_MAX); // do not let it overflow
}
} else {
if (Company::IsValidID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP;
t->ratings[st->owner] = max(new_rating, INT16_MIN);
t->ratings[st->owner] = std::max(new_rating, INT16_MIN);
}
}
});
@@ -3648,7 +3719,7 @@ static void UpdateTownGrowCounter(Town *t, uint16 prev_growth_rate)
{
if (t->growth_rate == TOWN_GROWTH_RATE_NONE) return;
if (prev_growth_rate == TOWN_GROWTH_RATE_NONE) {
t->grow_counter = min(t->growth_rate, t->grow_counter);
t->grow_counter = std::min<uint16>(t->growth_rate, t->grow_counter);
return;
}
t->grow_counter = RoundDivSU((uint32)t->grow_counter * (t->growth_rate + 1), prev_growth_rate + 1);
@@ -3689,7 +3760,7 @@ static uint GetNormalGrowthRate(Town *t)
};
int n = CountActiveStations(t);
uint16 m = _grow_count_values[t->fund_buildings_months != 0 ? 0 : 1][min(n, 5)];
uint16 m = _grow_count_values[t->fund_buildings_months != 0 ? 0 : 1][std::min(n, 5)];
int growth_multiplier;
if (_settings_game.economy.town_growth_rate == 0) {