summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-12-01 00:17:05 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit2e39637db226f1326da7c2f0814b2dbb320191a1 (patch)
tree430e869f69cb0a7bf99be9fc14c1087be73ed795 /src/town_cmd.cpp
parent41fa16f3254ffa9f44b85d6570a2293e8438b427 (diff)
downloadopenttd-2e39637db226f1326da7c2f0814b2dbb320191a1.tar.xz
Codechange: Don't use a global for the 'not enough cash' message.
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 5afc1d2c9..87d42628a 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1935,41 +1935,41 @@ static bool IsUniqueTownName(const std::string &name)
* @param text Custom name for the town. If empty, the town name parts will be used.
* @return the cost of this operation or an error
*/
-std::tuple<CommandCost, TownID> CmdFoundTown(DoCommandFlag flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32 townnameparts, const std::string &text)
+std::tuple<CommandCost, Money, TownID> CmdFoundTown(DoCommandFlag flags, TileIndex tile, TownSize size, bool city, TownLayout layout, bool random_location, uint32 townnameparts, const std::string &text)
{
TownNameParams par(_settings_game.game_creation.town_name);
- if (size >= TSZ_END) return { CMD_ERROR, INVALID_TOWN };
- if (layout >= NUM_TLS) return { CMD_ERROR, INVALID_TOWN };
+ if (size >= TSZ_END) return { CMD_ERROR, 0, INVALID_TOWN };
+ if (layout >= NUM_TLS) return { CMD_ERROR, 0, INVALID_TOWN };
/* Some things are allowed only in the scenario editor and for game scripts. */
if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) {
- if (_settings_game.economy.found_town == TF_FORBIDDEN) return { CMD_ERROR, INVALID_TOWN };
- if (size == TSZ_LARGE) return { CMD_ERROR, INVALID_TOWN };
- if (random_location) return { CMD_ERROR, INVALID_TOWN };
+ if (_settings_game.economy.found_town == TF_FORBIDDEN) return { CMD_ERROR, 0, INVALID_TOWN };
+ if (size == TSZ_LARGE) return { CMD_ERROR, 0, INVALID_TOWN };
+ if (random_location) return { CMD_ERROR, 0, INVALID_TOWN };
if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT && layout != _settings_game.economy.town_layout) {
- return { CMD_ERROR, INVALID_TOWN };
+ return { CMD_ERROR, 0, INVALID_TOWN };
}
} else if (_current_company == OWNER_DEITY && random_location) {
/* Random parameter is not allowed for Game Scripts. */
- return { CMD_ERROR, INVALID_TOWN };
+ return { CMD_ERROR, 0, INVALID_TOWN };
}
if (text.empty()) {
/* If supplied name is empty, townnameparts has to generate unique automatic name */
- if (!VerifyTownName(townnameparts, &par)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), INVALID_TOWN };
+ if (!VerifyTownName(townnameparts, &par)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, INVALID_TOWN };
} else {
/* If name is not empty, it has to be unique custom name */
- if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return { CMD_ERROR, INVALID_TOWN };
- if (!IsUniqueTownName(text)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), INVALID_TOWN };
+ if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return { CMD_ERROR, 0, INVALID_TOWN };
+ if (!IsUniqueTownName(text)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, INVALID_TOWN };
}
/* Allocate town struct */
- if (!Town::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_TOWNS), INVALID_TOWN };
+ if (!Town::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_TOWNS), 0, INVALID_TOWN };
if (!random_location) {
CommandCost ret = TownCanBePlacedHere(tile);
- if (ret.Failed()) return { ret, INVALID_TOWN };
+ if (ret.Failed()) return { ret, 0, INVALID_TOWN };
}
static const byte price_mult[][TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }};
@@ -1985,8 +1985,7 @@ std::tuple<CommandCost, TownID> CmdFoundTown(DoCommandFlag flags, TileIndex tile
TownID new_town = INVALID_TOWN;
if (flags & DC_EXEC) {
if (cost.GetCost() > GetAvailableMoneyForCommand()) {
- _additional_cash_required = cost.GetCost();
- return { CommandCost(EXPENSES_OTHER), INVALID_TOWN };
+ return { CommandCost(EXPENSES_OTHER), cost.GetCost(), INVALID_TOWN };
}
Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
@@ -2031,7 +2030,7 @@ std::tuple<CommandCost, TownID> CmdFoundTown(DoCommandFlag flags, TileIndex tile
Game::NewEvent(new ScriptEventTownFounded(t->index));
}
}
- return { cost, new_town };
+ return { cost, 0, new_town };
}
/**