Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [1.8.0] Compiling & Running on Arch Linux

[1.8.0] Compiling & Running on Arch Linux 2 months 3 weeks ago #6694

It's pretty easy, make a file called "PKGBUILD" with the following contents, then run "makepkg -si". After installing, you can start openttd by running "openttd" like usual. The packages "openttd-opengfx", "openttd-openmsx" and "openttd-opensfx" are necessary for graphics, music and sound, respectively.

Warning: Spoiler! [ Click to expand ]


EDIT: PS: Thank you, once again, BTPro devs for making this wonderful client.
The following user(s) said Thank You: ST2
  • gentz
  • Topic Author
  • Offline
  • Fresh BTPro Poster
  • Fresh BTPro Poster
  • Posts: 6
  • Thank you received: 5

Please Log in or Create an account to join the conversation.

Last edit: by gentz.

[1.8.0] Compiling & Running on Arch Linux 2 months 2 weeks ago #6699

I found that powerfunnding was broken, so I wrote this first patch bellow. Apply with:
patch -p1 < "../powerfundfix.diff"

I'm working on a smart leveler, which will continually retry to level your land for you. Patch for that is also includes bellow.
patch -p1 --ignore-whitespace < ../gentz-leveler-patch.diff
It's got a couple issues:
- If the highest/lowest tile can not be leveled (radar tower, bridge, road, nearby mountain, ect are in the way) it will keep trying to level that place.
- On servers, there is some sort of command throttling. This manifests in a delay to all your actions, including chatting. 300MS delay added.
- Command issuing delay means we don't see the new height of a tile till a couple calls latter. Causes wasted money, as we do unneeded terraforming operations.
- It will fallback to decreasing/increasing height one tile at a time. Optimizations could allow more, but meh.

The last two problems could probably fixed by putting my code in the write place. If you know where that right place is, please tell me.
  • gentz
  • Topic Author
  • Offline
  • Fresh BTPro Poster
  • Fresh BTPro Poster
  • Posts: 6
  • Thank you received: 5

Please Log in or Create an account to join the conversation.

Last edit: by gentz.

[1.8.0] Compiling & Running on Arch Linux 2 months 2 weeks ago #6700

Powerfund fix:
diff --git a/src/lang/english.txt b/lang/english.txt
index 4a8b4a1..e646b08 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -5221,7 +5221,5 @@ STR_TTE_STATION                                                 :{WHITE}{STRING}
 STR_LAND_AREA_INFORMATION_POP                                   :{BLACK}Population: {LTBLUE}{NUM}
 
-STR_CONFIG_SETTING_POWERFUND_MONEY                              :Powerfund minimum needed money for fund: {STRING2}
-STR_CONFIG_SETTING_POWERFUND_HOUSES                             :Maximum amount of houses to powerfund up to
 
 ######## Zoning toolbar
 
diff --git a/settings_type.h b/settings_type.h
index 6a84a11..4419e22 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -170,7 +170,5 @@ struct GUISettings {
 	bool   enable_extra_tooltips;            ///< enable extra tooltips when hovering over various elements
         uint8  cb_distance_check;                ///< zoning cb distance
-        uint32 powerfund_money;                  ///< minimum amount of money for powerfund to work
-        uint16 powerfund_houses;                 ///< powerfunding maximum houses limit
 
 	uint8  community;                        ///< chosen community nice=0, btpro=1
 	uint32  btpro_version;
index 568cfe8..a9e8d3a 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -836,8 +836,4 @@ static void DoRegularFunding(Town *t)
        bool fund_regularly = HasBit(t->fund_regularly, _local_company);
        bool do_powerfund = HasBit(t->do_powerfund, _local_company);
 
-       if (do_powerfund && (_settings_client.gui.powerfund_money > Company::Get(_local_company)->money ||
-                   _settings_client.gui.powerfund_houses < t->cache.num_houses)) {
-           do_powerfund = false;
-       }
 

Smart leveler v2:
diff --git a/findversion.sh b/findversion.sh
index 6d74d86..128665a 100755
--- a/findversion.sh
+++ b/findversion.sh
@@ -67,6 +67,9 @@ fi
 cd `dirname "$0"`
 ROOT_DIR=`pwd`
 
+	# We are an exported source bundle
+	cat $ROOT_DIR/.ottdrev
+	exit
 # Determine if we are using a modified version
 # Assume the dir is not modified
 MODIFIED="0"
diff --git a/src/command.cpp b/src/command.cpp
index 8936cfc..a8d7a5a 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -602,7 +602,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
 
 	if (!estimate_only && !only_sending && callback != NULL) {
 		callback(res, tile, p1, p2);
-	}
+    }
 
 	return res.Succeeded();
 }
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 1594bfb..ff97295 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -36,7 +36,12 @@
 #include "game/game.hpp"
 #include "goal_base.h"
 #include "story_base.h"
+#include "error.h"
 
+#include <algorithm>
+#include <chrono>
+
+#include "terraform_gui.h"
 #include "cargo_type.h"
 #include "table/strings.h"
 
@@ -273,6 +278,142 @@ void UpdateLandscapingLimits()
 		c->clear_limit     = min(c->clear_limit     + _settings_game.construction.clear_per_64k_frames,     (uint32)_settings_game.construction.clear_frame_burst << 16);
 		c->tree_limit      = min(c->tree_limit      + _settings_game.construction.tree_per_64k_frames,      (uint32)_settings_game.construction.tree_frame_burst << 16);
 	}
+
+    CompanyByte old = _current_company;
+    _current_company = _local_company;
+
+	const Company *c2 = Company::GetIfValid(_current_company);
+    if (c2 == NULL) {
+        // game is still loading, or we don't got a corp
+        _current_company = old;
+        return;
+    }
+
+	if ((int64)c2->money < 10000) {
+        // Cancel since we lack enough money.
+        if (!incomplete_terraforms.empty())
+        {
+            ShowErrorMessage(
+                STR_ERROR_CANCEL_LEVEL_LAND_HERE,
+                STR_ERROR_CANCEL_LEVEL_LAND_HERE_MONETARY,
+                WL_INFO,
+                TileX(incomplete_terraforms[0].tile) * TILE_SIZE,
+                TileY(incomplete_terraforms[0].tile) * TILE_SIZE
+            );
+            incomplete_terraforms.clear();
+        }
+        _current_company = old;
+        return;
+    }
+
+    static auto last_time = std::chrono::system_clock::now();
+    auto now_time = std::chrono::system_clock::now();
+    auto elapsed_time = now_time - last_time;
+    if (elapsed_time < std::chrono::milliseconds(300)) {
+        // delay
+        _current_company = old;
+        return;
+    }
+
+    std::swap(now_time, last_time);
+
+    auto in_ter = incomplete_terraforms;
+    for (auto& st_data: in_ter) {
+    	uint tar_h = TileHeight(st_data.p1);
+
+        TileIterator *iter = HasBit(st_data.p2, 0)
+            ? (TileIterator *)new DiagonalTileIterator(st_data.tile, st_data.p1)
+            : new OrthogonalTileIterator(st_data.tile, st_data.p1);
+
+        uint lowest_h = tar_h;
+        uint highest_h = tar_h;
+        TileIndex lowest_t = st_data.p1;
+        TileIndex highest_t = st_data.p1;
+
+        for (; *iter != INVALID_TILE; ++(*iter)) {
+            TileIndex tile = *iter;
+    	    uint cur_h = TileHeight(tile);
+            if (cur_h < lowest_h) {
+                lowest_t = tile;
+                lowest_h = cur_h;
+            }
+            if (cur_h > highest_h) {
+                highest_t = tile;
+                highest_h = cur_h;
+            }
+        }
+
+        if (lowest_h == tar_h && highest_h == tar_h) {
+            incomplete_terraforms.erase(
+                std::remove_if(
+                    incomplete_terraforms.begin(), incomplete_terraforms.end(),
+                    [&](const SmartTerraformData& st_data2) {
+                        return st_data.tile == st_data2.tile && st_data.p1 == st_data2.p1 && st_data.p2 == st_data2.p2;
+                    }
+                ), incomplete_terraforms.end()
+            );
+        }
+
+        if (lowest_h < tar_h) {
+//            while(lowest_h < tar_h) {
+                DoCommandP(
+                    lowest_t,
+                    lowest_t,
+                    LM_RAISE << 1,
+                    CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_RAISE_LAND_HERE),
+                    CcTerraform
+                );
+                DEBUG(misc, 0, "Gentz C - terra up, l %u t %u", lowest_h, tar_h);
+                ++lowest_h;
+//            }
+        }
+
+        DEBUG(misc, 0, "Gentz C1 - terra done, l %u t %u", lowest_h, tar_h);
+
+        if (highest_h > tar_h) {
+//            while (highest_h > tar_h) {
+                DEBUG(misc, 0, "Gentz C - terra down, l %u t %u", highest_h, tar_h);
+                DoCommandP(
+                    highest_t,
+                    highest_t,
+                    LM_LOWER << 1,
+                    CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LOWER_LAND_HERE),
+                    CcTerraform
+                );
+                --highest_h;
+//            }
+        }
+
+        DEBUG(misc, 0, "Gentz C2 - terra done, l %u t %u", highest_h, tar_h);
+    }
+
+    in_ter = incomplete_terraforms;
+    for (auto& st_data: in_ter) {
+        DEBUG(misc, 0, "Gentz C - here");
+		DoCommandP(st_data.tile, st_data.p1, st_data.p2, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
+        st_data.try_num += 1;
+    }
+
+    incomplete_terraforms.erase(
+        std::remove_if(
+            incomplete_terraforms.begin(), incomplete_terraforms.end(),
+            [&](const SmartTerraformData& st_data) {
+                if (st_data.try_num == 5000)
+                {
+                    ShowErrorMessage(
+                        STR_ERROR_CANCEL_LEVEL_LAND_HERE,
+                        STR_ERROR_CANCEL_LEVEL_LAND_HERE_TRY_LIMIT,
+                        WL_INFO,
+                        TileX(st_data.tile) * TILE_SIZE,
+                        TileY(st_data.tile) * TILE_SIZE
+                    );
+                    return true;
+                }
+                return false;
+            }
+        ), incomplete_terraforms.end()
+    );
+    _current_company = old;
 }
 
 /**
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 588140c..1909500 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2511,6 +2511,8 @@ STR_LANDSCAPING_TOOLBAR                                         :{WHITE}Landscap
 STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND                  :{BLACK}Lower a corner of land. Dragging lowers the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND                  :{BLACK}Raise a corner of land. Dragging raises the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_LEVEL_LAND_TOOLTIP                              :{BLACK}Level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_SMART_LEVEL_LAND_TOOLTIP                              :{BLACK}Smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_CANCEL_SMART_LEVEL_LAND_TOOLTIP                 :{BLACK}Cancel smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND                           :{BLACK}Purchase land for future use. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_RULER_TOOL                              :{BLACK}Use a virtual ruler to measure distance and height
 
@@ -4212,6 +4214,9 @@ STR_ERROR_BRIBE_FAILED                                          :{WHITE}Your att
 STR_ERROR_CAN_T_RAISE_LAND_HERE                                 :{WHITE}Can't raise land here...
 STR_ERROR_CAN_T_LOWER_LAND_HERE                                 :{WHITE}Can't lower land here...
 STR_ERROR_CAN_T_LEVEL_LAND_HERE                                 :{WHITE}Can't level land here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE                                :{WHITE}Canceled level lend here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_MONETARY                       :{WHITE}... Bellow 10K limit.
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_TRY_LIMIT                      :{WHITE}... reached try limit.
 STR_ERROR_EXCAVATION_WOULD_DAMAGE                               :{WHITE}Excavation would damage tunnel
 STR_ERROR_ALREADY_AT_SEA_LEVEL                                  :{WHITE}... already at sea level
 STR_ERROR_TOO_HIGH                                              :{WHITE}... too high
diff --git a/src/lang/english_AU.txt b/src/lang/english_AU.txt
index d516962..21b6e52 100644
--- a/src/lang/english_AU.txt
+++ b/src/lang/english_AU.txt
@@ -2449,6 +2449,8 @@ STR_LANDSCAPING_TOOLBAR                                         :{WHITE}Landscap
 STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND                  :{BLACK}Lower a corner of land. Dragging lowers the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND                  :{BLACK}Raise a corner of land. Dragging raises the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_LEVEL_LAND_TOOLTIP                              :{BLACK}Level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_SMART_LEVEL_LAND_TOOLTIP                              :{BLACK}Smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_CANCEL_SMART_LEVEL_LAND_TOOLTIP                 :{BLACK}Cancel smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND                           :{BLACK}Purchase land for future use. Shift toggles building/showing cost estimate
 
 # Object construction window
@@ -4083,6 +4085,9 @@ STR_ERROR_BRIBE_FAILED                                          :{WHITE}Your att
 STR_ERROR_CAN_T_RAISE_LAND_HERE                                 :{WHITE}Can't raise land here...
 STR_ERROR_CAN_T_LOWER_LAND_HERE                                 :{WHITE}Can't lower land here...
 STR_ERROR_CAN_T_LEVEL_LAND_HERE                                 :{WHITE}Can't level land here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE                                :{WHITE}Canceled level lend here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_MONETARY                       :{WHITE}... Bellow 10K limit.
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_TRY_LIMIT                      :{WHITE}... reached try limit.
 STR_ERROR_EXCAVATION_WOULD_DAMAGE                               :{WHITE}Excavation would damage tunnel
 STR_ERROR_ALREADY_AT_SEA_LEVEL                                  :{WHITE}... already at sea level
 STR_ERROR_TOO_HIGH                                              :{WHITE}... too high
diff --git a/src/lang/english_US.txt b/src/lang/english_US.txt
index 1f38c3a..9c4223e 100644
--- a/src/lang/english_US.txt
+++ b/src/lang/english_US.txt
@@ -2477,6 +2477,8 @@ STR_LANDSCAPING_TOOLBAR                                         :{WHITE}Landscap
 STR_LANDSCAPING_TOOLTIP_LOWER_A_CORNER_OF_LAND                  :{BLACK}Lower a corner of land. Dragging lowers the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND                  :{BLACK}Raise a corner of land. Dragging raises the first selected corner and levels the selected area to the new corner height. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_LEVEL_LAND_TOOLTIP                              :{BLACK}Level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_SMART_LEVEL_LAND_TOOLTIP                        :{BLACK}Smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
+STR_LANDSCAPING_CANCEL_SMART_LEVEL_LAND_TOOLTIP                 :{BLACK}Cancel smartly level an area of land to the height of the first selected corner. Ctrl selects the area diagonally. Shift toggles building/showing cost estimate
 STR_LANDSCAPING_TOOLTIP_PURCHASE_LAND                           :{BLACK}Purchase land for future use. Shift toggles building/showing cost estimate
 
 # Object construction window
@@ -4151,6 +4153,9 @@ STR_ERROR_BRIBE_FAILED                                          :{WHITE}Your att
 STR_ERROR_CAN_T_RAISE_LAND_HERE                                 :{WHITE}Can't raise land here...
 STR_ERROR_CAN_T_LOWER_LAND_HERE                                 :{WHITE}Can't lower land here...
 STR_ERROR_CAN_T_LEVEL_LAND_HERE                                 :{WHITE}Can't level land here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE                                :{WHITE}Canceled level lend here...
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_MONETARY                       :{WHITE}... Bellow 10K limit.
+STR_ERROR_CANCEL_LEVEL_LAND_HERE_TRY_LIMIT                      :{WHITE}... reached try limit.
 STR_ERROR_EXCAVATION_WOULD_DAMAGE                               :{WHITE}Excavation would damage tunnel
 STR_ERROR_ALREADY_AT_SEA_LEVEL                                  :{WHITE}... already at sea level
 STR_ERROR_TOO_HIGH                                              :{WHITE}... too high
diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq
index aca1944..32ceaf1 100644
--- a/src/script/api/game/game_window.hpp.sq
+++ b/src/script/api/game/game_window.hpp.sq
@@ -1124,6 +1124,8 @@ void SQGSWindow_Register(Squirrel *engine)
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_LOWER_LAND,                         "WID_TT_LOWER_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_RAISE_LAND,                         "WID_TT_RAISE_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_LEVEL_LAND,                         "WID_TT_LEVEL_LAND");
+	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_SMART_LEVEL_LAND,                   "WID_TT_SMART_LEVEL_LAND");
+	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_CANCEL_SMART_LEVEL_LAND,             "WID_TT_CANCEL_SMART_LEVEL_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_DEMOLISH,                           "WID_TT_DEMOLISH");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_BUY_LAND,                           "WID_TT_BUY_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TT_PLANT_TREES,                        "WID_TT_PLANT_TREES");
@@ -1137,6 +1139,8 @@ void SQGSWindow_Register(Squirrel *engine)
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_LOWER_LAND,                        "WID_ETT_LOWER_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_RAISE_LAND,                        "WID_ETT_RAISE_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_LEVEL_LAND,                        "WID_ETT_LEVEL_LAND");
+	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_SMART_LEVEL_LAND,                  "WID_ETT_SMART_LEVEL_LAND");
+	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_CANCEL_SMART_LEVEL_LAND,           "WID_ETT_CANCEL_SMART_LEVEL_LAND");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_ROCKS,                       "WID_ETT_PLACE_ROCKS");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_DESERT,                      "WID_ETT_PLACE_DESERT");
 	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_ETT_PLACE_OBJECT,                      "WID_ETT_PLACE_OBJECT");
diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp
index 4ae105a..bd1eb47 100644
--- a/src/script/api/script_window.hpp
+++ b/src/script/api/script_window.hpp
@@ -2311,6 +2311,8 @@ public:
 		WID_TT_LOWER_LAND                            = ::WID_TT_LOWER_LAND,                            ///< Lower land button.
 		WID_TT_RAISE_LAND                            = ::WID_TT_RAISE_LAND,                            ///< Raise land button.
 		WID_TT_LEVEL_LAND                            = ::WID_TT_LEVEL_LAND,                            ///< Level land button.
+		WID_TT_SMART_LEVEL_LAND                      = ::WID_TT_SMART_LEVEL_LAND,                      ///< Smart level land button.
+		WID_TT_CANCEL_SMART_LEVEL_LAND                      = ::WID_TT_CANCEL_SMART_LEVEL_LAND,        ///< Cancel smart level land button.
 		WID_TT_DEMOLISH                              = ::WID_TT_DEMOLISH,                              ///< Demolish aka dynamite button.
 		WID_TT_BUY_LAND                              = ::WID_TT_BUY_LAND,                              ///< Buy land button.
 		WID_TT_PLANT_TREES                           = ::WID_TT_PLANT_TREES,                           ///< Plant trees button (note: opens separate window, no place-push-button).
@@ -2328,6 +2330,8 @@ public:
 		WID_ETT_LOWER_LAND                           = ::WID_ETT_LOWER_LAND,                           ///< Lower land button.
 		WID_ETT_RAISE_LAND                           = ::WID_ETT_RAISE_LAND,                           ///< Raise land button.
 		WID_ETT_LEVEL_LAND                           = ::WID_ETT_LEVEL_LAND,                           ///< Level land button.
+		WID_ETT_SMART_LEVEL_LAND                     = ::WID_ETT_SMART_LEVEL_LAND,                     ///< Smart level land button.
+		WID_ETT_CANCEL_SMART_LEVEL_LAND              = ::WID_ETT_CANCEL_SMART_LEVEL_LAND,              ///< Cancel smart level land button.
 		WID_ETT_PLACE_ROCKS                          = ::WID_ETT_PLACE_ROCKS,                          ///< Place rocks button.
 		WID_ETT_PLACE_DESERT                         = ::WID_ETT_PLACE_DESERT,                         ///< Place desert button (in tropical climate).
 		WID_ETT_PLACE_OBJECT                         = ::WID_ETT_PLACE_OBJECT,                         ///< Place transmitter button.
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index ca3f93e..eb525ba 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -17,7 +17,6 @@
 #include "window_gui.h"
 #include "window_func.h"
 #include "viewport_func.h"
-#include "command_func.h"
 #include "signs_func.h"
 #include "sound_func.h"
 #include "base_station_base.h"
@@ -41,6 +40,8 @@
 
 #include "safeguards.h"
 
+#include <algorithm>
+
 void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
 {
 	if (result.Succeeded()) {
@@ -51,6 +52,7 @@ void CcTerraform(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2
 	}
 }
 
+std::vector<SmartTerraformData> incomplete_terraforms;
 
 /** Scenario editor command that generates desert areas */
 static void GenerateDesertArea(TileIndex end, TileIndex start)
@@ -128,6 +130,19 @@ bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_t
 		case DDSP_LEVEL_AREA:
 			DoCommandP(end_tile, start_tile, LM_LEVEL << 1 | (_ctrl_pressed ? 1 : 0), CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
 			break;
+		case DDSP_SMART_LEVEL_AREA:
+			DoCommandP(end_tile, start_tile, LM_LEVEL << 1 | (_ctrl_pressed ? 1 : 0) | 0b1000, CMD_LEVEL_LAND | CMD_MSG(STR_ERROR_CAN_T_LEVEL_LAND_HERE), CcTerraform);
+            SmartTerraformData st_data;
+            st_data.tile = end_tile;
+            st_data.p1 = start_tile;
+            st_data.p2 = LM_LEVEL << 1 | (_ctrl_pressed ? 1 : 0) | 0b1000;
+            st_data.try_num = 0;
+            incomplete_terraforms.push_back(st_data);
+
+			break;
+		case DDSP_CANCEL_SMART_LEVEL_AREA:
+            incomplete_terraforms.clear();
+            break;
 		case DDSP_CREATE_ROCKS:
 			GenerateRockyArea(end_tile, start_tile);
 			break;
@@ -198,6 +213,16 @@ struct TerraformToolbarWindow : Window {
 				this->last_user_action = widget;
 				break;
 
+			case WID_TT_SMART_LEVEL_LAND: // Smart level land button
+				HandlePlacePushButton(this, WID_TT_SMART_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
+				this->last_user_action = widget;
+				break;
+
+			case WID_TT_CANCEL_SMART_LEVEL_LAND: // Cancel smart level land button
+				HandlePlacePushButton(this, WID_TT_CANCEL_SMART_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
+				this->last_user_action = widget;
+				break;
+
 			case WID_TT_DEMOLISH: // Demolish aka dynamite button
 				HandlePlacePushButton(this, WID_TT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
 				this->last_user_action = widget;
@@ -245,6 +270,14 @@ struct TerraformToolbarWindow : Window {
 				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
 				break;
 
+			case WID_TT_SMART_LEVEL_LAND: // Smart level land button
+				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_SMART_LEVEL_AREA);
+				break;
+
+			case WID_TT_CANCEL_SMART_LEVEL_LAND: // Cancel smart level land button
+				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CANCEL_SMART_LEVEL_AREA);
+				break;
+
 			case WID_TT_DEMOLISH: // Demolish aka dynamite button
 				PlaceProc_DemolishArea(tile);
 				break;
@@ -286,6 +319,8 @@ struct TerraformToolbarWindow : Window {
 				case DDSP_RAISE_AND_LEVEL_AREA:
 				case DDSP_LOWER_AND_LEVEL_AREA:
 				case DDSP_LEVEL_AREA:
+				case DDSP_SMART_LEVEL_AREA:
+				case DDSP_CANCEL_SMART_LEVEL_AREA:
 					GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
 					break;
 				case DDSP_MEASURE:
@@ -319,7 +354,7 @@ static EventState TerraformToolbarGlobalHotkeys(int hotkey)
 static Hotkey terraform_hotkeys[] = {
 	Hotkey('Q' | WKC_GLOBAL_HOTKEY, "lower", WID_TT_LOWER_LAND),
 	Hotkey('W' | WKC_GLOBAL_HOTKEY, "raise", WID_TT_RAISE_LAND),
-	Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_LEVEL_LAND),
+	Hotkey('E' | WKC_GLOBAL_HOTKEY, "level", WID_TT_SMART_LEVEL_LAND),
 	Hotkey('D' | WKC_GLOBAL_HOTKEY, "dynamite", WID_TT_DEMOLISH),
 	Hotkey('U', "buyland", WID_TT_BUY_LAND),
 	Hotkey('I', "trees", WID_TT_PLANT_TREES),
@@ -342,6 +377,10 @@ static const NWidgetPart _nested_terraform_widgets[] = {
 								SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
 		NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_LEVEL_LAND), SetMinimalSize(22, 22),
 								SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
+		NWidget(WWT_IMGBTN, COLOUR_GREEN, WID_TT_SMART_LEVEL_LAND), SetMinimalSize(22, 22),
+								SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_SMART_LEVEL_LAND_TOOLTIP),
+		NWidget(WWT_IMGBTN, COLOUR_GREEN, WID_TT_CANCEL_SMART_LEVEL_LAND), SetMinimalSize(22, 22),
+								SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_LANDSCAPING_CANCEL_SMART_LEVEL_LAND_TOOLTIP),
 
 		NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), EndContainer(),
 
@@ -478,6 +517,10 @@ static const NWidgetPart _nested_scen_edit_land_gen_widgets[] = {
 										SetFill(0, 1), SetDataTip(SPR_IMG_TERRAFORM_UP, STR_LANDSCAPING_TOOLTIP_RAISE_A_CORNER_OF_LAND),
 			NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_LEVEL_LAND), SetMinimalSize(22, 22),
 										SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_LEVEL_LAND_TOOLTIP),
+			NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_SMART_LEVEL_LAND), SetMinimalSize(22, 22),
+										SetFill(0, 1), SetDataTip(SPR_IMG_LEVEL_LAND, STR_LANDSCAPING_SMART_LEVEL_LAND_TOOLTIP),
+			NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_CANCEL_SMART_LEVEL_LAND), SetMinimalSize(22, 22),
+										SetFill(0, 1), SetDataTip(SPR_IMG_DYNAMITE, STR_LANDSCAPING_CANCEL_SMART_LEVEL_LAND_TOOLTIP),
 			NWidget(WWT_IMGBTN, COLOUR_GREY, WID_ETT_PLACE_ROCKS), SetMinimalSize(22, 22),
 										SetFill(0, 1), SetDataTip(SPR_IMG_ROCKS, STR_TERRAFORM_TOOLTIP_PLACE_ROCKY_AREAS_ON_LANDSCAPE),
 			NWidget(NWID_SELECTION, INVALID_COLOUR, WID_ETT_SHOW_PLACE_DESERT),
@@ -617,6 +660,16 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
 				this->last_user_action = widget;
 				break;
 
+			case WID_ETT_SMART_LEVEL_LAND: // Smart level land button
+				HandlePlacePushButton(this, WID_ETT_SMART_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
+				this->last_user_action = widget;
+				break;
+
+			case WID_ETT_CANCEL_SMART_LEVEL_LAND: // Cancel smart level land button
+				HandlePlacePushButton(this, WID_ETT_CANCEL_SMART_LEVEL_LAND, SPR_CURSOR_LEVEL_LAND, HT_POINT | HT_DIAGONAL);
+				this->last_user_action = widget;
+				break;
+
 			case WID_ETT_PLACE_ROCKS: // Place rocks button
 				HandlePlacePushButton(this, WID_ETT_PLACE_ROCKS, SPR_CURSOR_ROCKY_AREA, HT_RECT);
 				this->last_user_action = widget;
@@ -688,6 +741,14 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
 				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_LEVEL_AREA);
 				break;
 
+			case WID_ETT_SMART_LEVEL_LAND: // Smart level land button
+				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_SMART_LEVEL_AREA);
+				break;
+
+			case WID_ETT_CANCEL_SMART_LEVEL_LAND: // Cancel smart level land button
+				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CANCEL_SMART_LEVEL_AREA);
+				break;
+
 			case WID_ETT_PLACE_ROCKS: // Place rocks button
 				VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_ROCKS);
 				break;
@@ -715,6 +776,8 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
 				case DDSP_RAISE_AND_LEVEL_AREA:
 				case DDSP_LOWER_AND_LEVEL_AREA:
 				case DDSP_LEVEL_AREA:
+				case DDSP_SMART_LEVEL_AREA:
+				case DDSP_CANCEL_SMART_LEVEL_AREA:
 				case DDSP_DEMOLISH_AREA:
 					GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
 					break;
diff --git a/src/terraform_gui.h b/src/terraform_gui.h
index 7d2de32..bc49df9 100644
--- a/src/terraform_gui.h
+++ b/src/terraform_gui.h
@@ -13,8 +13,21 @@
 #define TERRAFORM_GUI_H
 
 #include "window_type.h"
+#include "command_func.h"
+#include "debug.h"
+
+#include <vector>
 
 Window *ShowTerraformToolbar(Window *link = NULL);
 Window *ShowEditorTerraformToolbar();
 
+struct SmartTerraformData {
+	TileIndex tile;
+	uint32 p1;
+	uint32 p2;
+    int try_num;
+};
+
+extern std::vector<SmartTerraformData> incomplete_terraforms;
+
 #endif /* TERRAFORM_GUI_H */
diff --git a/src/viewport_type.h b/src/viewport_type.h
index 7979155..528637d 100644
--- a/src/viewport_type.h
+++ b/src/viewport_type.h
@@ -97,33 +97,35 @@ DECLARE_ENUM_AS_BIT_SET(ViewportPlaceMethod)
  * you've selected it.
  */
 enum ViewportDragDropSelectionProcess {
-	DDSP_DEMOLISH_AREA,        ///< Clear area
-	DDSP_RAISE_AND_LEVEL_AREA, ///< Raise / level area
-	DDSP_LOWER_AND_LEVEL_AREA, ///< Lower / level area
-	DDSP_LEVEL_AREA,           ///< Level area
-	DDSP_CREATE_DESERT,        ///< Fill area with desert
-	DDSP_CREATE_ROCKS,         ///< Fill area with rocks
-	DDSP_CREATE_WATER,         ///< Create a canal
-	DDSP_CREATE_RIVER,         ///< Create rivers
-	DDSP_PLANT_TREES,          ///< Plant trees
-	DDSP_BUILD_BRIDGE,         ///< Bridge placement
-	DDSP_MEASURE,              ///< Measurement tool
+	DDSP_DEMOLISH_AREA,           ///< Clear area
+	DDSP_RAISE_AND_LEVEL_AREA,    ///< Raise / level area
+	DDSP_LOWER_AND_LEVEL_AREA,    ///< Lower / level area
+	DDSP_LEVEL_AREA,              ///< Level area
+	DDSP_SMART_LEVEL_AREA,        ///< Smart level area
+	DDSP_CANCEL_SMART_LEVEL_AREA, ///< Cancel smart level area
+	DDSP_CREATE_DESERT,           ///< Fill area with desert
+	DDSP_CREATE_ROCKS,            ///< Fill area with rocks
+	DDSP_CREATE_WATER,            ///< Create a canal
+	DDSP_CREATE_RIVER,            ///< Create rivers
+	DDSP_PLANT_TREES,             ///< Plant trees
+	DDSP_BUILD_BRIDGE,            ///< Bridge placement
+	DDSP_MEASURE,                 ///< Measurement tool
 
 	/* Rail specific actions */   
-	DDSP_PLACE_RAIL,           ///< Rail placement
-	DDSP_BUILD_SIGNALS,        ///< Signal placement
-	DDSP_BUILD_STATION,        ///< Station placement
-	DDSP_REMOVE_STATION,       ///< Station removal
-	DDSP_CONVERT_RAIL,         ///< Rail conversion
+	DDSP_PLACE_RAIL,              ///< Rail placement
+	DDSP_BUILD_SIGNALS,           ///< Signal placement
+	DDSP_BUILD_STATION,           ///< Station placement
+	DDSP_REMOVE_STATION,          ///< Station removal
+	DDSP_CONVERT_RAIL,            ///< Rail conversion
 
 	/* Road specific actions */   
-	DDSP_PLACE_ROAD_X_DIR,     ///< Road placement (X axis)
-	DDSP_PLACE_ROAD_Y_DIR,     ///< Road placement (Y axis)
-	DDSP_PLACE_AUTOROAD,       ///< Road placement (auto)
-	DDSP_BUILD_BUSSTOP,        ///< Road stop placement (buses)
-	DDSP_BUILD_TRUCKSTOP,      ///< Road stop placement (trucks)
-	DDSP_REMOVE_BUSSTOP,       ///< Road stop removal (buses)
-	DDSP_REMOVE_TRUCKSTOP,     ///< Road stop removal (trucks)
+	DDSP_PLACE_ROAD_X_DIR,        ///< Road placement (X axis)
+	DDSP_PLACE_ROAD_Y_DIR,        ///< Road placement (Y axis)
+	DDSP_PLACE_AUTOROAD,          ///< Road placement (auto)
+	DDSP_BUILD_BUSSTOP,           ///< Road stop placement (buses)
+	DDSP_BUILD_TRUCKSTOP,         ///< Road stop placement (trucks)
+	DDSP_REMOVE_BUSSTOP,          ///< Road stop removal (buses)
+	DDSP_REMOVE_TRUCKSTOP,        ///< Road stop removal (trucks)
 };
 
 #endif /* VIEWPORT_TYPE_H */
diff --git a/src/widgets/terraform_widget.h b/src/widgets/terraform_widget.h
index e56b389..3fa816a 100644
--- a/src/widgets/terraform_widget.h
+++ b/src/widgets/terraform_widget.h
@@ -19,6 +19,8 @@ enum TerraformToolbarWidgets {
 	WID_TT_LOWER_LAND = WID_TT_BUTTONS_START, ///< Lower land button.
 	WID_TT_RAISE_LAND,                        ///< Raise land button.
 	WID_TT_LEVEL_LAND,                        ///< Level land button.
+	WID_TT_SMART_LEVEL_LAND,                  ///< Smart Level land button.
+	WID_TT_CANCEL_SMART_LEVEL_LAND,           ///< Cancle smart level land button.
 	WID_TT_DEMOLISH,                          ///< Demolish aka dynamite button.
 	WID_TT_BUY_LAND,                          ///< Buy land button.
 	WID_TT_PLANT_TREES,                       ///< Plant trees button (note: opens separate window, no place-push-button).
@@ -37,6 +39,8 @@ enum EditorTerraformToolbarWidgets {
 	WID_ETT_LOWER_LAND,                          ///< Lower land button.
 	WID_ETT_RAISE_LAND,                          ///< Raise land button.
 	WID_ETT_LEVEL_LAND,                          ///< Level land button.
+	WID_ETT_SMART_LEVEL_LAND,                    ///< Smart level land button.
+	WID_ETT_CANCEL_SMART_LEVEL_LAND,             ///< Cancel smart level land button.
 	WID_ETT_PLACE_ROCKS,                         ///< Place rocks button.
 	WID_ETT_PLACE_DESERT,                        ///< Place desert button (in tropical climate).
 	WID_ETT_PLACE_OBJECT,                        ///< Place transmitter button.

Changes:
v2:
Only issue one command per z level. Decreases chance of "throttling" on large mountains.
The following user(s) said Thank You: Frank
  • gentz
  • Topic Author
  • Offline
  • Fresh BTPro Poster
  • Fresh BTPro Poster
  • Posts: 6
  • Thank you received: 5

Please Log in or Create an account to join the conversation.

Last edit: by gentz.
  • Page:
  • 1
Time to create page: 0.084 seconds
Best hosting deal on hostgator coupon or play poker on party poker
Copyright 2018 [1.8.0] Compiling & Running on Arch Linux - BTPro - OpenTTD Community.