summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 20:57:51 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 20:57:51 +0000
commit5ff98b45c1f9097f521c95cfa46728e1f39a8f6d (patch)
tree0d77bfbaf5ca7406b93994b211fbdb5ace243b2f /src/town_cmd.cpp
parente53b2f2ab0ef24298e3bb511367b344b88a4a4c0 (diff)
downloadopenttd-5ff98b45c1f9097f521c95cfa46728e1f39a8f6d.tar.xz
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 51d99b558..04957e622 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2439,26 +2439,33 @@ const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect)
* @param tile Unused.
* @param flags Type of operation.
* @param p1 Town ID to expand.
- * @param p2 Unused.
+ * @param p2 Amount to grow, or 0 to grow a random size up to the current amount of houses.
* @param text Unused.
* @return Empty cost or an error.
*/
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (_game_mode != GM_EDITOR) return CMD_ERROR;
+ if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) return CMD_ERROR;
Town *t = Town::GetIfValid(p1);
if (t == NULL) return CMD_ERROR;
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);
+ if (p2 == 0) {
+ 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;
+ t->num_houses -= amount;
+ } else {
+ for (; p2 > 0; p2--) {
+ /* Try several times to grow, as we are really suppose to grow */
+ for (uint i = 0; i < 25; i++) if (GrowTown(t)) break;
+ }
+ }
UpdateTownRadius(t);
UpdateTownMaxPass(t);