本文整理汇总了C++中CommandCost类的典型用法代码示例。如果您正苦于以下问题:C++ CommandCost类的具体用法?C++ CommandCost怎么用?C++ CommandCost使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandCost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendAllVehiclesToDepot
/**
* Send all vehicles of type to depots
* @param flags the flags used for DoCommand()
* @param service should the vehicles only get service in the depots
* @param vli identifier of the vehicle list
* @return 0 for success and CMD_ERROR if no vehicle is able to go to depot
*/
static CommandCost SendAllVehiclesToDepot(DoCommandFlag flags, bool service, const VehicleListIdentifier &vli)
{
VehicleList list;
if (!GenerateVehicleSortList(&list, vli)) return CMD_ERROR;
/* Send all the vehicles to a depot */
bool had_success = false;
for (uint i = 0; i < list.Length(); i++) {
const Vehicle *v = list[i];
CommandCost ret = DoCommand(v->tile, v->index | (service ? DEPOT_SERVICE : 0U) | DEPOT_DONT_CANCEL, 0, flags, GetCmdSendToDepot(vli.vtype));
if (ret.Succeeded()) {
had_success = true;
/* Return 0 if DC_EXEC is not set this is a valid goto depot command)
* In this case we know that at least one vehicle can be sent to a depot
* and we will issue the command. We can now safely quit the loop, knowing
* it will succeed at least once. With DC_EXEC we really need to send them to the depot */
if (!(flags & DC_EXEC)) break;
}
}
return had_success ? CommandCost() : CMD_ERROR;
}
示例2: CmdSetTimetableStart
/**
* Set the start date of the timetable.
* @param tile Not used.
* @param flags Operation to perform.
* @param p1 Vehicle id.
* @param p2 The timetable start date in ticks.
*/
CommandCost CmdSetTimetableStart(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (!_settings_game.order.timetabling) return CMD_ERROR;
Vehicle *v = Vehicle::GetIfValid(GB(p1, 0, 16));
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
/* Don't let a timetable start more than 15 years into the future or 1 year in the past. */
Date start_date = (Date)p2;
if (start_date < 0 || start_date > MAX_DAY) return CMD_ERROR;
if (start_date - _date > 15 * DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (_date - start_date > DAYS_IN_LEAP_YEAR) return CMD_ERROR;
if (flags & DC_EXEC) {
v->lateness_counter = 0;
ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
v->timetable_start = start_date;
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
}
return CommandCost();
}
示例3: RemoveBuoy
/**
* Remove a buoy
* @param tile TileIndex been queried
* @param flags operation to perform
* @pre IsBuoyTile(tile)
* @return cost or failure of operation
*/
CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
{
/* XXX: strange stuff, allow clearing as invalid company when clearing landscape */
if (!Company::IsValidID(_current_company) && !(flags & DC_BANKRUPT)) return_cmd_error(INVALID_STRING_ID);
Waypoint *wp = Waypoint::GetByTile(tile);
if (HasStationInUse(wp->index, false, _current_company)) return_cmd_error(STR_ERROR_BUOY_IS_IN_USE);
/* remove the buoy if there is a ship on tile when company goes bankrupt... */
if (!(flags & DC_BANKRUPT)) {
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
}
if (flags & DC_EXEC) {
wp->facilities &= ~FACIL_DOCK;
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
/* We have to set the water tile's state to the same state as before the
* buoy was placed. Otherwise one could plant a buoy on a canal edge,
* remove it and flood the land (if the canal edge is at level 0) */
MakeWaterKeepingClass(tile, GetTileOwner(tile));
wp->rect.AfterRemoveTile(wp, tile);
wp->UpdateVirtCoord();
wp->delete_ctr = 0;
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_WAYPOINT_BUOY]);
}
示例4: CmdDepotSellAllVehicles
/**
* Sells all vehicles in a depot
* @param tile Tile of the depot where the depot is
* @param flags type of operation
* @param p1 Vehicle type
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
VehicleList list;
CommandCost cost(EXPENSES_NEW_VEHICLES);
VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1);
if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR;
uint sell_command = GetCmdSellVeh(vehicle_type);
/* Get the list of vehicles in the depot */
BuildDepotVehicleList(vehicle_type, tile, &list, &list);
CommandCost last_error = CMD_ERROR;
bool had_success = false;
for (uint i = 0; i < list.Length(); i++) {
CommandCost ret = DoCommand(tile, list[i]->index | (1 << 20), 0, flags, sell_command);
if (ret.Succeeded()) {
cost.AddCost(ret);
had_success = true;
} else {
last_error = ret;
}
}
return had_success ? cost : last_error;
}
示例5: CmdRenameWaypoint
/**
* Rename a waypoint.
* @param tile unused
* @param flags type of operation
* @param p1 id of waypoint
* @param p2 unused
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Waypoint *wp = Waypoint::GetIfValid(p1);
if (wp == NULL) return CMD_ERROR;
if (wp->owner != OWNER_NONE) {
CommandCost ret = CheckOwnership(wp->owner);
if (ret.Failed()) return ret;
}
bool reset = StrEmpty(text);
if (!reset) {
if (Utf8StringLength(text) >= MAX_LENGTH_STATION_NAME_CHARS) return CMD_ERROR;
if (!IsUniqueWaypointName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
}
if (flags & DC_EXEC) {
free(wp->name);
wp->name = reset ? NULL : strdup(text);
wp->UpdateVirtCoord();
}
return CommandCost();
}
示例6: RemoveShipDepot
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
{
if (!IsShipDepot(tile)) return CMD_ERROR;
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
TileIndex tile2 = GetOtherShipDepotTile(tile);
/* do not check for ship on tile when company goes bankrupt */
if (!(flags & DC_BANKRUPT)) {
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
if (ret.Failed()) return ret;
}
if (flags & DC_EXEC) {
delete Depot::GetByTile(tile);
Company *c = Company::GetIfValid(GetTileOwner(tile));
if (c != NULL) {
c->infrastructure.water -= 2 * LOCK_DEPOT_TILE_FACTOR;
DirtyCompanyInfrastructureWindows(c->index);
}
MakeWaterKeepingClass(tile, GetTileOwner(tile));
MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
}
示例7: RemoveShipDepot
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
{
if (!IsShipDepot(tile)) return CMD_ERROR;
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
TileIndex tile2 = GetOtherShipDepotTile(tile);
/* do not check for ship on tile when company goes bankrupt */
if (!(flags & DC_BANKRUPT)) {
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile2);
if (ret.Failed()) return ret;
}
if (flags & DC_EXEC) {
delete Depot::GetByTile(tile);
MakeWaterKeepingClass(tile, GetTileOwner(tile));
MakeWaterKeepingClass(tile2, GetTileOwner(tile2));
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_DEPOT_SHIP]);
}
示例8: CmdRenameDepot
/**
* Rename a depot.
* @param tile unused
* @param flags type of operation
* @param p1 id of depot
* @param p2 unused
* @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(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Depot *d = Depot::GetIfValid(p1);
if (d == NULL) return CMD_ERROR;
CommandCost ret = CheckTileOwnership(d->xy);
if (ret.Failed()) return ret;
bool reset = StrEmpty(text);
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) {
free(d->name);
if (reset) {
d->name = NULL;
MakeDefaultName(d);
} else {
d->name = strdup(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();
}
示例9: CmdRefitShip
/** Refits a ship to the specified cargo type.
* @param tile unused
* @param flags type of operation
* @param p1 vehicle ID of the ship to refit
* @param p2 various bitstuffed elements
* - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
* - p2 = (bit 8-15) - the new cargo subtype to refit to
* - p2 = (bit 16) - refit only this vehicle (ignored)
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
CargoID new_cid = GB(p2, 0, 8); // gets the cargo number
byte new_subtype = GB(p2, 8, 8);
Ship *v = Ship::GetIfValid(p1);
if (v == NULL) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
if (!v->IsStoppedInDepot()) return_cmd_error(STR_ERROR_SHIP_MUST_BE_STOPPED_IN_DEPOT);
if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_CAN_T_REFIT_DESTROYED_VEHICLE);
/* Check cargo */
if (new_cid >= NUM_CARGO) return CMD_ERROR;
CommandCost cost = RefitVehicle(v, true, new_cid, new_subtype, flags);
if (flags & DC_EXEC) {
v->colourmap = PAL_NONE; // invalidate vehicle colour map
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
SetWindowDirty(WC_VEHICLE_DEPOT, v->tile);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
}
v->InvalidateNewGRFCacheOfChain(); // always invalidate; querycost might have filled it
return cost;
}
示例10: IsValidTileForWaypoint
/**
* Check whether the given tile is suitable for a waypoint.
* @param tile the tile to check for suitability
* @param axis the axis of the waypoint
* @param waypoint Waypoint the waypoint to check for is already joined to. If we find another waypoint it can join to it will throw an error.
*/
static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint)
{
/* if waypoint is set, then we have special handling to allow building on top of already existing waypoints.
* so waypoint points to INVALID_STATION if we can build on any waypoint.
* Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */
if (waypoint != NULL && IsTileType(tile, MP_STATION)) {
if (!IsRailWaypoint(tile)) {
return ClearTile_Station(tile, DC_AUTO); // get error message
} else {
StationID wp = GetStationIndex(tile);
if (*waypoint == INVALID_STATION) {
*waypoint = wp;
} else if (*waypoint != wp) {
return_cmd_error(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING);
}
}
}
if (GetAxisForNewWaypoint(tile) != axis) return_cmd_error(STR_ERROR_NO_SUITABLE_RAILROAD_TRACK);
Owner owner = GetTileOwner(tile);
CommandCost ret = CheckOwnership(owner);
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile);
if (ret.Failed()) return ret;
Slope tileh = GetTileSlope(tile);
if (tileh != SLOPE_FLAT &&
(!_settings_game.construction.build_on_slopes || IsSteepSlope(tileh) || !(tileh & (0x3 << axis)) || !(tileh & ~(0x3 << axis)))) {
return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
}
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
return CommandCost();
}
示例11: RemoveLock
/**
* Remove a lock.
* @param tile Central tile of the lock.
* @param flags Operation to perform.
* @return The cost in case of success, or an error code if it failed.
*/
static CommandCost RemoveLock(TileIndex tile, DoCommandFlag flags)
{
if (GetTileOwner(tile) != OWNER_NONE) {
CommandCost ret = CheckTileOwnership(tile);
if (ret.Failed()) return ret;
}
TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
/* make sure no vehicle is on the tile. */
CommandCost ret = EnsureNoVehicleOnGround(tile);
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
if (ret.Failed()) return ret;
if (flags & DC_EXEC) {
DoClearSquare(tile);
MakeWaterKeepingClass(tile + delta, GetTileOwner(tile + delta));
MakeWaterKeepingClass(tile - delta, GetTileOwner(tile - delta));
MarkCanalsAndRiversAroundDirty(tile - delta);
MarkCanalsAndRiversAroundDirty(tile + delta);
}
return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_CLEAR_LOCK]);
}
示例12: CmdChangeServiceInt
/**
* Change the service interval of a vehicle
* @param tile unused
* @param flags type of operation
* @param p1 vehicle ID that is being service-interval-changed
* @param p2 bitmask
* - p2 = (bit 0-15) - new service interval
* - p2 = (bit 16) - service interval is custom flag
* - p2 = (bit 17) - service interval is percentage flag
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Vehicle *v = Vehicle::GetIfValid(p1);
if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
const Company *company = Company::Get(v->owner);
bool iscustom = HasBit(p2, 16);
bool ispercent = iscustom ? HasBit(p2, 17) : company->settings.vehicle.servint_ispercent;
uint16 serv_int;
if (iscustom) {
serv_int = GB(p2, 0, 16);
if (serv_int != GetServiceIntervalClamped(serv_int, ispercent)) return CMD_ERROR;
} else {
serv_int = CompanyServiceInterval(company, v->type);
}
if (flags & DC_EXEC) {
v->SetServiceInterval(serv_int);
v->SetServiceIntervalIsCustom(iscustom);
v->SetServiceIntervalIsPercent(ispercent);
SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
}
return CommandCost();
}
示例13: CopyHeadSpecificThings
/**
* Copy head specific things to the new vehicle chain after it was successfully constructed
* @param old_head The old front vehicle (no wagons attached anymore)
* @param new_head The new head of the completely replaced vehicle chain
* @param flags the command flags to use
*/
static CommandCost CopyHeadSpecificThings(Vehicle *old_head, Vehicle *new_head, DoCommandFlag flags)
{
CommandCost cost = CommandCost();
/* Share orders */
if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, new_head->index | CO_SHARE << 30, old_head->index, DC_EXEC, CMD_CLONE_ORDER));
/* Copy group membership */
if (cost.Succeeded() && old_head != new_head) cost.AddCost(DoCommand(0, old_head->group_id, new_head->index, DC_EXEC, CMD_ADD_VEHICLE_GROUP));
/* Perform start/stop check whether the new vehicle suits newgrf restrictions etc. */
if (cost.Succeeded()) {
/* Start the vehicle, might be denied by certain things */
assert((new_head->vehstatus & VS_STOPPED) != 0);
cost.AddCost(CmdStartStopVehicle(new_head, true));
/* Stop the vehicle again, but do not care about evil newgrfs allowing starting but not stopping :p */
if (cost.Succeeded()) cost.AddCost(CmdStartStopVehicle(new_head, false));
}
/* Last do those things which do never fail (resp. we do not care about), but which are not undo-able */
if (cost.Succeeded() && old_head != new_head && (flags & DC_EXEC) != 0) {
/* Copy other things which cannot be copied by a command and which shall not stay resetted from the build vehicle command */
new_head->CopyVehicleConfigAndStatistics(old_head);
/* Switch vehicle windows/news to the new vehicle, so they are not closed/deleted when the old vehicle is sold */
ChangeVehicleViewports(old_head->index, new_head->index);
ChangeVehicleViewWindow(old_head->index, new_head->index);
ChangeVehicleNews(old_head->index, new_head->index);
}
return cost;
}
示例14: CmdBuildBuoy
/**
* Build a buoy.
* @param tile tile where to place the buoy
* @param flags operation to perform
* @param p1 unused
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
if (tile == 0) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
WaterClass wc;
if ((flags & DC_PASTE) && !(flags & DC_EXEC)) {
/* When pasting a buoy, there may be no water yet (a canal will be placed when DC_EXE'ing).
* Ignore that there is no water so we can calculate the cost more precisely. */
wc = WATER_CLASS_INVALID;
} else {
if (!HasTileWaterGround(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
wc = GetWaterClass(tile);
}
if (IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
/* Check if there is an already existing, deleted, waypoint close to us that we can reuse. */
Waypoint *wp = FindDeletedWaypointCloseTo(tile, STR_SV_STNAME_BUOY, OWNER_NONE);
if (wp == NULL && !Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
CommandCost cost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_WAYPOINT_BUOY]);
if (!IsWaterTile(tile)) {
CommandCost ret = DoCommand(tile, 0, 0, flags | DC_AUTO, CMD_LANDSCAPE_CLEAR);
if (ret.Failed()) return ret;
cost.AddCost(ret);
}
if (flags & DC_EXEC) {
if (wp == NULL) {
wp = new Waypoint(tile);
} else {
/* Move existing (recently deleted) buoy to the new location */
wp->xy = tile;
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
}
wp->rect.BeforeAddTile(tile, StationRect::ADD_TRY);
wp->string_id = STR_SV_STNAME_BUOY;
wp->facilities |= FACIL_DOCK;
wp->owner = OWNER_NONE;
wp->build_date = _date;
if (wp->town == NULL) MakeDefaultName(wp);
assert(wc != WATER_CLASS_INVALID);
MakeBuoy(tile, wp->index, wc);
wp->UpdateVirtCoord();
InvalidateWindowData(WC_WAYPOINT_VIEW, wp->index);
}
return cost;
}
示例15: CmdInstantCopyPaste
/**
* Copy a piece of map and instantly paste at given location.
*
* @param tile Tile where to paste (northern).
* @param flags Command flags.
* @param p1 Various bits:
* \li bits 0..27 [28] - northern tile of the source area
* \li bits 28..31 [4] - rail type (RailType) to convert to, ignored if CPM_CONVERT_RAILTYPE mode is off
* @param p2 Various bits:
* \li bits 0..5 [6] - source area width
* \li bits 6..11 [6] - source area height
* \li bits 12..15 [4] - additional amount of tile heights to add to each tile (-8..7)
* \li bits 16..18 [3] - transformation to perform (DirTransformation)
* \li bits 19..27 [9] - mode (CopyPasteMode)
* \li bits 28..31 [4] - [ unused ]
* @param text Unused.
* @return The cost of this operation or an error.
*/
CommandCost CmdInstantCopyPaste(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
CopyPasteParams copy_paste;
/* extract and validate source area */
copy_paste.src_area.tile = GenericTileIndex(TileIndex(GB(p1, 0, 28)));
copy_paste.src_area.w = GB(p2, 0, 6);
copy_paste.src_area.h = GB(p2, 6, 6);
CommandCost ret = ValParamCopyPasteArea(copy_paste.src_area);
if (ret.Failed()) return ret;
/* calculate and validate destination area */
copy_paste.dst_area = TransformTileArea(copy_paste.src_area, GenericTileIndex(tile), copy_paste.transformation);
ret = ValParamCopyPasteArea(copy_paste.dst_area);
if (ret.Failed()) return ret;
/* extract and validate copy/paste mode */
copy_paste.mode = (CopyPasteMode)GB(p2, 19, 9);
if (!ValParamCopyPasteMode(copy_paste.mode)) return CMD_ERROR;
/* extract and validate rail type */
copy_paste.railtype = (RailType)GB(p1, 28, 4);
if (!ValParamRailtype(copy_paste.railtype)) return CMD_ERROR;
/* extract transformation */
copy_paste.transformation = (DirTransformation)GB(p2, 16, 3);
/* extract the additional number of height units */
int additional_height_delta = GB(p2, 12, 4); // this is a 4-bit SIGNED integer (-8..7)
additional_height_delta |= -(additional_height_delta & (1 << 3)); // propagate the sign bit
/* calculate the height */
copy_paste.height_delta = CalcCopyPasteHeightDelta(copy_paste.src_area, copy_paste.dst_area, copy_paste.transformation, additional_height_delta);
/* when copy and paste areas are too close each other, firstly
* copy to the clipboard and then from the clipboard to the map */
if (CopyPasteAreasMayColide(copy_paste)) {
Map *clipboard = GetClipboardBuffer(INSTANT_COPY_PASTE_BUFFER);
/* Copy to a buffer, but only in the first stage of the command.
* In a single player game and also while we are a server, the first one is non-DC_EXEC
* stage (which is fallowed then by a DC_EXEC stage). When we are a client, there is only
* one stage which is either a single non-DC_EXEC stage (shift pressed), or a single DC_EXEC
* stage (command comming from the network). */
if ((_networking && !_network_server) || !(flags & DC_EXEC)) {
CopyToClipboard(clipboard, copy_paste.src_area);
}
/* paste from the clipboard */
ret = PasteFromClipboard(clipboard, tile, flags, copy_paste.mode, copy_paste.transformation, copy_paste.railtype, additional_height_delta);
} else {
/* copy/paste directly */
InitializePasting(flags, copy_paste);
DoCopyPaste(copy_paste);
ret = FinalizePasting();
}
return ret;
}