Merge branch 'master' into jgrpp

# Conflicts:
#	config.lib
#	projects/openttd_vs140.vcxproj
#	projects/openttd_vs140.vcxproj.filters
#	projects/openttd_vs141.vcxproj
#	projects/openttd_vs141.vcxproj.filters
#	projects/openttd_vs142.vcxproj
#	projects/openttd_vs142.vcxproj.filters
#	src/aircraft_cmd.cpp
#	src/base_station_base.h
#	src/core/pool_type.hpp
#	src/disaster_vehicle.cpp
#	src/economy.cpp
#	src/engine.cpp
#	src/group.h
#	src/group_cmd.cpp
#	src/group_gui.cpp
#	src/lang/english.txt
#	src/lang/german.txt
#	src/linkgraph/linkgraph_gui.cpp
#	src/network/network_command.cpp
#	src/network/network_server.cpp
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/road_cmd.cpp
#	src/saveload/afterload.cpp
#	src/saveload/cargopacket_sl.cpp
#	src/saveload/linkgraph_sl.cpp
#	src/saveload/order_sl.cpp
#	src/saveload/station_sl.cpp
#	src/saveload/town_sl.cpp
#	src/saveload/vehicle_sl.cpp
#	src/screenshot.cpp
#	src/screenshot.h
#	src/settings_gui.cpp
#	src/settings_type.h
#	src/smallmap_gui.cpp
#	src/station.cpp
#	src/station_cmd.cpp
#	src/table/settings.ini
#	src/toolbar_gui.cpp
#	src/town_cmd.cpp
#	src/train.h
#	src/train_cmd.cpp
#	src/train_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/vehiclelist.cpp
#	src/window_type.h
This commit is contained in:
Jonathan G Rennison
2020-01-06 18:45:51 +00:00
281 changed files with 2714 additions and 2467 deletions

View File

@@ -245,8 +245,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
bool indtypes[NUM_INDUSTRYTYPES];
memset(indtypes, 0, sizeof(indtypes));
const Station *s;
FOR_ALL_STATIONS(s) {
for (const Station *s : Station::Iterate()) {
if (s != st && s->town == t) {
if (s->indtype != IT_INVALID) {
indtypes[s->indtype] = true;
@@ -443,9 +442,7 @@ void Station::MoveSign(TileIndex new_xy)
/** Update the virtual coords needed to draw the station sign for all stations. */
void UpdateAllStationVirtCoords()
{
BaseStation *st;
FOR_ALL_BASE_STATIONS(st) {
for (BaseStation *st : BaseStation::Iterate()) {
st->UpdateVirtCoord();
}
}
@@ -463,9 +460,7 @@ void BaseStation::FillCachedName()
void ClearAllStationCachedNames()
{
BaseStation *st;
FOR_ALL_BASE_STATIONS(st) {
for (BaseStation *st : BaseStation::Iterate()) {
st->cached_name.reset();
}
}
@@ -2186,8 +2181,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags)
delete cur_stop;
/* Make sure no vehicle is going to the old roadstop */
RoadVehicle *v;
FOR_ALL_ROADVEHICLES(v) {
for (RoadVehicle *v : RoadVehicle::Iterate()) {
if (v->First() == v && v->current_order.IsType(OT_GOTO_STATION) &&
v->dest_tile == tile) {
v->SetDestTile(v->GetOrderStationLocation(st->index));
@@ -2285,23 +2279,6 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
return had_success ? cost : last_error;
}
/**
* Computes the minimal distance from town's xy to any airport's tile.
* @param it An iterator over all airport tiles.
* @param town_tile town's tile (t->xy)
* @return minimal manhattan distance from town_tile to any airport's tile
*/
static uint GetMinimalAirportDistanceToTile(TileIterator &it, TileIndex town_tile)
{
uint mindist = UINT_MAX;
for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) {
mindist = min(mindist, DistanceManhattan(town_tile, cur_tile));
}
return mindist;
}
/**
* Get a possible noise reduction factor based on distance from town center.
* The further you get, the less noise you generate.
@@ -2341,14 +2318,25 @@ uint8 GetAirportNoiseLevelForDistance(const AirportSpec *as, uint distance)
*/
Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint &mindist)
{
Town *t, *nearest = nullptr;
uint add = as->size_x + as->size_y - 2; // GetMinimalAirportDistanceToTile can differ from DistanceManhattan by this much
mindist = UINT_MAX - add; // prevent overflow
FOR_ALL_TOWNS(t) {
if (DistanceManhattan(t->xy, it) < mindist + add) { // avoid calling GetMinimalAirportDistanceToTile too often
TileIterator *copy = it.Clone();
uint dist = GetMinimalAirportDistanceToTile(*copy, t->xy);
delete copy;
assert(Town::GetNumItems() > 0);
Town *nearest = nullptr;
uint perimeter_min_x = TileX(it);
uint perimeter_min_y = TileY(it);
uint perimeter_max_x = perimeter_min_x + as->size_x - 1;
uint perimeter_max_y = perimeter_min_y + as->size_y - 1;
mindist = UINT_MAX - 1; // prevent overflow
std::unique_ptr<TileIterator> copy(it.Clone());
for (TileIndex cur_tile = *copy; cur_tile != INVALID_TILE; cur_tile = ++*copy) {
if (TileX(cur_tile) == perimeter_min_x || TileX(cur_tile) == perimeter_max_x || TileY(cur_tile) == perimeter_min_y || TileY(cur_tile) == perimeter_max_y) {
Town *t = CalcClosestTownFromTile(cur_tile, mindist + 1);
if (t == nullptr) continue;
uint dist = DistanceManhattan(t->xy, cur_tile);
if (dist == mindist && t->index < nearest->index) nearest = t;
if (dist < mindist) {
nearest = t;
mindist = dist;
@@ -2363,12 +2351,9 @@ Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint
/** Recalculate the noise generated by the airports of each town */
void UpdateAirportsNoise()
{
Town *t;
const Station *st;
for (Town *t : Town::Iterate()) t->noise_reached = 0;
FOR_ALL_TOWNS(t) t->noise_reached = 0;
FOR_ALL_STATIONS(st) {
for (const Station *st : Station::Iterate()) {
if (st->airport.tile != INVALID_TILE && st->airport.type != AT_OILRIG) {
const AirportSpec *as = st->airport.GetSpec();
AirportTileIterator it(st);
@@ -2388,8 +2373,7 @@ void UpdateAirportsNoise()
*/
static CommandCost CanRemoveAirport(Station *st, DoCommandFlag flags)
{
const Aircraft *a;
FOR_ALL_AIRCRAFT(a) {
for (const Aircraft *a : Aircraft::Iterate()) {
if (!a->IsNormalAircraft()) continue;
if (a->targetairport == st->index && a->state != FLYING)
return_cmd_error(STR_ERROR_AIRCRAFT_IN_THE_WAY);
@@ -2510,8 +2494,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} else if (action != AIRPORT_UPGRADE) {
Town *t = ClosestTownFromTile(tile, UINT_MAX);
uint num = 0;
const Station *st;
FOR_ALL_STATIONS(st) {
for (const Station *st : Station::Iterate()) {
if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
}
if (num >= 2) {
@@ -2958,8 +2941,7 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
* will be selected and in case of no appropriate order it will just
* wander around the world. */
if (!(st->facilities & FACIL_DOCK)) {
Ship *s;
FOR_ALL_SHIPS(s) {
for (Ship *s : Ship::Iterate()) {
if (s->current_order.IsType(OT_LOADING) && s->current_order.GetDestination() == st->index) {
s->LeaveStation();
}
@@ -3933,9 +3915,8 @@ void DeleteStaleLinks(Station *from)
if (auto_distributed) {
/* Have all vehicles refresh their next hops before deciding to
* remove the node. */
OrderList *l;
std::vector<Vehicle *> vehicles;
FOR_ALL_ORDER_LISTS(l) {
for (OrderList *l : OrderList::Iterate()) {
bool found_from = false;
bool found_to = false;
for (Order *order = l->GetFirstOrder(); order != nullptr; order = order->next) {
@@ -4066,8 +4047,7 @@ void OnTick_Station()
{
if (_game_mode == GM_EDITOR) return;
BaseStation *st;
FOR_ALL_BASE_STATIONS(st) {
for (BaseStation *st : BaseStation::Iterate()) {
StationHandleSmallTick(st);
/* Clean up the link graph about once a week. */
@@ -4090,9 +4070,7 @@ void OnTick_Station()
/** Monthly loop for stations. */
void StationMonthlyLoop()
{
Station *st;
FOR_ALL_STATIONS(st) {
for (Station *st : Station::Iterate()) {
for (CargoID i = 0; i < NUM_CARGO; i++) {
GoodsEntry *ge = &st->goods[i];
SB(ge->status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge->status, GoodsEntry::GES_CURRENT_MONTH, 1));
@@ -4164,9 +4142,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
static bool IsUniqueStationName(const char *name)
{
const Station *st;
FOR_ALL_STATIONS(st) {
for (const Station *st : Station::Iterate()) {
if (st->name != nullptr && strcmp(st->name, name) == 0) return false;
}
@@ -4993,8 +4969,7 @@ void DumpStationFlowStats(char *b, const char *last)
{
btree::btree_map<uint, uint> count_map;
btree::btree_map<uint, uint> invalid_map;
const Station *st;
FOR_ALL_STATIONS(st) {
for (const Station *st : Station::Iterate()) {
for (CargoID i = 0; i < NUM_CARGO; i++) {
const GoodsEntry &ge = st->goods[i];
for (FlowStatMap::const_iterator it(ge.flows.begin()); it != ge.flows.end(); ++it) {