Mercurial > hg > openttd
annotate src/vehicle_cmd.cpp @ 14176:41303b56f42c draft
(svn r18724) -Fix [FS#3475] (r17899): refitting a non-refittable vehicle to it's default cargotype failed, causing problems for AIs
author | yexo <yexo@openttd.org> |
---|---|
date | Mon, 04 Jan 2010 18:50:50 +0000 |
parents | 9b98b4f050e5 |
children | 860ea22258ba |
rev | line source |
---|---|
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
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/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12632
diff
changeset
|
9 |
11350
8a62f1cb73a3
(svn r15700) -Codechange: split Cmd* from signs.cpp to signs_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
11349
diff
changeset
|
10 /** @file vehicle_cmd.cpp Commands for vehicles. */ |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
11 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
13 #include "roadveh.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
14 #include "gfx_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
15 #include "news_func.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
16 #include "airport.h" |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
17 #include "command_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
18 #include "company_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
19 #include "vehicle_gui.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
20 #include "train.h" |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
21 #include "aircraft.h" |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
22 #include "newgrf_engine.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
23 #include "newgrf_text.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
24 #include "functions.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
25 #include "window_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
26 #include "vehicle_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
27 #include "string_func.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
28 #include "depot_map.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
29 #include "vehiclelist.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
30 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
31 #include "table/strings.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
32 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
33 /* Tables used in vehicle.h to find the right command for a certain vehicle type */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
34 const uint32 _veh_build_proc_table[] = { |
12953
045a6264ea5b
(svn r17446) -Codechange: rename BUILD with BUY for strings that are about building (in the future buying) vehicles.
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
35 CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_BUY_TRAIN), |
045a6264ea5b
(svn r17446) -Codechange: rename BUILD with BUY for strings that are about building (in the future buying) vehicles.
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
36 CMD_BUILD_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_BUY_ROAD_VEHICLE), |
045a6264ea5b
(svn r17446) -Codechange: rename BUILD with BUY for strings that are about building (in the future buying) vehicles.
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
37 CMD_BUILD_SHIP | CMD_MSG(STR_ERROR_CAN_T_BUY_SHIP), |
045a6264ea5b
(svn r17446) -Codechange: rename BUILD with BUY for strings that are about building (in the future buying) vehicles.
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
38 CMD_BUILD_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_BUY_AIRCRAFT), |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
39 }; |
12485
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
40 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
41 const uint32 _veh_sell_proc_table[] = { |
12485
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
42 CMD_SELL_RAIL_WAGON | CMD_MSG(STR_ERROR_CAN_T_SELL_TRAIN), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
43 CMD_SELL_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_SELL_ROAD_VEHICLE), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
44 CMD_SELL_SHIP | CMD_MSG(STR_ERROR_CAN_T_SELL_SHIP), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
45 CMD_SELL_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_SELL_AIRCRAFT), |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
46 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
47 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
48 const uint32 _veh_refit_proc_table[] = { |
12485
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
49 CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_ERROR_CAN_T_REFIT_TRAIN), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
50 CMD_REFIT_ROAD_VEH | CMD_MSG(STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
51 CMD_REFIT_SHIP | CMD_MSG(STR_ERROR_CAN_T_REFIT_SHIP), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
52 CMD_REFIT_AIRCRAFT | CMD_MSG(STR_ERROR_CAN_T_REFIT_AIRCRAFT), |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
53 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
54 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
55 const uint32 _send_to_depot_proc_table[] = { |
12485
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
56 /* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
57 CMD_SEND_TRAIN_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT) | CMD_NO_TEST_IF_IN_NETWORK, |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
58 CMD_SEND_ROADVEH_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
59 CMD_SEND_SHIP_TO_DEPOT | CMD_MSG(STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT), |
cf4a59021c9d
(svn r16922) -Codechange: unduplicate some vehicle CMD_*s and move the setting of the error message to a single place
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
60 CMD_SEND_AIRCRAFT_TO_HANGAR | CMD_MSG(STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR), |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
61 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
62 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
63 /** Start/Stop a vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
64 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
65 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
66 * @param p1 vehicle to start/stop |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
67 * @param p2 bit 0: Shall the start/stop newgrf callback be evaluated (only valid with DC_AUTOREPLACE for network safety) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
68 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
69 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
70 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
71 CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
72 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
73 /* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
74 if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
75 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
76 Vehicle *v = Vehicle::GetIfValid(p1); |
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
77 if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
78 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
79 switch (v->type) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
80 case VEH_TRAIN: |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12619
diff
changeset
|
81 if ((v->vehstatus & VS_STOPPED) && Train::From(v)->tcache.cached_power == 0) return_cmd_error(STR_ERROR_TRAIN_START_NO_CATENARY); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
82 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
83 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
84 case VEH_SHIP: |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
85 case VEH_ROAD: |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
86 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
87 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
88 case VEH_AIRCRAFT: { |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
89 Aircraft *a = Aircraft::From(v); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
90 /* cannot stop airplane when in flight, or when taking off / landing */ |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
91 if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
92 } break; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
93 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
94 default: return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
95 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
96 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
97 /* Check if this vehicle can be started/stopped. The callback will fail or |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
98 * return 0xFF if it can. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
99 uint16 callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
100 if (callback != CALLBACK_FAILED && GB(callback, 0, 8) != 0xFF && HasBit(p2, 0)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
101 StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
102 return_cmd_error(error); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
103 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
104 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
105 if (flags & DC_EXEC) { |
12483
84df0c285bc4
(svn r16920) -Codechange: shuffle some strings around to simplify looking up vehicle type specific strings for a specific message
rubidium <rubidium@openttd.org>
parents:
12482
diff
changeset
|
106 if (v->IsStoppedInDepot() && (flags & DC_AUTOREPLACE) == 0) DeleteVehicleNews(p1, STR_NEWS_TRAIN_IS_WAITING + v->type); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
107 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
108 v->vehstatus ^= VS_STOPPED; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
109 if (v->type != VEH_TRAIN) v->cur_speed = 0; // trains can stop 'slowly' |
13094
c72c656565a6
(svn r17594) -Fix: Vehicle image was not always updated when needed.
frosch <frosch@openttd.org>
parents:
13070
diff
changeset
|
110 v->MarkDirty(); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13015
diff
changeset
|
111 SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13015
diff
changeset
|
112 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13015
diff
changeset
|
113 SetWindowClassesDirty(GetWindowClassForVehicleType(v->type)); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
114 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
115 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
116 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
117 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
118 /** Starts or stops a lot of vehicles |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
119 * @param tile Tile of the depot where the vehicles are started/stopped (only used for depots) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
120 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
121 * @param p1 Station/Order/Depot ID (only used for vehicle list windows) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
122 * @param p2 bitmask |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
123 * - bit 0-4 Vehicle type |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
124 * - bit 5 false = start vehicles, true = stop vehicles |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
125 * - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
126 * - bit 8-11 Vehicle List Window type (ignored unless bit 1 is set) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
127 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
128 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
129 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
130 CommandCost CmdMassStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
131 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
132 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
133 CommandCost return_value = CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
134 VehicleType vehicle_type = (VehicleType)GB(p2, 0, 5); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
135 bool start_stop = HasBit(p2, 5); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
136 bool vehicle_list_window = HasBit(p2, 6); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
137 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
138 if (vehicle_list_window) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
139 uint32 id = p1; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
140 uint16 window_type = p2 & VLW_MASK; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
141 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
142 GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
143 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
144 /* Get the list of vehicles in the depot */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
145 BuildDepotVehicleList(vehicle_type, tile, &list, NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
146 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
147 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
148 for (uint i = 0; i < list.Length(); i++) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
149 const Vehicle *v = list[i]; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
150 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
151 if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
152 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
153 if (!vehicle_list_window) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
154 if (vehicle_type == VEH_TRAIN) { |
13933
a71da8c8c5e2
(svn r18465) -Codechange: simplify CheckTrainInDepot and remove some unneeded wrapper functions
rubidium <rubidium@openttd.org>
parents:
13743
diff
changeset
|
155 if (!Train::From(v)->IsInDepot()) continue; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
156 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
157 if (!(v->vehstatus & VS_HIDDEN)) continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
158 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
159 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
160 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
161 CommandCost ret = DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
162 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
163 if (CmdSucceeded(ret)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
164 return_value = CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
165 /* We know that the command is valid for at least one vehicle. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
166 * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
167 if (!(flags & DC_EXEC)) break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
168 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
169 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
170 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
171 return return_value; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
172 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
173 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
174 /** Sells all vehicles in a depot |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
175 * @param tile Tile of the depot where the depot is |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
176 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
177 * @param p1 Vehicle type |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
178 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
179 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
180 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
181 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
182 CommandCost CmdDepotSellAllVehicles(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
183 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
184 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
185 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
186 CommandCost cost(EXPENSES_NEW_VEHICLES); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
187 VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
12494
c6663c02b4b2
(svn r16931) -Cleanup (r16922): one semicolon too much
smatz <smatz@openttd.org>
parents:
12487
diff
changeset
|
188 uint sell_command = GetCmdSellVeh(vehicle_type); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
189 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
190 /* Get the list of vehicles in the depot */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
191 BuildDepotVehicleList(vehicle_type, tile, &list, &list); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
192 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
193 for (uint i = 0; i < list.Length(); i++) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
194 CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
195 if (CmdSucceeded(ret)) cost.AddCost(ret); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
196 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
197 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
198 if (cost.GetCost() == 0) return CMD_ERROR; // no vehicles to sell |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
199 return cost; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
200 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
201 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
202 /** Autoreplace all vehicles in the depot |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
203 * Note: this command can make incorrect cost estimations |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
204 * Luckily the final price can only drop, not increase. This is due to the fact that |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
205 * estimation can't predict wagon removal so it presumes worst case which is no income from selling wagons. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
206 * @param tile Tile of the depot where the vehicles are |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
207 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
208 * @param p1 Type of vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
209 * @param p2 If bit 0 is set, then either replace all or nothing (instead of replacing until money runs out) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
210 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
211 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
212 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
213 CommandCost CmdDepotMassAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
214 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
215 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
216 CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
217 VehicleType vehicle_type = (VehicleType)GB(p1, 0, 8); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
218 bool all_or_nothing = HasBit(p2, 0); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
219 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
220 if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
221 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
222 /* Get the list of vehicles in the depot */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
223 BuildDepotVehicleList(vehicle_type, tile, &list, &list, true); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
224 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
225 bool did_something = false; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
226 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
227 for (uint i = 0; i < list.Length(); i++) { |
12015
f51061a22830
(svn r16421) -Codechange: do not unnecessarily remove constness or unnecessarily add it.
rubidium <rubidium@openttd.org>
parents:
11987
diff
changeset
|
228 const Vehicle *v = list[i]; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
229 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
230 /* Ensure that the vehicle completely in the depot */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
231 if (!v->IsInDepot()) continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
232 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
233 CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
234 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
235 if (CmdSucceeded(ret)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
236 did_something = true; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
237 cost.AddCost(ret); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
238 } else { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12494
diff
changeset
|
239 if (ret.GetErrorMessage() != STR_ERROR_AUTOREPLACE_NOTHING_TO_DO && all_or_nothing) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
240 /* We failed to replace a vehicle even though we set all or nothing. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
241 * We should never reach this if DC_EXEC is set since then it should |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
242 * have failed the estimation guess. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
243 assert(!(flags & DC_EXEC)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
244 /* Now we will have to return an error. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
245 return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
246 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
247 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
248 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
249 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
250 if (!did_something) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
251 /* Either we didn't replace anything or something went wrong. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
252 * Either way we want to return an error and not execute this command. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
253 cost = CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
254 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
255 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
256 return cost; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
257 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
258 |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
259 /** Learn the price of refitting a certain engine |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
260 * @param engine_type Which engine to refit |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
261 * @return Price for refitting |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
262 */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
263 static CommandCost GetRefitCost(EngineID engine_type) |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
264 { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
265 ExpensesType expense_type; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
266 const Engine *e = Engine::Get(engine_type); |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
267 Price base_price; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
268 uint cost_factor = e->info.refit_cost; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
269 switch (e->type) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
270 case VEH_SHIP: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
271 base_price = PR_BUILD_VEHICLE_SHIP; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
272 expense_type = EXPENSES_SHIP_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
273 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
274 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
275 case VEH_ROAD: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
276 base_price = PR_BUILD_VEHICLE_ROAD; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
277 expense_type = EXPENSES_ROADVEH_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
278 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
279 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
280 case VEH_AIRCRAFT: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
281 base_price = PR_BUILD_VEHICLE_AIRCRAFT; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
282 expense_type = EXPENSES_AIRCRAFT_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
283 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
284 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
285 case VEH_TRAIN: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
286 base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
287 cost_factor <<= 1; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
288 expense_type = EXPENSES_TRAIN_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
289 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
290 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
291 default: NOT_REACHED(); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
292 } |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
293 return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grffile, -10)); |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
294 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
295 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
296 /** |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
297 * Refits a vehicle (chain). |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
298 * This is the vehicle-type independent part of the CmdRefitXXX functions. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
299 * @param v The vehicle to refit. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
300 * @param only_this Whether to only refit this vehicle, or the whole chain. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
301 * @param new_cid Cargotype to refit to |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
302 * @param new_subtype Cargo subtype to refit to |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
303 * @param flags Command flags |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
304 * @return refit cost; or CMD_ERROR if no vehicle was actually refitable to the cargo |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
305 */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
306 CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags) |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
307 { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
308 CommandCost cost(v->GetExpenseType(false)); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
309 uint total_capacity = 0; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
310 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
311 v->InvalidateNewGRFCacheOfChain(); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
312 for (; v != NULL; v = (only_this ? NULL : v->Next())) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
313 const Engine *e = Engine::Get(v->engine_type); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
314 if (!e->CanCarryCargo() || !HasBit(e->info.refit_mask, new_cid)) continue; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
315 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
316 /* Back up the vehicle's cargo type */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
317 CargoID temp_cid = v->cargo_type; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
318 byte temp_subtype = v->cargo_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
319 v->cargo_type = new_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
320 v->cargo_subtype = new_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
321 |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
322 uint16 mail_capacity; |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
323 uint amount = GetVehicleCapacity(v, &mail_capacity); |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
324 total_capacity += amount; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
325 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
326 /* Restore the original cargo type */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
327 v->cargo_type = temp_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
328 v->cargo_subtype = temp_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
329 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
330 if (new_cid != v->cargo_type) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
331 cost.AddCost(GetRefitCost(v->engine_type)); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
332 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
333 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
334 if (flags & DC_EXEC) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
335 v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
336 v->cargo_type = new_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
337 v->cargo_cap = amount; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
338 v->cargo_subtype = new_subtype; |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
339 if (v->type == VEH_AIRCRAFT) { |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
340 Vehicle *u = v->Next(); |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
341 u->cargo_cap = mail_capacity; |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
342 u->cargo.Truncate(mail_capacity); |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
343 } |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
344 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
345 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
346 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
347 _returned_refit_capacity = total_capacity; |
14176
41303b56f42c
(svn r18724) -Fix [FS#3475] (r17899): refitting a non-refittable vehicle to it's default cargotype failed, causing problems for AIs
yexo <yexo@openttd.org>
parents:
13962
diff
changeset
|
348 return cost; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
349 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
350 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
351 /** Test if a name is unique among vehicle names. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
352 * @param name Name to test. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
353 * @return True ifffffff the name is unique. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
354 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
355 static bool IsUniqueVehicleName(const char *name) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
356 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
357 const Vehicle *v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
358 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
359 FOR_ALL_VEHICLES(v) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
360 if (v->name != NULL && strcmp(v->name, name) == 0) return false; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
361 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
362 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
363 return true; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
364 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
365 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
366 /** Clone the custom name of a vehicle, adding or incrementing a number. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
367 * @param src Source vehicle, with a custom name. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
368 * @param dst Destination vehicle. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
369 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
370 static void CloneVehicleName(const Vehicle *src, Vehicle *dst) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
371 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
372 char buf[256]; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
373 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
374 /* Find the position of the first digit in the last group of digits. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
375 size_t number_position; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
376 for (number_position = strlen(src->name); number_position > 0; number_position--) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
377 /* The design of UTF-8 lets this work simply without having to check |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
378 * for UTF-8 sequences. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
379 if (src->name[number_position - 1] < '0' || src->name[number_position - 1] > '9') break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
380 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
381 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
382 /* Format buffer and determine starting number. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
383 int num; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
384 if (number_position == strlen(src->name)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
385 /* No digit at the end, so start at number 2. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
386 strecpy(buf, src->name, lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
387 strecat(buf, " ", lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
388 number_position = strlen(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
389 num = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
390 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
391 /* Found digits, parse them and start at the next number. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
392 strecpy(buf, src->name, lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
393 buf[number_position] = '\0'; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
394 num = strtol(&src->name[number_position], NULL, 10) + 1; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
395 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
396 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
397 /* Check if this name is already taken. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
398 for (int max_iterations = 1000; max_iterations > 0; max_iterations--, num++) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
399 /* Attach the number to the temporary name. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
400 seprintf(&buf[number_position], lastof(buf), "%d", num); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
401 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
402 /* Check the name is unique. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
403 if (IsUniqueVehicleName(buf)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
404 dst->name = strdup(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
405 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
406 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
407 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
408 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
409 /* All done. If we didn't find a name, it'll just use its default. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
410 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
411 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
412 /** Clone a vehicle. If it is a train, it will clone all the cars too |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
413 * @param tile tile of the depot where the cloned vehicle is build |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
414 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
415 * @param p1 the original vehicle's index |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
416 * @param p2 1 = shared orders, else copied orders |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
417 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
418 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
419 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
420 CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
421 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
422 CommandCost total_cost(EXPENSES_NEW_VEHICLES); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
423 uint32 build_argument = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
424 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
425 Vehicle *v = Vehicle::GetIfValid(p1); |
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
426 if (v == NULL) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
427 Vehicle *v_front = v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
428 Vehicle *w = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
429 Vehicle *w_front = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
430 Vehicle *w_rear = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
431 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
432 /* |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
433 * v_front is the front engine in the original vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
434 * v is the car/vehicle of the original vehicle, that is currently being copied |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
435 * w_front is the front engine of the cloned vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
436 * w is the car/vehicle currently being cloned |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
437 * w_rear is the rear end of the cloned train. It's used to add more cars and is only used by trains |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
438 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
439 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
440 if (!CheckOwnership(v->owner)) return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
441 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
442 if (v->type == VEH_TRAIN && (!Train::From(v)->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
443 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
444 /* check that we can allocate enough vehicles */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
445 if (!(flags & DC_EXEC)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
446 int veh_counter = 0; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
447 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
448 veh_counter++; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
449 } while ((v = v->Next()) != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
450 |
11900
46d45a7511f9
(svn r16300) -Codechange: reduce usage of Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
451 if (!Vehicle::CanAllocateItem(veh_counter)) { |
11730
a39da1e4c1f5
(svn r16118) -Change/cleanup: remove the hexadecimal 'in TTD the string had this ID' from 'some' strings and replace the string name with something more sensible.
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
452 return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
453 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
454 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
455 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
456 v = v_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
457 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
458 do { |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
459 if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
460 /* we build the rear ends of multiheaded trains with the front ones */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
461 continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
462 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
463 |
13015
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
464 /* In case we're building a multi headed vehicle and the maximum number of |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
465 * vehicles is almost reached (e.g. max trains - 1) not all vehicles would |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
466 * be cloned. When the non-primary engines were build they were seen as |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
467 * 'new' vehicles whereas they would immediately be joined with a primary |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
468 * engine. This caused the vehicle to be not build as 'the limit' had been |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
469 * reached, resulting in partially build vehicles and such. */ |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
470 DoCommandFlag build_flags = flags; |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
471 if ((flags & DC_EXEC) && !v->IsPrimaryVehicle()) build_flags |= DC_AUTOREPLACE; |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
472 |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
473 CommandCost cost = DoCommand(tile, v->engine_type, build_argument, build_flags, GetCmdBuildVeh(v)); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
474 build_argument = 3; // ensure that we only assign a number to the first engine |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
475 |
13015
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
476 if (CmdFailed(cost)) { |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
477 /* Can't build a part, then sell the stuff we already made; clear up the mess */ |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
478 if (w_front != NULL) DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
479 return cost; |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
480 } |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
481 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
482 total_cost.AddCost(cost); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
483 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
484 if (flags & DC_EXEC) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
485 w = Vehicle::Get(_new_vehicle_id); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
486 |
12114
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
487 if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) { |
f020ec6be498
(svn r16527) -Codechange: use static member functions instead of simple casts when converting Vehicle to specialised vehicle types. Includes safety check
smatz <smatz@openttd.org>
parents:
12082
diff
changeset
|
488 SetBit(Train::From(w)->flags, VRF_REVERSE_DIRECTION); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
489 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
490 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
491 if (v->type == VEH_TRAIN && !Train::From(v)->IsFrontEngine()) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
492 /* this s a train car |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
493 * add this unit to the end of the train */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
494 CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
495 if (CmdFailed(result)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
496 /* The train can't be joined to make the same consist as the original. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
497 * Sell what we already made (clean up) and return an error. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
498 DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
499 DoCommand(w_front->tile, w->index, 1, flags, GetCmdSellVeh(w)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
500 return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
501 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
502 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
503 /* this is a front engine or not a train. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
504 w_front = w; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
505 w->service_interval = v->service_interval; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
506 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
507 w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
508 } |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
509 } while (v->type == VEH_TRAIN && (v = Train::From(v)->GetNextVehicle()) != NULL); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
510 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12032
diff
changeset
|
511 if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
512 /* for trains this needs to be the front engine due to the callback function */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
513 _new_vehicle_id = w_front->index; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
514 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
515 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
516 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
517 /* Cloned vehicles belong to the same group */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
518 DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
519 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
520 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
521 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
522 /* Take care of refitting. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
523 w = w_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
524 v = v_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
525 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
526 /* Both building and refitting are influenced by newgrf callbacks, which |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
527 * makes it impossible to accurately estimate the cloning costs. In |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
528 * particular, it is possible for engines of the same type to be built with |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
529 * different numbers of articulated parts, so when refitting we have to |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
530 * loop over real vehicles first, and then the articulated parts of those |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
531 * vehicles in a different loop. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
532 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
533 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
534 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
535 assert(w != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
536 |
13962
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
537 /* Find out what's the best sub type */ |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
538 byte subtype = GetBestFittingSubType(v, w); |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
539 if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) { |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
540 CommandCost cost = DoCommand(0, w->index, v->cargo_type | (subtype << 8) | 1U << 16, flags, GetCmdRefitVeh(v)); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
541 if (CmdSucceeded(cost)) total_cost.AddCost(cost); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
542 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
543 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
544 if (w->type == VEH_TRAIN && Train::From(w)->HasArticulatedPart()) { |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
545 w = Train::From(w)->GetNextArticPart(); |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
546 } else if (w->type == VEH_ROAD && RoadVehicle::From(w)->HasArticulatedPart()) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
547 w = w->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
548 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
549 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
550 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
551 } else { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
552 const Engine *e = Engine::Get(v->engine_type); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
553 CargoID initial_cargo = (e->CanCarryCargo() ? e->GetDefaultCargoType() : (CargoID)CT_INVALID); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
554 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
555 if (v->cargo_type != initial_cargo && initial_cargo != CT_INVALID) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
556 total_cost.AddCost(GetRefitCost(v->engine_type)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
557 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
558 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
559 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
560 if (v->type == VEH_TRAIN && Train::From(v)->HasArticulatedPart()) { |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
561 v = Train::From(v)->GetNextArticPart(); |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
562 } else if (v->type == VEH_ROAD && RoadVehicle::From(v)->HasArticulatedPart()) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
563 v = v->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
564 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
565 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
566 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
567 } while (v != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
568 |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
569 if ((flags & DC_EXEC) && v->type == VEH_TRAIN) w = Train::From(w)->GetNextVehicle(); |
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
570 } while (v->type == VEH_TRAIN && (v = Train::From(v)->GetNextVehicle()) != NULL); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
571 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
572 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
573 /* |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
574 * Set the orders of the vehicle. Cannot do it earlier as we need |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
575 * the vehicle refitted before doing this, otherwise the moved |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
576 * cargo types might not match (passenger vs non-passenger) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
577 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
578 DoCommand(0, (v_front->index << 16) | w_front->index, p2 & 1 ? CO_SHARE : CO_COPY, flags, CMD_CLONE_ORDER); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
579 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
580 /* Now clone the vehicle's name, if it has one. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
581 if (v_front->name != NULL) CloneVehicleName(v_front, w_front); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
582 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
583 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
584 /* Since we can't estimate the cost of cloning a vehicle accurately we must |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
585 * check whether the company has enough money manually. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
586 if (!CheckCompanyHasMoney(total_cost)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
587 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
588 /* The vehicle has already been bought, so now it must be sold again. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
589 DoCommand(w_front->tile, w_front->index, 1, flags, GetCmdSellVeh(w_front)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
590 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
591 return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
592 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
593 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
594 return total_cost; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
595 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
596 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
597 /** |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
598 * Send all vehicles of type to depots |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
599 * @param type type of vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
600 * @param flags the flags used for DoCommand() |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
601 * @param service should the vehicles only get service in the depots |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
602 * @param owner owner of the vehicles to send |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
603 * @param vlw_flag tells what kind of list requested the goto depot |
13070
1c4c4ae8d716
(svn r17570) -Fix: a number of Doxygen warnings about missing parameters, which were sometimes missing and sometimes just typos
rubidium <rubidium@openttd.org>
parents:
13067
diff
changeset
|
604 * @param id general purpose id whoms meaning is given by @c vlw_flag; e.g. StationID for station lists |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
605 * @return 0 for success and CMD_ERROR if no vehicle is able to go to depot |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
606 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
607 CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool service, Owner owner, uint16 vlw_flag, uint32 id) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
608 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
609 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
610 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
611 GenerateVehicleSortList(&list, type, owner, id, vlw_flag); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
612 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
613 /* Send all the vehicles to a depot */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
614 for (uint i = 0; i < list.Length(); i++) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
615 const Vehicle *v = list[i]; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
616 CommandCost ret = DoCommand(v->tile, v->index, (service ? 1 : 0) | DEPOT_DONT_CANCEL, flags, GetCmdSendToDepot(type)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
617 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
618 /* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
619 * In this case we know that at least one vehicle can be sent to a depot |
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
620 * and we will issue the command. We can now safely quit the loop, knowing |
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
621 * it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
622 if (CmdSucceeded(ret) && !(flags & DC_EXEC)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
623 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
624 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
625 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
626 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
627 return (flags & DC_EXEC) ? CommandCost() : CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
628 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
629 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
630 /** Give a custom name to your vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
631 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
632 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
633 * @param p1 vehicle ID to name |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
634 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
635 * @param text the new name or an empty string when resetting to the default |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
636 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
637 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
638 CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
639 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
640 Vehicle *v = Vehicle::GetIfValid(p1); |
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
641 if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
642 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
643 bool reset = StrEmpty(text); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
644 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
645 if (!reset) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
646 if (strlen(text) >= MAX_LENGTH_VEHICLE_NAME_BYTES) return CMD_ERROR; |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12619
diff
changeset
|
647 if (!(flags & DC_AUTOREPLACE) && !IsUniqueVehicleName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
648 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
649 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
650 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
651 free(v->name); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
652 v->name = reset ? NULL : strdup(text); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
653 InvalidateWindowClassesData(WC_TRAINS_LIST, 1); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
654 MarkWholeScreenDirty(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
655 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
656 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
657 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
658 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
659 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
660 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
661 /** Change the service interval of a vehicle |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
662 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
663 * @param flags type of operation |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
664 * @param p1 vehicle ID that is being service-interval-changed |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
665 * @param p2 new service interval |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
666 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
667 * @return the cost of this operation or an error |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
668 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
669 CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
670 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
671 Vehicle *v = Vehicle::GetIfValid(p1); |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12015
diff
changeset
|
672 if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
673 |
12032
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12015
diff
changeset
|
674 uint16 serv_int = GetServiceIntervalClamped(p2, v->owner); // Double check the service interval from the user-input |
2afeb10ae6ba
(svn r16439) -Change: Make the default vehicle servicing settings company-based settings, so in a multiplayer game everyone can change them.
yexo <yexo@openttd.org>
parents:
12015
diff
changeset
|
675 if (serv_int != p2) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
676 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
677 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
678 v->service_interval = serv_int; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
13015
diff
changeset
|
679 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
680 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
681 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
682 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
683 } |