MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / CmdRenameTown

Function CmdRenameTown

src/town_cmd.cpp:3093–3120  ·  view source on GitHub ↗

* Rename a town (server-only). * @param flags type of operation * @param town_id town ID to rename * @param text the new name or an empty string when resetting to the default * @return the cost of this operation or an error */

Source from the content-addressed store, hash-verified

3091 * @return the cost of this operation or an error
3092 */
3093CommandCost CmdRenameTown(DoCommandFlags flags, TownID town_id, const std::string &text)
3094{
3095 Town *t = Town::GetIfValid(town_id);
3096 if (t == nullptr) return CMD_ERROR;
3097
3098 bool reset = text.empty();
3099
3100 if (!reset) {
3101 if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return CMD_ERROR;
3102 if (!IsUniqueTownName(text)) return CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE);
3103 }
3104
3105 if (flags.Test(DoCommandFlag::Execute)) {
3106 t->cached_name.clear();
3107 if (reset) {
3108 t->name.clear();
3109 } else {
3110 t->name = text;
3111 }
3112
3113 t->UpdateVirtCoord();
3114 InvalidateWindowData(WC_TOWN_DIRECTORY, 0, TDIWD_FORCE_RESORT);
3115 ClearAllStationCachedNames();
3116 ClearAllIndustryCachedNames();
3117 UpdateAllStationVirtCoords();
3118 }
3119 return CommandCost();
3120}
3121
3122/**
3123 * Determines the first cargo with a certain town effect

Callers

nothing calls this directly

Calls 11

Utf8StringLengthFunction · 0.85
IsUniqueTownNameFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80
InvalidateWindowDataFunction · 0.70
emptyMethod · 0.45
clearMethod · 0.45
UpdateVirtCoordMethod · 0.45

Tested by

no test coverage detected