summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-08-02 21:06:06 +0000
committerterkhen <terkhen@openttd.org>2010-08-02 21:06:06 +0000
commitca0751adb82094a3f7d0042f386f72f43b756575 (patch)
treecc120ec01aa7d7503c771157794a95594329af21 /src/town_cmd.cpp
parentf2edc728e6c8d8b74226058ab5842ef60bf34592 (diff)
downloadopenttd-ca0751adb82094a3f7d0042f386f72f43b756575.tar.xz
(svn r20322) -Codechange: Move Expand town code to a command.
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp44
1 files changed, 26 insertions, 18 deletions
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();
}
/**