Merge branch 'master' into jgrpp

Remove the viewport sign cache as this is now superseded by the kd tree
implementation

# Conflicts:
#	src/crashlog.cpp
#	src/lang/english.txt
#	src/misc.cpp
#	src/pathfinder/follow_track.hpp
#	src/pbs.cpp
#	src/rail_cmd.cpp
#	src/saveload/vehicle_sl.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/ship_cmd.cpp
#	src/station.cpp
#	src/station_base.h
#	src/station_cmd.cpp
#	src/table/settings.ini
#	src/thread/thread_morphos.cpp
#	src/town_cmd.cpp
#	src/train_cmd.cpp
#	src/viewport.cpp
#	src/waypoint.cpp
This commit is contained in:
Jonathan G Rennison
2019-03-12 18:00:36 +00:00
177 changed files with 3131 additions and 2247 deletions

View File

@@ -183,6 +183,10 @@ Industry::~Industry()
DeleteSubsidyWith(ST_INDUSTRY, this->index);
CargoPacket::InvalidateAllFrom(ST_INDUSTRY, this->index);
for (Station *st : this->stations_near) {
st->industries_near.erase(this);
}
}
/**
@@ -192,7 +196,6 @@ Industry::~Industry()
void Industry::PostDestructor(size_t index)
{
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
Station::RecomputeIndustriesNearForAll();
}
@@ -517,8 +520,6 @@ static bool TransportIndustryGoods(TileIndex tile)
const IndustrySpec *indspec = GetIndustrySpec(i->type);
bool moved_cargo = false;
StationFinder stations(i->location);
for (uint j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint cw = min(i->produced_cargo_waiting[j], 255);
if (cw > indspec->minimal_cargo && i->produced_cargo[j] != CT_INVALID) {
@@ -529,7 +530,7 @@ static bool TransportIndustryGoods(TileIndex tile)
i->this_month_production[j] += cw;
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, stations.GetStations());
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, ST_INDUSTRY, i->index, &i->stations_near);
i->this_month_transported[j] += am;
moved_cargo |= (am != 0);
@@ -1652,6 +1653,37 @@ static void AdvertiseIndustryOpening(const Industry *ind)
Game::NewEvent(new ScriptEventIndustryOpen(ind->index));
}
/**
* Populate an industry's list of nearby stations, and if it accepts any cargo, also
* add the industry to each station's nearby industry list.
* @param ind Industry
*/
static void PopulateStationsNearby(Industry *ind)
{
if (ind->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) {
/* Industry has a neutral station. Use it and ignore any other nearby stations. */
ind->stations_near.insert(ind->neutral_station);
ind->neutral_station->industries_near.clear();
ind->neutral_station->industries_near.insert(ind);
return;
}
/* Get our list of nearby stations. */
FindStationsAroundTiles(ind->location, &ind->stations_near, false);
/* Test if industry can accept cargo */
uint cargo_index;
for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
if (ind->accepts_cargo[cargo_index] != CT_INVALID) break;
}
if (cargo_index >= lengthof(ind->accepts_cargo)) return;
/* Cargo is accepted, add industry to nearby stations nearby industry list. */
for (Station *st : ind->stations_near) {
st->industries_near.insert(ind);
}
}
/**
* Put an industry on the map.
* @param i Just allocated poolitem, mostly empty.
@@ -1825,7 +1857,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
}
InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, 0);
Station::RecomputeIndustriesNearForAll();
if (!_generating_world) PopulateStationsNearby(i);
}
/**
@@ -2430,11 +2462,7 @@ static void CanCargoServiceIndustry(CargoID cargo, Industry *ind, bool *c_accept
*/
static int WhoCanServiceIndustry(Industry *ind)
{
/* Find all stations within reach of the industry */
StationList stations;
FindStationsAroundTiles(ind->location, &stations);
if (stations.Length() == 0) return 0; // No stations found at all => nobody services
if (ind->stations_near.size() == 0) return 0; // No stations found at all => nobody services
const Vehicle *v;
int result = 0;
@@ -2470,7 +2498,7 @@ static int WhoCanServiceIndustry(Industry *ind)
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
if (stations.Contains(st)) {
if (ind->stations_near.find(st) != ind->stations_near.end()) {
if (v->owner == _local_company) return 2; // Company services industry
result = 1; // Competitor services industry
}
@@ -2909,3 +2937,8 @@ extern const TileTypeProcs _tile_type_industry_procs = {
GetFoundation_Industry, // get_foundation_proc
TerraformTile_Industry, // terraform_tile_proc
};
bool IndustryCompare::operator() (const Industry *lhs, const Industry *rhs) const
{
return lhs->index < rhs->index;
}