summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp3
-rw-r--r--src/command_type.h1
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/town_cmd.cpp44
-rw-r--r--src/town_gui.cpp10
5 files changed, 39 insertions, 20 deletions
diff --git a/src/command.cpp b/src/command.cpp
index ab5d29764..b24745bd4 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -134,9 +134,9 @@ CommandProc CmdSellShareInCompany;
CommandProc CmdBuyCompany;
CommandProc CmdFoundTown;
-
CommandProc CmdRenameTown;
CommandProc CmdDoTownAction;
+CommandProc CmdExpandTown;
CommandProc CmdChangeSetting;
CommandProc CmdChangeCompanySetting;
@@ -288,6 +288,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdFoundTown, CMD_NO_TEST), // CMD_FOUND_TOWN; founding random town can fail only in exec run
DEF_CMD(CmdRenameTown, CMD_SERVER), // CMD_RENAME_TOWN
DEF_CMD(CmdDoTownAction, 0), // CMD_DO_TOWN_ACTION
+ DEF_CMD(CmdExpandTown, CMD_OFFLINE), // CMD_EXPAND_TOWN
DEF_CMD(CmdSellShip, 0), // CMD_SELL_SHIP
DEF_CMD(CmdBuildShip, 0), // CMD_BUILD_SHIP
diff --git a/src/command_type.h b/src/command_type.h
index 19132a27f..8f74d6e61 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -235,6 +235,7 @@ enum Commands {
CMD_FOUND_TOWN, ///< found a town
CMD_RENAME_TOWN, ///< rename a town
CMD_DO_TOWN_ACTION, ///< do a action from the town detail window (like advertises or bribe)
+ CMD_EXPAND_TOWN, ///< expand a town
CMD_SELL_SHIP, ///< sell a ship
CMD_BUILD_SHIP, ///< build a new ship
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 4a8c00adf..c2bc3f748 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3447,6 +3447,7 @@ STR_ERROR_PROTECTED :{WHITE}This com
STR_ERROR_CAN_T_GENERATE_TOWN :{WHITE}Can't build any towns
STR_ERROR_CAN_T_RENAME_TOWN :{WHITE}Can't rename town...
STR_ERROR_CAN_T_FOUND_TOWN_HERE :{WHITE}Can't found town here...
+STR_ERROR_CAN_T_EXPAND_TOWN :{WHITE}Can't expand town...
STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB :{WHITE}... too close to edge of map
STR_ERROR_TOO_CLOSE_TO_ANOTHER_TOWN :{WHITE}... too close to another town
STR_ERROR_TOO_MANY_TOWNS :{WHITE}... too many towns
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index e64951bb1..702de3fc6 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2315,29 +2315,37 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return CommandCost();
}
-/** Called from GUI */
-void ExpandTown(Town *t)
+/**
+ * Expand a town (scenario editor only).
+ * @param tile Unused.
+ * @param flags Type of operation.
+ * @param p1 Town ID to expand.
+ * @param p2 Unused.
+ * @param text Unused.
+ * @return Empty cost or an error.
+ */
+CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- /* Warn the users if towns are not allowed to build roads,
- * but do this only onces per openttd run. */
- static bool warned_no_roads = false;
- if (!_settings_game.economy.allow_town_roads && !warned_no_roads) {
- ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING);
- warned_no_roads = true;
- }
+ if (_game_mode != GM_EDITOR) return CMD_ERROR;
+ Town *t = Town::GetIfValid(p1);
+ if (t == NULL) return CMD_ERROR;
- /* The more houses, the faster we grow */
- uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
- t->num_houses += amount;
- UpdateTownRadius(t);
+ if (flags & DC_EXEC) {
+ /* The more houses, the faster we grow */
+ uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
+ t->num_houses += amount;
+ UpdateTownRadius(t);
- uint n = amount * 10;
- do GrowTown(t); while (--n);
+ uint n = amount * 10;
+ do GrowTown(t); while (--n);
- t->num_houses -= amount;
- UpdateTownRadius(t);
+ t->num_houses -= amount;
+ UpdateTownRadius(t);
- UpdateTownMaxPass(t);
+ UpdateTownMaxPass(t);
+ }
+
+ return CommandCost();
}
/**
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index e19bac29f..4a50b1211 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -454,7 +454,15 @@ public:
break;
case TVW_EXPAND: // expand town - only available on Scenario editor
- ExpandTown(this->town);
+ /* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */
+ static bool _warn_town_no_roads = false;
+
+ if (!_settings_game.economy.allow_town_roads && !_warn_town_no_roads) {
+ ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING);
+ _warn_town_no_roads = true;
+ }
+
+ DoCommandP(0, this->window_number, 0, CMD_EXPAND_TOWN | CMD_MSG(STR_ERROR_CAN_T_EXPAND_TOWN));
break;
case TVW_DELETE: // delete town - only available on Scenario editor