(svn r25968) -Add: [Script] ScriptTown::TOWN_GROWTH_NONE to indicate no town growth via ScriptTown::SetGrowthRate and GetGrowthRate.

This commit is contained in:
frosch 2013-11-12 17:57:12 +00:00
parent b1f41a0afb
commit 9a41aefcc4
8 changed files with 22 additions and 9 deletions

View File

@ -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_MEDIUM, "TOWN_SIZE_MEDIUM");
SQAITown.DefSQConst(engine, ScriptTown::TOWN_SIZE_LARGE, "TOWN_SIZE_LARGE"); 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_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.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL");
SQAITown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, "."); SQAITown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, ".");

View File

@ -23,6 +23,7 @@
* \li AIStation::HasCargoRating * \li AIStation::HasCargoRating
* \li AITile::GetTerrainType * \li AITile::GetTerrainType
* \li AITown::FoundTown * \li AITown::FoundTown
* \li AITown::TOWN_GROWTH_NONE
* *
* Other changes: * Other changes:
* \li AIStation::GetCargoRating does return -1 for cargo-station combinations that * \li AIStation::GetCargoRating does return -1 for cargo-station combinations that

View File

@ -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_MEDIUM, "TOWN_SIZE_MEDIUM");
SQGSTown.DefSQConst(engine, ScriptTown::TOWN_SIZE_LARGE, "TOWN_SIZE_LARGE"); 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_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.DefSQConst(engine, ScriptTown::TOWN_GROWTH_NORMAL, "TOWN_GROWTH_NORMAL");
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, "."); SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetTownCount, "GetTownCount", 1, ".");

View File

@ -30,6 +30,7 @@
* \li GSTile::GetTerrainType * \li GSTile::GetTerrainType
* \li GSTown::FoundTown * \li GSTown::FoundTown
* \li GSTown::SetName * \li GSTown::SetName
* \li GSTown::TOWN_GROWTH_NONE
* \li GSTown::TOWN_GROWTH_NORMAL * \li GSTown::TOWN_GROWTH_NORMAL
* *
* Other changes: * Other changes:

View File

@ -163,6 +163,10 @@
days_between_town_growth = 0; days_between_town_growth = 0;
break; break;
case TOWN_GROWTH_NONE:
days_between_town_growth = TOWN_GROW_RATE_CUSTOM_NONE;
break;
default: default:
days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS; days_between_town_growth = days_between_town_growth * DAY_TICKS / TOWN_GROWTH_TICKS;
EnforcePrecondition(false, days_between_town_growth < TOWN_GROW_RATE_CUSTOM); EnforcePrecondition(false, days_between_town_growth < TOWN_GROW_RATE_CUSTOM);
@ -179,6 +183,8 @@
const Town *t = ::Town::Get(town_id); 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; return ((t->growth_rate & ~TOWN_GROW_RATE_CUSTOM) * TOWN_GROWTH_TICKS + DAY_TICKS) / DAY_TICKS;
} }

View File

@ -120,6 +120,7 @@ public:
* Special values for SetGrowthRate. * Special values for SetGrowthRate.
*/ */
enum TownGrowth { 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. 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. * Set the amount of days between town growth.
* @param town_id The index of the town. * @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 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. * @return True if the action succeeded.
* @note Even when setting a growth rate, towns only grow when the conditions for growth (SetCargoCoal) are met, * @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. * 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. * Get the amount of days between town growth.
* @param town_id The index of the town. * @param town_id The index of the town.
* @pre IsValidTown(town_id). * @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. * @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); static int32 GetGrowthRate(TownID town_id);

View File

@ -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_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 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; typedef Pool<Town, TownID, 64, 64000> TownPool;
extern TownPool _town_pool; extern TownPool _town_pool;

View File

@ -2513,14 +2513,14 @@ CommandCost CmdTownSetText(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
* @param tile Unused. * @param tile Unused.
* @param flags Type of operation. * @param flags Type of operation.
* @param p1 Town ID to cargo game of. * @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. * @param text Unused.
* @return Empty cost or an error. * @return Empty cost or an error.
*/ */
CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) CommandCost CmdTownGrowthRate(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{ {
if (_current_company != OWNER_DEITY) return CMD_ERROR; 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; if (GB(p2, 16, 16) != 0) return CMD_ERROR;
Town *t = Town::GetIfValid(p1); Town *t = Town::GetIfValid(p1);
@ -2826,11 +2826,12 @@ static CommandCost TownActionFundBuildings(Town *t, DoCommandFlag flags)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
/* Build next tick */ /* Build next tick */
t->grow_counter = 1; t->grow_counter = 1;
/* If we were not already growing */
SetBit(t->flags, TOWN_IS_GROWING);
/* And grow for 3 months */ /* And grow for 3 months */
t->fund_buildings_months = 3; t->fund_buildings_months = 3;
/* Enable growth (also checking GameScript's opinion) */
UpdateTownGrowRate(t);
SetWindowDirty(WC_TOWN_VIEW, t->index); SetWindowDirty(WC_TOWN_VIEW, t->index);
} }
return CommandCost(); return CommandCost();
@ -3048,7 +3049,7 @@ static void UpdateTownGrowRate(Town *t)
} }
if ((t->growth_rate & TOWN_GROW_RATE_CUSTOM) != 0) { 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); SetWindowDirty(WC_TOWN_VIEW, t->index);
return; return;
} }