summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2011-12-19 20:59:19 +0000
committertruebrain <truebrain@openttd.org>2011-12-19 20:59:19 +0000
commitafcf07ac8a0d5adede1b412600042a9f3b482648 (patch)
tree7fec6be73ba17fd98c3dee69e65d0a15aa7feaed /src/script/api
parentc7c1deaf41a2ce8cfa30ea2eaf1ef808e6529eae (diff)
downloadopenttd-afcf07ac8a0d5adede1b412600042a9f3b482648.tar.xz
(svn r23620) -Add: ScriptTown::SetCargoGoal and ScriptTown::SetGrowthRate (GameScript only)
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/game/game_town.hpp.sq2
-rw-r--r--src/script/api/script_town.cpp18
-rw-r--r--src/script/api/script_town.hpp23
3 files changed, 43 insertions, 0 deletions
diff --git a/src/script/api/game/game_town.hpp.sq b/src/script/api/game/game_town.hpp.sq
index cd8e6731e..b5837bc17 100644
--- a/src/script/api/game/game_town.hpp.sq
+++ b/src/script/api/game/game_town.hpp.sq
@@ -47,7 +47,9 @@ void SQGSTown_Register(Squirrel *engine)
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetLastMonthSupplied, "GetLastMonthSupplied", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetLastMonthTransportedPercentage, "GetLastMonthTransportedPercentage", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetLastMonthReceived, "GetLastMonthReceived", 3, ".ii");
+ SQGSTown.DefSQStaticMethod(engine, &ScriptTown::SetCargoGoal, "SetCargoGoal", 4, ".iii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetCargoGoal, "GetCargoGoal", 3, ".ii");
+ SQGSTown.DefSQStaticMethod(engine, &ScriptTown::SetGrowthRate, "SetGrowthRate", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetGrowthRate, "GetGrowthRate", 2, ".i");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetDistanceManhattanToTile, "GetDistanceManhattanToTile", 3, ".ii");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetDistanceSquareToTile, "GetDistanceSquareToTile", 3, ".ii");
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index c2c8d442b..d213f1d0d 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -103,6 +103,14 @@
return t->received[towneffect_id].old_act;
}
+/* static */ bool ScriptTown::SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, uint32 goal)
+{
+ EnforcePrecondition(false, IsValidTown(town_id));
+ EnforcePrecondition(false, ScriptCargo::IsValidTownEffect(towneffect_id));
+
+ return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id | (towneffect_id << 16), goal, CMD_TOWN_CARGO_GOAL);
+}
+
/* static */ uint32 ScriptTown::GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id)
{
if (!IsValidTown(town_id)) return -1;
@@ -123,6 +131,16 @@
}
}
+/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, uint16 days_between_town_growth)
+{
+ days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS;
+
+ EnforcePrecondition(false, IsValidTown(town_id));
+ EnforcePrecondition(false, (days_between_town_growth & TOWN_GROW_RATE_CUSTOM) == 0);
+
+ return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, days_between_town_growth, CMD_TOWN_GROWTH_RATE);
+}
+
/* static */ int32 ScriptTown::GetGrowthRate(TownID town_id)
{
if (!IsValidTown(town_id)) return false;
diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp
index a52932a3c..0cee78694 100644
--- a/src/script/api/script_town.hpp
+++ b/src/script/api/script_town.hpp
@@ -192,6 +192,18 @@ public:
static int32 GetLastMonthReceived(TownID town_id, ScriptCargo::TownEffect towneffect_id);
/**
+ * Set the goal of a cargo for this town.
+ * @param town_id The index of the town.
+ * @param towneffect_id The index of the cargo.
+ * @param goal The new goal.
+ * @pre IsValidTown(town_id).
+ * @pre ScriptCargo::IsValidTownEffect(cargo_id).
+ * @return True if the action succeeded.
+ * @api -ai
+ */
+ static bool SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, uint32 goal);
+
+ /**
* Get the amount of cargo that needs to be delivered (per TownEffect) for a
* town to grow. All goals need to be reached before a town will grow.
* @param town_id The index of the town.
@@ -205,6 +217,17 @@ public:
static uint32 GetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id);
/**
+ * Set the amount of days between town growth.
+ * @param town_id The index of the town.
+ * @param days_between_town_growth The amont of days between town growth.
+ * @pre IsValidTown(town_id).
+ * @return True if the action succeeded.
+ * @note If 'Fund Building' and 'economy.town_growth_rate' is active, the game will often set a new GrowthRate.
+ * @api -ai
+ */
+ static bool SetGrowthRate(TownID town_id, uint16 days_between_town_growth);
+
+ /**
* Get the amount of days between town growth.
* @param town_id The index of the town.
* @pre IsValidTown(town_id).