Mercurial > hg > openttd
annotate src/vehicle_cmd.cpp @ 13175:3f4cc2986131 draft
(svn r17682) -Codechange: remove erroneous space before some commas
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 02 Oct 2009 15:13:15 +0000 |
parents | c72c656565a6 |
children | d3edbd44dacd |
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) { |
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
|
155 if (CheckTrainInDepot(Train::From(v), false) == -1) 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 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
259 /** 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
|
260 * @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
|
261 * @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
|
262 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
263 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
|
264 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
265 const Vehicle *v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
266 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
267 FOR_ALL_VEHICLES(v) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
268 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
|
269 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
270 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
271 return true; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
272 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
273 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
274 /** 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
|
275 * @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
|
276 * @param dst Destination vehicle. |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
277 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
278 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
|
279 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
280 char buf[256]; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
281 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
282 /* 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
|
283 size_t number_position; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
284 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
|
285 /* 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
|
286 * for UTF-8 sequences. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
287 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
|
288 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
289 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
290 /* 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
|
291 int num; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
292 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
|
293 /* 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
|
294 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
|
295 strecat(buf, " ", lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
296 number_position = strlen(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
297 num = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
298 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
299 /* 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
|
300 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
|
301 buf[number_position] = '\0'; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
302 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
|
303 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
304 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
305 /* 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
|
306 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
|
307 /* 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
|
308 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
|
309 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
310 /* 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
|
311 if (IsUniqueVehicleName(buf)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
312 dst->name = strdup(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
313 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
314 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
315 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
316 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
317 /* 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
|
318 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
319 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
320 /** 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
|
321 * @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
|
322 * @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
|
323 * @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
|
324 * @param p2 1 = shared orders, else copied orders |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
325 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
326 * @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
|
327 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
328 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
|
329 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
330 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
|
331 uint32 build_argument = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
332 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
333 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
|
334 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
|
335 Vehicle *v_front = v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
336 Vehicle *w = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
337 Vehicle *w_front = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
338 Vehicle *w_rear = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
339 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
340 /* |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
341 * 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
|
342 * 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
|
343 * 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
|
344 * 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
|
345 * 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
|
346 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
347 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
348 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
|
349 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
350 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
|
351 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
352 /* 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
|
353 if (!(flags & DC_EXEC)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
354 int veh_counter = 0; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
355 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
356 veh_counter++; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
357 } 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
|
358 |
11900
46d45a7511f9
(svn r16300) -Codechange: reduce usage of Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
359 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
|
360 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
|
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 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
364 v = v_front; |
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 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
|
367 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
|
368 /* 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
|
369 continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
370 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
371 |
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
|
372 /* 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
|
373 * 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
|
374 * 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
|
375 * '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
|
376 * 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
|
377 * 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
|
378 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
|
379 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
|
380 |
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
|
381 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
|
382 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
|
383 |
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
|
384 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
|
385 /* 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
|
386 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
|
387 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
|
388 } |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
389 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
390 total_cost.AddCost(cost); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
391 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
392 if (flags & DC_EXEC) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
393 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
|
394 |
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
|
395 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
|
396 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
|
397 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
398 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
399 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
|
400 /* 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
|
401 * 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
|
402 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
|
403 if (CmdFailed(result)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
404 /* 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
|
405 * 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
|
406 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
|
407 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
|
408 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
|
409 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
410 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
411 /* 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
|
412 w_front = w; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
413 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
|
414 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
415 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
|
416 } |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
417 } 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
|
418 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12032
diff
changeset
|
419 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
|
420 /* 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
|
421 _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
|
422 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
423 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
424 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
425 /* 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
|
426 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
|
427 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
428 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
429 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
430 /* Take care of refitting. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
431 w = w_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
432 v = v_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
433 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
434 /* 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
|
435 * 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
|
436 * 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
|
437 * 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
|
438 * 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
|
439 * 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
|
440 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
441 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
442 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
443 assert(w != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
444 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
445 if (w->cargo_type != v->cargo_type || w->cargo_subtype != v->cargo_subtype) { |
13175
3f4cc2986131
(svn r17682) -Codechange: remove erroneous space before some commas
rubidium <rubidium@openttd.org>
parents:
13094
diff
changeset
|
446 CommandCost cost = DoCommand(0, w->index, v->cargo_type | (v->cargo_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
|
447 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
|
448 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
449 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
450 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
|
451 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
|
452 } 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
|
453 w = w->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
454 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
455 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
456 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
457 } else { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
458 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
|
459 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
|
460 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
461 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
|
462 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
|
463 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
464 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
465 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
466 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
|
467 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
|
468 } 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
|
469 v = v->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
470 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
471 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
472 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
473 } while (v != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
474 |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
475 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
|
476 } 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
|
477 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
478 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
479 /* |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
480 * 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
|
481 * 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
|
482 * 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
|
483 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
484 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
|
485 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
486 /* 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
|
487 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
|
488 } |
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 /* 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
|
491 * 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
|
492 if (!CheckCompanyHasMoney(total_cost)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
493 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
494 /* 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
|
495 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
|
496 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
497 return CMD_ERROR; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
498 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
499 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
500 return total_cost; |
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 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
503 /** |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
504 * 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
|
505 * @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
|
506 * @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
|
507 * @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
|
508 * @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
|
509 * @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
|
510 * @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
|
511 * @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
|
512 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
513 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
|
514 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
515 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
516 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
517 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
|
518 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
519 /* 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
|
520 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
|
521 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
|
522 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
|
523 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
524 /* 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
|
525 * 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
|
526 * 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
|
527 * 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
|
528 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
|
529 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
530 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
531 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
532 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
533 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
|
534 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
535 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
536 /** 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
|
537 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
538 * @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
|
539 * @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
|
540 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
541 * @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
|
542 * @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
|
543 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
544 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
|
545 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
546 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
|
547 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
|
548 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
549 bool reset = StrEmpty(text); |
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 if (!reset) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
552 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
|
553 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
|
554 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
555 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
556 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
557 free(v->name); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
558 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
|
559 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
|
560 MarkWholeScreenDirty(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
561 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
562 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
563 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
564 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
565 |
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 /** 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
|
568 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
569 * @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
|
570 * @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
|
571 * @param p2 new service interval |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
572 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
573 * @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
|
574 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
575 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
|
576 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
577 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
|
578 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
|
579 |
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
|
580 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
|
581 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
|
582 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
583 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
584 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
|
585 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
|
586 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
587 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
588 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
589 } |