mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 22:28:56 +00:00
(svn r20322) -Codechange: Move Expand town code to a command.
This commit is contained in:
parent
f2edc728e6
commit
ca0751adb8
@ -134,9 +134,9 @@ CommandProc CmdSellShareInCompany;
|
||||
CommandProc CmdBuyCompany;
|
||||
|
||||
CommandProc CmdFoundTown;
|
||||
|
||||
CommandProc CmdRenameTown;
|
||||
CommandProc CmdDoTownAction;
|
||||
CommandProc CmdExpandTown;
|
||||
|
||||
CommandProc CmdChangeSetting;
|
||||
CommandProc CmdChangeCompanySetting;
|
||||
@ -288,6 +288,7 @@ static const Command _command_proc_table[] = {
|
||||
DEF_CMD(CmdFoundTown, CMD_NO_TEST), // CMD_FOUND_TOWN; founding random town can fail only in exec run
|
||||
DEF_CMD(CmdRenameTown, CMD_SERVER), // CMD_RENAME_TOWN
|
||||
DEF_CMD(CmdDoTownAction, 0), // CMD_DO_TOWN_ACTION
|
||||
DEF_CMD(CmdExpandTown, CMD_OFFLINE), // CMD_EXPAND_TOWN
|
||||
|
||||
DEF_CMD(CmdSellShip, 0), // CMD_SELL_SHIP
|
||||
DEF_CMD(CmdBuildShip, 0), // CMD_BUILD_SHIP
|
||||
|
@ -235,6 +235,7 @@ enum Commands {
|
||||
CMD_FOUND_TOWN, ///< found a town
|
||||
CMD_RENAME_TOWN, ///< rename a town
|
||||
CMD_DO_TOWN_ACTION, ///< do a action from the town detail window (like advertises or bribe)
|
||||
CMD_EXPAND_TOWN, ///< expand a town
|
||||
|
||||
CMD_SELL_SHIP, ///< sell a ship
|
||||
CMD_BUILD_SHIP, ///< build a new ship
|
||||
|
@ -3447,6 +3447,7 @@ STR_ERROR_PROTECTED :{WHITE}This com
|
||||
STR_ERROR_CAN_T_GENERATE_TOWN :{WHITE}Can't build any towns
|
||||
STR_ERROR_CAN_T_RENAME_TOWN :{WHITE}Can't rename town...
|
||||
STR_ERROR_CAN_T_FOUND_TOWN_HERE :{WHITE}Can't found town here...
|
||||
STR_ERROR_CAN_T_EXPAND_TOWN :{WHITE}Can't expand town...
|
||||
STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB :{WHITE}... too close to edge of map
|
||||
STR_ERROR_TOO_CLOSE_TO_ANOTHER_TOWN :{WHITE}... too close to another town
|
||||
STR_ERROR_TOO_MANY_TOWNS :{WHITE}... too many towns
|
||||
|
@ -2315,29 +2315,37 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/** Called from GUI */
|
||||
void ExpandTown(Town *t)
|
||||
/**
|
||||
* Expand a town (scenario editor only).
|
||||
* @param tile Unused.
|
||||
* @param flags Type of operation.
|
||||
* @param p1 Town ID to expand.
|
||||
* @param p2 Unused.
|
||||
* @param text Unused.
|
||||
* @return Empty cost or an error.
|
||||
*/
|
||||
CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
||||
{
|
||||
/* Warn the users if towns are not allowed to build roads,
|
||||
* but do this only onces per openttd run. */
|
||||
static bool warned_no_roads = false;
|
||||
if (!_settings_game.economy.allow_town_roads && !warned_no_roads) {
|
||||
ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING);
|
||||
warned_no_roads = true;
|
||||
if (_game_mode != GM_EDITOR) 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);
|
||||
|
||||
uint n = amount * 10;
|
||||
do GrowTown(t); while (--n);
|
||||
|
||||
t->num_houses -= amount;
|
||||
UpdateTownRadius(t);
|
||||
|
||||
UpdateTownMaxPass(t);
|
||||
}
|
||||
|
||||
/* The more houses, the faster we grow */
|
||||
uint amount = RandomRange(ClampToU16(t->num_houses / 10)) + 3;
|
||||
t->num_houses += amount;
|
||||
UpdateTownRadius(t);
|
||||
|
||||
uint n = amount * 10;
|
||||
do GrowTown(t); while (--n);
|
||||
|
||||
t->num_houses -= amount;
|
||||
UpdateTownRadius(t);
|
||||
|
||||
UpdateTownMaxPass(t);
|
||||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -454,7 +454,15 @@ public:
|
||||
break;
|
||||
|
||||
case TVW_EXPAND: // expand town - only available on Scenario editor
|
||||
ExpandTown(this->town);
|
||||
/* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */
|
||||
static bool _warn_town_no_roads = false;
|
||||
|
||||
if (!_settings_game.economy.allow_town_roads && !_warn_town_no_roads) {
|
||||
ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING);
|
||||
_warn_town_no_roads = true;
|
||||
}
|
||||
|
||||
DoCommandP(0, this->window_number, 0, CMD_EXPAND_TOWN | CMD_MSG(STR_ERROR_CAN_T_EXPAND_TOWN));
|
||||
break;
|
||||
|
||||
case TVW_DELETE: // delete town - only available on Scenario editor
|
||||
|
Loading…
Reference in New Issue
Block a user