summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2019-04-15 18:06:25 +0200
committerCharles Pigott <charlespigott@googlemail.com>2019-08-17 22:02:22 +0100
commit5feb06e3f3495b1ee5dde4387b6b491c9f72f859 (patch)
treea316cc5938beee7ab9e1fec16f74035b87c94170 /src/industry_cmd.cpp
parentb870596f153c17d9aa915ca67b8f6414d73cb31f (diff)
downloadopenttd-5feb06e3f3495b1ee5dde4387b6b491c9f72f859.tar.xz
Add: Scale oil refinery edge distance up by map size
Also scales oil rig distance up, since they use the same algorithm.
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 4e4ff5c82..38edc0835 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1226,6 +1226,29 @@ static CommandCost CheckNewIndustry_Forest(TileIndex tile)
}
/**
+ * 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)
+{
+ 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.
* @return Succeeded or failed command.
@@ -1233,7 +1256,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);
}
@@ -1248,8 +1272,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);
}