summaryrefslogtreecommitdiff
path: root/src/water_cmd.cpp
diff options
context:
space:
mode:
authorTyler Trahan <tyler@tylertrahan.com>2021-04-02 04:13:27 -0400
committerGitHub <noreply@github.com>2021-04-02 10:13:27 +0200
commitadb9fa3b36cf1031591363dcd3b6f591fd485ab0 (patch)
treec4a60aac18320d45c01629f348b8471e11379bce /src/water_cmd.cpp
parentbde5396d118371c16db57cfd2ad0b15e4e606cd3 (diff)
downloadopenttd-adb9fa3b36cf1031591363dcd3b6f591fd485ab0.tar.xz
Feature: Press ctrl to build diagonal rivers in Scenario Editor (#8880)
Diffstat (limited to 'src/water_cmd.cpp')
-rw-r--r--src/water_cmd.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp
index 6a3b73065..731954c2e 100644
--- a/src/water_cmd.cpp
+++ b/src/water_cmd.cpp
@@ -437,7 +437,9 @@ bool RiverModifyDesertZone(TileIndex tile, void *)
* @param tile end tile of stretch-dragging
* @param flags type of operation
* @param p1 start tile of stretch-dragging
- * @param p2 waterclass to build. sea and river can only be built in scenario editor
+ * @param p2 various bitstuffed data
+ * bits 0-1: waterclass to build. sea and river can only be built in scenario editor
+ * bit 2: Whether to use the Orthogonal (0) or Diagonal (1) iterator.
* @param text unused
* @return the cost of this operation or an error
*/
@@ -449,13 +451,23 @@ CommandCost CmdBuildCanal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Outside of the editor you can only build canals, not oceans */
if (wc != WATER_CLASS_CANAL && _game_mode != GM_EDITOR) return CMD_ERROR;
- TileArea ta(tile, p1);
-
/* Outside the editor you can only drag canals, and not areas */
- if (_game_mode != GM_EDITOR && ta.w != 1 && ta.h != 1) return CMD_ERROR;
+ if (_game_mode != GM_EDITOR) {
+ TileArea ta(tile, p1);
+ if (ta.w != 1 && ta.h != 1) return CMD_ERROR;
+ }
CommandCost cost(EXPENSES_CONSTRUCTION);
- TILE_AREA_LOOP(tile, ta) {
+
+ std::unique_ptr<TileIterator> iter;
+ if (HasBit(p2, 2)) {
+ iter = std::make_unique<DiagonalTileIterator>(tile, p1);
+ } else {
+ iter = std::make_unique<OrthogonalTileIterator>(tile, p1);
+ }
+
+ for (; *iter != INVALID_TILE; ++(*iter)) {
+ TileIndex tile = *iter;
CommandCost ret;
Slope slope = GetTileSlope(tile);