Mercurial > hg > openttd
annotate src/vehicle_cmd.cpp @ 15620:f8e9a3f0c140 draft
(svn r20283) -Codechange: Unify start of doygen comments.
author | frosch <frosch@openttd.org> |
---|---|
date | Sun, 01 Aug 2010 19:22:34 +0000 |
parents | e4640748f223 |
children | a60a50f29f64 |
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 "news_func.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
15 #include "airport.h" |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
16 #include "cmd_helper.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" |
14258
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
14232
diff
changeset
|
30 #include "engine_base.h" |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
31 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
32 #include "table/strings.h" |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
33 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
34 /* 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 }; |
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
|
41 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
48 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
55 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
56 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
|
57 /* 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 }; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
63 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
64 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
65 * Start/Stop a vehicle |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
66 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
67 * @param flags type of operation |
15088
a63b4234140f
(svn r19714) -Feature: ctrl+click on a vehicle to start/stop it
smatz <smatz@openttd.org>
parents:
15040
diff
changeset
|
68 * @param p1 vehicle to start/stop, don't forget to change CcStartStopVehicle if you modify this! |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
69 * @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
|
70 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
71 * @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
|
72 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
73 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
|
74 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
75 /* 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
|
76 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
|
77 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
78 Vehicle *v = Vehicle::GetIfValid(p1); |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
79 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
80 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
81 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
82 if (ret.Failed()) return ret; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
83 |
15323
7ef84bf590b7
(svn r19964) -Add: Show an error message when trying to start a crashed or destroyed vehicle.
terkhen <terkhen@openttd.org>
parents:
15312
diff
changeset
|
84 if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_ERROR_VEHICLE_IS_DESTROYED); |
7ef84bf590b7
(svn r19964) -Add: Show an error message when trying to start a crashed or destroyed vehicle.
terkhen <terkhen@openttd.org>
parents:
15312
diff
changeset
|
85 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
86 switch (v->type) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
87 case VEH_TRAIN: |
14750
bf6990330311
(svn r19338) -Codechange: Move the acceleration cache to GroundVehicle.
terkhen <terkhen@openttd.org>
parents:
14465
diff
changeset
|
88 if ((v->vehstatus & VS_STOPPED) && Train::From(v)->acc_cache.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
|
89 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
90 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
91 case VEH_SHIP: |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
92 case VEH_ROAD: |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
93 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
94 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11949
diff
changeset
|
95 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
|
96 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
|
97 /* cannot stop airplane when in flight, or when taking off / landing */ |
15312
9c5f42023621
(svn r19953) -Fix [FS#3874]: Don't show an error message when trying to start/stop a crashed plane.
terkhen <terkhen@openttd.org>
parents:
15088
diff
changeset
|
98 if (!(v->vehstatus & VS_CRASHED) && a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT); |
15618
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15323
diff
changeset
|
99 break; |
e4640748f223
(svn r20281) -Codechange: unify case scope closure + break coding style
rubidium <rubidium@openttd.org>
parents:
15323
diff
changeset
|
100 } |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
101 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
102 default: return CMD_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 /* 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
|
106 * 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
|
107 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
|
108 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
|
109 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
|
110 return_cmd_error(error); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
111 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
112 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
113 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
|
114 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
|
115 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
116 v->vehstatus ^= VS_STOPPED; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
123 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
124 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
125 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
126 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
127 * Starts or stops a lot of vehicles |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
128 * @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
|
129 * @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
|
130 * @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
|
131 * @param p2 bitmask |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
132 * - 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
|
133 * - 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
|
134 * - bit 6 if set, then it's a vehicle list window, not a depot and Tile is ignored in this case |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
135 * - bit 8-11 Vehicle List Window type (ignored unless bit 6 is set) |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
136 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
137 * @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
|
138 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
139 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
|
140 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
141 VehicleList list; |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
142 VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p2); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
143 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
|
144 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
|
145 |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
146 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR; |
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
147 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
148 if (vehicle_list_window) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
149 uint32 id = p1; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
150 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
|
151 |
15039
53c099f9a3a9
(svn r19656) -Codechange/Fix: Report back if invalid vehicle lists are requested.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
152 if (!GenerateVehicleSortList(&list, vehicle_type, _current_company, id, window_type)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
153 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
154 /* 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
|
155 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
|
156 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
157 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
158 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
|
159 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
|
160 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
161 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
|
162 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
163 if (!vehicle_list_window) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
164 if (vehicle_type == VEH_TRAIN) { |
13933
a71da8c8c5e2
(svn r18465) -Codechange: simplify CheckTrainInDepot and remove some unneeded wrapper functions
rubidium <rubidium@openttd.org>
parents:
13743
diff
changeset
|
165 if (!Train::From(v)->IsInDepot()) continue; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
166 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
167 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
|
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 |
14465
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
171 /* Just try and don't care if some vehicle's can't be stopped. */ |
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
172 DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE); |
11349
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 |
14465
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
175 return CommandCost(); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
176 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
177 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
178 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
179 * Sells all vehicles in a depot |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
180 * @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
|
181 * @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
|
182 * @param p1 Vehicle type |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
183 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
184 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
185 * @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
|
186 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
187 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
|
188 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
189 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
190 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
191 CommandCost cost(EXPENSES_NEW_VEHICLES); |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
192 VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1); |
12494
c6663c02b4b2
(svn r16931) -Cleanup (r16922): one semicolon too much
smatz <smatz@openttd.org>
parents:
12487
diff
changeset
|
193 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
|
194 |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
195 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR; |
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
196 |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
197 /* 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
|
198 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
|
199 |
14897
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
200 CommandCost last_error = CMD_ERROR; |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
201 bool had_success = false; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
202 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
|
203 CommandCost ret = DoCommand(tile, list[i]->index, 1, flags, sell_command); |
14897
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
204 if (ret.Succeeded()) { |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
205 cost.AddCost(ret); |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
206 had_success = true; |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
207 } else { |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
208 last_error = ret; |
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
209 } |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
210 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
211 |
14897
671004f47e42
(svn r19493) -Codechange: Keep track of last error in CmdDepotSellAllVehicles().
alberth <alberth@openttd.org>
parents:
14893
diff
changeset
|
212 return had_success ? cost : last_error; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
213 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
214 |
14465
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
215 /** |
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
216 * Autoreplace all vehicles in the depot |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
217 * @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
|
218 * @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
|
219 * @param p1 Type of vehicle |
14465
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
220 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
221 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
222 * @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
|
223 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
224 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
|
225 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
226 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
227 CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES); |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
228 VehicleType vehicle_type = Extract<VehicleType, 0, 3>(p1); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
229 |
15037
ae5f1c6f349c
(svn r19654) -Codechange: Use Extract<> in more places.
frosch <frosch@openttd.org>
parents:
14901
diff
changeset
|
230 if (!IsCompanyBuildableVehicleType(vehicle_type)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
231 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
|
232 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
233 /* 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
|
234 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
|
235 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
236 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
|
237 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
|
238 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
239 /* 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
|
240 if (!v->IsInDepot()) continue; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
241 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
242 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
|
243 |
14465
a03b4e5abfbd
(svn r19024) -Fix [FS#3577]: mass stopping/starting/autoreplacing gave empty errors when there were no vehicles
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
244 if (ret.Succeeded()) cost.AddCost(ret); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
245 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
246 return cost; |
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 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
249 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
250 * Learn the price of refitting a certain engine |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
251 * @param engine_type Which engine to refit |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
252 * @return Price for refitting |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
253 */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
254 static CommandCost GetRefitCost(EngineID engine_type) |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
255 { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
256 ExpensesType expense_type; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
257 const Engine *e = Engine::Get(engine_type); |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
258 Price base_price; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
259 uint cost_factor = e->info.refit_cost; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
260 switch (e->type) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
261 case VEH_SHIP: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
262 base_price = PR_BUILD_VEHICLE_SHIP; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
263 expense_type = EXPENSES_SHIP_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
264 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
265 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
266 case VEH_ROAD: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
267 base_price = PR_BUILD_VEHICLE_ROAD; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
268 expense_type = EXPENSES_ROADVEH_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
269 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
270 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
271 case VEH_AIRCRAFT: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
272 base_price = PR_BUILD_VEHICLE_AIRCRAFT; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
273 expense_type = EXPENSES_AIRCRAFT_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
274 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
275 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
276 case VEH_TRAIN: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
277 base_price = (e->u.rail.railveh_type == RAILVEH_WAGON) ? PR_BUILD_VEHICLE_WAGON : PR_BUILD_VEHICLE_TRAIN; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
278 cost_factor <<= 1; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
279 expense_type = EXPENSES_TRAIN_RUN; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
280 break; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
281 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
282 default: NOT_REACHED(); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
283 } |
13743
c84d609b6877
(svn r18268) -Feature: [NewGRF] Make price base multipliers related to vehicles only apply to the GRF locally, if it defines engines of that type itself.
frosch <frosch@openttd.org>
parents:
13741
diff
changeset
|
284 return CommandCost(expense_type, GetPrice(base_price, cost_factor, e->grffile, -10)); |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
285 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
286 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
287 /** |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
288 * Refits a vehicle (chain). |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
289 * This is the vehicle-type independent part of the CmdRefitXXX functions. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
290 * @param v The vehicle to refit. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
291 * @param only_this Whether to only refit this vehicle, or the whole chain. |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
292 * @param new_cid Cargotype to refit to |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
293 * @param new_subtype Cargo subtype to refit to |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
294 * @param flags Command flags |
14886
3128bb512766
(svn r19482) -Doc: Doxygen additions/updates.
alberth <alberth@openttd.org>
parents:
14815
diff
changeset
|
295 * @return Refit cost. |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
296 */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
297 CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_subtype, DoCommandFlag flags) |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
298 { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
299 CommandCost cost(v->GetExpenseType(false)); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
300 uint total_capacity = 0; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
301 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
302 v->InvalidateNewGRFCacheOfChain(); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
303 for (; v != NULL; v = (only_this ? NULL : v->Next())) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
304 const Engine *e = Engine::Get(v->engine_type); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
305 if (!e->CanCarryCargo() || !HasBit(e->info.refit_mask, new_cid)) continue; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
306 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
307 /* Back up the vehicle's cargo type */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
308 CargoID temp_cid = v->cargo_type; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
309 byte temp_subtype = v->cargo_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
310 v->cargo_type = new_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
311 v->cargo_subtype = new_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
312 |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
313 uint16 mail_capacity; |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
314 uint amount = GetVehicleCapacity(v, &mail_capacity); |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
315 total_capacity += amount; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
316 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
317 /* Restore the original cargo type */ |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
318 v->cargo_type = temp_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
319 v->cargo_subtype = temp_subtype; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
320 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
321 if (new_cid != v->cargo_type) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
322 cost.AddCost(GetRefitCost(v->engine_type)); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
323 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
324 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
325 if (flags & DC_EXEC) { |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
326 v->cargo.Truncate((v->cargo_type == new_cid) ? amount : 0); |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
327 v->cargo_type = new_cid; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
328 v->cargo_cap = amount; |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
329 v->cargo_subtype = new_subtype; |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
330 if (v->type == VEH_AIRCRAFT) { |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
331 Vehicle *u = v->Next(); |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
332 u->cargo_cap = mail_capacity; |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
333 u->cargo.Truncate(mail_capacity); |
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
334 } |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
335 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
336 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
337 |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
338 _returned_refit_capacity = total_capacity; |
14176
41303b56f42c
(svn r18724) -Fix [FS#3475] (r17899): refitting a non-refittable vehicle to it's default cargotype failed, causing problems for AIs
yexo <yexo@openttd.org>
parents:
13962
diff
changeset
|
339 return cost; |
13390
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
340 } |
d3edbd44dacd
(svn r17899) -Codechange: Deduplicate code for refitting vehicles.
frosch <frosch@openttd.org>
parents:
13175
diff
changeset
|
341 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
342 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
343 * Test if a name is unique among vehicle names. |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
344 * @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
|
345 * @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
|
346 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
347 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
|
348 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
349 const Vehicle *v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
350 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
351 FOR_ALL_VEHICLES(v) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
352 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
|
353 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
354 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
355 return true; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
356 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
357 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
358 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
359 * Clone the custom name of a vehicle, adding or incrementing a number. |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
360 * @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
|
361 * @param dst Destination vehicle. |
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 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
|
364 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
365 char buf[256]; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
366 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
367 /* 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
|
368 size_t number_position; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
369 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
|
370 /* 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
|
371 * for UTF-8 sequences. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
372 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
|
373 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
374 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
375 /* 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
|
376 int num; |
14901
a79ad74932d1
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
peter1138 <peter1138@openttd.org>
parents:
14898
diff
changeset
|
377 byte padding = 0; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
378 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
|
379 /* 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
|
380 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
|
381 strecat(buf, " ", lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
382 number_position = strlen(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
383 num = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
384 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
385 /* 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
|
386 strecpy(buf, src->name, lastof(buf)); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
387 buf[number_position] = '\0'; |
14901
a79ad74932d1
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
peter1138 <peter1138@openttd.org>
parents:
14898
diff
changeset
|
388 char *endptr; |
a79ad74932d1
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
peter1138 <peter1138@openttd.org>
parents:
14898
diff
changeset
|
389 num = strtol(&src->name[number_position], &endptr, 10) + 1; |
a79ad74932d1
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
peter1138 <peter1138@openttd.org>
parents:
14898
diff
changeset
|
390 padding = endptr - &src->name[number_position]; |
11349
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 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
393 /* 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
|
394 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
|
395 /* Attach the number to the temporary name. */ |
14901
a79ad74932d1
(svn r19498) -Feature [FS#3710]: Keep number padding intact when cloning vehicle names.
peter1138 <peter1138@openttd.org>
parents:
14898
diff
changeset
|
396 seprintf(&buf[number_position], lastof(buf), "%0*d", padding, num); |
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 /* 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
|
399 if (IsUniqueVehicleName(buf)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
400 dst->name = strdup(buf); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
401 break; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
402 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
403 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
404 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
405 /* 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
|
406 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
407 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
408 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
409 * Clone a vehicle. If it is a train, it will clone all the cars too |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
410 * @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
|
411 * @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
|
412 * @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
|
413 * @param p2 1 = shared orders, else copied orders |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
414 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
415 * @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
|
416 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
417 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
|
418 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
419 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
|
420 uint32 build_argument = 2; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
421 |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
422 Vehicle *v = Vehicle::GetIfValid(p1); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15039
diff
changeset
|
423 if (v == NULL || !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
|
424 Vehicle *v_front = v; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
425 Vehicle *w = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
426 Vehicle *w_front = NULL; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
427 Vehicle *w_rear = NULL; |
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 * 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
|
431 * 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
|
432 * 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
|
433 * 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
|
434 * 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
|
435 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
436 |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
437 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
438 if (ret.Failed()) return ret; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
439 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
440 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
|
441 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
442 /* 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
|
443 if (!(flags & DC_EXEC)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
444 int veh_counter = 0; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
445 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
446 veh_counter++; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
447 } 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
|
448 |
11900
46d45a7511f9
(svn r16300) -Codechange: reduce usage of Vehicle::AllocateList
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
449 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
|
450 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
|
451 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
452 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
453 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
454 v = v_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
455 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
456 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
|
457 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
|
458 /* 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
|
459 continue; |
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 |
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
|
462 /* 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
|
463 * 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
|
464 * 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
|
465 * '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
|
466 * 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
|
467 * 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
|
468 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
|
469 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
|
470 |
29efbe666d4a
(svn r17509) -Fix [FS#3196]: if building a part fails during cloning, sell what was already cloned instead of leaving it 'for free'
rubidium <rubidium@openttd.org>
parents:
12953
diff
changeset
|
471 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
|
472 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
|
473 |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
474 if (cost.Failed()) { |
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
|
475 /* 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
|
476 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
|
477 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
|
478 } |
11349
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 total_cost.AddCost(cost); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
481 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
482 if (flags & DC_EXEC) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
483 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
|
484 |
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
|
485 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
|
486 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
|
487 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
488 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12228
diff
changeset
|
489 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
|
490 /* 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
|
491 * 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
|
492 CommandCost result = DoCommand(0, (w_rear->index << 16) | w->index, 1, flags, CMD_MOVE_RAIL_VEHICLE); |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
493 if (result.Failed()) { |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
494 /* 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
|
495 * 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
|
496 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
|
497 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
|
498 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
|
499 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
500 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
501 /* 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
|
502 w_front = w; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
503 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
|
504 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
505 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
|
506 } |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
507 } 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
|
508 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12032
diff
changeset
|
509 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
|
510 /* 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
|
511 _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
|
512 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
513 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
514 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
515 /* 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
|
516 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
|
517 } |
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 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
520 /* Take care of refitting. */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
521 w = w_front; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
522 v = v_front; |
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 /* 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
|
525 * 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
|
526 * 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
|
527 * 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
|
528 * 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
|
529 * 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
|
530 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
531 do { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
532 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
533 assert(w != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
534 |
13962
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
535 /* Find out what's the best sub type */ |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
536 byte subtype = GetBestFittingSubType(v, w); |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
537 if (w->cargo_type != v->cargo_type || w->cargo_subtype != subtype) { |
9b98b4f050e5
(svn r18498) -Fix [FS#2616]: cloning of vehicles could create vehicles with invalid cargo sub types for the build year of the vehicle. Fall back to another cargo sub type with the exact same name, otherwise fallback to cargo sub type 0.
rubidium <rubidium@openttd.org>
parents:
13933
diff
changeset
|
538 CommandCost cost = DoCommand(0, w->index, v->cargo_type | (subtype << 8) | 1U << 16, flags, GetCmdRefitVeh(v)); |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
539 if (cost.Succeeded()) total_cost.AddCost(cost); |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
540 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
541 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
542 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
|
543 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
|
544 } 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
|
545 w = w->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
546 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
547 break; |
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 } else { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11900
diff
changeset
|
550 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
|
551 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
|
552 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
553 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
|
554 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
|
555 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
556 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
557 |
12305
217431f4bc67
(svn r16722) -Codechange: unify the naming of the Is/Set/HasArticulatedPart functions
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
558 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
|
559 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
|
560 } 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
|
561 v = v->Next(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
562 } else { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
563 break; |
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 } while (v != NULL); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
566 |
12306
d0ff55a976ad
(svn r16723) -Codechange: make GetNextArticPart(), GetLastEnginePart(), GetNextVehicle(), GetPrevVehicle(), GetNextUnit(), GetPrevUnit() members of Train
smatz <smatz@openttd.org>
parents:
12305
diff
changeset
|
567 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
|
568 } 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
|
569 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
570 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
571 /* |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
572 * 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
|
573 * 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
|
574 * 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
|
575 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
576 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
|
577 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
578 /* 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
|
579 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
|
580 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
581 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
582 /* 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
|
583 * 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
|
584 if (!CheckCompanyHasMoney(total_cost)) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
585 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
586 /* 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
|
587 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
|
588 } |
14232
860ea22258ba
(svn r18783) -Codechange: make CheckCompanyHasMoney set an error on the CommandCost it tests when you don't have enough money instead of setting a global variable.
rubidium <rubidium@openttd.org>
parents:
14176
diff
changeset
|
589 return total_cost; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
590 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
591 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
592 return total_cost; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
593 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
594 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
595 /** |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
596 * 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
|
597 * @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
|
598 * @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
|
599 * @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
|
600 * @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
|
601 * @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
|
602 * @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
|
603 * @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
|
604 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
605 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
|
606 { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
607 VehicleList list; |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
608 |
15039
53c099f9a3a9
(svn r19656) -Codechange/Fix: Report back if invalid vehicle lists are requested.
frosch <frosch@openttd.org>
parents:
15037
diff
changeset
|
609 if (!GenerateVehicleSortList(&list, type, owner, id, vlw_flag)) return CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
610 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
611 /* Send all the vehicles to a depot */ |
14893
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
612 bool had_success = false; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
613 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
|
614 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
|
615 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
|
616 |
14893
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
617 if (ret.Succeeded()) { |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
618 had_success = true; |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
619 |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
620 /* Return 0 if DC_EXEC is not set this is a valid goto depot command) |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
621 * In this case we know that at least one vehicle can be sent to a depot |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
622 * and we will issue the command. We can now safely quit the loop, knowing |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
623 * it will succeed at least once. With DC_EXEC we really need to send them to the depot */ |
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
624 if (!(flags & DC_EXEC)) break; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
625 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
626 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
627 |
14893
0a799fd7f1a8
(svn r19489) -Codechange: Introduce a had_success variable in SendAllVehiclesToDepot().
alberth <alberth@openttd.org>
parents:
14886
diff
changeset
|
628 return had_success ? CommandCost() : CMD_ERROR; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
629 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
630 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
631 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
632 * Give a custom name to your vehicle |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
633 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
634 * @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
|
635 * @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
|
636 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
637 * @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
|
638 * @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
|
639 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
640 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
|
641 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
642 Vehicle *v = Vehicle::GetIfValid(p1); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15039
diff
changeset
|
643 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
644 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
645 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
646 if (ret.Failed()) return ret; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
647 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
648 bool reset = StrEmpty(text); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
649 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
650 if (!reset) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
651 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
|
652 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
|
653 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
654 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
655 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
656 free(v->name); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
657 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
|
658 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
|
659 MarkWholeScreenDirty(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
660 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
661 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
662 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
663 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
664 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
665 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
666 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15618
diff
changeset
|
667 * Change the service interval of a vehicle |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
668 * @param tile unused |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
669 * @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
|
670 * @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
|
671 * @param p2 new service interval |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
672 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
673 * @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
|
674 */ |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
675 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
|
676 { |
11949
c89301974eb8
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
677 Vehicle *v = Vehicle::GetIfValid(p1); |
15040
3314e49704e7
(svn r19657) -Fix: Add saneness checks for front vehicles.
frosch <frosch@openttd.org>
parents:
15039
diff
changeset
|
678 if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR; |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
679 |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
680 CommandCost ret = CheckOwnership(v->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14750
diff
changeset
|
681 if (ret.Failed()) return ret; |
11349
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
682 |
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
|
683 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
|
684 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
|
685 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
686 if (flags & DC_EXEC) { |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
687 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
|
688 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
|
689 } |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
690 |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
691 return CommandCost(); |
bf07f69e1221
(svn r15699) -Codechange: split Cmd* from vehicle.cpp to vehicle_cmd.cpp.
rubidium <rubidium@openttd.org>
parents:
diff
changeset
|
692 } |