summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp2
-rw-r--r--src/script/api/game/game_town.hpp.sq1
-rw-r--r--src/script/api/script_town.cpp8
-rw-r--r--src/script/api/script_town.hpp11
-rw-r--r--src/town_cmd.cpp23
5 files changed, 36 insertions, 9 deletions
diff --git a/src/command.cpp b/src/command.cpp
index acc5c6756..46b6d6852 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -265,7 +265,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdFoundTown, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_FOUND_TOWN; founding random town can fail only in exec run
DEF_CMD(CmdRenameTown, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN
DEF_CMD(CmdDoTownAction, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DO_TOWN_ACTION
- DEF_CMD(CmdExpandTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_EXPAND_TOWN
+ DEF_CMD(CmdExpandTown, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_EXPAND_TOWN
DEF_CMD(CmdDeleteTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DELETE_TOWN
DEF_CMD(CmdOrderRefit, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ORDER_REFIT
diff --git a/src/script/api/game/game_town.hpp.sq b/src/script/api/game/game_town.hpp.sq
index ef20b0418..cd8e6731e 100644
--- a/src/script/api/game/game_town.hpp.sq
+++ b/src/script/api/game/game_town.hpp.sq
@@ -55,6 +55,7 @@ void SQGSTown_Register(Squirrel *engine)
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::IsCity, "IsCity", 2, ".i");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRoadReworkDuration, "GetRoadReworkDuration", 2, ".i");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetExclusiveRightsDuration, "GetExclusiveRightsDuration", 2, ".i");
+ SQGSTown.DefSQStaticMethod(engine, &ScriptTown::ExpandTown, "ExpandTown", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRating, "GetRating", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetAllowedNoise, "GetAllowedNoise", 2, ".i");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRoadLayout, "GetRoadLayout", 2, ".i");
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index 554d5f7ae..c2c8d442b 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -200,6 +200,14 @@
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION);
}
+/* static */ bool ScriptTown::ExpandTown(TownID town_id, int houses)
+{
+ EnforcePrecondition(false, IsValidTown(town_id));
+ EnforcePrecondition(false, houses > 0);
+
+ return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, houses, CMD_EXPAND_TOWN);
+}
+
/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
{
if (!IsValidTown(town_id)) return TOWN_RATING_INVALID;
diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp
index 518eb7002..a52932a3c 100644
--- a/src/script/api/script_town.hpp
+++ b/src/script/api/script_town.hpp
@@ -313,6 +313,17 @@ public:
static bool PerformTownAction(TownID town_id, TownAction town_action);
/**
+ * Expand the town.
+ * @param town_id The town to expand.
+ * @param houses The amount of houses to grow the town with.
+ * @pre IsValidTown(town_id).
+ * @pre houses > 0.
+ * @return True if the action succeeded.
+ * @api -ai
+ */
+ static bool ExpandTown(TownID town_id, int houses);
+
+ /**
* Get the rating of a company within a town.
* @param town_id The town to get the rating for.
* @param company_id The company to get the rating for.
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);