* 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 */
| 3091 | * @return the cost of this operation or an error |
| 3092 | */ |
| 3093 | CommandCost 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 |
nothing calls this directly
no test coverage detected