Update to 1.10.0-beta1
This commit is contained in:
@@ -37,9 +37,11 @@
|
||||
#include "pbs.h"
|
||||
#include "company_base.h"
|
||||
#include "newgrf_railtype.h"
|
||||
#include "newgrf_roadtype.h"
|
||||
#include "object_base.h"
|
||||
#include "water.h"
|
||||
#include "company_gui.h"
|
||||
#include "station_func.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "table/bridge_land.h"
|
||||
@@ -84,7 +86,7 @@ void ResetBridges()
|
||||
{
|
||||
/* First, free sprite table data */
|
||||
for (BridgeType i = 0; i < MAX_BRIDGES; i++) {
|
||||
if (_bridge[i].sprite_table != NULL) {
|
||||
if (_bridge[i].sprite_table != nullptr) {
|
||||
for (BridgePieces j = BRIDGE_PIECE_NORTH; j < BRIDGE_PIECE_INVALID; j++) free(_bridge[i].sprite_table[j]);
|
||||
free(_bridge[i].sprite_table);
|
||||
}
|
||||
@@ -150,7 +152,7 @@ static inline const PalSpriteID *GetBridgeSpriteTable(int index, BridgePieces ta
|
||||
{
|
||||
const BridgeSpec *bridge = GetBridgeSpec(index);
|
||||
assert(table < BRIDGE_PIECE_INVALID);
|
||||
if (bridge->sprite_table == NULL || bridge->sprite_table[table] == NULL) {
|
||||
if (bridge->sprite_table == nullptr || bridge->sprite_table[table] == nullptr) {
|
||||
return _bridge_sprite_table[index][table];
|
||||
} else {
|
||||
return bridge->sprite_table[table];
|
||||
@@ -230,7 +232,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
CompanyID company = _current_company;
|
||||
|
||||
RailType railtype = INVALID_RAILTYPE;
|
||||
RoadTypes roadtypes = ROADTYPES_NONE;
|
||||
RoadType roadtype = INVALID_ROADTYPE;
|
||||
|
||||
/* unpack parameters */
|
||||
BridgeType bridge_type = GB(p2, 0, 8);
|
||||
@@ -242,8 +244,8 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
/* type of bridge */
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_ROAD:
|
||||
roadtypes = Extract<RoadTypes, 8, 2>(p2);
|
||||
if (!HasExactlyOneBit(roadtypes) || !HasRoadTypesAvail(company, roadtypes)) return CMD_ERROR;
|
||||
roadtype = Extract<RoadType, 8, 6>(p2);
|
||||
if (!ValParamRoadType(roadtype)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case TRANSPORT_RAIL:
|
||||
@@ -268,7 +270,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
company = OWNER_TOWN;
|
||||
|
||||
/* If we are not within a town, we are not owned by the town */
|
||||
if (town == NULL || DistanceSquare(tile_start, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
||||
if (town == nullptr || DistanceSquare(tile_start, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
||||
company = OWNER_NONE;
|
||||
}
|
||||
}
|
||||
@@ -313,23 +315,48 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
Owner owner;
|
||||
bool is_new_owner;
|
||||
RoadType road_rt = INVALID_ROADTYPE;
|
||||
RoadType tram_rt = INVALID_ROADTYPE;
|
||||
if (IsBridgeTile(tile_start) && IsBridgeTile(tile_end) &&
|
||||
GetOtherBridgeEnd(tile_start) == tile_end &&
|
||||
GetTunnelBridgeTransportType(tile_start) == transport_type) {
|
||||
/* Replace a current bridge. */
|
||||
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_RAIL:
|
||||
/* Keep the reservation, the path stays valid. */
|
||||
pbs_reservation = HasTunnelBridgeReservation(tile_start);
|
||||
break;
|
||||
|
||||
case TRANSPORT_ROAD:
|
||||
/* Do not remove road types when upgrading a bridge */
|
||||
road_rt = GetRoadTypeRoad(tile_start);
|
||||
tram_rt = GetRoadTypeTram(tile_start);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
/* If this is a railway bridge, make sure the railtypes match. */
|
||||
if (transport_type == TRANSPORT_RAIL && GetRailType(tile_start) != railtype) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
|
||||
/* If this is a road bridge, make sure the roadtype matches. */
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
RoadType existing_rt = RoadTypeIsRoad(roadtype) ? road_rt : tram_rt;
|
||||
if (existing_rt != roadtype && existing_rt != INVALID_ROADTYPE) {
|
||||
return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
|
||||
}
|
||||
}
|
||||
|
||||
/* Do not replace town bridges with lower speed bridges, unless in scenario editor. */
|
||||
if (!(flags & DC_QUERY_COST) && IsTileOwner(tile_start, OWNER_TOWN) &&
|
||||
GetBridgeSpec(bridge_type)->speed < GetBridgeSpec(GetBridgeType(tile_start))->speed &&
|
||||
_game_mode != GM_EDITOR) {
|
||||
Town *t = ClosestTownFromTile(tile_start, UINT_MAX);
|
||||
|
||||
if (t == NULL) {
|
||||
if (t == nullptr) {
|
||||
return CMD_ERROR;
|
||||
} else {
|
||||
SetDParam(0, t->index);
|
||||
@@ -338,7 +365,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
}
|
||||
|
||||
/* Do not replace the bridge with the same bridge type. */
|
||||
if (!(flags & DC_QUERY_COST) && (bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || (roadtypes & ~GetRoadTypes(tile_start)) == 0)) {
|
||||
if (!(flags & DC_QUERY_COST) && (bridge_type == GetBridgeType(tile_start)) && (transport_type != TRANSPORT_ROAD || road_rt == roadtype || tram_rt == roadtype)) {
|
||||
return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||
}
|
||||
|
||||
@@ -353,20 +380,6 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
/* If bridge belonged to bankrupt company, it has a new owner now */
|
||||
is_new_owner = (owner == OWNER_NONE);
|
||||
if (is_new_owner) owner = company;
|
||||
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_RAIL:
|
||||
/* Keep the reservation, the path stays valid. */
|
||||
pbs_reservation = HasTunnelBridgeReservation(tile_start);
|
||||
break;
|
||||
|
||||
case TRANSPORT_ROAD:
|
||||
/* Do not remove road types when upgrading a bridge */
|
||||
roadtypes |= GetRoadTypes(tile_start);
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
} else {
|
||||
/* Build a new bridge. */
|
||||
|
||||
@@ -471,6 +484,13 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
is_new_owner = true;
|
||||
}
|
||||
|
||||
bool hasroad = road_rt != INVALID_ROADTYPE;
|
||||
bool hastram = tram_rt != INVALID_ROADTYPE;
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
if (RoadTypeIsRoad(roadtype)) road_rt = roadtype;
|
||||
if (RoadTypeIsTram(roadtype)) tram_rt = roadtype;
|
||||
}
|
||||
|
||||
/* do the drill? */
|
||||
if (flags & DC_EXEC) {
|
||||
DiagDirection dir = AxisToDiagDir(direction);
|
||||
@@ -479,7 +499,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_RAIL:
|
||||
/* Add to company infrastructure count if required. */
|
||||
if (is_new_owner && c != NULL) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
if (is_new_owner && c != nullptr) c->infrastructure.rail[railtype] += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
MakeRailBridgeRamp(tile_start, owner, bridge_type, dir, railtype);
|
||||
MakeRailBridgeRamp(tile_end, owner, bridge_type, ReverseDiagDir(dir), railtype);
|
||||
SetTunnelBridgeReservation(tile_start, pbs_reservation);
|
||||
@@ -487,31 +507,35 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
break;
|
||||
|
||||
case TRANSPORT_ROAD: {
|
||||
RoadTypes prev_roadtypes = IsBridgeTile(tile_start) ? GetRoadTypes(tile_start) : ROADTYPES_NONE;
|
||||
if (is_new_owner) {
|
||||
/* Also give unowned present roadtypes to new owner */
|
||||
if (HasBit(prev_roadtypes, ROADTYPE_ROAD) && GetRoadOwner(tile_start, ROADTYPE_ROAD) == OWNER_NONE) ClrBit(prev_roadtypes, ROADTYPE_ROAD);
|
||||
if (HasBit(prev_roadtypes, ROADTYPE_TRAM) && GetRoadOwner(tile_start, ROADTYPE_TRAM) == OWNER_NONE) ClrBit(prev_roadtypes, ROADTYPE_TRAM);
|
||||
if (hasroad && GetRoadOwner(tile_start, RTT_ROAD) == OWNER_NONE) hasroad = false;
|
||||
if (hastram && GetRoadOwner(tile_start, RTT_TRAM) == OWNER_NONE) hastram = false;
|
||||
}
|
||||
if (c != NULL) {
|
||||
if (c != nullptr) {
|
||||
/* Add all new road types to the company infrastructure counter. */
|
||||
RoadType new_rt;
|
||||
FOR_EACH_SET_ROADTYPE(new_rt, roadtypes ^ prev_roadtypes) {
|
||||
if (!hasroad && road_rt != INVALID_ROADTYPE) {
|
||||
/* A full diagonal road tile has two road bits. */
|
||||
c->infrastructure.road[new_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
c->infrastructure.road[road_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
}
|
||||
if (!hastram && tram_rt != INVALID_ROADTYPE) {
|
||||
/* A full diagonal road tile has two road bits. */
|
||||
c->infrastructure.road[tram_rt] += (bridge_len + 2) * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
}
|
||||
}
|
||||
Owner owner_road = HasBit(prev_roadtypes, ROADTYPE_ROAD) ? GetRoadOwner(tile_start, ROADTYPE_ROAD) : company;
|
||||
Owner owner_tram = HasBit(prev_roadtypes, ROADTYPE_TRAM) ? GetRoadOwner(tile_start, ROADTYPE_TRAM) : company;
|
||||
MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, roadtypes);
|
||||
MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), roadtypes);
|
||||
Owner owner_road = hasroad ? GetRoadOwner(tile_start, RTT_ROAD) : company;
|
||||
Owner owner_tram = hastram ? GetRoadOwner(tile_start, RTT_TRAM) : company;
|
||||
MakeRoadBridgeRamp(tile_start, owner, owner_road, owner_tram, bridge_type, dir, road_rt, tram_rt);
|
||||
MakeRoadBridgeRamp(tile_end, owner, owner_road, owner_tram, bridge_type, ReverseDiagDir(dir), road_rt, tram_rt);
|
||||
break;
|
||||
}
|
||||
|
||||
case TRANSPORT_WATER:
|
||||
if (is_new_owner && c != NULL) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
if (is_new_owner && c != nullptr) c->infrastructure.water += (bridge_len + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
MakeAqueductBridgeRamp(tile_start, owner, dir);
|
||||
MakeAqueductBridgeRamp(tile_end, owner, ReverseDiagDir(dir));
|
||||
CheckForDockingTile(tile_start);
|
||||
CheckForDockingTile(tile_end);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -534,16 +558,24 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
|
||||
*/
|
||||
Company *c = Company::GetIfValid(company);
|
||||
if (!(flags & DC_QUERY_COST) || (c != NULL && c->is_ai)) {
|
||||
if (!(flags & DC_QUERY_COST) || (c != nullptr && c->is_ai)) {
|
||||
bridge_len += 2; // begin and end tiles/ramps
|
||||
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_ROAD: cost.AddCost(bridge_len * _price[PR_BUILD_ROAD] * 2 * CountBits(roadtypes)); break;
|
||||
case TRANSPORT_ROAD:
|
||||
if (road_rt != INVALID_ROADTYPE) {
|
||||
cost.AddCost(bridge_len * 2 * RoadBuildCost(road_rt));
|
||||
}
|
||||
if (tram_rt != INVALID_ROADTYPE) {
|
||||
cost.AddCost(bridge_len * 2 * RoadBuildCost(tram_rt));
|
||||
}
|
||||
break;
|
||||
|
||||
case TRANSPORT_RAIL: cost.AddCost(bridge_len * RailBuildCost(railtype)); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if (c != NULL) bridge_len = CalcBridgeLenCostFactor(bridge_len);
|
||||
if (c != nullptr) bridge_len = CalcBridgeLenCostFactor(bridge_len);
|
||||
|
||||
if (transport_type != TRANSPORT_WATER) {
|
||||
cost.AddCost((int64)bridge_len * _price[PR_BUILD_BRIDGE] * GetBridgeSpec(bridge_type)->price >> 8);
|
||||
@@ -562,7 +594,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u
|
||||
* Build Tunnel.
|
||||
* @param start_tile start tile of tunnel
|
||||
* @param flags type of operation
|
||||
* @param p1 bit 0-5 railtype or roadtypes
|
||||
* @param p1 bit 0-5 railtype or roadtype
|
||||
* bit 8-9 transport type
|
||||
* @param p2 unused
|
||||
* @param text unused
|
||||
@@ -573,9 +605,8 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
CompanyID company = _current_company;
|
||||
|
||||
TransportType transport_type = Extract<TransportType, 8, 2>(p1);
|
||||
|
||||
RailType railtype = INVALID_RAILTYPE;
|
||||
RoadTypes rts = ROADTYPES_NONE;
|
||||
RoadType roadtype = INVALID_ROADTYPE;
|
||||
_build_tunnel_endtile = 0;
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_RAIL:
|
||||
@@ -584,8 +615,8 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
break;
|
||||
|
||||
case TRANSPORT_ROAD:
|
||||
rts = Extract<RoadTypes, 0, 2>(p1);
|
||||
if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(company, rts)) return CMD_ERROR;
|
||||
roadtype = Extract<RoadType, 0, 6>(p1);
|
||||
if (!ValParamRoadType(roadtype)) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
default: return CMD_ERROR;
|
||||
@@ -598,7 +629,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
company = OWNER_TOWN;
|
||||
|
||||
/* If we are not within a town, we are not owned by the town */
|
||||
if (town == NULL || DistanceSquare(start_tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
||||
if (town == nullptr || DistanceSquare(start_tile, town->xy) > town->cache.squared_town_zone_radius[HZB_TOWN_EDGE]) {
|
||||
company = OWNER_NONE;
|
||||
}
|
||||
}
|
||||
@@ -680,10 +711,9 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
/* Mark the tile as already cleared for the terraform command.
|
||||
* Do this for all tiles (like trees), not only objects. */
|
||||
ClearedObjectArea *coa = FindClearedObject(end_tile);
|
||||
if (coa == NULL) {
|
||||
coa = _cleared_object_areas.Append();
|
||||
coa->first_tile = end_tile;
|
||||
coa->area = TileArea(end_tile, 1, 1);
|
||||
if (coa == nullptr) {
|
||||
/*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)});
|
||||
coa = &_cleared_object_areas.back();
|
||||
}
|
||||
|
||||
/* Hide the tile from the terraforming command */
|
||||
@@ -699,10 +729,11 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
* Deliberately clear the coa pointer to avoid leaving dangling pointers which could
|
||||
* inadvertently be dereferenced.
|
||||
*/
|
||||
assert(coa >= _cleared_object_areas.Begin() && coa < _cleared_object_areas.End());
|
||||
size_t coa_index = coa - _cleared_object_areas.Begin();
|
||||
ClearedObjectArea *begin = _cleared_object_areas.data();
|
||||
assert(coa >= begin && coa < begin + _cleared_object_areas.size());
|
||||
size_t coa_index = coa - begin;
|
||||
assert(coa_index < UINT_MAX); // more than 2**32 cleared areas would be a bug in itself
|
||||
coa = NULL;
|
||||
coa = nullptr;
|
||||
|
||||
ret = DoCommand(end_tile, end_tileh & start_tileh, 0, flags, CMD_TERRAFORM_LAND);
|
||||
_cleared_object_areas[(uint)coa_index].first_tile = old_first_tile;
|
||||
@@ -713,7 +744,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
|
||||
/* Pay for the rail/road in the tunnel including entrances */
|
||||
switch (transport_type) {
|
||||
case TRANSPORT_ROAD: cost.AddCost((tiles + 2) * _price[PR_BUILD_ROAD] * 2); break;
|
||||
case TRANSPORT_ROAD: cost.AddCost((tiles + 2) * RoadBuildCost(roadtype) * 2); break;
|
||||
case TRANSPORT_RAIL: cost.AddCost((tiles + 2) * RailBuildCost(railtype)); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -722,20 +753,17 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1,
|
||||
Company *c = Company::GetIfValid(company);
|
||||
uint num_pieces = (tiles + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
if (transport_type == TRANSPORT_RAIL) {
|
||||
if (!IsTunnelTile(start_tile) && c != NULL) c->infrastructure.rail[railtype] += num_pieces;
|
||||
if (c != nullptr) c->infrastructure.rail[railtype] += num_pieces;
|
||||
MakeRailTunnel(start_tile, company, direction, railtype);
|
||||
MakeRailTunnel(end_tile, company, ReverseDiagDir(direction), railtype);
|
||||
AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, company);
|
||||
YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction));
|
||||
} else {
|
||||
if (c != NULL) {
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, rts ^ (IsTunnelTile(start_tile) ? GetRoadTypes(start_tile) : ROADTYPES_NONE)) {
|
||||
c->infrastructure.road[rt] += num_pieces * 2; // A full diagonal road has two road bits.
|
||||
}
|
||||
}
|
||||
MakeRoadTunnel(start_tile, company, direction, rts);
|
||||
MakeRoadTunnel(end_tile, company, ReverseDiagDir(direction), rts);
|
||||
if (c != nullptr) c->infrastructure.road[roadtype] += num_pieces * 2; // A full diagonal road has two road bits.
|
||||
RoadType road_rt = RoadTypeIsRoad(roadtype) ? roadtype : INVALID_ROADTYPE;
|
||||
RoadType tram_rt = RoadTypeIsTram(roadtype) ? roadtype : INVALID_ROADTYPE;
|
||||
MakeRoadTunnel(start_tile, company, direction, road_rt, tram_rt);
|
||||
MakeRoadTunnel(end_tile, company, ReverseDiagDir(direction), road_rt, tram_rt);
|
||||
}
|
||||
DirtyCompanyInfrastructureWindows(company);
|
||||
}
|
||||
@@ -756,12 +784,13 @@ static inline CommandCost CheckAllowRemoveTunnelBridge(TileIndex tile)
|
||||
|
||||
switch (GetTunnelBridgeTransportType(tile)) {
|
||||
case TRANSPORT_ROAD: {
|
||||
RoadTypes rts = GetRoadTypes(tile);
|
||||
RoadType road_rt = GetRoadTypeRoad(tile);
|
||||
RoadType tram_rt = GetRoadTypeTram(tile);
|
||||
Owner road_owner = _current_company;
|
||||
Owner tram_owner = _current_company;
|
||||
|
||||
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
||||
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
||||
if (road_rt != INVALID_ROADTYPE) road_owner = GetRoadOwner(tile, RTT_ROAD);
|
||||
if (tram_rt != INVALID_ROADTYPE) tram_owner = GetRoadOwner(tile, RTT_TRAM);
|
||||
|
||||
/* We can remove unowned road and if the town allows it */
|
||||
if (road_owner == OWNER_TOWN && _current_company != OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) {
|
||||
@@ -808,7 +837,7 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
||||
|
||||
_build_tunnel_endtile = endtile;
|
||||
|
||||
Town *t = NULL;
|
||||
Town *t = nullptr;
|
||||
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
||||
t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
|
||||
|
||||
@@ -833,10 +862,10 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
||||
Track track = DiagDirToDiagTrack(dir);
|
||||
Owner owner = GetTileOwner(tile);
|
||||
|
||||
Train *v = NULL;
|
||||
Train *v = nullptr;
|
||||
if (HasTunnelBridgeReservation(tile)) {
|
||||
v = GetTrainForReservation(tile, track);
|
||||
if (v != NULL) FreeTrainTrackReservation(v);
|
||||
if (v != nullptr) FreeTrainTrackReservation(v);
|
||||
}
|
||||
|
||||
if (Company::IsValidID(owner)) {
|
||||
@@ -854,17 +883,11 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
YapfNotifyTrackLayoutChange(endtile, track);
|
||||
|
||||
if (v != NULL) TryPathReserve(v);
|
||||
if (v != nullptr) TryPathReserve(v);
|
||||
} else {
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
|
||||
/* A full diagonal road tile has two road bits. */
|
||||
Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
|
||||
if (c != NULL) {
|
||||
c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
DirtyCompanyInfrastructureWindows(c->index);
|
||||
}
|
||||
}
|
||||
/* 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));
|
||||
|
||||
DoClearSquare(tile);
|
||||
DoClearSquare(endtile);
|
||||
@@ -893,7 +916,7 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
||||
DiagDirection direction = GetTunnelBridgeDirection(tile);
|
||||
TileIndexDiff delta = TileOffsByDiagDir(direction);
|
||||
|
||||
Town *t = NULL;
|
||||
Town *t = nullptr;
|
||||
if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
|
||||
t = ClosestTownFromTile(tile, UINT_MAX); // town penalty rating
|
||||
|
||||
@@ -917,33 +940,35 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
||||
bool rail = GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL;
|
||||
Owner owner = GetTileOwner(tile);
|
||||
int height = GetBridgeHeight(tile);
|
||||
Train *v = NULL;
|
||||
Train *v = nullptr;
|
||||
|
||||
if (rail && HasTunnelBridgeReservation(tile)) {
|
||||
v = GetTrainForReservation(tile, DiagDirToDiagTrack(direction));
|
||||
if (v != NULL) FreeTrainTrackReservation(v);
|
||||
if (v != nullptr) FreeTrainTrackReservation(v);
|
||||
}
|
||||
|
||||
bool removetile = false;
|
||||
bool removeendtile = false;
|
||||
|
||||
/* Update company infrastructure counts. */
|
||||
if (rail) {
|
||||
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
} else if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
|
||||
Company *c = Company::GetIfValid(GetRoadOwner(tile, rt));
|
||||
if (c != NULL) {
|
||||
/* A full diagonal road tile has two road bits. */
|
||||
c->infrastructure.road[rt] -= len * 2 * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
DirtyCompanyInfrastructureWindows(c->index);
|
||||
}
|
||||
}
|
||||
/* 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));
|
||||
} else { // Aqueduct
|
||||
if (Company::IsValidID(owner)) Company::Get(owner)->infrastructure.water -= len * TUNNELBRIDGE_TRACKBIT_FACTOR;
|
||||
removetile = IsDockingTile(tile);
|
||||
removeendtile = IsDockingTile(endtile);
|
||||
}
|
||||
DirtyCompanyInfrastructureWindows(owner);
|
||||
|
||||
DoClearSquare(tile);
|
||||
DoClearSquare(endtile);
|
||||
|
||||
if (removetile) RemoveDockingTile(tile);
|
||||
if (removeendtile) RemoveDockingTile(endtile);
|
||||
for (TileIndex c = tile + delta; c != endtile; c += delta) {
|
||||
/* do not let trees appear from 'nowhere' after removing bridge */
|
||||
if (IsNormalRoadTile(c) && GetRoadside(c) == ROADSIDE_TREES) {
|
||||
@@ -963,7 +988,7 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
||||
YapfNotifyTrackLayoutChange(tile, track);
|
||||
YapfNotifyTrackLayoutChange(endtile, track);
|
||||
|
||||
if (v != NULL) TryPathReserve(v, true);
|
||||
if (v != nullptr) TryPathReserve(v, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1018,7 +1043,7 @@ static int DrawPillarColumn(int z_bottom, int z_top, const PalSpriteID *psid, in
|
||||
{
|
||||
int cur_z;
|
||||
for (cur_z = z_top; cur_z >= z_bottom; cur_z -= TILE_HEIGHT) {
|
||||
DrawPillar(psid, x, y, cur_z, w, h, NULL);
|
||||
DrawPillar(psid, x, y, cur_z, w, h, nullptr);
|
||||
}
|
||||
return cur_z;
|
||||
}
|
||||
@@ -1082,19 +1107,90 @@ static void DrawBridgePillars(const PalSpriteID *psid, const TileInfo *ti, Axis
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the trambits over an already drawn (lower end) of a bridge.
|
||||
* @param x the x of the bridge
|
||||
* @param y the y of the bridge
|
||||
* @param z the z of the bridge
|
||||
* @param offset number representing whether to level or sloped and the direction
|
||||
* @param overlay do we want to still see the road?
|
||||
* @param head are we drawing bridge head?
|
||||
* Draws the road and trambits over an already drawn (lower end) of a bridge.
|
||||
* @param head_tile bridge head tile with roadtype information
|
||||
* @param x the x of the bridge
|
||||
* @param y the y of the bridge
|
||||
* @param z the z of the bridge
|
||||
* @param offset sprite offset identifying flat to sloped bridge tiles
|
||||
* @param head are we drawing bridge head?
|
||||
*/
|
||||
static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bool head)
|
||||
static void DrawBridgeRoadBits(TileIndex head_tile, int x, int y, int z, int offset, bool head)
|
||||
{
|
||||
static const SpriteID tram_offsets[2][6] = { { 107, 108, 109, 110, 111, 112 }, { 4, 5, 15, 16, 17, 18 } };
|
||||
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
|
||||
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
|
||||
RoadType road_rt = GetRoadTypeRoad(head_tile);
|
||||
RoadType tram_rt = GetRoadTypeTram(head_tile);
|
||||
const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
|
||||
const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
|
||||
|
||||
SpriteID seq_back[4] = { 0 };
|
||||
bool trans_back[4] = { false };
|
||||
SpriteID seq_front[4] = { 0 };
|
||||
bool trans_front[4] = { false };
|
||||
|
||||
static const SpriteID overlay_offsets[6] = { 0, 1, 11, 12, 13, 14 };
|
||||
static const SpriteID back_offsets[6] = { 95, 96, 99, 102, 100, 101 };
|
||||
static const SpriteID front_offsets[6] = { 97, 98, 103, 106, 104, 105 };
|
||||
|
||||
if (head || !IsInvisibilitySet(TO_BRIDGES)) {
|
||||
/* Road underlay takes precedence over tram */
|
||||
trans_back[0] = !head && IsTransparencySet(TO_BRIDGES);
|
||||
if (road_rti != nullptr) {
|
||||
if (road_rti->UsesOverlay()) {
|
||||
seq_back[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
|
||||
}
|
||||
} else if (tram_rti != nullptr) {
|
||||
if (tram_rti->UsesOverlay()) {
|
||||
seq_back[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_BRIDGE, head ? TCX_NORMAL : TCX_ON_BRIDGE) + offset;
|
||||
} else {
|
||||
seq_back[0] = SPR_TRAMWAY_BRIDGE + offset;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw road overlay */
|
||||
trans_back[1] = !head && IsTransparencySet(TO_BRIDGES);
|
||||
if (road_rti != nullptr) {
|
||||
if (road_rti->UsesOverlay()) {
|
||||
seq_back[1] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
if (seq_back[1] != 0) seq_back[1] += overlay_offsets[offset];
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw tram overlay */
|
||||
trans_back[2] = !head && IsTransparencySet(TO_BRIDGES);
|
||||
if (tram_rti != nullptr) {
|
||||
if (tram_rti->UsesOverlay()) {
|
||||
seq_back[2] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_OVERLAY, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
if (seq_back[2] != 0) seq_back[2] += overlay_offsets[offset];
|
||||
} else if (road_rti != nullptr) {
|
||||
seq_back[2] = SPR_TRAMWAY_OVERLAY + overlay_offsets[offset];
|
||||
}
|
||||
}
|
||||
|
||||
/* Road catenary takes precedence over tram */
|
||||
trans_back[3] = IsTransparencySet(TO_CATENARY);
|
||||
trans_front[0] = IsTransparencySet(TO_CATENARY);
|
||||
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
|
||||
seq_back[3] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
seq_front[0] = GetCustomRoadSprite(road_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
if (seq_back[3] == 0 || seq_front[0] == 0) {
|
||||
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
|
||||
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
|
||||
} else {
|
||||
seq_back[3] += 23 + offset;
|
||||
seq_front[0] += 23 + offset;
|
||||
}
|
||||
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
|
||||
seq_back[3] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_BACK, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
seq_front[0] = GetCustomRoadSprite(tram_rti, head_tile, ROTSG_CATENARY_FRONT, head ? TCX_NORMAL : TCX_ON_BRIDGE);
|
||||
if (seq_back[3] == 0 || seq_front[0] == 0) {
|
||||
seq_back[3] = SPR_TRAMWAY_BASE + back_offsets[offset];
|
||||
seq_front[0] = SPR_TRAMWAY_BASE + front_offsets[offset];
|
||||
} else {
|
||||
seq_back[3] += 23 + offset;
|
||||
seq_front[0] += 23 + offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const uint size_x[6] = { 1, 16, 16, 1, 16, 1 };
|
||||
static const uint size_y[6] = { 16, 1, 1, 16, 1, 16 };
|
||||
@@ -1103,28 +1199,25 @@ static void DrawBridgeTramBits(int x, int y, int z, int offset, bool overlay, bo
|
||||
|
||||
/* The sprites under the vehicles are drawn as SpriteCombine. StartSpriteCombine() has already been called
|
||||
* The bounding boxes here are the same as for bridge front/roof */
|
||||
if (head || !IsInvisibilitySet(TO_BRIDGES)) {
|
||||
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + tram_offsets[overlay][offset], PAL_NONE,
|
||||
x, y, size_x[offset], size_y[offset], 0x28, z,
|
||||
!head && IsTransparencySet(TO_BRIDGES));
|
||||
}
|
||||
|
||||
/* Do not draw catenary if it is set invisible */
|
||||
if (!IsInvisibilitySet(TO_CATENARY)) {
|
||||
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + back_offsets[offset], PAL_NONE,
|
||||
x, y, size_x[offset], size_y[offset], 0x28, z,
|
||||
IsTransparencySet(TO_CATENARY));
|
||||
for (uint i = 0; i < lengthof(seq_back); ++i) {
|
||||
if (seq_back[i] != 0) {
|
||||
AddSortableSpriteToDraw(seq_back[i], PAL_NONE,
|
||||
x, y, size_x[offset], size_y[offset], 0x28, z,
|
||||
trans_back[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Start a new SpriteCombine for the front part */
|
||||
EndSpriteCombine();
|
||||
StartSpriteCombine();
|
||||
|
||||
/* For sloped sprites the bounding box needs to be higher, as the pylons stop on a higher point */
|
||||
if (!IsInvisibilitySet(TO_CATENARY)) {
|
||||
AddSortableSpriteToDraw(SPR_TRAMWAY_BASE + front_offsets[offset], PAL_NONE,
|
||||
x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
|
||||
IsTransparencySet(TO_CATENARY), front_bb_offset_x[offset], front_bb_offset_y[offset]);
|
||||
for (uint i = 0; i < lengthof(seq_front); ++i) {
|
||||
if (seq_front[i] != 0) {
|
||||
AddSortableSpriteToDraw(seq_front[i], PAL_NONE,
|
||||
x, y, size_x[offset] + front_bb_offset_x[offset], size_y[offset] + front_bb_offset_y[offset], 0x28, z,
|
||||
trans_front[i],
|
||||
front_bb_offset_x[offset], front_bb_offset_y[offset]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1188,19 +1281,36 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
|
||||
DrawGroundSprite(image, PAL_NONE);
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
RoadTypes rts = GetRoadTypes(ti->tile);
|
||||
RoadType road_rt = GetRoadTypeRoad(ti->tile);
|
||||
RoadType tram_rt = GetRoadTypeTram(ti->tile);
|
||||
const RoadTypeInfo *road_rti = road_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(road_rt);
|
||||
const RoadTypeInfo *tram_rti = tram_rt == INVALID_ROADTYPE ? nullptr : GetRoadTypeInfo(tram_rt);
|
||||
uint sprite_offset = DiagDirToAxis(tunnelbridge_direction) == AXIS_X ? 1 : 0;
|
||||
|
||||
if (HasBit(rts, ROADTYPE_TRAM)) {
|
||||
static const SpriteID tunnel_sprites[2][4] = { { 28, 78, 79, 27 }, { 5, 76, 77, 4 } };
|
||||
DrawRoadOverlays(ti, PAL_NONE, road_rti, tram_rti, sprite_offset, sprite_offset);
|
||||
|
||||
DrawGroundSprite(SPR_TRAMWAY_BASE + tunnel_sprites[rts - ROADTYPES_TRAM][tunnelbridge_direction], PAL_NONE);
|
||||
|
||||
/* Do not draw wires if they are invisible */
|
||||
if (!IsInvisibilitySet(TO_CATENARY)) {
|
||||
catenary = true;
|
||||
StartSpriteCombine();
|
||||
AddSortableSpriteToDraw(SPR_TRAMWAY_TUNNEL_WIRES + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
|
||||
/* Road catenary takes precedence over tram */
|
||||
SpriteID catenary_sprite_base = 0;
|
||||
if (road_rti != nullptr && HasRoadCatenaryDrawn(road_rt)) {
|
||||
catenary_sprite_base = GetCustomRoadSprite(road_rti, ti->tile, ROTSG_CATENARY_FRONT);
|
||||
if (catenary_sprite_base == 0) {
|
||||
catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
|
||||
} else {
|
||||
catenary_sprite_base += 19;
|
||||
}
|
||||
} else if (tram_rti != nullptr && HasRoadCatenaryDrawn(tram_rt)) {
|
||||
catenary_sprite_base = GetCustomRoadSprite(tram_rti, ti->tile, ROTSG_CATENARY_FRONT);
|
||||
if (catenary_sprite_base == 0) {
|
||||
catenary_sprite_base = SPR_TRAMWAY_TUNNEL_WIRES;
|
||||
} else {
|
||||
catenary_sprite_base += 19;
|
||||
}
|
||||
}
|
||||
|
||||
if (catenary_sprite_base != 0) {
|
||||
catenary = true;
|
||||
StartSpriteCombine();
|
||||
AddSortableSpriteToDraw(catenary_sprite_base + tunnelbridge_direction, PAL_NONE, ti->x, ti->y, BB_data[10], BB_data[11], TILE_HEIGHT, ti->z, IsTransparencySet(TO_CATENARY), BB_data[8], BB_data[9], BB_Z_SEPARATOR);
|
||||
}
|
||||
} else {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
||||
@@ -1294,20 +1404,18 @@ static void DrawTile_TunnelBridge(TileInfo *ti)
|
||||
AddSortableSpriteToDraw(psid->sprite, psid->pal, ti->x, ti->y, 16, 16, ti->tileh == SLOPE_FLAT ? 0 : 8, ti->z);
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
RoadTypes rts = GetRoadTypes(ti->tile);
|
||||
|
||||
if (HasBit(rts, ROADTYPE_TRAM)) {
|
||||
uint offset = tunnelbridge_direction;
|
||||
int z = ti->z;
|
||||
if (ti->tileh != SLOPE_FLAT) {
|
||||
offset = (offset + 1) & 1;
|
||||
z += TILE_HEIGHT;
|
||||
} else {
|
||||
offset += 2;
|
||||
}
|
||||
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
||||
DrawBridgeTramBits(ti->x, ti->y, z, offset, HasBit(rts, ROADTYPE_ROAD), true);
|
||||
uint offset = tunnelbridge_direction;
|
||||
int z = ti->z;
|
||||
if (ti->tileh != SLOPE_FLAT) {
|
||||
offset = (offset + 1) & 1;
|
||||
z += TILE_HEIGHT;
|
||||
} else {
|
||||
offset += 2;
|
||||
}
|
||||
|
||||
/* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
||||
DrawBridgeRoadBits(ti->tile, ti->x, ti->y, z, offset, true);
|
||||
|
||||
EndSpriteCombine();
|
||||
} else if (transport_type == TRANSPORT_RAIL) {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(ti->tile));
|
||||
@@ -1465,15 +1573,8 @@ void DrawBridgeMiddle(const TileInfo *ti)
|
||||
psid++;
|
||||
|
||||
if (transport_type == TRANSPORT_ROAD) {
|
||||
RoadTypes rts = GetRoadTypes(rampsouth);
|
||||
|
||||
if (HasBit(rts, ROADTYPE_TRAM)) {
|
||||
/* DrawBridgeTramBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
||||
DrawBridgeTramBits(x, y, bridge_z, axis ^ 1, HasBit(rts, ROADTYPE_ROAD), false);
|
||||
} else {
|
||||
EndSpriteCombine();
|
||||
StartSpriteCombine();
|
||||
}
|
||||
/* DrawBridgeRoadBits() calls EndSpriteCombine() and StartSpriteCombine() */
|
||||
DrawBridgeRoadBits(rampsouth, x, y, bridge_z, axis ^ 1, false);
|
||||
} else if (transport_type == TRANSPORT_RAIL) {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo(GetRailType(rampsouth));
|
||||
if (rti->UsesOverlay() && !IsInvisibilitySet(TO_BRIDGES)) {
|
||||
@@ -1593,9 +1694,20 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
|
||||
|
||||
Owner road_owner = INVALID_OWNER;
|
||||
Owner tram_owner = INVALID_OWNER;
|
||||
RoadTypes rts = GetRoadTypes(tile);
|
||||
if (HasBit(rts, ROADTYPE_ROAD)) road_owner = GetRoadOwner(tile, ROADTYPE_ROAD);
|
||||
if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
|
||||
RoadType road_rt = GetRoadTypeRoad(tile);
|
||||
RoadType tram_rt = GetRoadTypeTram(tile);
|
||||
if (road_rt != INVALID_ROADTYPE) {
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(road_rt);
|
||||
td->roadtype = rti->strings.name;
|
||||
td->road_speed = rti->max_speed / 2;
|
||||
road_owner = GetRoadOwner(tile, RTT_ROAD);
|
||||
}
|
||||
if (tram_rt != INVALID_ROADTYPE) {
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(tram_rt);
|
||||
td->tramtype = rti->strings.name;
|
||||
td->tram_speed = rti->max_speed / 2;
|
||||
tram_owner = GetRoadOwner(tile, RTT_TRAM);
|
||||
}
|
||||
|
||||
/* Is there a mix of owners? */
|
||||
if ((tram_owner != INVALID_OWNER && tram_owner != td->owner[0]) ||
|
||||
@@ -1624,7 +1736,9 @@ static void GetTileDesc_TunnelBridge(TileIndex tile, TileDesc *td)
|
||||
}
|
||||
}
|
||||
} else if (tt == TRANSPORT_ROAD && !IsTunnel(tile)) {
|
||||
td->road_speed = GetBridgeSpec(GetBridgeType(tile))->speed;
|
||||
uint16 spd = GetBridgeSpec(GetBridgeType(tile))->speed;
|
||||
if (road_rt != INVALID_ROADTYPE && (td->road_speed == 0 || spd < td->road_speed)) td->road_speed = spd;
|
||||
if (tram_rt != INVALID_ROADTYPE && (td->tram_speed == 0 || spd < td->tram_speed)) td->tram_speed = spd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1660,7 +1774,7 @@ static void TileLoop_TunnelBridge(TileIndex tile)
|
||||
static TrackStatus GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
|
||||
{
|
||||
TransportType transport_type = GetTunnelBridgeTransportType(tile);
|
||||
if (transport_type != mode || (transport_type == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0)) return 0;
|
||||
if (transport_type != mode || (transport_type == TRANSPORT_ROAD && !HasTileRoadType(tile, (RoadTramType)sub_mode))) return 0;
|
||||
|
||||
DiagDirection dir = GetTunnelBridgeDirection(tile);
|
||||
if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0;
|
||||
@@ -1674,17 +1788,18 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
|
||||
* don't want to update the infrastructure counts twice. */
|
||||
uint num_pieces = tile < other_end ? (GetTunnelBridgeLength(tile, other_end) + 2) * TUNNELBRIDGE_TRACKBIT_FACTOR : 0;
|
||||
|
||||
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
/* Update all roadtypes, no matter if they are present */
|
||||
if (GetRoadOwner(tile, rt) == old_owner) {
|
||||
if (HasBit(GetRoadTypes(tile), rt)) {
|
||||
if (GetRoadOwner(tile, rtt) == old_owner) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt != INVALID_ROADTYPE) {
|
||||
/* Update company infrastructure counts. A full diagonal road tile has two road bits.
|
||||
* No need to dirty windows here, we'll redraw the whole screen anyway. */
|
||||
Company::Get(old_owner)->infrastructure.road[rt] -= num_pieces * 2;
|
||||
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.road[rt] += num_pieces * 2;
|
||||
}
|
||||
|
||||
SetRoadOwner(tile, rt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
|
||||
SetRoadOwner(tile, rtt, new_owner == INVALID_OWNER ? OWNER_NONE : new_owner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1906,14 +2021,14 @@ extern const TileTypeProcs _tile_type_tunnelbridge_procs = {
|
||||
DrawTile_TunnelBridge, // draw_tile_proc
|
||||
GetSlopePixelZ_TunnelBridge, // get_slope_z_proc
|
||||
ClearTile_TunnelBridge, // clear_tile_proc
|
||||
NULL, // add_accepted_cargo_proc
|
||||
nullptr, // add_accepted_cargo_proc
|
||||
GetTileDesc_TunnelBridge, // get_tile_desc_proc
|
||||
GetTileTrackStatus_TunnelBridge, // get_tile_track_status_proc
|
||||
NULL, // click_tile_proc
|
||||
NULL, // animate_tile_proc
|
||||
nullptr, // click_tile_proc
|
||||
nullptr, // animate_tile_proc
|
||||
TileLoop_TunnelBridge, // tile_loop_proc
|
||||
ChangeTileOwner_TunnelBridge, // change_tile_owner_proc
|
||||
NULL, // add_produced_cargo_proc
|
||||
nullptr, // add_produced_cargo_proc
|
||||
VehicleEnter_TunnelBridge, // vehicle_enter_tile_proc
|
||||
GetFoundation_TunnelBridge, // get_foundation_proc
|
||||
TerraformTile_TunnelBridge, // terraform_tile_proc
|
||||
|
||||
Reference in New Issue
Block a user