Update to 12.0-beta1

This commit is contained in:
dP
2021-08-15 14:57:29 +03:00
parent ac7d3eba75
commit 9df4f2c4fc
666 changed files with 61302 additions and 20466 deletions

View File

@@ -105,7 +105,7 @@ CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID c
ta.Expand(1);
/* check around to see if there are any stations there owned by the company */
TILE_AREA_LOOP(tile_cur, ta) {
for (TileIndex tile_cur : ta) {
if (IsTileType(tile_cur, MP_STATION)) {
StationID t = GetStationIndex(tile_cur);
if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
@@ -498,20 +498,20 @@ static void ShowRejectOrAcceptNews(const Station *st, uint num_items, CargoID *c
/**
* Get the cargo types being produced around the tile (in a rectangle).
* @param tile Northtile of area
* @param north_tile Northern most tile of area
* @param w X extent of the area
* @param h Y extent of the area
* @param rad Search radius in addition to the given area
*/
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
{
CargoArray produced;
std::set<IndustryID> industries;
TileArea ta = TileArea(tile, w, h).Expand(rad);
TileArea ta = TileArea(north_tile, w, h).Expand(rad);
/* Loop over all tiles to get the produced cargo of
* everything except industries */
TILE_AREA_LOOP(tile, ta) {
for (TileIndex tile : ta) {
if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
AddProducedCargo(tile, produced);
}
@@ -535,21 +535,21 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
/**
* Get the acceptance of cargoes around the tile in 1/8.
* @param tile Center of the search area
* @param center_tile Center of the search area
* @param w X extent of area
* @param h Y extent of area
* @param rad Search radius in addition to given area
* @param always_accepted bitmask of cargo accepted by houses and headquarters; can be nullptr
* @param ind Industry associated with neutral station (e.g. oil rig) or nullptr
*/
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted)
CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted)
{
CargoArray acceptance;
if (always_accepted != nullptr) *always_accepted = 0;
TileArea ta = TileArea(tile, w, h).Expand(rad);
TileArea ta = TileArea(center_tile, w, h).Expand(rad);
TILE_AREA_LOOP(tile, ta) {
for (TileIndex tile : ta) {
/* Ignore industry if it has a neutral station. */
if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
@@ -872,7 +872,7 @@ static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag fl
const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
TILE_AREA_LOOP(tile_cur, tile_area) {
for (TileIndex tile_cur : tile_area) {
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -954,7 +954,7 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags
CommandCost cost(EXPENSES_CONSTRUCTION);
int allowed_z = -1;
TILE_AREA_LOOP(cur_tile, tile_area) {
for (TileIndex cur_tile : tile_area) {
CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -1109,13 +1109,13 @@ static inline byte *CreateMulti(byte *layout, int n, byte b)
* @param plat_len The length of the platforms.
* @param statspec The specification of the station to (possibly) get the layout from.
*/
void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec)
void GetStationLayout(byte *layout, uint numtracks, uint plat_len, const StationSpec *statspec)
{
if (statspec != nullptr && statspec->lengths >= plat_len &&
statspec->platforms[plat_len - 1] >= numtracks &&
statspec->layouts[plat_len - 1][numtracks - 1]) {
if (statspec != nullptr && statspec->layouts.size() >= plat_len &&
statspec->layouts[plat_len - 1].size() >= numtracks &&
!statspec->layouts[plat_len - 1][numtracks - 1].empty()) {
/* Custom layout defined, follow it. */
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1],
memcpy(layout, statspec->layouts[plat_len - 1][numtracks - 1].data(),
plat_len * numtracks);
return;
}
@@ -1124,9 +1124,9 @@ void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSp
CreateSingle(layout, numtracks);
} else {
if (numtracks & 1) layout = CreateSingle(layout, plat_len);
numtracks >>= 1;
int n = numtracks >> 1;
while (--numtracks >= 0) {
while (--n >= 0) {
layout = CreateMulti(layout, plat_len, 4);
layout = CreateMulti(layout, plat_len, 6);
}
@@ -1250,7 +1250,7 @@ static void RestoreTrainReservation(Train *v)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
/* Unpack parameters */
RailType rt = Extract<RailType, 0, 6>(p1);
@@ -1435,7 +1435,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
}
TILE_AREA_LOOP(tile, update_reservation_area) {
for (TileIndex tile : update_reservation_area) {
/* Don't even try to make eye candy parts reserved. */
if (IsStationTileBlocked(tile)) continue;
@@ -1563,7 +1563,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
CommandCost error;
/* Do the action for every tile into the area */
TILE_AREA_LOOP(tile, ta) {
for (TileIndex tile : ta) {
/* Make sure the specified tile is a rail station */
if (!HasStationTileRail(tile)) continue;
@@ -1659,7 +1659,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
TileIndex end = p1 == 0 ? start : p1;
if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
@@ -1693,7 +1693,7 @@ CommandCost CmdRemoveFromRailStation(TileIndex start, DoCommandFlag flags, uint3
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRemoveFromRailWaypoint(TileIndex start, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
TileIndex end = p1 == 0 ? start : p1;
if (start >= MapSize() || end >= MapSize()) return CMD_ERROR;
@@ -1729,7 +1729,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
CommandCost cost(EXPENSES_CONSTRUCTION);
/* clear all areas of the station */
TILE_AREA_LOOP(tile, ta) {
for (TileIndex tile : ta) {
/* only remove tiles that are actually train station tiles */
if (st->TileBelongsToRailStation(tile)) {
std::vector<T*> affected_stations; // dummy
@@ -1832,7 +1832,7 @@ static CommandCost FindJoiningRoadStop(StationID existing_stop, StationID statio
* @param text Unused.
* @return The cost of this operation or an error.
*/
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
bool type = HasBit(p2, 0);
bool is_drive_through = HasBit(p2, 1);
@@ -1894,7 +1894,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
if (flags & DC_EXEC) {
/* Check every tile in the area. */
TILE_AREA_LOOP(cur_tile, roadstop_area) {
for (TileIndex cur_tile : roadstop_area) {
/* Get existing road types and owners before any tile clearing */
RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
@@ -2029,7 +2029,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
}
/* Update company infrastructure counts. */
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
RoadType rt = GetRoadType(tile, rtt);
UpdateCompanyRoadInfrastructure(rt, GetRoadOwner(tile, rtt), -static_cast<int>(ROAD_STOP_TRACKBIT_FACTOR));
}
@@ -2082,7 +2082,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
* @param text Unused.
* @return The cost of this operation or an error.
*/
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
uint8 width = (uint8)GB(p1, 0, 8);
uint8 height = (uint8)GB(p1, 8, 8);
@@ -2101,7 +2101,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
bool had_success = false;
TILE_AREA_LOOP(cur_tile, roadstop_area) {
for (TileIndex cur_tile : roadstop_area) {
/* Make sure the specified tile is a road stop of the correct type */
if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
@@ -2110,7 +2110,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
RoadType road_type[] = { INVALID_ROADTYPE, INVALID_ROADTYPE };
Owner road_owner[] = { OWNER_NONE, OWNER_NONE };
if (IsDriveThroughStopTile(cur_tile)) {
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
road_type[rtt] = GetRoadType(cur_tile, rtt);
if (road_type[rtt] == INVALID_ROADTYPE) continue;
road_owner[rtt] = GetRoadOwner(cur_tile, rtt);
@@ -2241,7 +2241,7 @@ void UpdateAirportsNoise()
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
StationID station_to_join = GB(p2, 16, 16);
bool reuse = (station_to_join != NEW_STATION);
@@ -2396,7 +2396,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
TileIndex tile_cur = st->airport.GetHangarTile(i);
OrderBackup::Reset(tile_cur, false);
DeleteWindowById(WC_VEHICLE_DEPOT, tile_cur);
CloseWindowById(WC_VEHICLE_DEPOT, tile_cur);
}
const AirportSpec *as = st->airport.GetSpec();
@@ -2409,7 +2409,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
}
TILE_AREA_LOOP(tile_cur, st->airport) {
for (TileIndex tile_cur : st->airport) {
if (!st->TileBelongsToAirport(tile_cur)) continue;
CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
@@ -2458,7 +2458,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
if (!Station::IsValidID(p1)) return CMD_ERROR;
Station *st = Station::Get(p1);
@@ -2513,7 +2513,7 @@ static const byte _dock_h_chk[4] = { 1, 2, 1, 2 };
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
StationID station_to_join = GB(p2, 16, 16);
bool reuse = (station_to_join != NEW_STATION);
@@ -2843,8 +2843,8 @@ static void DrawTile_Station(TileInfo *ti)
}
/* Ensure the chosen tile layout is valid for this custom station */
if (statspec->renderdata != nullptr) {
layout = &statspec->renderdata[tile_layout < statspec->tiles ? tile_layout : (uint)GetRailStationAxis(ti->tile)];
if (!statspec->renderdata.empty()) {
layout = &statspec->renderdata[tile_layout < statspec->renderdata.size() ? tile_layout : (uint)GetRailStationAxis(ti->tile)];
if (!layout->NeedsPreprocessing()) {
t = layout;
layout = nullptr;
@@ -2993,8 +2993,7 @@ draw_default_foundation:
/* Sprite layout which needs preprocessing */
bool separate_ground = HasBit(statspec->flags, SSF_SEPARATE_GROUND);
uint32 var10_values = layout->PrepareLayout(total_offset, rti->fallback_railtype, 0, 0, separate_ground);
uint8 var10;
FOR_EACH_SET_BIT(var10, var10_values) {
for (uint8 var10 : SetBitIterator(var10_values)) {
uint32 var10_relocation = GetCustomStationRelocation(statspec, st, ti->tile, var10);
layout->ProcessRegisters(var10, var10_relocation, separate_ground);
}
@@ -3466,10 +3465,9 @@ static void UpdateStationRating(Station *st)
byte_inc_sat(&st->time_since_load);
byte_inc_sat(&st->time_since_unload);
const CargoSpec *cs;
FOR_ALL_CARGOSPECS(cs) {
for (const CargoSpec *cs : CargoSpec::Iterate()) {
GoodsEntry *ge = &st->goods[cs->Index()];
/* Slowly increase the rating back to his original level in the case we
/* Slowly increase the rating back to its original level in the case we
* didn't deliver cargo yet to this station. This happens when a bribe
* failed while you didn't moved that cargo yet to a station. */
if (!ge->HasRating() && ge->rating < INITIAL_STATION_RATING) {
@@ -3753,7 +3751,7 @@ void IncreaseStats(Station *st, CargoID cargo, StationID next_station_id, uint c
ge2.link_graph = lg->index;
ge2.node = lg->AddNode(st2);
} else {
DEBUG(misc, 0, "Can't allocate link graph");
Debug(misc, 0, "Can't allocate link graph");
}
} else {
lg = LinkGraph::Get(ge2.link_graph);
@@ -3895,7 +3893,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
ge.link_graph = lg->index;
ge.node = lg->AddNode(st);
} else {
DEBUG(misc, 0, "Can't allocate link graph");
Debug(misc, 0, "Can't allocate link graph");
}
} else {
lg = LinkGraph::Get(ge.link_graph);
@@ -3916,7 +3914,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
return amount;
}
static bool IsUniqueStationName(const char *name)
static bool IsUniqueStationName(const std::string &name)
{
for (const Station *st : Station::Iterate()) {
if (!st->name.empty() && st->name == name) return false;
@@ -3934,7 +3932,7 @@ static bool IsUniqueStationName(const char *name)
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
{
Station *st = Station::GetIfValid(p1);
if (st == nullptr) return CMD_ERROR;
@@ -3942,7 +3940,7 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
CommandCost ret = CheckOwnership(st->owner);
if (ret.Failed()) return ret;
bool reset = StrEmpty(text);
bool reset = text.empty();
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
@@ -4082,7 +4080,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
/* If there is some cargo left due to rounding issues distribute it among the best rated stations. */
if (amount > moving) {
std::sort(used_stations.begin(), used_stations.end(), [type](const StationInfo &a, const StationInfo &b) {
std::stable_sort(used_stations.begin(), used_stations.end(), [type](const StationInfo &a, const StationInfo &b) {
return b.first->goods[type].rating < a.first->goods[type].rating;
});
@@ -4121,7 +4119,7 @@ void UpdateStationDockingTiles(Station *st)
int y1 = std::max<int>(y - 1, 0);
TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
TILE_AREA_LOOP(tile, ta) {
for (TileIndex tile : ta) {
if (IsValidTile(tile) && IsPossibleDockingTile(tile)) CheckForDockingTile(tile);
}
}
@@ -4129,7 +4127,7 @@ void UpdateStationDockingTiles(Station *st)
void BuildOilRig(TileIndex tile)
{
if (!Station::CanAllocateItem()) {
DEBUG(misc, 0, "Can't allocate station for oilrig at 0x%X, reverting to oilrig only", tile);
Debug(misc, 0, "Can't allocate station for oilrig at 0x{:X}, reverting to oilrig only", tile);
return;
}
@@ -4179,7 +4177,7 @@ void DeleteOilRig(TileIndex tile)
static void ChangeTileOwner_Station(TileIndex tile, Owner old_owner, Owner new_owner)
{
if (IsRoadStopTile(tile)) {
FOR_ALL_ROADTRAMTYPES(rtt) {
for (RoadTramType rtt : _roadtramtypes) {
/* Update all roadtypes, no matter if they are present */
if (GetRoadOwner(tile, rtt) == old_owner) {
RoadType rt = GetRoadType(tile, rtt);