depot_cmd.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "command_func.h"
00014 #include "depot_base.h"
00015 #include "functions.h"
00016 #include "string_func.h"
00017 #include "town.h"
00018 #include "vehicle_gui.h"
00019 #include "vehiclelist.h"
00020 #include "window_func.h"
00021
00022 #include "table/strings.h"
00023
00024
00025 static bool IsUniqueDepotName(const char *name)
00026 {
00027 const Depot *d;
00028
00029 FOR_ALL_DEPOTS(d) {
00030 if (d->name != NULL && strcmp(d->name, name) == 0) return false;
00031 }
00032
00033 return true;
00034 }
00035
00045 CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00046 {
00047 Depot *d = Depot::GetIfValid(p1);
00048 if (d == NULL) return CMD_ERROR;
00049
00050 CommandCost ret = CheckTileOwnership(d->xy);
00051 if (ret.Failed()) return ret;
00052
00053 bool reset = StrEmpty(text);
00054
00055 if (!reset) {
00056 if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR;
00057 if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
00058 }
00059
00060 if (flags & DC_EXEC) {
00061 free(d->name);
00062
00063 if (reset) {
00064 d->name = NULL;
00065 MakeDefaultName(d);
00066 } else {
00067 d->name = strdup(text);
00068 }
00069
00070
00071 SetWindowClassesDirty(WC_VEHICLE_ORDERS);
00072 SetWindowDirty(WC_VEHICLE_DEPOT, d->xy);
00073
00074
00075 VehicleType vt;
00076 switch (GetTileType(d->xy)) {
00077 default: NOT_REACHED();
00078 case MP_RAILWAY: vt = VEH_TRAIN; break;
00079 case MP_ROAD: vt = VEH_ROAD; break;
00080 case MP_WATER: vt = VEH_SHIP; break;
00081 }
00082 SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack());
00083 }
00084 return CommandCost();
00085 }