summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-11-12 17:56:35 +0000
committerfrosch <frosch@openttd.org>2013-11-12 17:56:35 +0000
commitb1f41a0afb460071db2dbbfcb64140488f073382 (patch)
tree3d7589f178f39c5b013e3977308e6d01eb1278b4
parent41184fb871c6debe23f6b2c133373b6a3261cfce (diff)
downloadopenttd-b1f41a0afb460071db2dbbfcb64140488f073382.tar.xz
(svn r25967) -Add: [NoGo] GSTown::TOWN_GROWTH_NORMAL to reset a town growth rate set previously via GSTown::SetGrowthRate.
-rw-r--r--bin/game/compat_1.2.nut8
-rw-r--r--bin/game/compat_1.3.nut8
-rw-r--r--src/script/api/ai/ai_town.hpp.sq1
-rw-r--r--src/script/api/game/game_town.hpp.sq1
-rw-r--r--src/script/api/game_changelog.hpp1
-rw-r--r--src/script/api/script_town.cpp15
-rw-r--r--src/script/api/script_town.hpp11
-rw-r--r--src/script/api/template/template_town.hpp.sq2
8 files changed, 42 insertions, 5 deletions
diff --git a/bin/game/compat_1.2.nut b/bin/game/compat_1.2.nut
index f9a63e698..6126809c8 100644
--- a/bin/game/compat_1.2.nut
+++ b/bin/game/compat_1.2.nut
@@ -8,3 +8,11 @@
*/
GSLog.Info("1.2 API compatability in effect.");
+
+GSTown._SetGrowthRate <- GSTown.SetGrowthRate;
+GSTown.SetGrowthRate <- function(town_id, days_between_town_growth)
+{
+ /* Growth rate 0 caused resetting the custom growth rate. While this was undocumented, it was used nevertheless (ofc). */
+ if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL;
+ return GSTown._SetGrowthRate(town_id, days_between_town_growth);
+}
diff --git a/bin/game/compat_1.3.nut b/bin/game/compat_1.3.nut
index 656794c89..d58a34685 100644
--- a/bin/game/compat_1.3.nut
+++ b/bin/game/compat_1.3.nut
@@ -8,3 +8,11 @@
*/
GSLog.Info("1.3 API compatability in effect.");
+
+GSTown._SetGrowthRate <- GSTown.SetGrowthRate;
+GSTown.SetGrowthRate <- function(town_id, days_between_town_growth)
+{
+ /* Growth rate 0 caused resetting the custom growth rate. While this was undocumented, it was used nevertheless (ofc). */
+ if (days_between_town_growth == 0) days_between_town_growth = GSTown.TOWN_GROWTH_NORMAL;
+ return GSTown._SetGrowthRate(town_id, days_between_town_growth);
+}
diff --git a/src/script/api/ai/ai_town.hpp.sq b/src/script/api/ai/ai_town.hpp.sq
index d626424ed..c8ef39ed4 100644
--- a/src/script/api/ai/ai_town.hpp.sq
+++ b/src/script/api/ai/ai_town.hpp.sq
@@ -48,6 +48,7 @@ void SQAITown_Register(Squirrel *engine)
SQAITown.DefSQConst(engine, ScriptTown::TOWN_SIZE_MEDIUM, "TOWN_SIZE_MEDIUM");
SQAITown.DefSQConst(engine, ScriptTown::TOWN_SIZE_LARGE, "TOWN_SIZE_LARGE");
SQAITown.DefSQConst(engine, ScriptTown::TOWN_SIZE_INVALID, "TOWN_SIZE_INVALID");
+ SQAITown.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL");
SQAITown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, ".");
SQAITown.DefSQStaticMethod(engine, &ScriptTown::IsValidTown, "IsValidTown", 2, ".i");
diff --git a/src/script/api/game/game_town.hpp.sq b/src/script/api/game/game_town.hpp.sq
index af5b15944..7c07a0cd9 100644
--- a/src/script/api/game/game_town.hpp.sq
+++ b/src/script/api/game/game_town.hpp.sq
@@ -48,6 +48,7 @@ void SQGSTown_Register(Squirrel *engine)
SQGSTown.DefSQConst(engine, ScriptTown::TOWN_SIZE_MEDIUM, "TOWN_SIZE_MEDIUM");
SQGSTown.DefSQConst(engine, ScriptTown::TOWN_SIZE_LARGE, "TOWN_SIZE_LARGE");
SQGSTown.DefSQConst(engine, ScriptTown::TOWN_SIZE_INVALID, "TOWN_SIZE_INVALID");
+ SQGSTown.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, ".");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::IsValidTown, "IsValidTown", 2, ".i");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 59893a19a..53b116200 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -30,6 +30,7 @@
* \li GSTile::GetTerrainType
* \li GSTown::FoundTown
* \li GSTown::SetName
+ * \li GSTown::TOWN_GROWTH_NORMAL
*
* Other changes:
* \li GSGoal::New can now create up to 64000 concurrent goals. The old limit was 256 goals.
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index 9926d2277..b37d7bd1e 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -156,10 +156,19 @@
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, uint32 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);
+
+ switch (days_between_town_growth) {
+ case TOWN_GROWTH_NORMAL:
+ days_between_town_growth = 0;
+ break;
+
+ default:
+ days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS;
+ EnforcePrecondition(false, days_between_town_growth < TOWN_GROW_RATE_CUSTOM);
+ if (days_between_town_growth == 0) days_between_town_growth = 1; // as fast as possible
+ break;
+ }
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, days_between_town_growth, CMD_TOWN_GROWTH_RATE);
}
diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp
index e91af80cc..7c8ad3f20 100644
--- a/src/script/api/script_town.hpp
+++ b/src/script/api/script_town.hpp
@@ -117,6 +117,13 @@ public:
};
/**
+ * Special values for SetGrowthRate.
+ */
+ enum TownGrowth {
+ TOWN_GROWTH_NORMAL = 0x10000, ///< Use default town growth algorithm instead of custom growth rate.
+ };
+
+ /**
* Gets the number of towns.
* @return The number of towns.
*/
@@ -249,9 +256,9 @@ public:
/**
* Set the amount of days between town growth.
* @param town_id The index of the town.
- * @param days_between_town_growth The amount of days between town growth.
+ * @param days_between_town_growth The amount of days between town growth, or TOWN_GROWTH_NORMAL.
* @pre IsValidTown(town_id).
- * @pre days_between_town_growth <= 30000.
+ * @pre days_between_town_growth <= 30000 || days_between_town_growth == TOWN_GROWTH_NORMAL.
* @return True if the action succeeded.
* @note Even when setting a growth rate, towns only grow when the conditions for growth (SetCargoCoal) are met,
* and the game settings (economy.town_growth_rate) allow town growth at all.
diff --git a/src/script/api/template/template_town.hpp.sq b/src/script/api/template/template_town.hpp.sq
index 3c48d9835..0ec1c285d 100644
--- a/src/script/api/template/template_town.hpp.sq
+++ b/src/script/api/template/template_town.hpp.sq
@@ -21,6 +21,8 @@ namespace SQConvert {
template <> inline int Return<ScriptTown::RoadLayout>(HSQUIRRELVM vm, ScriptTown::RoadLayout res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> inline ScriptTown::TownSize GetParam(ForceType<ScriptTown::TownSize>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptTown::TownSize)tmp; }
template <> inline int Return<ScriptTown::TownSize>(HSQUIRRELVM vm, ScriptTown::TownSize res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> inline ScriptTown::TownGrowth GetParam(ForceType<ScriptTown::TownGrowth>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptTown::TownGrowth)tmp; }
+ template <> inline int Return<ScriptTown::TownGrowth>(HSQUIRRELVM vm, ScriptTown::TownGrowth res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow ScriptTown to be used as Squirrel parameter */
template <> inline ScriptTown *GetParam(ForceType<ScriptTown *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptTown *)instance; }