mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 11:23:21 +00:00
(svn r25967) -Add: [NoGo] GSTown::TOWN_GROWTH_NORMAL to reset a town growth rate set previously via GSTown::SetGrowthRate.
This commit is contained in:
parent
41184fb871
commit
b1f41a0afb
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -116,6 +116,13 @@ public:
|
||||
TOWN_SIZE_INVALID = -1, ///< Invalid town size.
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -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; }
|
||||
|
Loading…
Reference in New Issue
Block a user