Remove SIGTYPE_LAST_NOPBS
[openttd/fttd.git] / src / depot_cmd.cpp
blob5fb2b2de2ffe461f407fbce54ca5b009625a9099
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file depot_cmd.cpp %Command Handling for depots. */
12 #include "stdafx.h"
13 #include "command_func.h"
14 #include "depot_base.h"
15 #include "company_func.h"
16 #include "string_func.h"
17 #include "town.h"
18 #include "vehicle_gui.h"
19 #include "vehiclelist.h"
20 #include "window_func.h"
22 #include "table/strings.h"
24 /**
25 * Check whether the given name is globally unique amongst depots.
26 * @param name The name to check.
27 * @return True if there is no depot with the given name.
29 static bool IsUniqueDepotName(const char *name)
31 const Depot *d;
33 FOR_ALL_DEPOTS(d) {
34 if (d->name != NULL && strcmp(d->name, name) == 0) return false;
37 return true;
40 /**
41 * Rename a depot.
42 * @param tile unused
43 * @param flags type of operation
44 * @param p1 id of depot
45 * @param p2 unused
46 * @param text the new name or an empty string when resetting to the default
47 * @return the cost of this operation or an error
49 CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
51 Depot *d = Depot::GetIfValid(p1);
52 if (d == NULL) return CMD_ERROR;
54 CommandCost ret = CheckTileOwnership(d->xy);
55 if (ret.Failed()) return ret;
57 bool reset = StrEmpty(text);
59 if (!reset) {
60 if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR;
61 if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
64 if (flags & DC_EXEC) {
65 free(d->name);
67 if (reset) {
68 d->name = NULL;
69 MakeDefaultName(d);
70 } else {
71 d->name = strdup(text);
74 /* Update the orders and depot */
75 SetWindowClassesDirty(WC_VEHICLE_ORDERS);
76 SetWindowDirty(WC_VEHICLE_DEPOT, d->xy);
78 /* Update the depot list */
79 VehicleType vt = GetDepotVehicleType(d->xy);
80 SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack());
82 return CommandCost();