Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale oil refinery edge distance up by map size #7514

Merged
merged 1 commit into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/industry_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,29 @@ static CommandCost CheckNewIndustry_Forest(TileIndex tile)
return CommandCost();
}

/**
* Check if a tile is within a distance from map edges, scaled by map dimensions independently.
* Each dimension is checked independently, and dimensions smaller than 256 are not scaled.
* @param tile Which tile to check distance of.
* @param maxdist Normal distance on a 256x256 map.
* @return True if the tile is near the map edge.
*/
static bool CheckScaledDistanceFromEdge(TileIndex tile, uint maxdist)
nielsmh marked this conversation as resolved.
Show resolved Hide resolved
{
uint maxdist_x = maxdist;
uint maxdist_y = maxdist;

if (MapSizeX() > 256) maxdist_x *= MapSizeX() / 256;
if (MapSizeY() > 256) maxdist_y *= MapSizeY() / 256;

if (DistanceFromEdgeDir(tile, DIAGDIR_NE) < maxdist_x) return true;
if (DistanceFromEdgeDir(tile, DIAGDIR_NW) < maxdist_y) return true;
if (DistanceFromEdgeDir(tile, DIAGDIR_SW) < maxdist_x) return true;
if (DistanceFromEdgeDir(tile, DIAGDIR_SE) < maxdist_y) return true;

return false;
}

/**
* Check the conditions of #CHECK_REFINERY (Industry should be positioned near edge of the map).
* @param tile %Tile to perform the checking.
Expand All @@ -1226,7 +1249,8 @@ static CommandCost CheckNewIndustry_Forest(TileIndex tile)
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
{
if (_game_mode == GM_EDITOR) return CommandCost();
if (DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return CommandCost();

if (CheckScaledDistanceFromEdge(TILE_ADDXY(tile, 1, 1), _settings_game.game_creation.oil_refinery_limit)) return CommandCost();

return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
}
Expand All @@ -1241,8 +1265,9 @@ extern bool _ignore_restrictions;
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
{
if (_game_mode == GM_EDITOR && _ignore_restrictions) return CommandCost();

if (TileHeight(tile) == 0 &&
DistanceFromEdge(TILE_ADDXY(tile, 1, 1)) < _settings_game.game_creation.oil_refinery_limit) return CommandCost();
CheckScaledDistanceFromEdge(TILE_ADDXY(tile, 1, 1), _settings_game.game_creation.oil_refinery_limit)) return CommandCost();

return_cmd_error(STR_ERROR_CAN_ONLY_BE_POSITIONED);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lang/english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,8 @@ STR_CONFIG_SETTING_TERRAIN_TYPE :Terrain type: {
STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT :(TerraGenesis only) Hilliness of the landscape
STR_CONFIG_SETTING_INDUSTRY_DENSITY :Industry density: {STRING2}
STR_CONFIG_SETTING_INDUSTRY_DENSITY_HELPTEXT :Set how many industries should be generated and what level should be maintained during the game
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE :Maximum distance from edge for Oil refineries: {STRING2}
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT :Oil refineries are only constructed near the map border, that is at the coast for island maps
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE :Maximum distance from edge for Oil industries: {STRING2}
STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT :Limit for how far from the map border oil refineries and oil rigs can be constructed. On island maps this ensures they are near the coast. On maps larger than 256 tiles, this value is scaled up.
STR_CONFIG_SETTING_SNOWLINE_HEIGHT :Snow line height: {STRING2}
STR_CONFIG_SETTING_SNOWLINE_HEIGHT_HELPTEXT :Control at what height snow starts in sub-arctic landscape. Snow also affects industry generation and town growth requirements
STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN :Roughness of terrain: {STRING2}
Expand Down