mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
(svn r23617) -Add: ScriptTown::ExpandTown, to grow a town (GameScript only)
This commit is contained in:
parent
79071a2482
commit
37954d5098
@ -265,7 +265,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdFoundTown, CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_FOUND_TOWN; founding random town can fail only in exec run
|
||||
DEF_CMD(CmdRenameTown, CMD_SERVER, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_TOWN
|
||||
DEF_CMD(CmdDoTownAction, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DO_TOWN_ACTION
|
||||
DEF_CMD(CmdExpandTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_EXPAND_TOWN
|
||||
DEF_CMD(CmdExpandTown, CMD_DEITY, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_EXPAND_TOWN
|
||||
DEF_CMD(CmdDeleteTown, CMD_OFFLINE, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_DELETE_TOWN
|
||||
|
||||
DEF_CMD(CmdOrderRefit, 0, CMDT_ROUTE_MANAGEMENT ), // CMD_ORDER_REFIT
|
||||
|
@ -55,6 +55,7 @@ void SQGSTown_Register(Squirrel *engine)
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::IsCity, "IsCity", 2, ".i");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRoadReworkDuration, "GetRoadReworkDuration", 2, ".i");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetExclusiveRightsDuration, "GetExclusiveRightsDuration", 2, ".i");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::ExpandTown, "ExpandTown", 3, ".ii");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRating, "GetRating", 3, ".ii");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetAllowedNoise, "GetAllowedNoise", 2, ".i");
|
||||
SQGSTown.DefSQStaticMethod(engine, &ScriptTown::GetRoadLayout, "GetRoadLayout", 2, ".i");
|
||||
|
@ -200,6 +200,14 @@
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, town_action, CMD_DO_TOWN_ACTION);
|
||||
}
|
||||
|
||||
/* static */ bool ScriptTown::ExpandTown(TownID town_id, int houses)
|
||||
{
|
||||
EnforcePrecondition(false, IsValidTown(town_id));
|
||||
EnforcePrecondition(false, houses > 0);
|
||||
|
||||
return ScriptObject::DoCommand(::Town::Get(town_id)->xy, town_id, houses, CMD_EXPAND_TOWN);
|
||||
}
|
||||
|
||||
/* static */ ScriptTown::TownRating ScriptTown::GetRating(TownID town_id, ScriptCompany::CompanyID company_id)
|
||||
{
|
||||
if (!IsValidTown(town_id)) return TOWN_RATING_INVALID;
|
||||
|
@ -312,6 +312,17 @@ public:
|
||||
*/
|
||||
static bool PerformTownAction(TownID town_id, TownAction town_action);
|
||||
|
||||
/**
|
||||
* Expand the town.
|
||||
* @param town_id The town to expand.
|
||||
* @param houses The amount of houses to grow the town with.
|
||||
* @pre IsValidTown(town_id).
|
||||
* @pre houses > 0.
|
||||
* @return True if the action succeeded.
|
||||
* @api -ai
|
||||
*/
|
||||
static bool ExpandTown(TownID town_id, int houses);
|
||||
|
||||
/**
|
||||
* Get the rating of a company within a town.
|
||||
* @param town_id The town to get the rating for.
|
||||
|
@ -2439,26 +2439,33 @@ const CargoSpec *FindFirstCargoWithTownEffect(TownEffect effect)
|
||||
* @param tile Unused.
|
||||
* @param flags Type of operation.
|
||||
* @param p1 Town ID to expand.
|
||||
* @param p2 Unused.
|
||||
* @param p2 Amount to grow, or 0 to grow a random size up to the current amount of houses.
|
||||
* @param text Unused.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
if (_game_mode != GM_EDITOR) return CMD_ERROR;
|
||||
if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) return CMD_ERROR;
|
||||
Town *t = Town::GetIfValid(p1);
|
||||
if (t == NULL) return CMD_ERROR;
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
/* The more houses, the faster we grow */
|
||||
uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
|
||||
t->num_houses += amount;
|
||||
UpdateTownRadius(t);
|
||||
if (p2 == 0) {
|
||||
uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
|
||||
t->num_houses += amount;
|
||||
UpdateTownRadius(t);
|
||||
|
||||
uint n = amount * 10;
|
||||
do GrowTown(t); while (--n);
|
||||
uint n = amount * 10;
|
||||
do GrowTown(t); while (--n);
|
||||
|
||||
t->num_houses -= amount;
|
||||
t->num_houses -= amount;
|
||||
} else {
|
||||
for (; p2 > 0; p2--) {
|
||||
/* Try several times to grow, as we are really suppose to grow */
|
||||
for (uint i = 0; i < 25; i++) if (GrowTown(t)) break;
|
||||
}
|
||||
}
|
||||
UpdateTownRadius(t);
|
||||
|
||||
UpdateTownMaxPass(t);
|
||||
|
Loading…
Reference in New Issue
Block a user