(svn r20322) -Codechange: Move Expand town code to a command.

This commit is contained in:
terkhen 2010-08-02 21:06:06 +00:00
parent f2edc728e6
commit ca0751adb8
5 changed files with 41 additions and 22 deletions

View File

@ -134,9 +134,9 @@ CommandProc CmdSellShareInCompany;
CommandProc CmdBuyCompany; CommandProc CmdBuyCompany;
CommandProc CmdFoundTown; CommandProc CmdFoundTown;
CommandProc CmdRenameTown; CommandProc CmdRenameTown;
CommandProc CmdDoTownAction; CommandProc CmdDoTownAction;
CommandProc CmdExpandTown;
CommandProc CmdChangeSetting; CommandProc CmdChangeSetting;
CommandProc CmdChangeCompanySetting; 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(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(CmdRenameTown, CMD_SERVER), // CMD_RENAME_TOWN
DEF_CMD(CmdDoTownAction, 0), // CMD_DO_TOWN_ACTION 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(CmdSellShip, 0), // CMD_SELL_SHIP
DEF_CMD(CmdBuildShip, 0), // CMD_BUILD_SHIP DEF_CMD(CmdBuildShip, 0), // CMD_BUILD_SHIP

View File

@ -235,6 +235,7 @@ enum Commands {
CMD_FOUND_TOWN, ///< found a town CMD_FOUND_TOWN, ///< found a town
CMD_RENAME_TOWN, ///< rename 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_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_SELL_SHIP, ///< sell a ship
CMD_BUILD_SHIP, ///< build a new ship CMD_BUILD_SHIP, ///< build a new ship

View File

@ -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_GENERATE_TOWN :{WHITE}Can't build any towns
STR_ERROR_CAN_T_RENAME_TOWN :{WHITE}Can't rename town... 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_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_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_CLOSE_TO_ANOTHER_TOWN :{WHITE}... too close to another town
STR_ERROR_TOO_MANY_TOWNS :{WHITE}... too many towns STR_ERROR_TOO_MANY_TOWNS :{WHITE}... too many towns

View File

@ -2315,29 +2315,37 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return CommandCost(); 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, if (_game_mode != GM_EDITOR) return CMD_ERROR;
* but do this only onces per openttd run. */ Town *t = Town::GetIfValid(p1);
static bool warned_no_roads = false; if (t == NULL) return CMD_ERROR;
if (!_settings_game.economy.allow_town_roads && !warned_no_roads) {
ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING); if (flags & DC_EXEC) {
warned_no_roads = true; /* 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 */ return CommandCost();
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);
} }
/** /**

View File

@ -454,7 +454,15 @@ public:
break; break;
case TVW_EXPAND: // expand town - only available on Scenario editor 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; break;
case TVW_DELETE: // delete town - only available on Scenario editor case TVW_DELETE: // delete town - only available on Scenario editor