Files
@ r28769:123ae3cb0017
Branch filter:
Location: cpp/openttd-patchpack/source/src/depot_cmd.cpp - annotation
r28769:123ae3cb0017
2.4 KiB
text/x-c
Codechange: Add support for number format and abbreviations pragmas/attributes to strgen
r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r18845:66bf168f1100 r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r17263:a75c87f7e037 r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r16069:5049a8060a4d r15162:d47b50bb10ac r26094:7572e88decb3 r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r21383:942c32fb8b0e r21383:942c32fb8b0e r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r17630:7d818445376d r25561:3defb050f30b r15162:d47b50bb10ac r23957:a76e956cb358 r24214:a65c412aafcc r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r26095:00c14d52e378 r26112:8e77e1979a31 r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r26112:8e77e1979a31 r15162:d47b50bb10ac r26112:8e77e1979a31 r23607:36c15679007d r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r25562:30716ba6a396 r15162:d47b50bb10ac r15162:d47b50bb10ac r16668:989c9aae97ec r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r24214:a65c412aafcc r15162:d47b50bb10ac r15162:d47b50bb10ac r24214:a65c412aafcc r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac r20821:e1ecbf7996ac r16069:5049a8060a4d r15162:d47b50bb10ac r15162:d47b50bb10ac r15162:d47b50bb10ac | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file depot_cmd.cpp %Command Handling for depots. */
#include "stdafx.h"
#include "command_func.h"
#include "depot_base.h"
#include "company_func.h"
#include "string_func.h"
#include "town.h"
#include "vehicle_gui.h"
#include "vehiclelist.h"
#include "window_func.h"
#include "depot_cmd.h"
#include "table/strings.h"
#include "safeguards.h"
/**
* Check whether the given name is globally unique amongst depots.
* @param name The name to check.
* @return True if there is no depot with the given name.
*/
static bool IsUniqueDepotName(const std::string &name)
{
for (const Depot *d : Depot::Iterate()) {
if (!d->name.empty() && d->name == name) return false;
}
return true;
}
/**
* Rename a depot.
* @param flags type of operation
* @param depot_id id of depot
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameDepot(DoCommandFlag flags, DepotID depot_id, const std::string &text)
{
Depot *d = Depot::GetIfValid(depot_id);
if (d == nullptr) return CMD_ERROR;
CommandCost ret = CheckTileOwnership(d->xy);
if (ret.Failed()) return ret;
bool reset = text.empty();
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
if (flags & DC_EXEC) {
if (reset) {
d->name.clear();
MakeDefaultName(d);
} else {
d->name = text;
}
/* Update the orders and depot */
SetWindowClassesDirty(WC_VEHICLE_ORDERS);
SetWindowDirty(WC_VEHICLE_DEPOT, d->xy);
/* Update the depot list */
VehicleType vt = GetDepotVehicleType(d->xy);
SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack());
}
return CommandCost();
}
|