Changeset - r23420:9c4e5ff5cf11
[Not reviewed]
master
0 14 0
PeterN - 5 years ago 2019-03-08 18:30:44
peter@fuzzle.org
Feature: Industries with neutral stations (e.g. Oil Rig) only supply/accept cargo to/from their neutral station. (#7234)

This change is a controlled by a game setting, located under Environment ->
Industries which allows toggling the behaviour. It defaults to enabled.

"Company stations can serve industries with attached neutral stations"

When enabled, industries with attached neutral station (such as Oil Rigs) may
also be served by company-owned stations built nearby. This is the traditional
behaviour.

When disabled, these industries may only be served by their neutral station.
Any nearby company-owned stations won't be able to serve them, nor will the
neutral station serve anything else other than the industry.
14 files changed with 81 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1045,12 +1045,17 @@ static uint DeliverGoodsToIndustry(const
 
	uint accepted = 0;
 

	
 
	for (uint i = 0; i < st->industries_near.Length() && num_pieces != 0; i++) {
 
		Industry *ind = st->industries_near[i];
 
		if (ind->index == source) continue;
 

	
 
		if (!_settings_game.station.serve_neutral_industries) {
 
			/* If this industry is only served by its neutral station, check it's us. */
 
			if (ind->neutral_station != NULL && ind->neutral_station != st) continue;
 
		}
 

	
 
		uint cargo_index;
 
		for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
 
			if (cargo_type == ind->accepts_cargo[cargo_index]) break;
 
		}
 
		/* Check if matching cargo has been found */
 
		if (cargo_index >= lengthof(ind->accepts_cargo)) continue;
src/industry.h
Show inline comments
 
@@ -15,12 +15,13 @@
 
#include <algorithm>
 
#include "newgrf_storage.h"
 
#include "subsidy_type.h"
 
#include "industry_map.h"
 
#include "industrytype.h"
 
#include "tilearea_type.h"
 
#include "station_base.h"
 

	
 

	
 
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
 
extern IndustryPool _industry_pool;
 

	
 
/**
 
@@ -38,12 +39,13 @@ enum ProductionLevels {
 
/**
 
 * Defines the internal data of a functional industry.
 
 */
 
struct Industry : IndustryPool::PoolItem<&_industry_pool> {
 
	TileArea location;                                     ///< Location of the industry
 
	Town *town;                                            ///< Nearest town
 
	Station *neutral_station;                              ///< Associated neutral station
 
	CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS];          ///< 16 production cargo slots
 
	uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS];   ///< amount of cargo produced per cargo
 
	uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS];    ///< incoming cargo waiting to be processed
 
	byte production_rate[INDUSTRY_NUM_OUTPUTS];            ///< production rate for each cargo
 
	byte prod_level;                                       ///< general production level
 
	CargoID accepts_cargo[INDUSTRY_NUM_INPUTS];            ///< 16 input cargo slots
src/industry_cmd.cpp
Show inline comments
 
@@ -514,24 +514,30 @@ static bool TransportIndustryGoods(TileI
 
{
 
	Industry *i = Industry::GetByTile(tile);
 
	const IndustrySpec *indspec = GetIndustrySpec(i->type);
 
	bool moved_cargo = false;
 

	
 
	StationFinder stations(i->location);
 
	StationList neutral;
 

	
 
	if (i->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) {
 
		/* Industry has a neutral station. Use it and ignore any other nearby stations. */
 
		*neutral.Append() = i->neutral_station;
 
	}
 

	
 
	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) {
 
			i->produced_cargo_waiting[j] -= cw;
 

	
 
			/* fluctuating economy? */
 
			if (EconomyIsInRecession()) cw = (cw + 1) / 2;
 

	
 
			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, neutral.Length() != 0 ? &neutral : stations.GetStations());
 
			i->this_month_transported[j] += am;
 

	
 
			moved_cargo |= (am != 0);
 
		}
 
	}
 

	
src/lang/english.txt
Show inline comments
 
@@ -1181,12 +1181,14 @@ STR_CONFIG_SETTING_MAX_HEIGHTLEVEL      
 
STR_CONFIG_SETTING_MAX_HEIGHTLEVEL_HELPTEXT                     :Set the maximum allowed height for mountains on the map
 
STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN                            :{WHITE}You can't set the maximum map height to this value. At least one mountain on the map is higher
 
STR_CONFIG_SETTING_AUTOSLOPE                                    :Allow landscaping under buildings, tracks, etc.: {STRING2}
 
STR_CONFIG_SETTING_AUTOSLOPE_HELPTEXT                           :Allow landscaping under buildings and tracks without removing them
 
STR_CONFIG_SETTING_CATCHMENT                                    :Allow more realistically sized catchment areas: {STRING2}
 
STR_CONFIG_SETTING_CATCHMENT_HELPTEXT                           :Have differently sized catchment areas for different types of stations and airports
 
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES                     :Company stations can serve industries with attached neutral stations: {STRING2}
 
STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES_HELPTEXT            :When enabled, industries with attached stations (such as Oil Rigs) may also be served by company owned stations built nearby. When disabled, these industries may only be served by their attached stations. Any nearby company stations won't be able to serve them, nor will the attached station serve anything else other than the industry
 
STR_CONFIG_SETTING_EXTRADYNAMITE                                :Allow removal of more town-owned roads, bridges and tunnels: {STRING2}
 
STR_CONFIG_SETTING_EXTRADYNAMITE_HELPTEXT                       :Make it easier to remove town-owned infrastructure and buildings
 
STR_CONFIG_SETTING_TRAIN_LENGTH                                 :Maximum length of trains: {STRING2}
 
STR_CONFIG_SETTING_TRAIN_LENGTH_HELPTEXT                        :Set the maximum length of trains
 
STR_CONFIG_SETTING_TILE_LENGTH                                  :{COMMA} tile{P 0 "" s}
 
STR_CONFIG_SETTING_SMOKE_AMOUNT                                 :Amount of vehicle smoke/sparks: {STRING2}
src/saveload/afterload.cpp
Show inline comments
 
@@ -3082,12 +3082,31 @@ bool AfterLoadGame()
 

	
 
	if (IsSavegameVersionBefore(SLV_TOWN_CARGOGEN)) {
 
		/* Ensure the original cargo generation mode is used */
 
		_settings_game.economy.town_cargogen_mode = TCGM_ORIGINAL;
 
	}
 

	
 
	if (IsSavegameVersionBefore(SLV_SERVE_NEUTRAL_INDUSTRIES)) {
 
		/* Ensure the original neutral industry/station behaviour is used */
 
		_settings_game.station.serve_neutral_industries = true;
 

	
 
		/* Link oil rigs to their industry and back. */
 
		Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			if (IsTileType(st->xy, MP_STATION) && IsOilRig(st->xy)) {
 
				/* Industry tile is always adjacent during construction by TileDiffXY(0, 1) */
 
				st->industry = Industry::GetByTile(st->xy + TileDiffXY(0, 1));
 
				st->industry->neutral_station = st;
 
			}
 
		}
 
	} else {
 
		/* Link neutral station back to industry, as this is not saved. */
 
		Industry *ind;
 
		FOR_ALL_INDUSTRIES(ind) if (ind->neutral_station != NULL) ind->neutral_station->industry = ind;
 
	}
 

	
 
	/* Station acceptance is some kind of cache */
 
	if (IsSavegameVersionBefore(SLV_127)) {
 
		Station *st;
 
		FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
 
	}
 

	
src/saveload/industry_sl.cpp
Show inline comments
 
@@ -22,12 +22,13 @@ static OldPersistentStorage _old_ind_per
 
static const SaveLoad _industry_desc[] = {
 
	SLE_CONDVAR(Industry, location.tile,              SLE_FILE_U16 | SLE_VAR_U32,  SL_MIN_VERSION, SLV_6),
 
	SLE_CONDVAR(Industry, location.tile,              SLE_UINT32,                  SLV_6, SL_MAX_VERSION),
 
	    SLE_VAR(Industry, location.w,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_VAR(Industry, location.h,                 SLE_FILE_U8 | SLE_VAR_U16),
 
	    SLE_REF(Industry, town,                       REF_TOWN),
 
	SLE_CONDREF(Industry, neutral_station,            REF_STATION,                SLV_SERVE_NEUTRAL_INDUSTRIES, SL_MAX_VERSION),
 
	SLE_CONDNULL( 2, SL_MIN_VERSION, SLV_61),       ///< used to be industry's produced_cargo
 
	SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,   2,              SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
 
	SLE_CONDARR(Industry, produced_cargo,             SLE_UINT8,  16,             SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
 
	SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16,  3,              SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
 
	SLE_CONDARR(Industry, incoming_cargo_waiting,     SLE_UINT16, 16,             SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
 
	SLE_CONDARR(Industry, produced_cargo_waiting,     SLE_UINT16,  2,               SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
src/saveload/saveload.h
Show inline comments
 
@@ -291,12 +291,14 @@ enum SaveLoadVersion : uint16 {
 
	SLV_GROUP_LIVERIES,                     ///< 205  PR#7108 Livery storage change and group liveries.
 
	SLV_SHIPS_STOP_IN_LOCKS,                ///< 206  PR#7150 Ship/lock movement changes.
 
	SLV_FIX_CARGO_MONITOR,                  ///< 207  PR#7175 v1.9  Cargo monitor data packing fix to support 64 cargotypes.
 
	SLV_TOWN_CARGOGEN,                      ///< 208  PR#6965 New algorithms for town building cargo generation.
 
	SLV_SHIP_CURVE_PENALTY,                 ///< 209  PR#7289 Configurable ship curve penalties.
 

	
 
	SLV_SERVE_NEUTRAL_INDUSTRIES,           ///< 210  PR#7234 Company stations can serve industries with attached neutral stations.
 

	
 
	SL_MAX_VERSION,                         ///< Highest possible saveload version
 
};
 

	
 
/** Save or load result codes. */
 
enum SaveOrLoadResult {
 
	SL_OK     = 0, ///< completed successfully
src/settings_gui.cpp
Show inline comments
 
@@ -1740,12 +1740,13 @@ static SettingsContainer &GetSettingsTre
 
			{
 
				industries->Add(new SettingEntry("construction.raw_industry_construction"));
 
				industries->Add(new SettingEntry("construction.industry_platform"));
 
				industries->Add(new SettingEntry("economy.multiple_industry_per_town"));
 
				industries->Add(new SettingEntry("game_creation.oil_refinery_limit"));
 
				industries->Add(new SettingEntry("economy.smooth_economy"));
 
				industries->Add(new SettingEntry("station.serve_neutral_industries"));
 
			}
 

	
 
			SettingsPage *cdist = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST));
 
			{
 
				cdist->Add(new SettingEntry("linkgraph.recalc_time"));
 
				cdist->Add(new SettingEntry("linkgraph.recalc_interval"));
src/settings_type.h
Show inline comments
 
@@ -524,12 +524,13 @@ struct LinkGraphSettings {
 
	}
 
};
 

	
 
/** Settings related to stations. */
 
struct StationSettings {
 
	bool   modified_catchment;               ///< different-size catchment areas
 
	bool   serve_neutral_industries;         ///< company stations can serve industries with attached neutral stations
 
	bool   adjacent_stations;                ///< allow stations to be built directly adjacent to other stations
 
	bool   distant_join_stations;            ///< allow to join non-adjacent stations
 
	bool   never_expire_airports;            ///< never expire airports
 
	byte   station_spread;                   ///< amount a station may spread
 
};
 

	
src/station.cpp
Show inline comments
 
@@ -353,12 +353,18 @@ static bool FindIndustryToDeliver(TileIn
 
 */
 
void Station::RecomputeIndustriesNear()
 
{
 
	this->industries_near.Clear();
 
	if (this->rect.IsEmpty()) return;
 

	
 
	if (!_settings_game.station.serve_neutral_industries && this->industry != NULL) {
 
		/* Station is associated with an industry, so we only need to deliver to that industry. */
 
		*this->industries_near.Append() = this->industry;
 
		return;
 
	}
 

	
 
	RectAndIndustryVector riv = {
 
		this->GetCatchmentRect(),
 
		&this->industries_near
 
	};
 

	
 
	/* Compute maximum extent of acceptance rectangle wrt. station sign */
src/station_base.h
Show inline comments
 
@@ -470,12 +470,13 @@ public:
 
	byte last_vehicle_type;
 
	std::list<Vehicle *> loading_vehicles;
 
	GoodsEntry goods[NUM_CARGO];  ///< Goods at this station
 
	CargoTypes always_accepted;       ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo)
 

	
 
	IndustryVector industries_near; ///< Cached list of industries near the station that can accept cargo, @see DeliverGoodsToIndustry()
 
	Industry *industry;             ///< NOSAVE: Associated industry for neutral stations. (Rebuilt on load from Industry->st)
 

	
 
	Station(TileIndex tile = INVALID_TILE);
 
	~Station();
 

	
 
	void AddFacility(StationFacility new_facility_bit, TileIndex facil_xy);
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -503,12 +503,14 @@ CargoArray GetProductionAroundTiles(Tile
 
	 * area loop might not hit an industry tile while
 
	 * the industry would produce cargo for the station.
 
	 */
 
	const Industry *i;
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (!ta.Intersects(i->location)) continue;
 
		/* Skip industry with neutral station */
 
		if (i->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) continue;
 

	
 
		for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
 
			CargoID cargo = i->produced_cargo[j];
 
			if (cargo != CT_INVALID) produced[cargo]++;
 
		}
 
	}
 
@@ -520,14 +522,15 @@ CargoArray GetProductionAroundTiles(Tile
 
 * Get the acceptance of cargoes around the tile in 1/8.
 
 * @param 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 NULL
 
 * @param ind Industry associated with neutral station (e.g. oil rig) or NULL
 
 */
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted)
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted, const Industry *ind)
 
{
 
	CargoArray acceptance;
 
	if (always_accepted != NULL) *always_accepted = 0;
 

	
 
	int x = TileX(tile);
 
	int y = TileY(tile);
 
@@ -544,12 +547,21 @@ CargoArray GetAcceptanceAroundTiles(Tile
 
	assert(w > 0);
 
	assert(h > 0);
 

	
 
	for (int yc = y1; yc != y2; yc++) {
 
		for (int xc = x1; xc != x2; xc++) {
 
			TileIndex tile = TileXY(xc, yc);
 

	
 
			if (!_settings_game.station.serve_neutral_industries) {
 
				if (ind != NULL) {
 
					if (!IsTileType(tile, MP_INDUSTRY)) continue;
 
					if (Industry::GetByTile(tile) != ind) continue;
 
				} else {
 
					if (IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != NULL) continue;
 
				}
 
			}
 
			AddAcceptedCargo(tile, acceptance, always_accepted);
 
		}
 
	}
 

	
 
	return acceptance;
 
}
 
@@ -569,13 +581,14 @@ void UpdateStationAcceptance(Station *st
 
	if (!st->rect.IsEmpty()) {
 
		acceptance = GetAcceptanceAroundTiles(
 
			TileXY(st->rect.left, st->rect.top),
 
			st->rect.right  - st->rect.left + 1,
 
			st->rect.bottom - st->rect.top  + 1,
 
			st->GetCatchmentRadius(),
 
			&st->always_accepted
 
			&st->always_accepted,
 
			_settings_game.station.serve_neutral_industries ? NULL : st->industry
 
		);
 
	}
 

	
 
	/* Adjust in case our station only accepts fewer kinds of goods */
 
	for (CargoID i = 0; i < NUM_CARGO; i++) {
 
		uint amt = acceptance[i];
 
@@ -3792,12 +3805,14 @@ void FindStationsAroundTiles(const TileA
 

	
 
	uint min_x = (x > max_rad) ? x - max_rad : 0;
 
	uint max_x = x + location.w + max_rad;
 
	uint min_y = (y > max_rad) ? y - max_rad : 0;
 
	uint max_y = y + location.h + max_rad;
 

	
 
	IndustryID ind = IsTileType(location.tile, MP_INDUSTRY) ? GetIndustryIndex(location.tile) : INVALID_INDUSTRY;
 

	
 
	if (min_x == 0 && _settings_game.construction.freeform_edges) min_x = 1;
 
	if (min_y == 0 && _settings_game.construction.freeform_edges) min_y = 1;
 
	if (max_x >= MapSizeX()) max_x = MapSizeX() - 1;
 
	if (max_y >= MapSizeY()) max_y = MapSizeY() - 1;
 

	
 
	for (uint cy = min_y; cy < max_y; cy++) {
 
@@ -3806,12 +3821,15 @@ void FindStationsAroundTiles(const TileA
 
			if (!IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
			Station *st = Station::GetByTile(cur_tile);
 
			/* st can be NULL in case of waypoints */
 
			if (st == NULL) continue;
 

	
 
			/* Check if neutral station is attached to us */
 
			if (!_settings_game.station.serve_neutral_industries && st->industry != NULL && st->industry->index != ind) continue;
 

	
 
			if (_settings_game.station.modified_catchment) {
 
				int rad = st->GetCatchmentRadius();
 
				int rad_x = cx - x;
 
				int rad_y = cy - y;
 

	
 
				if (rad_x < -rad || rad_x >= rad + location.w) continue;
 
@@ -3915,12 +3933,15 @@ void BuildOilRig(TileIndex tile)
 
	Station *st = new Station(tile);
 
	st->town = ClosestTownFromTile(tile, UINT_MAX);
 

	
 
	st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
 

	
 
	assert(IsTileType(tile, MP_INDUSTRY));
 
	/* Mark industry as associated both ways */
 
	st->industry = Industry::GetByTile(tile);
 
	st->industry->neutral_station = st;
 
	DeleteAnimatedTile(tile);
 
	MakeOilrig(tile, st->index, GetWaterClass(tile));
 

	
 
	st->owner = OWNER_NONE;
 
	st->airport.type = AT_OILRIG;
 
	st->airport.Add(tile);
src/station_func.h
Show inline comments
 
@@ -16,22 +16,23 @@
 
#include "rail_type.h"
 
#include "road_type.h"
 
#include "vehicle_type.h"
 
#include "economy_func.h"
 
#include "rail.h"
 
#include "linkgraph/linkgraph_type.h"
 
#include "industry_type.h"
 

	
 
void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint radius);
 

	
 
void FindStationsAroundTiles(const TileArea &location, StationList *stations);
 

	
 
void ShowStationViewWindow(StationID station);
 
void UpdateAllStationVirtCoords();
 

	
 
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad);
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted = NULL);
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted = NULL, const Industry *ind = NULL);
 

	
 
void UpdateStationAcceptance(Station *st, bool show_msg);
 

	
 
const DrawTileSprites *GetStationTileLayout(StationType st, byte gfx);
 
void StationPickerDrawSprite(int x, int y, StationType st, RailType railtype, RoadType roadtype, int image);
 

	
src/table/settings.ini
Show inline comments
 
@@ -1218,12 +1218,21 @@ str      = STR_CONFIG_SETTING_CATCHMENT
 
strhelp  = STR_CONFIG_SETTING_CATCHMENT_HELPTEXT
 
proc     = StationCatchmentChanged
 
cat      = SC_EXPERT
 

	
 
[SDT_BOOL]
 
base     = GameSettings
 
var      = station.serve_neutral_industries
 
def      = true
 
from     = SLV_SERVE_NEUTRAL_INDUSTRIES
 
str      = STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES
 
strhelp  = STR_CONFIG_SETTING_SERVE_NEUTRAL_INDUSTRIES_HELPTEXT
 
proc     = StationCatchmentChanged
 

	
 
[SDT_BOOL]
 
base     = GameSettings
 
var      = order.gradual_loading
 
from     = SLV_40
 
guiflags = SGF_NO_NETWORK
 
def      = true
 
cat      = SC_EXPERT
 

	
0 comments (0 inline, 0 general)