diff options
author | frosch <frosch@openttd.org> | 2013-11-12 17:57:12 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2013-11-12 17:57:12 +0000 |
commit | 9a41aefcc4a75ca98dd73e022d058b52bbd2a26d (patch) | |
tree | 3629e7fd54b024dda142bd2fb2afadde9557949d | |
parent | b1f41a0afb460071db2dbbfcb64140488f073382 (diff) | |
download | openttd-9a41aefcc4a75ca98dd73e022d058b52bbd2a26d.tar.xz |
(svn r25968) -Add: [Script] ScriptTown::TOWN_GROWTH_NONE to indicate no town growth via ScriptTown::SetGrowthRate and GetGrowthRate.
-rw-r--r-- | src/script/api/ai/ai_town.hpp.sq | 1 | ||||
-rw-r--r-- | src/script/api/ai_changelog.hpp | 1 | ||||
-rw-r--r-- | src/script/api/game/game_town.hpp.sq | 1 | ||||
-rw-r--r-- | src/script/api/game_changelog.hpp | 1 | ||||
-rw-r--r-- | src/script/api/script_town.cpp | 6 | ||||
-rw-r--r-- | src/script/api/script_town.hpp | 7 | ||||
-rw-r--r-- | src/town.h | 3 | ||||
-rw-r--r-- | src/town_cmd.cpp | 11 |
8 files changed, 22 insertions, 9 deletions
diff --git a/src/script/api/ai/ai_town.hpp.sq b/src/script/api/ai/ai_town.hpp.sq index c8ef39ed4..27f1ec72e 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_NONE, "TOWN_GROWTH_NONE"); SQAITown.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL"); SQAITown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, "."); diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index 9b224d590..0852f679c 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -23,6 +23,7 @@ * \li AIStation::HasCargoRating * \li AITile::GetTerrainType * \li AITown::FoundTown + * \li AITown::TOWN_GROWTH_NONE * * Other changes: * \li AIStation::GetCargoRating does return -1 for cargo-station combinations that diff --git a/src/script/api/game/game_town.hpp.sq b/src/script/api/game/game_town.hpp.sq index 7c07a0cd9..0ef4e0ddd 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_NONE, "TOWN_GROWTH_NONE"); SQGSTown.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL"); SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, "."); diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 53b116200..e34dc4fda 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_NONE * \li GSTown::TOWN_GROWTH_NORMAL * * Other changes: diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp index b37d7bd1e..5d67cb76d 100644 --- a/src/script/api/script_town.cpp +++ b/src/script/api/script_town.cpp @@ -163,6 +163,10 @@ days_between_town_growth = 0; break; + case TOWN_GROWTH_NONE: + days_between_town_growth = TOWN_GROW_RATE_CUSTOM_NONE; + 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); @@ -179,6 +183,8 @@ const Town *t = ::Town::Get(town_id); + if (t->growth_rate == TOWN_GROW_RATE_CUSTOM_NONE) return TOWN_GROWTH_NONE; + return ((t->growth_rate & ~TOWN_GROW_RATE_CUSTOM) * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS; } diff --git a/src/script/api/script_town.hpp b/src/script/api/script_town.hpp index 7c8ad3f20..3f7cf998c 100644 --- a/src/script/api/script_town.hpp +++ b/src/script/api/script_town.hpp @@ -120,6 +120,7 @@ public: * Special values for SetGrowthRate. */ enum TownGrowth { + TOWN_GROWTH_NONE = 0xFFFF, ///< Town does not grow at all. TOWN_GROWTH_NORMAL = 0x10000, ///< Use default town growth algorithm instead of custom growth rate. }; @@ -256,9 +257,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, or TOWN_GROWTH_NORMAL. + * @param days_between_town_growth The amount of days between town growth, TOWN_GROWTH_NONE or TOWN_GROWTH_NORMAL. * @pre IsValidTown(town_id). - * @pre days_between_town_growth <= 30000 || days_between_town_growth == TOWN_GROWTH_NORMAL. + * @pre days_between_town_growth <= 30000 || days_between_town_growth == TOWN_GROWTH_NONE || 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. @@ -270,7 +271,7 @@ public: * Get the amount of days between town growth. * @param town_id The index of the town. * @pre IsValidTown(town_id). - * @return Amount of days between town growth. + * @return Amount of days between town growth, or TOWN_GROWTH_NONE. * @note This function does not indicate when it will grow next. It only tells you the time between growths. */ static int32 GetGrowthRate(TownID town_id); diff --git a/src/town.h b/src/town.h index c378dd3c3..42495971e 100644 --- a/src/town.h +++ b/src/town.h @@ -35,7 +35,8 @@ static const uint INVALID_TOWN = 0xFFFF; static const uint TOWN_GROWTH_WINTER = 0xFFFFFFFE; ///< The town only needs this cargo in the winter (any amount) static const uint TOWN_GROWTH_DESERT = 0xFFFFFFFF; ///< The town needs the cargo for growth when on desert (any amount) -static const uint16 TOWN_GROW_RATE_CUSTOM = 0x8000; ///< If this mask is applied to Town::grow_counter, the grow_counter will not be calculated by the system (but assumed to be set by scripts) +static const uint16 TOWN_GROW_RATE_CUSTOM = 0x8000; ///< If this mask is applied to Town::growth_rate, the grow_counter will not be calculated by the system (but assumed to be set by scripts) +static const uint16 TOWN_GROW_RATE_CUSTOM_NONE = 0xFFFF; ///< Special value for Town::growth_rate to disable town growth. typedef Pool<Town, TownID, 64, 64000> TownPool; extern TownPool _town_pool; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 38894fe76..72ef4a1a3 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2513,14 +2513,14 @@ CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 * @param tile Unused. * @param flags Type of operation. * @param p1 Town ID to cargo game of. - * @param p2 Amount of days between growth. + * @param p2 Amount of days between growth, or TOWN_GROW_RATE_CUSTOM_NONE, or 0 to reset custom growth rate. * @param text Unused. * @return Empty cost or an error. */ CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { if (_current_company != OWNER_DEITY) return CMD_ERROR; - if ((p2 & TOWN_GROW_RATE_CUSTOM) != 0) return CMD_ERROR; + if ((p2 & TOWN_GROW_RATE_CUSTOM) != 0 && p2 != TOWN_GROW_RATE_CUSTOM_NONE) return CMD_ERROR; if (GB(p2, 16, 16) != 0) return CMD_ERROR; Town *t = Town::GetIfValid(p1); @@ -2826,11 +2826,12 @@ static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags) if (flags & DC_EXEC) { /* Build next tick */ t->grow_counter = 1; - /* If we were not already growing */ - SetBit(t->flags, TOWN_IS_GROWING); /* And grow for 3 months */ t->fund_buildings_months = 3; + /* Enable growth (also checking GameScript's opinion) */ + UpdateTownGrowRate(t); + SetWindowDirty(WC_TOWN_VIEW, t->index); } return CommandCost(); @@ -3048,7 +3049,7 @@ static void UpdateTownGrowRate(Town *t) } if ((t->growth_rate & TOWN_GROW_RATE_CUSTOM) != 0) { - SetBit(t->flags, TOWN_IS_GROWING); + if (t->growth_rate != TOWN_GROW_RATE_CUSTOM_NONE) SetBit(t->flags, TOWN_IS_GROWING); SetWindowDirty(WC_TOWN_VIEW, t->index); return; } |