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

@@ -73,8 +73,7 @@ TownKdtree _town_kdtree(&Kdtree_TownXYFunc);
void RebuildTownKdtree()
{
std::vector<TownID> townids;
Town *town;
FOR_ALL_TOWNS(town) {
for (const Town *town : Town::Iterate()) {
townids.push_back(town->index);
}
_town_kdtree.Build(townids.begin(), townids.end());
@@ -118,12 +117,10 @@ Town::~Town()
DeleteWindowById(WC_TOWN_VIEW, this->index);
/* Check no industry is related to us. */
const Industry *i;
FOR_ALL_INDUSTRIES(i) assert(i->town != this);
for (const Industry *i : Industry::Iterate()) assert(i->town != this);
/* ... and no object is related to us. */
const Object *o;
FOR_ALL_OBJECTS(o) assert(o->town != this);
for (const Object *o : Object::Iterate()) assert(o->town != this);
/* Check no tile is related to us. */
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
@@ -162,12 +159,11 @@ Town::~Town()
*/
void Town::PostDestructor(size_t index)
{
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
UpdateNearestTownForRoadTiles(false);
/* Give objects a new home! */
Object *o;
FOR_ALL_OBJECTS(o) {
for (Object *o : Object::Iterate()) {
if (o->town == nullptr) o->town = CalcClosestTownFromTile(o->location.tile, UINT_MAX);
}
}
@@ -529,18 +525,14 @@ void Town::UpdateVirtCoord()
/** Update the virtual coords needed to draw the town sign for all towns. */
void UpdateAllTownVirtCoords()
{
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
t->UpdateVirtCoord();
}
}
void ClearAllTownCachedNames()
{
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
t->cached_name.reset();
}
}
@@ -556,7 +548,7 @@ static void ChangePopulation(Town *t, int mod)
InvalidateWindowData(WC_TOWN_VIEW, t->index); // Cargo requirements may appear/vanish for small populations
if (_settings_client.gui.population_in_label) t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_RESORT);
}
/**
@@ -567,9 +559,7 @@ static void ChangePopulation(Town *t, int mod)
uint32 GetWorldPopulation()
{
uint32 pop = 0;
const Town *t;
FOR_ALL_TOWNS(t) pop += t->cache.population;
for (const Town *t : Town::Iterate()) pop += t->cache.population;
return pop;
}
@@ -1028,10 +1018,9 @@ void UpdateTownCargoes(Town *t)
/** Updates the bitmap of all cargoes accepted by houses. */
void UpdateTownCargoBitmap()
{
Town *town;
_town_cargoes_accepted = 0;
FOR_ALL_TOWNS(town) {
for (const Town *town : Town::Iterate()) {
_town_cargoes_accepted |= town->cargo_accepted_total;
}
}
@@ -1058,8 +1047,7 @@ void OnTick_Town()
{
if (_game_mode == GM_EDITOR) return;
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
TownTickHandler(t);
}
}
@@ -2018,7 +2006,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
t->townnameparts = townnameparts;
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_REBUILD);
t->InitializeLayout(layout);
@@ -2076,9 +2064,7 @@ static CommandCost TownCanBePlacedHere(TileIndex tile)
*/
static bool IsUniqueTownName(const char *name)
{
const Town *t;
FOR_ALL_TOWNS(t) {
for (const Town *t : Town::Iterate()) {
if (t->name != nullptr && strcmp(t->name, name) == 0) return false;
}
@@ -3004,7 +2990,7 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
t->name = reset ? nullptr : stredup(text);
t->UpdateVirtCoord();
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_RESORT);
ClearAllStationCachedNames();
ClearAllIndustryCachedNames();
UpdateAllStationVirtCoords();
@@ -3125,6 +3111,35 @@ CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
return CommandCost();
}
/**
* Change the rating of a company in a town
* @param tile Unused.
* @param flags Type of operation.
* @param p1 Bit 0..15 = Town ID to change, bit 16..23 = Company ID to change.
* @param p2 Bit 0..15 = New rating of company (signed int16).
* @param text Unused.
* @return Empty cost or an error.
*/
CommandCost CmdTownRating(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (_current_company != OWNER_DEITY) return CMD_ERROR;
TownID town_id = (TownID)GB(p1, 0, 16);
Town *t = Town::GetIfValid(town_id);
if (t == nullptr) return CMD_ERROR;
CompanyID company_id = (CompanyID)GB(p1, 16, 8);
if (!Company::IsValidID(company_id)) return CMD_ERROR;
int16 new_rating = Clamp((int16)GB(p2, 0, 16), RATING_MINIMUM, RATING_MAXIMUM);
if (flags & DC_EXEC) {
t->ratings[company_id] = new_rating;
InvalidateWindowData(WC_TOWN_AUTHORITY, town_id);
}
return CommandCost();
}
/**
* Expand a town (scenario editor only).
* @param tile Unused.
@@ -3181,8 +3196,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (t == nullptr) return CMD_ERROR;
/* Stations refer to towns. */
const Station *st;
FOR_ALL_STATIONS(st) {
for (const Station *st : Station::Iterate()) {
if (st->town == t) {
/* Non-oil rig stations are always a problem. */
if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR;
@@ -3193,8 +3207,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
/* Depots refer to towns. */
const Depot *d;
FOR_ALL_DEPOTS(d) {
for (const Depot *d : Depot::Iterate()) {
if (d->town == t) return CMD_ERROR;
}
@@ -3468,8 +3481,7 @@ static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
t->unwanted[_current_company] = 6;
/* set all close by station ratings to 0 */
Station *st;
FOR_ALL_STATIONS(st) {
for (Station *st : Station::Iterate()) {
if (st->town == t && st->owner == _current_company) {
for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0;
}
@@ -3604,8 +3616,7 @@ static void ForAllStationsNearTown(Town *t, Func func)
static void UpdateTownRating(Town *t)
{
/* Increase company ratings if they're low */
const Company *c;
FOR_ALL_COMPANIES(c) {
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);
}
@@ -3793,9 +3804,7 @@ static void UpdateTownAmounts(Town *t)
static void UpdateTownUnwanted(Town *t)
{
const Company *c;
FOR_ALL_COMPANIES(c) {
for (const Company *c : Company::Iterate()) {
if (t->unwanted[c->index] > 0) t->unwanted[c->index]--;
}
}
@@ -3998,9 +4007,7 @@ CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType
void TownsMonthlyLoop()
{
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
if (t->road_build_months != 0) t->road_build_months--;
if (t->exclusive_counter != 0) {