169 * @param p2 unused |
169 * @param p2 unused |
170 */ |
170 */ |
171 CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
171 CommandCost CmdRenameGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
172 { |
172 { |
173 if (!IsValidGroupID(p1)) return CMD_ERROR; |
173 if (!IsValidGroupID(p1)) return CMD_ERROR; |
174 if (StrEmpty(_cmd_text) || strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR; |
|
175 |
174 |
176 Group *g = GetGroup(p1); |
175 Group *g = GetGroup(p1); |
177 if (g->owner != _current_player) return CMD_ERROR; |
176 if (g->owner != _current_player) return CMD_ERROR; |
178 |
177 |
179 if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
178 bool reset = StrEmpty(_cmd_text); |
|
179 |
|
180 if (!reset) { |
|
181 if (strlen(_cmd_text) >= MAX_LENGTH_GROUP_NAME_BYTES) return CMD_ERROR; |
|
182 if (!IsUniqueGroupName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
|
183 } |
180 |
184 |
181 if (flags & DC_EXEC) { |
185 if (flags & DC_EXEC) { |
182 /* Delete the old name */ |
186 /* Delete the old name */ |
183 free(g->name); |
187 free(g->name); |
184 /* Assign the new one */ |
188 /* Assign the new one */ |
185 g->name = strdup(_cmd_text); |
189 g->name = reset ? NULL : strdup(_cmd_text); |
186 |
190 |
187 InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); |
191 InvalidateWindowData(GetWindowClassForVehicleType(g->vehicle_type), (g->vehicle_type << 11) | VLW_GROUP_LIST | _current_player); |
188 } |
192 } |
189 |
193 |
190 return CommandCost(); |
194 return CommandCost(); |