Mercurial > hg > openttd
annotate src/vehicle.cpp @ 19973:f8c0e108128c draft
(svn r24905) -Feature(ish): Implement station randomisation triggers.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Fri, 11 Jan 2013 07:39:25 +0000 |
parents | 0dba7f49118c |
children | a916bd017086 |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
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:
12743
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:
12743
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:
12743
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
9 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
9081
diff
changeset
|
10 /** @file vehicle.cpp Base implementations of all vehicles. */ |
6423
72ac8bfaa32f
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents:
6350
diff
changeset
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
18627
1972f6346144
(svn r23474) -Codechange: move the declaration error related functions to error.h
rubidium <rubidium@openttd.org>
parents:
18511
diff
changeset
|
13 #include "error.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
14 #include "roadveh.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
15 #include "ship.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #include "spritecache.h" |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
17 #include "timetable.h" |
8224
c45446125bf0
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium <rubidium@openttd.org>
parents:
8214
diff
changeset
|
18 #include "viewport_func.h" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8736
diff
changeset
|
19 #include "news_func.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8114
diff
changeset
|
20 #include "command_func.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
21 #include "company_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
22 #include "train.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
23 #include "aircraft.h" |
15083
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15002
diff
changeset
|
24 #include "newgrf_debug.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
25 #include "newgrf_sound.h" |
9041
7a19e805faf6
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138 <peter1138@openttd.org>
parents:
9009
diff
changeset
|
26 #include "newgrf_station.h" |
10630
14053cbe3be4
(svn r14925) -Fix [FS#2500]: Abort dragging of vehicles in the group window when they are deleted.
frosch <frosch@openttd.org>
parents:
10577
diff
changeset
|
27 #include "group_gui.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
8108
diff
changeset
|
28 #include "strings_func.h" |
8123
c26c28875749
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium <rubidium@openttd.org>
parents:
8121
diff
changeset
|
29 #include "zoom_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
30 #include "date_func.h" |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
31 #include "vehicle_func.h" |
8212
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8211
diff
changeset
|
32 #include "autoreplace_func.h" |
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8211
diff
changeset
|
33 #include "autoreplace_gui.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12128
diff
changeset
|
34 #include "station_base.h" |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10679
diff
changeset
|
35 #include "ai/ai.hpp" |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
36 #include "depot_func.h" |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
37 #include "network/network.h" |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
38 #include "core/pool_func.hpp" |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
39 #include "economy_base.h" |
14009
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
40 #include "articulated_vehicles.h" |
14095
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
41 #include "roadstop_base.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:
14213
diff
changeset
|
42 #include "core/random_func.hpp" |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15127
diff
changeset
|
43 #include "core/backup_type.hpp" |
15859
e4a43875449c
(svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents:
15820
diff
changeset
|
44 #include "order_backup.h" |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
45 #include "sound_func.h" |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
46 #include "effectvehicle_func.h" |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
47 #include "effectvehicle_base.h" |
16079
f961c962db5d
(svn r20772) -Codechange: use packed VehicleListIdentifiers as window numbers
rubidium <rubidium@openttd.org>
parents:
16060
diff
changeset
|
48 #include "vehiclelist.h" |
17266
6f191e237da9
(svn r22006) -Fix [FS#4480]: smoke/sparks of trains would be shown under bridges, or rather through bridges
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
49 #include "bridge_map.h" |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
50 #include "tunnel_map.h" |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
51 #include "depot_map.h" |
18276
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
52 #include "gamelog.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
53 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
54 #include "table/strings.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8258
diff
changeset
|
55 |
18484
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
56 #define GEN_HASH(x, y) ((GB((y), 6 + ZOOM_LVL_SHIFT, 6) << 6) + GB((x), 7 + ZOOM_LVL_SHIFT, 6)) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
57 |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
58 VehicleID _new_vehicle_id; |
16489
7c956d217b83
(svn r21214) -Add: Display mail capacity when refitting an aircraft to passengers.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
59 uint16 _returned_refit_capacity; ///< Stores the capacity after a refit operation. |
7c956d217b83
(svn r21214) -Add: Display mail capacity when refitting an aircraft to passengers.
terkhen <terkhen@openttd.org>
parents:
16382
diff
changeset
|
60 uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refit operation (Aircraft only). |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
61 |
5792
88cf2dc7e649
(svn r8349) -Codechange: replaced CMD_REFIT_VEH() and similar defines with real static inline functions
bjarni <bjarni@openttd.org>
parents:
5763
diff
changeset
|
62 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
63 /** The pool with all our precious vehicles. */ |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
64 VehiclePool _vehicle_pool("Vehicle"); |
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
65 INSTANTIATE_POOL_METHODS(Vehicle) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
67 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
68 * Function to tell if a vehicle needs to be autorenewed |
10225
fe1681c9d05b
(svn r14448) -Codechange [FS#2328]: rename a few variables (based on a patch by planetmaker)
smatz <smatz@openttd.org>
parents:
10208
diff
changeset
|
69 * @param *c The vehicle owner |
19247
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
70 * @param use_renew_setting Should the company renew setting be considered? |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
71 * @return true if the vehicle is old enough for replacement |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
72 */ |
19247
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
73 bool Vehicle::NeedsAutorenewing(const Company *c, bool use_renew_setting) const |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
74 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
75 /* We can always generate the Company pointer when we have the vehicle. |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
76 * However this takes time and since the Company pointer is often present |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
77 * when this function is called then it's faster to pass the pointer as an |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
78 * argument rather than finding it again. */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
79 assert(c == Company::Get(this->owner)); |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
80 |
19247
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
81 if (use_renew_setting && !c->settings.engine_renew) return false; |
11913
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
82 if (this->age - this->max_age < (c->settings.engine_renew_months * 30)) return false; |
18032
9d7cd831df9b
(svn r22847) -Fix (r22816): Wagons shall not be processed by autorenew.
frosch <frosch@openttd.org>
parents:
18007
diff
changeset
|
83 |
9d7cd831df9b
(svn r22847) -Fix (r22816): Wagons shall not be processed by autorenew.
frosch <frosch@openttd.org>
parents:
18007
diff
changeset
|
84 /* Only engines need renewing */ |
9d7cd831df9b
(svn r22847) -Fix (r22816): Wagons shall not be processed by autorenew.
frosch <frosch@openttd.org>
parents:
18007
diff
changeset
|
85 if (this->type == VEH_TRAIN && !Train::From(this)->IsEngine()) return false; |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
86 |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
87 return true; |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
88 } |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
89 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
90 void VehicleServiceInDepot(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 v->date_of_last_service = _date; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
93 v->breakdowns_since_last_service = 0; |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
94 v->reliability = v->GetEngine()->reliability; |
19239
f8c2a425a11b
(svn r24128) -Change: Don't let vehicles break down directly after servicing.
michi_cc <michi_cc@openttd.org>
parents:
19235
diff
changeset
|
95 /* Prevent vehicles from breaking down directly after exiting the depot. */ |
f8c2a425a11b
(svn r24128) -Change: Don't let vehicles break down directly after servicing.
michi_cc <michi_cc@openttd.org>
parents:
19235
diff
changeset
|
96 v->breakdown_chance /= 4; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
97 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
99 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
100 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
101 * Check if the vehicle needs to go to a depot in near future (if a opportunity presents itself) for service or replacement. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
102 * |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
103 * @see NeedsAutomaticServicing() |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
104 * @return true if the vehicle should go to a depot if a opportunity presents itself. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
105 */ |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
106 bool Vehicle::NeedsServicing() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
107 { |
14007
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
108 /* Stopped or crashed vehicles will not move, as such making unmovable |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
109 * vehicles to go for service is lame. */ |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
110 if (this->vehstatus & (VS_STOPPED | VS_CRASHED)) return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
111 |
14007
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
112 /* Are we ready for the next service cycle? */ |
14009
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
113 const Company *c = Company::Get(this->owner); |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
114 if (c->settings.vehicle.servint_ispercent ? |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
115 (this->reliability >= this->GetEngine()->reliability * (100 - this->service_interval) / 100) : |
14007
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
116 (this->date_of_last_service + this->service_interval >= _date)) { |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
117 return false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
119 |
14007
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
120 /* If we're servicing anyway, because we have not disabled servicing when |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
121 * there are no breakdowns or we are playing with breakdowns, bail out. */ |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
122 if (!_settings_game.order.no_servicing_if_no_breakdowns || |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
123 _settings_game.difficulty.vehicle_breakdowns != 0) { |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
124 return true; |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
125 } |
15f1cb47c4ef
(svn r18549) -Fix: first do the time-since-last-service check and only then determine whether autoreplace needs to take place. This way they will not keep autoreplacing continuously on failure, but only after some timeout.
rubidium <rubidium@openttd.org>
parents:
13994
diff
changeset
|
126 |
14009
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
127 /* Test whether there is some pending autoreplace. |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
128 * Note: We do this after the service-interval test. |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
129 * There are a lot more reasons for autoreplace to fail than we can test here reasonably. */ |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
130 bool pending_replace = false; |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
131 Money needed_money = c->settings.engine_renew_money; |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
132 if (needed_money > c->money) return false; |
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
133 |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
134 for (const Vehicle *v = this; v != NULL; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : NULL) { |
19247
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
135 bool replace_when_old = false; |
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
136 EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id, &replace_when_old); |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
137 |
14009
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
138 /* Check engine availability */ |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
139 if (new_engine == INVALID_ENGINE || !HasBit(Engine::Get(new_engine)->company_avail, v->owner)) continue; |
19247
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
140 /* Is the vehicle old if we are not always replacing? */ |
2cf452279593
(svn r24136) -Feature [FS#4465]: Autoreplace vehicles only when they get old. (Vikthor)
michi_cc <michi_cc@openttd.org>
parents:
19239
diff
changeset
|
141 if (replace_when_old && !v->NeedsAutorenewing(c, false)) continue; |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
142 |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
143 /* Check refittability */ |
14028
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
144 uint32 available_cargo_types, union_mask; |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
145 GetArticulatedRefitMasks(new_engine, true, &union_mask, &available_cargo_types); |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
146 /* Is there anything to refit? */ |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
147 if (union_mask != 0) { |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
148 CargoID cargo_type; |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
149 /* We cannot refit to mixed cargoes in an automated way */ |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18627
diff
changeset
|
150 if (IsArticulatedVehicleCarryingDifferentCargoes(v, &cargo_type)) continue; |
14028
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
151 |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
152 /* Did the old vehicle carry anything? */ |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
153 if (cargo_type != CT_INVALID) { |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
154 /* We can't refit the vehicle to carry the cargo we want */ |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
155 if (!HasBit(available_cargo_types, cargo_type)) continue; |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
156 } |
bc26fd686681
(svn r18571) -Fix (r18551): Vehicles not carrying any cargo (e.g. engines) were not considered for sending to depot for replacement.
frosch <frosch@openttd.org>
parents:
14026
diff
changeset
|
157 } |
14009
809a3be57aef
(svn r18551) -Fix [FS#1762]: When autoreplace is the only allowed reason to send vehicles to depot, first check some minimal requirements (engine availability, refittability) and a heuristic for the needed money.
frosch <frosch@openttd.org>
parents:
14007
diff
changeset
|
158 |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
159 /* Check money. |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
160 * We want 2*(the price of the new vehicle) without looking at the value of the vehicle we are going to sell. */ |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
161 pending_replace = true; |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
162 needed_money += 2 * Engine::Get(new_engine)->GetCost(); |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
163 if (needed_money > c->money) return false; |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
164 } |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
165 |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
166 return pending_replace; |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
167 } |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
168 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
169 /** |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19948
diff
changeset
|
170 * Checks if the current order should be interrupted for a service-in-depot order. |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
171 * @see NeedsServicing() |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19948
diff
changeset
|
172 * @return true if the current order should be interrupted. |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
173 */ |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
174 bool Vehicle::NeedsAutomaticServicing() const |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
175 { |
17218
46deeeb7a878
(svn r21957) -Cleanup: gotodepot and timetabling settings are more or less useless; just don't use depot orders or timetabling if you don't want to use it
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
176 if (this->HasDepotOrder()) return false; |
16733
4b988ed6473a
(svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
16523
diff
changeset
|
177 if (this->current_order.IsType(OT_LOADING)) return false; |
8914
3559eb7e49a4
(svn r12684) -Fix [FS#1891]: manually given service at depot order is not forgotten anymore when autoservice 'interferes'.
rubidium <rubidium@openttd.org>
parents:
8902
diff
changeset
|
178 if (this->current_order.IsType(OT_GOTO_DEPOT) && this->current_order.GetDepotOrderType() != ODTFB_SERVICE) return false; |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
179 return NeedsServicing(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
182 uint Vehicle::Crash(bool flooded) |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
183 { |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
184 assert((this->vehstatus & VS_CRASHED) == 0); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
185 assert(this->Previous() == NULL); // IsPrimaryVehicle fails for free-wagon-chains |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
186 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
187 uint pass = 0; |
15322
ff08f0eb701d
(svn r19963) -Add: Stop a vehicle after it crashes or is destroyed.
terkhen <terkhen@openttd.org>
parents:
15292
diff
changeset
|
188 /* Stop the vehicle. */ |
ff08f0eb701d
(svn r19963) -Add: Stop a vehicle after it crashes or is destroyed.
terkhen <terkhen@openttd.org>
parents:
15292
diff
changeset
|
189 if (this->IsPrimaryVehicle()) this->vehstatus |= VS_STOPPED; |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
190 /* crash all wagons, and count passengers */ |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
191 for (Vehicle *v = this; v != NULL; v = v->Next()) { |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
192 if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo.Count(); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
193 v->vehstatus |= VS_CRASHED; |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
194 MarkSingleVehicleDirty(v); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
195 } |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
196 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
197 /* Dirty some windows */ |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
198 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18678
diff
changeset
|
199 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
200 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
201 SetWindowDirty(WC_VEHICLE_DEPOT, this->tile); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
202 |
19330
18f4204c3fb2
(svn r24219) -Fix [FS#5152]: immediately do the cargo payment on vehicle crashes instead of when they are cleared
rubidium <rubidium@openttd.org>
parents:
19253
diff
changeset
|
203 delete this->cargo_payment; |
18f4204c3fb2
(svn r24219) -Fix [FS#5152]: immediately do the cargo payment on vehicle crashes instead of when they are cleared
rubidium <rubidium@openttd.org>
parents:
19253
diff
changeset
|
204 this->cargo_payment = NULL; |
18f4204c3fb2
(svn r24219) -Fix [FS#5152]: immediately do the cargo payment on vehicle crashes instead of when they are cleared
rubidium <rubidium@openttd.org>
parents:
19253
diff
changeset
|
205 |
19253
3d3ef3d8ac33
(svn r24142) -Feature [FS#3576]: Randomise count of passengers killed in a crash. (riffraffselbow)
michi_cc <michi_cc@openttd.org>
parents:
19247
diff
changeset
|
206 return RandomRange(pass + 1); // Randomise deceased passengers. |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
207 } |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
208 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
209 |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
210 /** |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
211 * Displays a "NewGrf Bug" error message for a engine, and pauses the game if not networking. |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
212 * @param engine The engine that caused the problem |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
213 * @param part1 Part 1 of the error message, taking the grfname as parameter 1 |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
214 * @param part2 Part 2 of the error message, taking the engine as parameter 2 |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
215 * @param bug_type Flag to check and set in grfconfig |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
216 * @param critical Shall the "OpenTTD might crash"-message be shown when the player tries to unpause? |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
217 */ |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
218 void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical) |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
219 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
220 const Engine *e = Engine::Get(engine); |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
221 GRFConfig *grfconfig = GetGRFConfig(e->GetGRFID()); |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
222 |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
223 if (!HasBit(grfconfig->grf_bugs, bug_type)) { |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
224 SetBit(grfconfig->grf_bugs, bug_type); |
14711
74b0a8a64ff5
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents:
14707
diff
changeset
|
225 SetDParamStr(0, grfconfig->GetName()); |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
226 SetDParam(1, engine); |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14641
diff
changeset
|
227 ShowErrorMessage(part1, part2, WL_CRITICAL); |
11899
fc1af9d26d2c
(svn r16299) -Fix (r16242): don't use DoCommandP when the function can be called from another command
smatz <smatz@openttd.org>
parents:
11891
diff
changeset
|
228 if (!_networking) DoCommand(0, critical ? PM_PAUSED_ERROR : PM_PAUSED_NORMAL, 1, DC_EXEC, CMD_PAUSE); |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
229 } |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
230 |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
231 /* debug output */ |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
232 char buffer[512]; |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
233 |
14711
74b0a8a64ff5
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents:
14707
diff
changeset
|
234 SetDParamStr(0, grfconfig->GetName()); |
11351
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
235 GetString(buffer, part1, lastof(buffer)); |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
236 DEBUG(grf, 0, "%s", buffer + 3); |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
237 |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
238 SetDParam(1, engine); |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
239 GetString(buffer, part2, lastof(buffer)); |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
240 DEBUG(grf, 0, "%s", buffer + 3); |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
241 } |
11acaad65229
(svn r15701) -Fix [FS#2595]: Blame NewGRFs returning inconsistent information in purchase-list/after building before users have a chance to blame OpenTTD for incorrectly autorenewing/-replacing.
frosch <frosch@openttd.org>
parents:
11349
diff
changeset
|
242 |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
243 /** |
18276
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
244 * Logs a bug in GRF and shows a warning message if this |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
245 * is for the first time this happened. |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
246 * @param u first vehicle of chain |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
247 */ |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
248 void VehicleLengthChanged(const Vehicle *u) |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
249 { |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
250 /* show a warning once for each engine in whole game and once for each GRF after each game load */ |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
251 const Engine *engine = u->GetEngine(); |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
252 uint32 grfid = engine->grf_prop.grffile->grfid; |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
253 GRFConfig *grfconfig = GetGRFConfig(grfid); |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
254 if (GamelogGRFBugReverse(grfid, engine->grf_prop.local_id) || !HasBit(grfconfig->grf_bugs, GBUG_VEH_LENGTH)) { |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
255 ShowNewGrfVehicleError(u->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_VEHICLE_LENGTH, GBUG_VEH_LENGTH, true); |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
256 } |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
257 } |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
258 |
72e793b46dee
(svn r23112) -Codechange: Check if vehicle chain lengths stays constant when auto-refitting.
michi_cc <michi_cc@openttd.org>
parents:
18274
diff
changeset
|
259 /** |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
260 * Vehicle constructor. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
261 * @param type Type of the new vehicle. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
262 */ |
12065
6ac064c3a427
(svn r16472) -Codechange: set vehicle type in SpecializedVehicle constructor instead of constructor of each vehicle type
smatz <smatz@openttd.org>
parents:
12044
diff
changeset
|
263 Vehicle::Vehicle(VehicleType type) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
264 { |
12065
6ac064c3a427
(svn r16472) -Codechange: set vehicle type in SpecializedVehicle constructor instead of constructor of each vehicle type
smatz <smatz@openttd.org>
parents:
12044
diff
changeset
|
265 this->type = type; |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
266 this->coord.left = INVALID_COORD; |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
267 this->group_id = DEFAULT_GROUP; |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
268 this->fill_percent_te_id = INVALID_TE_ID; |
7497
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
269 this->first = this; |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
270 this->colourmap = PAL_NONE; |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
271 this->cargo_age_counter = 1; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
273 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
275 * Get a value for a vehicle's random_bits. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 * @return A random value from 0 to 255. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
278 byte VehicleRandomBits() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
279 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
280 return GB(Random(), 0, 8); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
281 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
283 /* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
284 * lookup times at the expense of memory usage. */ |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
285 const int HASH_BITS = 7; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
286 const int HASH_SIZE = 1 << HASH_BITS; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
287 const int HASH_MASK = HASH_SIZE - 1; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
288 const int TOTAL_HASH_SIZE = 1 << (HASH_BITS * 2); |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
289 const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
290 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
291 /* Resolution of the hash, 0 = 1*1 tile, 1 = 2*2 tiles, 2 = 4*4 tiles, etc. |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
292 * Profiling results show that 0 is fastest. */ |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
293 const int HASH_RES = 0; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
294 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
295 static Vehicle *_vehicle_tile_hash[TOTAL_HASH_SIZE]; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
296 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
297 static Vehicle *VehicleFromTileHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc, bool find_first) |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
298 { |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
299 for (int y = yl; ; y = (y + (1 << HASH_BITS)) & (HASH_MASK << HASH_BITS)) { |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
300 for (int x = xl; ; x = (x + 1) & HASH_MASK) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
301 Vehicle *v = _vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK]; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
302 for (; v != NULL; v = v->hash_tile_next) { |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
303 Vehicle *a = proc(v, data); |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
304 if (find_first && a != NULL) return a; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
305 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
306 if (x == xu) break; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
307 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
308 if (y == yu) break; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
309 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
310 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
311 return NULL; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
312 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
313 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
314 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
315 /** |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
316 * Helper function for FindVehicleOnPos/HasVehicleOnPos. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
317 * @note Do not call this function directly! |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
318 * @param x The X location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
319 * @param y The Y location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
320 * @param data Arbitrary data passed to proc |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
321 * @param proc The proc that determines whether a vehicle will be "found". |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
322 * @param find_first Whether to return on the first found or iterate over |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
323 * all vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
324 * @return the best matching or first vehicle (depending on find_first). |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
325 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
326 static Vehicle *VehicleFromPosXY(int x, int y, void *data, VehicleFromPosProc *proc, bool find_first) |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
327 { |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
328 const int COLL_DIST = 6; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
329 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
330 /* Hash area to scan is from xl,yl to xu,yu */ |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
331 int xl = GB((x - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
332 int xu = GB((x + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS); |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
333 int yl = GB((y - COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
334 int yu = GB((y + COLL_DIST) / TILE_SIZE, HASH_RES, HASH_BITS) << HASH_BITS; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
335 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
336 return VehicleFromTileHash(xl, yl, xu, yu, data, proc, find_first); |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
337 } |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
338 |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
339 /** |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
340 * Find a vehicle from a specific location. It will call proc for ALL vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
341 * on the tile and YOU must make SURE that the "best one" is stored in the |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
342 * data value and is ALWAYS the same regardless of the order of the vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
343 * where proc was called on! |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
344 * When you fail to do this properly you create an almost untraceable DESYNC! |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
345 * @note The return value of proc will be ignored. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
346 * @note Use this when you have the intention that all vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
347 * should be iterated over. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
348 * @param x The X location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
349 * @param y The Y location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
350 * @param data Arbitrary data passed to proc |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
351 * @param proc The proc that determines whether a vehicle will be "found". |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
352 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
353 void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc) |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
354 { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
355 VehicleFromPosXY(x, y, data, proc, false); |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
356 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
357 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
358 /** |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
359 * Checks whether a vehicle in on a specific location. It will call proc for |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
360 * vehicles until it returns non-NULL. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
361 * @note Use FindVehicleOnPosXY when you have the intention that all vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
362 * should be iterated over. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
363 * @param x The X location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
364 * @param y The Y location on the map |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
365 * @param data Arbitrary data passed to proc |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
366 * @param proc The proc that determines whether a vehicle will be "found". |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
367 * @return True if proc returned non-NULL. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
368 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
369 bool HasVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc) |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
370 { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
371 return VehicleFromPosXY(x, y, data, proc, true) != NULL; |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
372 } |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
373 |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
374 /** |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
375 * Helper function for FindVehicleOnPos/HasVehicleOnPos. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
376 * @note Do not call this function directly! |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
377 * @param tile The location on the map |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
378 * @param data Arbitrary data passed to \a proc. |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
379 * @param proc The proc that determines whether a vehicle will be "found". |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
380 * @param find_first Whether to return on the first found or iterate over |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
381 * all vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
382 * @return the best matching or first vehicle (depending on find_first). |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
383 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
384 static Vehicle *VehicleFromPos(TileIndex tile, void *data, VehicleFromPosProc *proc, bool find_first) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
385 { |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
386 int x = GB(TileX(tile), HASH_RES, HASH_BITS); |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
387 int y = GB(TileY(tile), HASH_RES, HASH_BITS) << HASH_BITS; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
388 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
389 Vehicle *v = _vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK]; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
390 for (; v != NULL; v = v->hash_tile_next) { |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
391 if (v->tile != tile) continue; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
392 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
393 Vehicle *a = proc(v, data); |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
394 if (find_first && a != NULL) return a; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
395 } |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
396 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
397 return NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
398 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
399 |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
400 /** |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
401 * Find a vehicle from a specific location. It will call \a proc for ALL vehicles |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
402 * on the tile and YOU must make SURE that the "best one" is stored in the |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
403 * data value and is ALWAYS the same regardless of the order of the vehicles |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
404 * where proc was called on! |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
405 * When you fail to do this properly you create an almost untraceable DESYNC! |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
406 * @note The return value of \a proc will be ignored. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
407 * @note Use this function when you have the intention that all vehicles |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
408 * should be iterated over. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
409 * @param tile The location on the map |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
410 * @param data Arbitrary data passed to \a proc. |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
411 * @param proc The proc that determines whether a vehicle will be "found". |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
412 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
413 void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
414 { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
415 VehicleFromPos(tile, data, proc, false); |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
416 } |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
417 |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
418 /** |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
419 * Checks whether a vehicle is on a specific location. It will call \a proc for |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
420 * vehicles until it returns non-NULL. |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
421 * @note Use #FindVehicleOnPos when you have the intention that all vehicles |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
422 * should be iterated over. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
423 * @param tile The location on the map |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
424 * @param data Arbitrary data passed to \a proc. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
425 * @param proc The \a proc that determines whether a vehicle will be "found". |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
426 * @return True if proc returned non-NULL. |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
427 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
428 bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc) |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
429 { |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
430 return VehicleFromPos(tile, data, proc, true) != NULL; |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
431 } |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
432 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
433 /** |
18274
c761b8c17062
(svn r23110) -Codechange: let the flying altitude return ints are well
rubidium <rubidium@openttd.org>
parents:
18272
diff
changeset
|
434 * Callback that returns 'real' vehicles lower or at height \c *(int*)data . |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
435 * @param v Vehicle to examine. |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
436 * @param data Pointer to height data. |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
437 * @return \a v if conditions are met, else \c NULL. |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
438 */ |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
439 static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
440 { |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
441 int z = *(int*)data; |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
442 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
443 if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
444 if (v->z_pos > z) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
445 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
446 return v; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
447 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
448 |
15382
8e0d118d93ce
(svn r20025) -Doc: Fix/add comments to let Doxygen know about the documentation.
alberth <alberth@openttd.org>
parents:
15362
diff
changeset
|
449 /** |
8e0d118d93ce
(svn r20025) -Doc: Fix/add comments to let Doxygen know about the documentation.
alberth <alberth@openttd.org>
parents:
15362
diff
changeset
|
450 * Ensure there is no vehicle at the ground at the given position. |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
451 * @param tile Position to examine. |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
452 * @return Succeeded command (ground is free) or failed command (a vehicle is found). |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
453 */ |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
454 CommandCost EnsureNoVehicleOnGround(TileIndex tile) |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
455 { |
18272
3ebab55c5495
(svn r23108) -Codechange: more uint -> int / byte -> int conversions for Z related variables
rubidium <rubidium@openttd.org>
parents:
18255
diff
changeset
|
456 int z = GetTileMaxPixelZ(tile); |
14705
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
457 |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
458 /* Value v is not safe in MP games, however, it is used to generate a local |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
459 * error message only (which may be different for different machines). |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
460 * Such a message does not affect MP synchronisation. |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
461 */ |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
462 Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true); |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
463 if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); |
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
464 return CommandCost(); |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
465 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
466 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
467 /** Procedure called for every vehicle found in tunnel/bridge in the hash map */ |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
468 static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
469 { |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
470 if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
471 if (v == (const Vehicle *)data) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
472 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
473 return v; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
474 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
475 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
476 /** |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
477 * Finds vehicle in tunnel / bridge |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
478 * @param tile first end |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
479 * @param endtile second end |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
480 * @param ignore Ignore this vehicle when searching |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
481 * @return Succeeded command (if tunnel/bridge is free) or failed command (if a vehicle is using the tunnel/bridge). |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
482 */ |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
483 CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore) |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
484 { |
14705
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
485 /* Value v is not safe in MP games, however, it is used to generate a local |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
486 * error message only (which may be different for different machines). |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
487 * Such a message does not affect MP synchronisation. |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
488 */ |
18359
58955df25ef4
(svn r23195) -Codechange: if we really need to cast away constness, use const_cast
rubidium <rubidium@openttd.org>
parents:
18337
diff
changeset
|
489 Vehicle *v = VehicleFromPos(tile, const_cast<Vehicle *>(ignore), &GetVehicleTunnelBridgeProc, true); |
58955df25ef4
(svn r23195) -Codechange: if we really need to cast away constness, use const_cast
rubidium <rubidium@openttd.org>
parents:
18337
diff
changeset
|
490 if (v == NULL) v = VehicleFromPos(endtile, const_cast<Vehicle *>(ignore), &GetVehicleTunnelBridgeProc, true); |
14705
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
491 |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
492 if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); |
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
493 return CommandCost(); |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
494 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
495 |
14777
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
496 static Vehicle *EnsureNoTrainOnTrackProc(Vehicle *v, void *data) |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
497 { |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
498 TrackBits rail_bits = *(TrackBits *)data; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
499 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
500 if (v->type != VEH_TRAIN) return NULL; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
501 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
502 Train *t = Train::From(v); |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
503 if ((t->track != rail_bits) && !TracksOverlap(t->track | rail_bits)) return NULL; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
504 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
505 return v; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
506 } |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
507 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
508 /** |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
509 * Tests if a vehicle interacts with the specified track bits. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
510 * All track bits interact except parallel #TRACK_BIT_HORZ or #TRACK_BIT_VERT. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
511 * |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
512 * @param tile The tile. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
513 * @param track_bits The track bits. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
514 * @return \c true if no train that interacts, is found. \c false if a train is found. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
515 */ |
14781
7550a3af1a05
(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.
alberth <alberth@openttd.org>
parents:
14778
diff
changeset
|
516 CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits) |
14777
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
517 { |
14778
9b5bbac35346
(svn r19366) -Codechange: Move setting of _error_message from the callback check routine to the caller.
alberth <alberth@openttd.org>
parents:
14777
diff
changeset
|
518 /* Value v is not safe in MP games, however, it is used to generate a local |
9b5bbac35346
(svn r19366) -Codechange: Move setting of _error_message from the callback check routine to the caller.
alberth <alberth@openttd.org>
parents:
14777
diff
changeset
|
519 * error message only (which may be different for different machines). |
9b5bbac35346
(svn r19366) -Codechange: Move setting of _error_message from the callback check routine to the caller.
alberth <alberth@openttd.org>
parents:
14777
diff
changeset
|
520 * Such a message does not affect MP synchronisation. |
9b5bbac35346
(svn r19366) -Codechange: Move setting of _error_message from the callback check routine to the caller.
alberth <alberth@openttd.org>
parents:
14777
diff
changeset
|
521 */ |
9b5bbac35346
(svn r19366) -Codechange: Move setting of _error_message from the callback check routine to the caller.
alberth <alberth@openttd.org>
parents:
14777
diff
changeset
|
522 Vehicle *v = VehicleFromPos(tile, &track_bits, &EnsureNoTrainOnTrackProc, true); |
14781
7550a3af1a05
(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.
alberth <alberth@openttd.org>
parents:
14778
diff
changeset
|
523 if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type); |
7550a3af1a05
(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.
alberth <alberth@openttd.org>
parents:
14778
diff
changeset
|
524 return CommandCost(); |
14777
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
525 } |
10083
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
526 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
527 static void UpdateVehicleTileHash(Vehicle *v, bool remove) |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
528 { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
529 Vehicle **old_hash = v->hash_tile_current; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
530 Vehicle **new_hash; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
531 |
6886
56eae6975d57
(svn r10129) -Fix (r10111): Test for x == INVALID_COORD instead of v->tile == INVALID_TILE to determine if a vehicle should be removed from the has.
peter1138 <peter1138@openttd.org>
parents:
6883
diff
changeset
|
532 if (remove) { |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
533 new_hash = NULL; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
534 } else { |
7371
e03ba4271be4
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138 <peter1138@openttd.org>
parents:
7358
diff
changeset
|
535 int x = GB(TileX(v->tile), HASH_RES, HASH_BITS); |
e03ba4271be4
(svn r10734) -Fix [FS#1030]: Revert r10513) and add special cases for collision detection on bridges/tunnels.
peter1138 <peter1138@openttd.org>
parents:
7358
diff
changeset
|
536 int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
537 new_hash = &_vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK]; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
538 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
539 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
540 if (old_hash == new_hash) return; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
541 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
542 /* Remove from the old position in the hash table */ |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
543 if (old_hash != NULL) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
544 if (v->hash_tile_next != NULL) v->hash_tile_next->hash_tile_prev = v->hash_tile_prev; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
545 *v->hash_tile_prev = v->hash_tile_next; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
546 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
547 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
548 /* Insert vehicle at beginning of the new position in the hash table */ |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
549 if (new_hash != NULL) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
550 v->hash_tile_next = *new_hash; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
551 if (v->hash_tile_next != NULL) v->hash_tile_next->hash_tile_prev = &v->hash_tile_next; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
552 v->hash_tile_prev = new_hash; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
553 *new_hash = v; |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
554 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
555 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
556 /* Remember current hash position */ |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
557 v->hash_tile_current = new_hash; |
6871
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
558 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
559 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
560 static Vehicle *_vehicle_viewport_hash[0x1000]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
561 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
562 static void UpdateVehicleViewportHash(Vehicle *v, int x, int y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
563 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
564 Vehicle **old_hash, **new_hash; |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
565 int old_x = v->coord.left; |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
566 int old_y = v->coord.top; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
567 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
568 new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_viewport_hash[GEN_HASH(x, y)]; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
569 old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_viewport_hash[GEN_HASH(old_x, old_y)]; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
570 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
571 if (old_hash == new_hash) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
572 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
573 /* remove from hash table? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
574 if (old_hash != NULL) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
575 if (v->hash_viewport_next != NULL) v->hash_viewport_next->hash_viewport_prev = v->hash_viewport_prev; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
576 *v->hash_viewport_prev = v->hash_viewport_next; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
577 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
578 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
579 /* insert into hash table? */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
580 if (new_hash != NULL) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
581 v->hash_viewport_next = *new_hash; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
582 if (v->hash_viewport_next != NULL) v->hash_viewport_next->hash_viewport_prev = &v->hash_viewport_next; |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
583 v->hash_viewport_prev = new_hash; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
584 *new_hash = v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
586 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
587 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
588 void ResetVehicleHash() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
589 { |
6883
bb3eb394463b
(svn r10126) -Fix (r10111, FS#864): old_new_hash cache was not reset when the position hash were
glx <glx@openttd.org>
parents:
6871
diff
changeset
|
590 Vehicle *v; |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
591 FOR_ALL_VEHICLES(v) { v->hash_tile_current = NULL; } |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
592 memset(_vehicle_viewport_hash, 0, sizeof(_vehicle_viewport_hash)); |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
593 memset(_vehicle_tile_hash, 0, sizeof(_vehicle_tile_hash)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
595 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
596 void ResetVehicleColourMap() |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
597 { |
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
598 Vehicle *v; |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
599 FOR_ALL_VEHICLES(v) { v->colourmap = PAL_NONE; } |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
600 } |
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
601 |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
602 /** |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
603 * List of vehicles that should check for autoreplace this tick. |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
604 * Mapping of vehicle -> leave depot immediately after autoreplace. |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
605 */ |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
606 typedef SmallMap<Vehicle *, bool, 4> AutoreplaceMap; |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
607 static AutoreplaceMap _vehicles_to_autoreplace; |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
608 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
609 void InitializeVehicles() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
610 { |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
611 _vehicles_to_autoreplace.Reset(); |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
612 ResetVehicleHash(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
613 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
614 |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10642
diff
changeset
|
615 uint CountVehiclesInChain(const Vehicle *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
616 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
617 uint count = 0; |
7492
09743324277c
(svn r11003) -Codechange: replace Vehicle->next to Vehicle->Next() and Vehicle->SetNext() so we can trap instances that change a next pointer and (in the future) update the first/previous pointers based on that.
rubidium <rubidium@openttd.org>
parents:
7490
diff
changeset
|
618 do count++; while ((v = v->Next()) != NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 return count; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
620 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
621 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
622 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
623 * Check if a vehicle is counted in num_engines in each company struct |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
624 * @return true if the vehicle is counted in num_engines |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
625 */ |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
626 bool Vehicle::IsEngineCountable() const |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
627 { |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
628 switch (this->type) { |
12384
d4b73a406cf3
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents:
12383
diff
changeset
|
629 case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft(); // don't count plane shadows and helicopter rotors |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
630 case VEH_TRAIN: |
17185
ccebafd2a9ba
(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.
terkhen <terkhen@openttd.org>
parents:
17170
diff
changeset
|
631 return !this->IsArticulatedPart() && // tenders and other articulated parts |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
632 !Train::From(this)->IsRearDualheaded(); // rear parts of multiheaded engines |
17123
a18c14f0bb2b
(svn r21860) -Codechange: Rename road vehicle subtype functions to match the train names.
terkhen <terkhen@openttd.org>
parents:
17121
diff
changeset
|
633 case VEH_ROAD: return RoadVehicle::From(this)->IsFrontEngine(); |
6857
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6838
diff
changeset
|
634 case VEH_SHIP: return true; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
635 default: return false; // Only count company buildable vehicles |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
636 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
637 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
638 |
16775
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
639 /** |
18122
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
640 * Check whether Vehicle::engine_type has any meaning. |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
641 * @return true if the vehicle has a useable engine type. |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
642 */ |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
643 bool Vehicle::HasEngineType() const |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
644 { |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
645 switch (this->type) { |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
646 case VEH_AIRCRAFT: return Aircraft::From(this)->IsNormalAircraft(); |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
647 case VEH_TRAIN: |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
648 case VEH_ROAD: |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
649 case VEH_SHIP: return true; |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
650 default: return false; |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
651 } |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
652 } |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
653 |
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
654 /** |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
655 * Retrieves the engine of the vehicle. |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
656 * @return Engine of the vehicle. |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
657 * @pre HasEngineType() == true |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
658 */ |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
659 const Engine *Vehicle::GetEngine() const |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
660 { |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
661 return Engine::Get(this->engine_type); |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
662 } |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
663 |
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
664 /** |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
665 * Retrieve the NewGRF the vehicle is tied to. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
666 * This is the GRF providing the Action 3 for the engine type. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
667 * @return NewGRF associated to the vehicle. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
668 */ |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
669 const GRFFile *Vehicle::GetGRF() const |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
670 { |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
671 return this->GetEngine()->GetGRF(); |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
672 } |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
673 |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
674 /** |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
675 * Retrieve the GRF ID of the NewGRF the vehicle is tied to. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
676 * This is the GRF providing the Action 3 for the engine type. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
677 * @return GRF ID of the associated NewGRF. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
678 */ |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
679 uint32 Vehicle::GetGRFID() const |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
680 { |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
681 return this->GetEngine()->GetGRFID(); |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
682 } |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
683 |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18238
diff
changeset
|
684 /** |
16775
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
685 * Handle the pathfinding result, especially the lost status. |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
686 * If the vehicle is now lost and wasn't previously fire an |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
687 * event to the AIs and a news message to the user. If the |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
688 * vehicle is not lost anymore remove the news message. |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
689 * @param path_found Whether the vehicle has a path to its destination. |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
690 */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
691 void Vehicle::HandlePathfindingResult(bool path_found) |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
692 { |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
693 if (path_found) { |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
694 /* Route found, is the vehicle marked with "lost" flag? */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
695 if (!HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return; |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
696 |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
697 /* Clear the flag as the PF's problem was solved. */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
698 ClrBit(this->vehicle_flags, VF_PATHFINDER_LOST); |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
699 /* Delete the news item. */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
700 DeleteVehicleNews(this->index, STR_NEWS_VEHICLE_IS_LOST); |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
701 return; |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
702 } |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
703 |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
704 /* Were we already lost? */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
705 if (HasBit(this->vehicle_flags, VF_PATHFINDER_LOST)) return; |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
706 |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
707 /* It is first time the problem occurred, set the "lost" flag. */ |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
708 SetBit(this->vehicle_flags, VF_PATHFINDER_LOST); |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
709 /* Notify user about the event. */ |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18484
diff
changeset
|
710 AI::NewEvent(this->owner, new ScriptEventVehicleLost(this->index)); |
16775
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
711 if (_settings_client.gui.lost_vehicle_warn && this->owner == _local_company) { |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
712 SetDParam(0, this->index); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
713 AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_IS_LOST, this->index); |
16775
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
714 } |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
715 } |
d56e38a88b03
(svn r21508) -Codechange: move the code to handle the pathfinder's "path found" status to a separate function
rubidium <rubidium@openttd.org>
parents:
16733
diff
changeset
|
716 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
717 /** Destroy all stuff that (still) needs the virtual functions to work properly */ |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
718 void Vehicle::PreDestructor() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
719 { |
7413
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7412
diff
changeset
|
720 if (CleaningPool()) return; |
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7412
diff
changeset
|
721 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
722 if (Station::IsValidID(this->last_station_visited)) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
723 Station::Get(this->last_station_visited)->loading_vehicles.remove(this); |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
724 |
10176
71daf486081d
(svn r14371) -Fix [FS#2313]: loading indicator didn't stay with the front engine when turning a train in a station.
rubidium <rubidium@openttd.org>
parents:
10175
diff
changeset
|
725 HideFillingPercent(&this->fill_percent_te_id); |
12376
8d88ccd3ee99
(svn r16801) -Fix [FS#3022]: cargo payments weren't destroyed when a vehicle was destructed. This only happened when you crashed a vehicle while it was unloading.
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
726 |
8d88ccd3ee99
(svn r16801) -Fix [FS#3022]: cargo payments weren't destroyed when a vehicle was destructed. This only happened when you crashed a vehicle while it was unloading.
rubidium <rubidium@openttd.org>
parents:
12304
diff
changeset
|
727 delete this->cargo_payment; |
6500
ad8ea1f30c99
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium <rubidium@openttd.org>
parents:
6492
diff
changeset
|
728 } |
ad8ea1f30c99
(svn r9683) -Fix [FS#423]: improved loading does not use a huge amount of processing power anymore when having a lot of trains.
rubidium <rubidium@openttd.org>
parents:
6492
diff
changeset
|
729 |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
730 if (this->IsEngineCountable()) { |
18154
ebcb3f30bd4a
(svn r22979) -Codechange: Add GroupStatistics::CountEngine().
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
731 GroupStatistics::CountEngine(this, -1); |
18153
ca071969f8d7
(svn r22978) -Codechange: Replace IncreaseGroupNumVehicle() and DecreaseGroupNumVehicle() with GroupStatistics::CountVehicle().
frosch <frosch@openttd.org>
parents:
18151
diff
changeset
|
732 if (this->IsPrimaryVehicle()) GroupStatistics::CountVehicle(this, -1); |
18160
9fd018e89254
(svn r22985) -Feature: Display autoreplace status in group GUI.
frosch <frosch@openttd.org>
parents:
18159
diff
changeset
|
733 GroupStatistics::UpdateAutoreplace(this->owner); |
18155
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
18154
diff
changeset
|
734 |
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
18154
diff
changeset
|
735 if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); |
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
18154
diff
changeset
|
736 DeleteGroupHighlightOfVehicle(this); |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5940
diff
changeset
|
737 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 |
10138
c41837ba7289
(svn r14324) -Fix [FS#2241]: free any blocks that a helicopter may have on an oilrig when the helicopter gets forcefully removed (bankruptcy). For other airports this isn't needed as they can't be used by multiple companies.
rubidium <rubidium@openttd.org>
parents:
10103
diff
changeset
|
739 if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) { |
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:
12112
diff
changeset
|
740 Aircraft *a = Aircraft::From(this); |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
741 Station *st = GetTargetAirportIfValid(a); |
10154
9648ad6039a9
(svn r14343) -Fix [FS#2300]: invalid v->u.air.targetairport could cause crashes at several places when the station pool got smaller
smatz <smatz@openttd.org>
parents:
10151
diff
changeset
|
742 if (st != NULL) { |
14859
304d377a82af
(svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents:
14815
diff
changeset
|
743 const AirportFTA *layout = st->airport.GetFTA()->layout; |
304d377a82af
(svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents:
14815
diff
changeset
|
744 CLRBITS(st->airport.flags, layout[a->previous_pos].block | layout[a->pos].block); |
10154
9648ad6039a9
(svn r14343) -Fix [FS#2300]: invalid v->u.air.targetairport could cause crashes at several places when the station pool got smaller
smatz <smatz@openttd.org>
parents:
10151
diff
changeset
|
745 } |
10138
c41837ba7289
(svn r14324) -Fix [FS#2241]: free any blocks that a helicopter may have on an oilrig when the helicopter gets forcefully removed (bankruptcy). For other airports this isn't needed as they can't be used by multiple companies.
rubidium <rubidium@openttd.org>
parents:
10103
diff
changeset
|
746 } |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
747 |
14095
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
748 |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
749 if (this->type == VEH_ROAD && this->IsPrimaryVehicle()) { |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
750 RoadVehicle *v = RoadVehicle::From(this); |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
751 if (!(v->vehstatus & VS_CRASHED) && IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) { |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
752 /* Leave the drive through roadstop, when you have not already left it. */ |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
753 RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile))->Leave(v); |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
754 } |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
755 } |
ba99afa62cd2
(svn r18642) -Fix [FS#3432]: when a company goes bankrupt and has vehicles on a drive through road stop that is not theirs, the 'filled' cache of the road stops would get corrupted
rubidium <rubidium@openttd.org>
parents:
14028
diff
changeset
|
756 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
757 if (this->Previous() == NULL) { |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
758 InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
759 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
760 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
761 if (this->IsPrimaryVehicle()) { |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
762 DeleteWindowById(WC_VEHICLE_VIEW, this->index); |
10528
faf41b99dbc3
(svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
763 DeleteWindowById(WC_VEHICLE_ORDERS, this->index); |
faf41b99dbc3
(svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
764 DeleteWindowById(WC_VEHICLE_REFIT, this->index); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
765 DeleteWindowById(WC_VEHICLE_DETAILS, this->index); |
10528
faf41b99dbc3
(svn r14785) -Fix [FS#2132]: vehicle list for station gets closed when station view is closed even when the vehicle list is stickied. Other vehicle lists are not deleted when their 'opening' window gets closed so do the same with the station view.
rubidium <rubidium@openttd.org>
parents:
10499
diff
changeset
|
766 DeleteWindowById(WC_VEHICLE_TIMETABLE, this->index); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
767 SetWindowDirty(WC_COMPANY, this->owner); |
15859
e4a43875449c
(svn r20541) -Fix: when removing a vehicle update the "clone orders of"-vehicle of a backed up order, or remove it if there is no vehicle sharing orders with that vehicle.
rubidium <rubidium@openttd.org>
parents:
15820
diff
changeset
|
768 OrderBackup::ClearVehicle(this); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
769 } |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
770 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
771 |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
772 this->cargo.Truncate(0); |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
773 DeleteVehicleOrders(this); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
774 DeleteDepotHighlightOfVehicle(this); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 |
9274
85a62fb8608f
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium <rubidium@openttd.org>
parents:
9259
diff
changeset
|
776 extern void StopGlobalFollowVehicle(const Vehicle *v); |
85a62fb8608f
(svn r13140) -Codechange: move the gui-list-sorting out of window_gui.h so window_gui.h only needs to be included in *_gui.cpp.
rubidium <rubidium@openttd.org>
parents:
9259
diff
changeset
|
777 StopGlobalFollowVehicle(this); |
12112
527e86d95414
(svn r16525) -Codechange: Notify small ufos on deletion of road vehicles, so they can head for somewhere else instead of stumbling over a ghost.
frosch <frosch@openttd.org>
parents:
12082
diff
changeset
|
778 |
527e86d95414
(svn r16525) -Codechange: Notify small ufos on deletion of road vehicles, so they can head for somewhere else instead of stumbling over a ghost.
frosch <frosch@openttd.org>
parents:
12082
diff
changeset
|
779 ReleaseDisastersTargetingVehicle(this->index); |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
780 } |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
781 |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
782 Vehicle::~Vehicle() |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
783 { |
17365
c21aec9d12f2
(svn r22111) -Codechange/fix-ish: upon cleaning a pool a destructor should not delete items from other pools
rubidium <rubidium@openttd.org>
parents:
17282
diff
changeset
|
784 if (CleaningPool()) { |
c21aec9d12f2
(svn r22111) -Codechange/fix-ish: upon cleaning a pool a destructor should not delete items from other pools
rubidium <rubidium@openttd.org>
parents:
17282
diff
changeset
|
785 this->cargo.OnCleanPool(); |
c21aec9d12f2
(svn r22111) -Codechange/fix-ish: upon cleaning a pool a destructor should not delete items from other pools
rubidium <rubidium@openttd.org>
parents:
17282
diff
changeset
|
786 return; |
c21aec9d12f2
(svn r22111) -Codechange/fix-ish: upon cleaning a pool a destructor should not delete items from other pools
rubidium <rubidium@openttd.org>
parents:
17282
diff
changeset
|
787 } |
7413
571c87eed06c
(svn r10799) -Fix: only calling QuickFree and not the destructor on pool cleanups might cause memory leaks due to the way C++ works.
rubidium <rubidium@openttd.org>
parents:
7412
diff
changeset
|
788 |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
789 /* sometimes, eg. for disaster vehicles, when company bankrupts, when removing crashed/flooded vehicles, |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
790 * it may happen that vehicle chain is deleted when visible */ |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
791 if (!(this->vehstatus & VS_HIDDEN)) MarkSingleVehicleDirty(this); |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
792 |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
793 Vehicle *v = this->Next(); |
7499
c63c7be0bee5
(svn r11014) -Fix (r11011) [FS#1170]: crash when selling the first train of a consist.
rubidium <rubidium@openttd.org>
parents:
7497
diff
changeset
|
794 this->SetNext(NULL); |
10492
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
795 |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
796 delete v; |
28fa021b003c
(svn r14747) -Codechange: remove DeleteVehicleChain in favour of the vehicle destructor as that was already doing the same for a few vehicle types.
rubidium <rubidium@openttd.org>
parents:
10490
diff
changeset
|
797 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
798 UpdateVehicleTileHash(this, true); |
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
799 UpdateVehicleViewportHash(this, INVALID_COORD, 0); |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
800 DeleteVehicleNews(this->index, INVALID_STRING_ID); |
15083
68d1f9ea65c3
(svn r19709) -Feature: NewGRF debugging/inspecting of (primarily) enabled callbacks and values of variables
rubidium <rubidium@openttd.org>
parents:
15002
diff
changeset
|
801 DeleteNewGRFInspectWindow(GetGrfSpecFeature(this->type), this->index); |
7398
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
802 } |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
803 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
804 /** |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16331
diff
changeset
|
805 * Adds a vehicle to the list of vehicles that visited a depot this tick |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 * @param *v vehicle to add |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
807 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
808 void VehicleEnteredDepotThisTick(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
809 { |
11850
c522c537333f
(svn r16240) -Fix: Make 'stop in depot'-orders only apply on the target depot, not those which are entered on the way to them.
frosch <frosch@openttd.org>
parents:
11838
diff
changeset
|
810 /* Vehicle should stop in the depot if it was in 'stopping' state */ |
c522c537333f
(svn r16240) -Fix: Make 'stop in depot'-orders only apply on the target depot, not those which are entered on the way to them.
frosch <frosch@openttd.org>
parents:
11838
diff
changeset
|
811 _vehicles_to_autoreplace[v] = !(v->vehstatus & VS_STOPPED); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
812 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
813 /* We ALWAYS set the stopped state. Even when the vehicle does not plan on |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
814 * stopping in the depot, so we stop it to ensure that it will not reserve |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
815 * the path out of the depot before we might autoreplace it to a different |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
816 * engine. The new engine would not own the reserved path we store that we |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
817 * stopped the vehicle, so autoreplace can start it again */ |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
818 v->vehstatus |= VS_STOPPED; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
819 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
820 |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
821 /** |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
822 * Increases the day counter for all vehicles and calls 1-day and 32-day handlers. |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
823 * Each tick, it processes vehicles with "index % DAY_TICKS == _date_fract", |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
824 * so each day, all vehicles are processes in DAY_TICKS steps. |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
825 */ |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
826 static void RunVehicleDayProc() |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
827 { |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
828 if (_game_mode != GM_NORMAL) return; |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
829 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
830 /* Run the day_proc for every DAY_TICKS vehicle starting at _date_fract. */ |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
831 for (size_t i = _date_fract; i < Vehicle::GetPoolSize(); i += DAY_TICKS) { |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
832 Vehicle *v = Vehicle::Get(i); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
833 if (v == NULL) continue; |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
834 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
835 /* Call the 32-day callback if needed */ |
18122
ed51ea71bb08
(svn r22947) -Fix: [NewGRF] Do not call CB 32 for disaster, effect vehicles or aircraft shadows/rotors.
frosch <frosch@openttd.org>
parents:
18032
diff
changeset
|
836 if ((v->day_counter & 0x1F) == 0 && v->HasEngineType()) { |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
837 uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v); |
12640
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
838 if (callback != CALLBACK_FAILED) { |
19948
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
839 if (HasBit(callback, 0)) { |
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
840 /* After a vehicle trigger, the graphics and properties of the vehicle could change. */ |
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
841 TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 |
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
842 v->MarkDirty(); |
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
843 } |
12640
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
844 if (HasBit(callback, 1)) v->colourmap = PAL_NONE; |
18312
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
845 |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
846 if (callback & ~3) ErrorUnknownCallbackResult(v->GetGRFID(), CBID_VEHICLE_32DAY_CALLBACK, callback); |
12640
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
847 } |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
848 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
849 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
850 /* This is called once per day for each vehicle, but not in the first tick of the day */ |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
851 v->OnNewDay(); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
852 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
853 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
854 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
855 void CallVehicleTicks() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
856 { |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
857 _vehicles_to_autoreplace.Clear(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
858 |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
859 RunVehicleDayProc(); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
860 |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
861 Station *st; |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
862 FOR_ALL_STATIONS(st) LoadUnloadStation(st); |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
863 |
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
864 Vehicle *v; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
865 FOR_ALL_VEHICLES(v) { |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11951
diff
changeset
|
866 /* Vehicle could be deleted in this tick */ |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
867 if (!v->Tick()) { |
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
868 assert(Vehicle::Get(vehicle_index) == NULL); |
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
869 continue; |
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
870 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11951
diff
changeset
|
871 |
11972
fd10870d74d4
(svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents:
11970
diff
changeset
|
872 assert(Vehicle::Get(vehicle_index) == v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
873 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
874 switch (v->type) { |
6621
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
875 default: break; |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
876 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
877 case VEH_TRAIN: |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
878 case VEH_ROAD: |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
879 case VEH_AIRCRAFT: |
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
880 case VEH_SHIP: |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
881 if (v->vcache.cached_cargo_age_period != 0) { |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
882 v->cargo_age_counter = min(v->cargo_age_counter, v->vcache.cached_cargo_age_period); |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
883 if (--v->cargo_age_counter == 0) { |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
884 v->cargo.AgeCargo(); |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
885 v->cargo_age_counter = v->vcache.cached_cargo_age_period; |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
886 } |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
887 } |
12635
8f1d500da613
(svn r17085) -Codechange: unify the place where vehicle's cargo ages
smatz <smatz@openttd.org>
parents:
12634
diff
changeset
|
888 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
889 if (v->type == VEH_TRAIN && Train::From(v)->IsWagon()) continue; |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
890 if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue; |
17123
a18c14f0bb2b
(svn r21860) -Codechange: Rename road vehicle subtype functions to match the train names.
terkhen <terkhen@openttd.org>
parents:
17121
diff
changeset
|
891 if (v->type == VEH_ROAD && !RoadVehicle::From(v)->IsFrontEngine()) continue; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
892 |
13943
1473565220a3
(svn r18479) -Fix (r6532): Direction is accounted for long before motion counter is updated
peter1138 <peter1138@openttd.org>
parents:
13936
diff
changeset
|
893 v->motion_counter += v->cur_speed; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
894 /* Play a running sound if the motion counter passes 256 (Do we not skip sounds?) */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
895 if (GB(v->motion_counter, 0, 8) < v->cur_speed) PlayVehicleSound(v, VSE_RUNNING); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
896 |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19948
diff
changeset
|
897 /* Play an alternating running sound every 16 ticks */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
898 if (GB(v->tick_counter, 0, 4) == 0) PlayVehicleSound(v, v->cur_speed > 0 ? VSE_RUNNING_16 : VSE_STOPPED_16); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
899 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
900 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
901 |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
902 Backup<CompanyByte> cur_company(_current_company, FILE_LINE); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
903 for (AutoreplaceMap::iterator it = _vehicles_to_autoreplace.Begin(); it != _vehicles_to_autoreplace.End(); it++) { |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
904 v = it->first; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
905 /* Autoreplace needs the current company set as the vehicle owner */ |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15127
diff
changeset
|
906 cur_company.Change(v->owner); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
907 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
908 /* Start vehicle if we stopped them in VehicleEnteredDepotThisTick() |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
909 * We need to stop them between VehicleEnteredDepotThisTick() and here or we risk that |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
910 * they are already leaving the depot again before being replaced. */ |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
911 if (it->second) v->vehstatus &= ~VS_STOPPED; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
912 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
913 /* Store the position of the effect as the vehicle pointer will become invalid later */ |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
914 int x = v->x_pos; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
915 int y = v->y_pos; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
916 int z = v->z_pos; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
917 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
918 const Company *c = Company::Get(_current_company); |
11913
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
919 SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->settings.engine_renew_money)); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
920 CommandCost res = DoCommand(0, v->index, 0, DC_EXEC, CMD_AUTOREPLACE_VEHICLE); |
11913
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
921 SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->settings.engine_renew_money)); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
922 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
923 if (!IsLocalCompany()) continue; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
924 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
925 if (res.Succeeded()) { |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
926 ShowCostOrIncomeAnimation(x, y, z, res.GetCost()); |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
927 continue; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
928 } |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
929 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
930 StringID error_message = res.GetErrorMessage(); |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
931 if (error_message == STR_ERROR_AUTOREPLACE_NOTHING_TO_DO || error_message == INVALID_STRING_ID) continue; |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
932 |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
933 if (error_message == STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY) error_message = STR_ERROR_AUTOREPLACE_MONEY_LIMIT; |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
934 |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
935 StringID message; |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
936 if (error_message == STR_ERROR_TRAIN_TOO_LONG_AFTER_REPLACEMENT) { |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
937 message = error_message; |
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
938 } else { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
939 message = STR_NEWS_VEHICLE_AUTORENEW_FAILED; |
8996
6a811008eb9f
(svn r12791) -Codechange: [autoreplace] Added a flag parameter (listens for DC_EXEC and DC_QUERY_COST) and included more info when returning CommandCost
bjarni <bjarni@openttd.org>
parents:
8980
diff
changeset
|
940 } |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
941 |
10574
bf4424d086f0
(svn r14831) -Codechange: use {VEHICLE} instead of Train/Ship/Road veh/Aircraft/{STRING} {COMMA} in lang files (part by Swallow)
smatz <smatz@openttd.org>
parents:
10571
diff
changeset
|
942 SetDParam(0, v->index); |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
943 SetDParam(1, error_message); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
944 AddVehicleAdviceNewsItem(message, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
945 } |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
946 |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15127
diff
changeset
|
947 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
948 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
949 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
950 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
951 * Add vehicle sprite for drawing to the screen. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
952 * @param v Vehicle to draw. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
953 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
954 static void DoDrawVehicle(const Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
955 { |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
956 SpriteID image = v->cur_image; |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
957 PaletteID pal = PAL_NONE; |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
958 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
959 if (v->vehstatus & VS_DEFPAL) pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
960 |
17726
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
961 /* Check whether the vehicle shall be transparent due to the game state */ |
17787
f494fc48030a
(svn r22572) -Fix: MSVC performance warning (assigning int to bool).
michi_cc <michi_cc@openttd.org>
parents:
17748
diff
changeset
|
962 bool shadowed = (v->vehstatus & VS_SHADOW) != 0; |
17726
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
963 |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
964 if (v->type == VEH_EFFECT) { |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
965 /* Check whether the vehicle shall be transparent/invisible due to GUI settings. |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
966 * However, transparent smoke and bubbles look weird, so always hide them. */ |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
967 TransparencyOption to = EffectVehicle::From(v)->GetTransparencyOption(); |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
968 if (to != TO_INVALID && (IsTransparencySet(to) || IsInvisibilitySet(to))) return; |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
969 } |
7ed1b225f4c2
(svn r22506) -Feature [FS#4625]: Make the transparency options for industries also affect the effect vehicles created by industries.
frosch <frosch@openttd.org>
parents:
17712
diff
changeset
|
970 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
971 AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
972 v->x_extent, v->y_extent, v->z_extent, v->z_pos, shadowed, v->x_bb_offs, v->y_bb_offs); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
973 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
974 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
975 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
976 * Add the vehicle sprites that should be drawn at a part of the screen. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
977 * @param dpi Rectangle being drawn. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
978 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
979 void ViewportAddVehicles(DrawPixelInfo *dpi) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
980 { |
6423
72ac8bfaa32f
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents:
6350
diff
changeset
|
981 /* The bounding rectangle */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
982 const int l = dpi->left; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
983 const int r = dpi->left + dpi->width; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
984 const int t = dpi->top; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
985 const int b = dpi->top + dpi->height; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
986 |
6423
72ac8bfaa32f
(svn r9559) -Documentation: doxygen and comment changes: 'U' and 'V' now. Almost done. Yeah. I know, I've already said that...
belugas <belugas@openttd.org>
parents:
6350
diff
changeset
|
987 /* The hash area to scan */ |
6905
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
988 int xl, xu, yl, yu; |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
989 |
18484
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
990 if (dpi->width + (70 * ZOOM_LVL_BASE) < (1 << (7 + 6 + ZOOM_LVL_SHIFT))) { |
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
991 xl = GB(l - (70 * ZOOM_LVL_BASE), 7 + ZOOM_LVL_SHIFT, 6); |
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
992 xu = GB(r, 7 + ZOOM_LVL_SHIFT, 6); |
6905
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
993 } else { |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
994 /* scan whole hash row */ |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
995 xl = 0; |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
996 xu = 0x3F; |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
997 } |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
998 |
18484
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
999 if (dpi->height + (70 * ZOOM_LVL_BASE) < (1 << (6 + 6 + ZOOM_LVL_SHIFT))) { |
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
1000 yl = GB(t - (70 * ZOOM_LVL_BASE), 6 + ZOOM_LVL_SHIFT, 6) << 6; |
7ccdedf22703
(svn r23328) -Change: Make the viewport vehicle position hash cover the same area.
peter1138 <peter1138@openttd.org>
parents:
18472
diff
changeset
|
1001 yu = GB(b, 6 + ZOOM_LVL_SHIFT, 6) << 6; |
6905
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1002 } else { |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1003 /* scan whole column */ |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1004 yl = 0; |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1005 yu = 0x3F << 6; |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1006 } |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1007 |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1008 for (int y = yl;; y = (y + (1 << 6)) & (0x3F << 6)) { |
bf5912475e5e
(svn r10154) -Fix [FS#870]: some vehicles were not drawn when having a high resolution and a high zoom-out level. Patch by B. N. SmatZ!.
rubidium <rubidium@openttd.org>
parents:
6904
diff
changeset
|
1009 for (int x = xl;; x = (x + 1) & 0x3F) { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
1010 const Vehicle *v = _vehicle_viewport_hash[x + y]; // already masked & 0xFFF |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1011 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1012 while (v != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1013 if (!(v->vehstatus & VS_HIDDEN) && |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1014 l <= v->coord.right && |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1015 t <= v->coord.bottom && |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1016 r >= v->coord.left && |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1017 b >= v->coord.top) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1018 DoDrawVehicle(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 } |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
1020 v = v->hash_viewport_next; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1021 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1022 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1023 if (x == xu) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1024 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1025 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1026 if (y == yu) break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1027 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1028 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1029 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1030 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1031 * Find the vehicle close to the clicked coordinates. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1032 * @param vp Viewport clicked in. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1033 * @param x X coordinate in the viewport. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1034 * @param y Y coordinate in the viewport. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1035 * @return Closest vehicle, or \c NULL if none found. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1036 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1037 Vehicle *CheckClickOnVehicle(const ViewPort *vp, int x, int y) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1038 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1039 Vehicle *found = NULL, *v; |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10225
diff
changeset
|
1040 uint dist, best_dist = UINT_MAX; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1041 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1042 if ((uint)(x -= vp->left) >= (uint)vp->width || (uint)(y -= vp->top) >= (uint)vp->height) return NULL; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1043 |
6626
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6621
diff
changeset
|
1044 x = ScaleByZoom(x, vp->zoom) + vp->virtual_left; |
f940341a80f0
(svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight <truelight@openttd.org>
parents:
6621
diff
changeset
|
1045 y = ScaleByZoom(y, vp->zoom) + vp->virtual_top; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1046 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1047 FOR_ALL_VEHICLES(v) { |
10642
29bc871ff8d1
(svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents:
10634
diff
changeset
|
1048 if ((v->vehstatus & (VS_HIDDEN | VS_UNCLICKABLE)) == 0 && |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1049 x >= v->coord.left && x <= v->coord.right && |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1050 y >= v->coord.top && y <= v->coord.bottom) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1051 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1052 dist = max( |
11322
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1053 abs(((v->coord.left + v->coord.right) >> 1) - x), |
0a63eacd2be7
(svn r15672) -Codechange: (left,right,top,bottom)_coord -> coord.(left,right,top,bottom), i.e. use Rect.
rubidium <rubidium@openttd.org>
parents:
11303
diff
changeset
|
1054 abs(((v->coord.top + v->coord.bottom) >> 1) - y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1055 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1056 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1057 if (dist < best_dist) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1058 found = v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1059 best_dist = dist; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1060 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1061 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1062 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1063 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1064 return found; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1065 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1066 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1067 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1068 * Decrease the value of a vehicle. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1069 * @param v %Vehicle to devaluate. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1070 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1071 void DecreaseVehicleValue(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1072 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1073 v->value -= v->value >> 8; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1074 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1075 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1076 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1077 static const byte _breakdown_chance[64] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1078 3, 3, 3, 3, 3, 3, 3, 3, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1079 4, 4, 5, 5, 6, 6, 7, 7, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1080 8, 8, 9, 9, 10, 10, 11, 11, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1081 12, 13, 13, 13, 13, 14, 15, 16, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1082 17, 19, 21, 25, 28, 31, 34, 37, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1083 40, 44, 48, 52, 56, 60, 64, 68, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1084 72, 80, 90, 100, 110, 120, 130, 140, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1085 150, 170, 190, 210, 230, 250, 250, 250, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1086 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1087 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1088 void CheckVehicleBreakdown(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1089 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1090 int rel, rel_old; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1091 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1092 /* decrease reliability */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1093 v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1094 if ((rel_old >> 8) != (rel >> 8)) SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1095 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12070
diff
changeset
|
1096 if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) || |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1097 _settings_game.difficulty.vehicle_breakdowns < 1 || |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1098 v->cur_speed < 5 || _game_mode == GM_MENU) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1099 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1100 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1101 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1102 uint32 r = Random(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1103 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1104 /* increase chance of failure */ |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1105 int chance = v->breakdown_chance + 1; |
8980
b4160d91b7c7
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1106 if (Chance16I(1, 25, r)) chance += 25; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1107 v->breakdown_chance = min(255, chance); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1108 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1109 /* calculate reliability value to use in comparison */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1110 rel = v->reliability; |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1111 if (v->type == VEH_SHIP) rel += 0x6666; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1112 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1113 /* reduced breakdowns? */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1114 if (_settings_game.difficulty.vehicle_breakdowns == 1) rel += 0x6666; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1115 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1116 /* check if to break down */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1117 if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1118 v->breakdown_ctr = GB(r, 16, 6) + 0x3F; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1119 v->breakdown_delay = GB(r, 24, 7) + 0x80; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1120 v->breakdown_chance = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1121 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1122 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1123 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1124 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1125 * Handle all of the aspects of a vehicle breakdown |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1126 * This includes adding smoke and sounds, and ending the breakdown when appropriate. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1127 * @return true iff the vehicle is stopped because of a breakdown |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1128 * @note This function always returns false for aircraft, since these never stop for breakdowns |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1129 */ |
15957
1452fca58b4f
(svn r20645) -Codechange [FS#4086]: unify the code for checking for breakdown handling as well (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15956
diff
changeset
|
1130 bool Vehicle::HandleBreakdown() |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1131 { |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1132 /* Possible states for Vehicle::breakdown_ctr |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1133 * 0 - vehicle is running normally |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1134 * 1 - vehicle is currently broken down |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1135 * 2 - vehicle is going to break down now |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1136 * >2 - vehicle is counting down to the actual breakdown event */ |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1137 switch (this->breakdown_ctr) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1138 case 0: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1139 return false; |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1140 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1141 case 2: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1142 this->breakdown_ctr = 1; |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1143 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1144 if (this->breakdowns_since_last_service != 255) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1145 this->breakdowns_since_last_service++; |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1146 } |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1147 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1148 if (this->type == VEH_AIRCRAFT) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1149 /* Aircraft just need this flag, the rest is handled elsewhere */ |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1150 this->vehstatus |= VS_AIRCRAFT_BROKEN; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1151 } else { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1152 this->cur_speed = 0; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1153 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1154 if (!PlayVehicleSound(this, VSE_BREAKDOWN)) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1155 SndPlayVehicleFx((_settings_game.game_creation.landscape != LT_TOYLAND) ? |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1156 (this->type == VEH_TRAIN ? SND_10_TRAIN_BREAKDOWN : SND_0F_VEHICLE_BREAKDOWN) : |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1157 (this->type == VEH_TRAIN ? SND_3A_COMEDY_BREAKDOWN_2 : SND_35_COMEDY_BREAKDOWN), this); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1158 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1159 |
19235
e8290cb0a4f8
(svn r24124) -Add [FS#4658]: [NewGRF] Misc engine flag to disable breakdown smoke. (Hirundo)
michi_cc <michi_cc@openttd.org>
parents:
19193
diff
changeset
|
1160 if (!(this->vehstatus & VS_HIDDEN) && !HasBit(EngInfo(this->engine_type)->misc_flags, EF_NO_BREAKDOWN_SMOKE)) { |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1161 EffectVehicle *u = CreateEffectVehicleRel(this, 4, 4, 5, EV_BREAKDOWN_SMOKE); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1162 if (u != NULL) u->animation_state = this->breakdown_delay * 2; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1163 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1164 } |
18220
8a968f3fbda2
(svn r23050) -Fix: [NewGRF] When vehicles break down, update the image cache after changing the vehicle state to make fish happy.
frosch <frosch@openttd.org>
parents:
18160
diff
changeset
|
1165 |
8a968f3fbda2
(svn r23050) -Fix: [NewGRF] When vehicles break down, update the image cache after changing the vehicle state to make fish happy.
frosch <frosch@openttd.org>
parents:
18160
diff
changeset
|
1166 this->MarkDirty(); // Update graphics after speed is zeroed |
8a968f3fbda2
(svn r23050) -Fix: [NewGRF] When vehicles break down, update the image cache after changing the vehicle state to make fish happy.
frosch <frosch@openttd.org>
parents:
18160
diff
changeset
|
1167 SetWindowDirty(WC_VEHICLE_VIEW, this->index); |
8a968f3fbda2
(svn r23050) -Fix: [NewGRF] When vehicles break down, update the image cache after changing the vehicle state to make fish happy.
frosch <frosch@openttd.org>
parents:
18160
diff
changeset
|
1168 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
8a968f3fbda2
(svn r23050) -Fix: [NewGRF] When vehicles break down, update the image cache after changing the vehicle state to make fish happy.
frosch <frosch@openttd.org>
parents:
18160
diff
changeset
|
1169 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1170 /* FALL THROUGH */ |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1171 case 1: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1172 /* Aircraft breakdowns end only when arriving at the airport */ |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1173 if (this->type == VEH_AIRCRAFT) return false; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1174 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1175 /* For trains this function is called twice per tick, so decrease v->breakdown_delay at half the rate */ |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1176 if ((this->tick_counter & (this->type == VEH_TRAIN ? 3 : 1)) == 0) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1177 if (--this->breakdown_delay == 0) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1178 this->breakdown_ctr = 0; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1179 this->MarkDirty(); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1180 SetWindowDirty(WC_VEHICLE_VIEW, this->index); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1181 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1182 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1183 return true; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1184 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1185 default: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1186 if (!this->current_order.IsType(OT_LOADING)) this->breakdown_ctr--; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1187 return false; |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1188 } |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1189 } |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1190 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1191 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1192 * Update age of a vehicle. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1193 * @param v Vehicle to update. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1194 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1195 void AgeVehicle(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1196 { |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1197 if (v->age < MAX_DAY) { |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1198 v->age++; |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1199 if (v->IsPrimaryVehicle() && v->age == VEHICLE_PROFIT_MIN_AGE + 1) GroupStatistics::VehicleReachedProfitAge(v); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1200 } |
7544
0b69698895b6
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium <rubidium@openttd.org>
parents:
7532
diff
changeset
|
1201 |
18007
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
1202 if (!v->IsPrimaryVehicle() && (v->type != VEH_TRAIN || !Train::From(v)->IsEngine())) return; |
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
1203 |
7544
0b69698895b6
(svn r11064) -Fix [FS#553]: when autorenew is enabled and it cannot renew the vehicle anymore (because the player cannot build the engine), the aging warnings as if autorenew is not enabled are shown.
rubidium <rubidium@openttd.org>
parents:
7532
diff
changeset
|
1204 int age = v->age - v->max_age; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1205 if (age == DAYS_IN_LEAP_YEAR * 0 || age == DAYS_IN_LEAP_YEAR * 1 || |
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1206 age == DAYS_IN_LEAP_YEAR * 2 || age == DAYS_IN_LEAP_YEAR * 3 || age == DAYS_IN_LEAP_YEAR * 4) { |
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1207 v->reliability_spd_dec <<= 1; |
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1208 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1209 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1210 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1211 |
11668
7fe77b6650cd
(svn r16048) -Fix/Feature-ish [FS#2740]: don't warn that crashed vehicles are getting old; upgrading them is impossible (racetrack)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
1212 /* Don't warn about non-primary or not ours vehicles or vehicles that are crashed */ |
7fe77b6650cd
(svn r16048) -Fix/Feature-ish [FS#2740]: don't warn that crashed vehicles are getting old; upgrading them is impossible (racetrack)
rubidium <rubidium@openttd.org>
parents:
11368
diff
changeset
|
1213 if (v->Previous() != NULL || v->owner != _local_company || (v->vehstatus & VS_CRASHED) != 0) return; |
10979
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1214 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1215 /* Don't warn if a renew is active */ |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
1216 if (Company::Get(v->owner)->settings.engine_renew && v->GetEngine()->company_avail != 0) return; |
10979
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1217 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1218 StringID str; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1219 if (age == -DAYS_IN_LEAP_YEAR) { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
1220 str = STR_NEWS_VEHICLE_IS_GETTING_OLD; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1221 } else if (age == 0) { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
1222 str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1223 } else if (age > 0 && (age % DAYS_IN_LEAP_YEAR) == 0) { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
1224 str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND; |
10979
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1225 } else { |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1226 return; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1227 } |
10979
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1228 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1229 SetDParam(0, v->index); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
1230 AddVehicleAdviceNewsItem(str, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1231 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1232 |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1233 /** |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1234 * Calculates how full a vehicle is. |
19776
370449780c21
(svn r24709) -Codechange: Simplify some code.
frosch <frosch@openttd.org>
parents:
19670
diff
changeset
|
1235 * @param front The front vehicle of the consist to check. |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1236 * @param colour The string to show depending on if we are unloading or loading |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1237 * @return A percentage of how full the Vehicle is. |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1238 */ |
19776
370449780c21
(svn r24709) -Codechange: Simplify some code.
frosch <frosch@openttd.org>
parents:
19670
diff
changeset
|
1239 uint8 CalcPercentVehicleFilled(const Vehicle *front, StringID *colour) |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1240 { |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1241 int count = 0; |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1242 int max = 0; |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1243 int cars = 0; |
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1244 int unloading = 0; |
7087
39792f9f0512
(svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium <rubidium@openttd.org>
parents:
7086
diff
changeset
|
1245 bool loading = false; |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1246 |
19778
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1247 bool is_loading = front->current_order.IsType(OT_LOADING); |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1248 |
15898
cfe6456564b2
(svn r20581) -Codechange: simplify getting the station in CalcPercentVehicleFilled
rubidium <rubidium@openttd.org>
parents:
15859
diff
changeset
|
1249 /* The station may be NULL when the (colour) string does not need to be set. */ |
19776
370449780c21
(svn r24709) -Codechange: Simplify some code.
frosch <frosch@openttd.org>
parents:
19670
diff
changeset
|
1250 const Station *st = Station::GetIfValid(front->last_station_visited); |
19778
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1251 assert(colour == NULL || (st != NULL && is_loading)); |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1252 |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1253 bool order_no_load = is_loading && (front->current_order.GetLoadType() & OLFB_NO_LOAD); |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1254 bool order_full_load = is_loading && (front->current_order.GetLoadType() & OLFB_FULL_LOAD); |
7087
39792f9f0512
(svn r10354) -Fix [FS#950]: loading indicator showed "^" when the train would load at the given station.
rubidium <rubidium@openttd.org>
parents:
7086
diff
changeset
|
1255 |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1256 /* Count up max and used */ |
19776
370449780c21
(svn r24709) -Codechange: Simplify some code.
frosch <frosch@openttd.org>
parents:
19670
diff
changeset
|
1257 for (const Vehicle *v = front; v != NULL; v = v->Next()) { |
7010
f0f87c5a431e
(svn r10266) -Codechange: keep track of the origin, time of travel and accumulated feeder share (transfers) of individual pieces of cargo. This means that cargo isn't thrown on a big pile when it's put in a station or unloaded at a station, however the GUI does not reflect these changes yet so you will not actually see it.
rubidium <rubidium@openttd.org>
parents:
6998
diff
changeset
|
1258 count += v->cargo.Count(); |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1259 max += v->cargo_cap; |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1260 if (v->cargo_cap != 0 && colour != NULL) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1261 unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
19778
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1262 loading |= !order_no_load && |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1263 (order_full_load || HasBit(st->goods[v->cargo_type].acceptance_pickup, GoodsEntry::GES_PICKUP)) && |
0bdaa4d2945e
(svn r24711) -Fix (r10354): Check whether to not display a ^ loading indicator at drop stations only worked if there was no other vehicle unloading for 255 ticks.
frosch <frosch@openttd.org>
parents:
19776
diff
changeset
|
1264 !HasBit(v->vehicle_flags, VF_LOADING_FINISHED) && !HasBit(v->vehicle_flags, VF_STOP_LOADING); |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1265 cars++; |
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1266 } |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1267 } |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1268 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1269 if (colour != NULL) { |
8897
723bed4b0900
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium <rubidium@openttd.org>
parents:
8892
diff
changeset
|
1270 if (unloading == 0 && loading) { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1271 *colour = STR_PERCENT_UP; |
19670
7bdc6f86cd62
(svn r24579) -Change [FS#5322] (r21961): Show no loading indicator when orders are 'no unloading and no loading' (sbr)
planetmaker <planetmaker@openttd.org>
parents:
19626
diff
changeset
|
1272 } else if (unloading == 0 && !loading) { |
7bdc6f86cd62
(svn r24579) -Change [FS#5322] (r21961): Show no loading indicator when orders are 'no unloading and no loading' (sbr)
planetmaker <planetmaker@openttd.org>
parents:
19626
diff
changeset
|
1273 *colour = STR_PERCENT_NONE; |
8897
723bed4b0900
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium <rubidium@openttd.org>
parents:
8892
diff
changeset
|
1274 } else if (cars == unloading || !loading) { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1275 *colour = STR_PERCENT_DOWN; |
8897
723bed4b0900
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium <rubidium@openttd.org>
parents:
8892
diff
changeset
|
1276 } else { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1277 *colour = STR_PERCENT_UP_DOWN; |
8897
723bed4b0900
(svn r12664) -Codechange: do not force the 'color' pointer to be non-NULL when trying to get the load percentage.
rubidium <rubidium@openttd.org>
parents:
8892
diff
changeset
|
1278 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1279 } |
7014
d03670858cef
(svn r10270) -Add: prefixed the loading indicator with an arrow, up meaning vehicle is loading, down meaning vehicle is unloading
truelight <truelight@openttd.org>
parents:
7010
diff
changeset
|
1280 |
6998
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1281 /* Train without capacity */ |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1282 if (max == 0) return 100; |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1283 |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1284 /* Return the percentage */ |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1285 return (count * 100) / max; |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1286 } |
13ea0d5f8acf
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight <truelight@openttd.org>
parents:
6980
diff
changeset
|
1287 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1288 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1289 * Vehicle entirely entered the depot, update its status, orders, vehicle windows, service it, etc. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1290 * @param v Vehicle that entered a depot. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1291 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1292 void VehicleEnterDepot(Vehicle *v) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1293 { |
12871
85bcb9cf3a84
(svn r17363) -Fix [FS#3163] (r16717): feed autoreplace the front of vehicles, otherwise it gets distracted and bails out
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
1294 /* Always work with the front of the vehicle */ |
85bcb9cf3a84
(svn r17363) -Fix [FS#3163] (r16717): feed autoreplace the front of vehicles, otherwise it gets distracted and bails out
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
1295 assert(v == v->First()); |
85bcb9cf3a84
(svn r17363) -Fix [FS#3163] (r16717): feed autoreplace the front of vehicles, otherwise it gets distracted and bails out
rubidium <rubidium@openttd.org>
parents:
12778
diff
changeset
|
1296 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1297 switch (v->type) { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1298 case VEH_TRAIN: { |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1299 Train *t = Train::From(v); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1300 SetWindowClassesDirty(WC_TRAINS_LIST); |
10314
6a7dcb87c104
(svn r14559) -Fix [FS#2387]: A train could be blocked inside a depot if it was reversed just after leaving the depot.
michi_cc <michi_cc@openttd.org>
parents:
10285
diff
changeset
|
1301 /* Clear path reservation */ |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12460
diff
changeset
|
1302 SetDepotReservation(t->tile, false); |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1303 if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(t->tile); |
10314
6a7dcb87c104
(svn r14559) -Fix [FS#2387]: A train could be blocked inside a depot if it was reversed just after leaving the depot.
michi_cc <michi_cc@openttd.org>
parents:
10285
diff
changeset
|
1304 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1305 UpdateSignalsOnSegment(t->tile, INVALID_DIAGDIR, t->owner); |
14213
41b2e7bf03da
(svn r18764) -Fix [FS#3422]: split the (un)load ticks counter and signal wait counter; sometimes they might get into eachother's way
rubidium <rubidium@openttd.org>
parents:
14095
diff
changeset
|
1306 t->wait_counter = 0; |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1307 t->force_proceed = TFP_NONE; |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1308 ClrBit(t->flags, VRF_TOGGLE_REVERSE); |
14261
2e1e5f37e2fb
(svn r18812) -Codechange: make some functions in train.h functions of Train.
rubidium <rubidium@openttd.org>
parents:
14258
diff
changeset
|
1309 t->ConsistChanged(true); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1310 break; |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1311 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1312 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1313 case VEH_ROAD: |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1314 SetWindowClassesDirty(WC_ROADVEH_LIST); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1315 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1316 |
15493
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1317 case VEH_SHIP: { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1318 SetWindowClassesDirty(WC_SHIPS_LIST); |
15493
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1319 Ship *ship = Ship::From(v); |
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1320 ship->state = TRACK_BIT_DEPOT; |
16382
198b969abcda
(svn r21098) -Codechange: Ships now store their max speed in the cache instead of recalculating it every time.
terkhen <terkhen@openttd.org>
parents:
16372
diff
changeset
|
1321 ship->UpdateCache(); |
15493
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1322 ship->UpdateViewport(true, true); |
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1323 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1324 break; |
15493
756dd50e46f2
(svn r20142) -Fix [FS#3880]: Ships were not marked as dirty when stopping inside a depot.
terkhen <terkhen@openttd.org>
parents:
15457
diff
changeset
|
1325 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1326 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1327 case VEH_AIRCRAFT: |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1328 SetWindowClassesDirty(WC_AIRCRAFT_LIST); |
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:
12112
diff
changeset
|
1329 HandleAircraftEnterHangar(Aircraft::From(v)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1330 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1331 default: NOT_REACHED(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1332 } |
15351
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15322
diff
changeset
|
1333 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1334 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1335 if (v->type != VEH_TRAIN) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1336 /* Trains update the vehicle list when the first unit enters the depot and calls VehicleEnterDepot() when the last unit enters. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1337 * We only increase the number of vehicles when the first one enters, so we will not need to search for more vehicles in the depot */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1339 } |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1340 SetWindowDirty(WC_VEHICLE_DEPOT, v->tile); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1341 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1342 v->vehstatus |= VS_HIDDEN; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1343 v->cur_speed = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1344 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1345 VehicleServiceInDepot(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1346 |
19948
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
1347 /* After a vehicle trigger, the graphics and properties of the vehicle could change. */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1348 TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
19948
e4c42446f3e6
(svn r24882) -Fix: desync when NewGRF changes the stats related to acceleration (power, weight, tractive effort, etc) during service or 32 day triggers
rubidium <rubidium@openttd.org>
parents:
19778
diff
changeset
|
1349 v->MarkDirty(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1350 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1351 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1352 SetWindowDirty(WC_VEHICLE_VIEW, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1353 |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1354 const Order *real_order = v->GetOrder(v->cur_real_order_index); |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1355 Order t = v->current_order; |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1356 v->current_order.MakeDummy(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1357 |
11838
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1358 /* Test whether we are heading for this depot. If not, do nothing. |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1359 * Note: The target depot for nearest-/manual-depot-orders is only updated on junctions, but we want to accept every depot. */ |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1360 if ((t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) && |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1361 real_order != NULL && !(real_order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) && |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1362 (v->type == VEH_AIRCRAFT ? t.GetDestination() != GetStationIndex(v->tile) : v->dest_tile != v->tile)) { |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1363 /* We are heading for another depot, keep driving. */ |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1364 return; |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1365 } |
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1366 |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8837
diff
changeset
|
1367 if (t.IsRefit()) { |
15292
e2c62d70dfcf
(svn r19931) -Fix (r19914): Convert assertion in Backup<> destructor into DEBUG() output. It was triggered on exceptions, especially when aborting world generation.
frosch <frosch@openttd.org>
parents:
15279
diff
changeset
|
1368 Backup<CompanyByte> cur_company(_current_company, v->owner, FILE_LINE); |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1369 CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(v)); |
15279
4e1862aebea2
(svn r19914) -Codechange: Wrap a helper class around temporary assignments of _current_company to ensure proper restoration.
frosch <frosch@openttd.org>
parents:
15127
diff
changeset
|
1370 cur_company.Restore(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1371 |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
1372 if (cost.Failed()) { |
10490
d1f6921e0f0f
(svn r14745) -Codechange: move "depot_list" and "leave_depot_immediately" out of the vehicle struct (saving up to 16 bytes per vehicle) as it is only used to tell a calling function entered a depot (for autoreplace).
rubidium <rubidium@openttd.org>
parents:
10314
diff
changeset
|
1373 _vehicles_to_autoreplace[v] = false; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1374 if (v->owner == _local_company) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1375 /* Notify the user that we stopped the vehicle */ |
10574
bf4424d086f0
(svn r14831) -Codechange: use {VEHICLE} instead of Train/Ship/Road veh/Aircraft/{STRING} {COMMA} in lang files (part by Swallow)
smatz <smatz@openttd.org>
parents:
10571
diff
changeset
|
1376 SetDParam(0, v->index); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
1377 AddVehicleAdviceNewsItem(STR_NEWS_ORDER_REFIT_FAILED, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1378 } |
15574
b75772da65d4
(svn r20234) -Fix [FS#3988]: refit costs from refit orders are subtracted from the vehicle yearly income
yexo <yexo@openttd.org>
parents:
15493
diff
changeset
|
1379 } else if (cost.GetCost() != 0) { |
b75772da65d4
(svn r20234) -Fix [FS#3988]: refit costs from refit orders are subtracted from the vehicle yearly income
yexo <yexo@openttd.org>
parents:
15493
diff
changeset
|
1380 v->profit_this_year -= cost.GetCost() << 8; |
b75772da65d4
(svn r20234) -Fix [FS#3988]: refit costs from refit orders are subtracted from the vehicle yearly income
yexo <yexo@openttd.org>
parents:
15493
diff
changeset
|
1381 if (v->owner == _local_company) { |
b75772da65d4
(svn r20234) -Fix [FS#3988]: refit costs from refit orders are subtracted from the vehicle yearly income
yexo <yexo@openttd.org>
parents:
15493
diff
changeset
|
1382 ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost()); |
b75772da65d4
(svn r20234) -Fix [FS#3988]: refit costs from refit orders are subtracted from the vehicle yearly income
yexo <yexo@openttd.org>
parents:
15493
diff
changeset
|
1383 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1384 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1385 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1386 |
11838
6bbaad5a6b54
(svn r16228) -Fix/Change (r16187): If we are heading for a different depot, do also not do the refitting-part of the depot-order.
frosch <frosch@openttd.org>
parents:
11808
diff
changeset
|
1387 if (t.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1388 /* Part of orders */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1389 v->DeleteUnreachedImplicitOrders(); |
7070
c856638fde6e
(svn r10335) -Fix (r10331): Increment the current order index *after* using it in UpdateVehicleTimetable.
maedhros <maedhros@openttd.org>
parents:
7038
diff
changeset
|
1390 UpdateVehicleTimetable(v, true); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1391 v->IncrementImplicitOrderIndex(); |
10285
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1392 } |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1393 if (t.GetDepotActionType() & ODATFB_HALT) { |
11850
c522c537333f
(svn r16240) -Fix: Make 'stop in depot'-orders only apply on the target depot, not those which are entered on the way to them.
frosch <frosch@openttd.org>
parents:
11838
diff
changeset
|
1394 /* Vehicles are always stopped on entering depots. Do not restart this one. */ |
c522c537333f
(svn r16240) -Fix: Make 'stop in depot'-orders only apply on the target depot, not those which are entered on the way to them.
frosch <frosch@openttd.org>
parents:
11838
diff
changeset
|
1395 _vehicles_to_autoreplace[v] = false; |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1396 if (v->owner == _local_company) { |
10574
bf4424d086f0
(svn r14831) -Codechange: use {VEHICLE} instead of Train/Ship/Road veh/Aircraft/{STRING} {COMMA} in lang files (part by Swallow)
smatz <smatz@openttd.org>
parents:
10571
diff
changeset
|
1397 SetDParam(0, v->index); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
1398 AddVehicleAdviceNewsItem(STR_NEWS_TRAIN_IS_WAITING + v->type, v->index); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1399 } |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18484
diff
changeset
|
1400 AI::NewEvent(v->owner, new ScriptEventVehicleWaitingInDepot(v->index)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1401 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1402 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1403 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1404 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1405 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1406 /** |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1407 * Update the position of the vehicle. This will update the hash that tells |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1408 * which vehicles are on a tile. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1409 * @param v The vehicle to update. |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1410 */ |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1411 void VehicleUpdatePosition(Vehicle *v) |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1412 { |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
1413 UpdateVehicleTileHash(v, false); |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1414 } |
18862
35dd3fb18d52
(svn r23711) -Codechange: don't chain the two vehicle hashes, but call them one by one
truebrain <truebrain@openttd.org>
parents:
18692
diff
changeset
|
1415 |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1416 /** |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1417 * Update the vehicle on the viewport, updating the right hash and setting the |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1418 * new coordinates. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1419 * @param v The vehicle to update. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1420 * @param dirty Mark the (new and old) coordinates of the vehicle as dirty. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1421 */ |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1422 void VehicleUpdateViewport(Vehicle *v, bool dirty) |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1423 { |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1424 int img = v->cur_image; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1425 Point pt = RemapCoords(v->x_pos + v->x_offs, v->y_pos + v->y_offs, v->z_pos); |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1426 const Sprite *spr = GetSprite(img, ST_NORMAL); |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1427 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1428 pt.x += spr->x_offs; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1429 pt.y += spr->y_offs; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1430 |
18863
58840c62f6da
(svn r23712) -Codechange: rename the two vehicle hashes we have to names that make clear where they differ in
truebrain <truebrain@openttd.org>
parents:
18862
diff
changeset
|
1431 UpdateVehicleViewportHash(v, pt.x, pt.y); |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1432 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1433 Rect old_coord = v->coord; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1434 v->coord.left = pt.x; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1435 v->coord.top = pt.y; |
18472
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
1436 v->coord.right = pt.x + spr->width + 2 * ZOOM_LVL_BASE; |
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
1437 v->coord.bottom = pt.y + spr->height + 2 * ZOOM_LVL_BASE; |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1438 |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1439 if (dirty) { |
19193
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1440 if (old_coord.left == INVALID_COORD) { |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1441 MarkSingleVehicleDirty(v); |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1442 } else { |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1443 MarkAllViewportsDirty( |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1444 min(old_coord.left, v->coord.left), |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1445 min(old_coord.top, v->coord.top), |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1446 max(old_coord.right, v->coord.right) + 1 * ZOOM_LVL_BASE, |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1447 max(old_coord.bottom, v->coord.bottom) + 1 * ZOOM_LVL_BASE |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1448 ); |
14aceba8ac29
(svn r24067) -Change/fix: do not redraw up to 25% of the map when making a new vehicle visible for the first time
rubidium <rubidium@openttd.org>
parents:
19093
diff
changeset
|
1449 } |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1450 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1451 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1452 |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1453 /** |
18864
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1454 * Update the position of the vehicle, and update the viewport. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1455 * @param v The vehicle to update. |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1456 */ |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1457 void VehicleUpdatePositionAndViewport(Vehicle *v) |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1458 { |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1459 VehicleUpdatePosition(v); |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1460 VehicleUpdateViewport(v, true); |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1461 } |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1462 |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1463 /** |
c8717ac828d0
(svn r23713) -Codechange: split VehicleMove() into two functions, to minimalize the work done where possible
truebrain <truebrain@openttd.org>
parents:
18863
diff
changeset
|
1464 * Marks viewports dirty where the vehicle's image is. |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1465 * @param v vehicle to mark dirty |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1466 */ |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1467 void MarkSingleVehicleDirty(const Vehicle *v) |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1468 { |
18472
11637619aa76
(svn r23316) -Feature: Add ability to zoom in to 2x and 4x level.
peter1138 <peter1138@openttd.org>
parents:
18446
diff
changeset
|
1469 MarkAllViewportsDirty(v->coord.left, v->coord.top, v->coord.right + 1 * ZOOM_LVL_BASE, v->coord.bottom + 1 * ZOOM_LVL_BASE); |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1470 } |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1471 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1472 /** |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1473 * Get position information of a vehicle when moving one pixel in the direction it is facing |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1474 * @param v Vehicle to move |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1475 * @return Position information after the move |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1476 */ |
6153 | 1477 GetNewVehiclePosResult GetNewVehiclePos(const Vehicle *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1478 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1479 static const int8 _delta_coord[16] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1480 -1,-1,-1, 0, 1, 1, 1, 0, /* x */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1481 -1, 0, 1, 1, 1, 0,-1,-1, /* y */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1482 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1483 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1484 int x = v->x_pos + _delta_coord[v->direction]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1485 int y = v->y_pos + _delta_coord[v->direction + 8]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1486 |
6153 | 1487 GetNewVehiclePosResult gp; |
1488 gp.x = x; | |
1489 gp.y = y; | |
1490 gp.old_tile = v->tile; | |
1491 gp.new_tile = TileVirtXY(x, y); | |
1492 return gp; | |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1493 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1494 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1495 static const Direction _new_direction_table[] = { |
13175
3f4cc2986131
(svn r17682) -Codechange: remove erroneous space before some commas
rubidium <rubidium@openttd.org>
parents:
13094
diff
changeset
|
1496 DIR_N, DIR_NW, DIR_W, |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1497 DIR_NE, DIR_SE, DIR_SW, |
13175
3f4cc2986131
(svn r17682) -Codechange: remove erroneous space before some commas
rubidium <rubidium@openttd.org>
parents:
13094
diff
changeset
|
1498 DIR_E, DIR_SE, DIR_S |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1499 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1500 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1501 Direction GetDirectionTowards(const Vehicle *v, int x, int y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1502 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1503 int i = 0; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1504 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1505 if (y >= v->y_pos) { |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1506 if (y != v->y_pos) i += 3; |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1507 i += 3; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1508 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1509 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1510 if (x >= v->x_pos) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1511 if (x != v->x_pos) i++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1512 i++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1513 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1514 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1515 Direction dir = v->direction; |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1516 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1517 DirDiff dirdiff = DirDifference(_new_direction_table[i], dir); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1518 if (dirdiff == DIRDIFF_SAME) return dir; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1519 return ChangeDir(dir, dirdiff > DIRDIFF_REVERSE ? DIRDIFF_45LEFT : DIRDIFF_45RIGHT); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1520 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1521 |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5955
diff
changeset
|
1522 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1523 * Call the tile callback function for a vehicle entering a tile |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1524 * @param v Vehicle entering the tile |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1525 * @param tile Tile entered |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1526 * @param x X position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1527 * @param y Y position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1528 * @return Some meta-data over the to be entered tile. |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5955
diff
changeset
|
1529 * @see VehicleEnterTileStatus to see what the bits in the return value mean. |
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5955
diff
changeset
|
1530 */ |
10496
4957395bd611
(svn r14751) -Codechange: put VehicleEnterTile declaration where it should be and use correct return type
smatz <smatz@openttd.org>
parents:
10493
diff
changeset
|
1531 VehicleEnterTileStatus VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1532 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1533 return _tile_type_procs[GetTileType(tile)]->vehicle_enter_tile_proc(v, tile, x, y); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1534 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1535 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1536 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1537 * Initializes the structure. Vehicle unit numbers are supposed not to change after |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1538 * struct initialization, except after each call to this->NextID() the returned value |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1539 * is assigned to a vehicle. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1540 * @param type type of vehicle |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1541 * @param owner owner of vehicles |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1542 */ |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1543 FreeUnitIDGenerator::FreeUnitIDGenerator(VehicleType type, CompanyID owner) : cache(NULL), maxid(0), curid(0) |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1544 { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1545 /* Find maximum */ |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1546 const Vehicle *v; |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1547 FOR_ALL_VEHICLES(v) { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1548 if (v->type == type && v->owner == owner) { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1549 this->maxid = max<UnitID>(this->maxid, v->unitnumber); |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1550 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1551 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1552 |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1553 if (this->maxid == 0) return; |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1554 |
14421
d8710fbbbacd
(svn r18978) -Fix [FS#3584](r14753): possible invalid memory access when merging companies
smatz <smatz@openttd.org>
parents:
14319
diff
changeset
|
1555 /* Reserving 'maxid + 2' because we need: |
d8710fbbbacd
(svn r18978) -Fix [FS#3584](r14753): possible invalid memory access when merging companies
smatz <smatz@openttd.org>
parents:
14319
diff
changeset
|
1556 * - space for the last item (with v->unitnumber == maxid) |
d8710fbbbacd
(svn r18978) -Fix [FS#3584](r14753): possible invalid memory access when merging companies
smatz <smatz@openttd.org>
parents:
14319
diff
changeset
|
1557 * - one free slot working as loop terminator in FreeUnitIDGenerator::NextID() */ |
d8710fbbbacd
(svn r18978) -Fix [FS#3584](r14753): possible invalid memory access when merging companies
smatz <smatz@openttd.org>
parents:
14319
diff
changeset
|
1558 this->cache = CallocT<bool>(this->maxid + 2); |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1559 |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1560 /* Fill the cache */ |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1561 FOR_ALL_VEHICLES(v) { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1562 if (v->type == type && v->owner == owner) { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1563 this->cache[v->unitnumber] = true; |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1564 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1565 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1566 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1567 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1568 /** Returns next free UnitID. Supposes the last returned value was assigned to a vehicle. */ |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1569 UnitID FreeUnitIDGenerator::NextID() |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1570 { |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1571 if (this->maxid <= this->curid) return ++this->curid; |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1572 |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1573 while (this->cache[++this->curid]) { } // it will stop, we reserved more space than needed |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1574 |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1575 return this->curid; |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1576 } |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1577 |
15724
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1578 /** |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1579 * Get an unused unit number for a vehicle (if allowed). |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1580 * @param type Type of vehicle |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1581 * @return A unused unit number for the given type of vehicle if it is allowed to build one, else \c UINT16_MAX. |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1582 */ |
6641
a988a86b0d0a
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium <rubidium@openttd.org>
parents:
6638
diff
changeset
|
1583 UnitID GetFreeUnitNumber(VehicleType type) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1584 { |
15724
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1585 /* Check whether it is allowed to build another vehicle. */ |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1586 uint max_veh; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1587 switch (type) { |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1588 case VEH_TRAIN: max_veh = _settings_game.vehicle.max_trains; break; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1589 case VEH_ROAD: max_veh = _settings_game.vehicle.max_roadveh; break; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1590 case VEH_SHIP: max_veh = _settings_game.vehicle.max_ships; break; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1591 case VEH_AIRCRAFT: max_veh = _settings_game.vehicle.max_aircraft; break; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1592 default: NOT_REACHED(); |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1593 } |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1594 |
18157
f20ba7062226
(svn r22982) -Cleanup: Remove CountCompanyVehicles() and use ALL_GROUP statistics instead.
frosch <frosch@openttd.org>
parents:
18156
diff
changeset
|
1595 const Company *c = Company::Get(_current_company); |
f20ba7062226
(svn r22982) -Cleanup: Remove CountCompanyVehicles() and use ALL_GROUP statistics instead.
frosch <frosch@openttd.org>
parents:
18156
diff
changeset
|
1596 if (c->group_all[type].num_vehicle >= max_veh) return UINT16_MAX; // Currently already at the limit, no room to make a new one. |
15724
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1597 |
10498
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1598 FreeUnitIDGenerator gen(type, _current_company); |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1599 |
730117b172e1
(svn r14753) -Fix (r1): after buying a company, one could have more vehicles with the same UnitID
smatz <smatz@openttd.org>
parents:
10496
diff
changeset
|
1600 return gen.NextID(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1601 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1602 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1603 |
7086
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1604 /** |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1605 * Check whether we can build infrastructure for the given |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1606 * vehicle type. This to disable building stations etc. when |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1607 * you are not allowed/able to have the vehicle type yet. |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1608 * @param type the vehicle type to check this for |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1609 * @return true if there is any reason why you may build |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1610 * the infrastructure for the given vehicle type |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1611 */ |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1612 bool CanBuildVehicleInfrastructure(VehicleType type) |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1613 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1614 assert(IsCompanyBuildableVehicleType(type)); |
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1615 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
1616 if (!Company::IsValidID(_local_company)) return false; |
17089
6e590e642890
(svn r21826) -Fix [FS#4007]: the expectations from the "always build infrastructure" setting name/description didn't match the behaviour
rubidium <rubidium@openttd.org>
parents:
17072
diff
changeset
|
1617 if (!_settings_client.gui.disable_unsuitable_building) return true; |
7086
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1618 |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1619 UnitID max; |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1620 switch (type) { |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1621 case VEH_TRAIN: max = _settings_game.vehicle.max_trains; break; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1622 case VEH_ROAD: max = _settings_game.vehicle.max_roadveh; break; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1623 case VEH_SHIP: max = _settings_game.vehicle.max_ships; break; |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9396
diff
changeset
|
1624 case VEH_AIRCRAFT: max = _settings_game.vehicle.max_aircraft; break; |
7086
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1625 default: NOT_REACHED(); |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1626 } |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1627 |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1628 /* We can build vehicle infrastructure when we may build the vehicle type */ |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1629 if (max > 0) { |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1630 /* Can we actually build the vehicle type? */ |
9070
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9065
diff
changeset
|
1631 const Engine *e; |
11b5b3f4175d
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents:
9065
diff
changeset
|
1632 FOR_ALL_ENGINES_OF_TYPE(e, type) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1633 if (HasBit(e->company_avail, _local_company)) return true; |
7086
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1634 } |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1635 return false; |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1636 } |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1637 |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1638 /* We should be able to build infrastructure when we have the actual vehicle type */ |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1639 const Vehicle *v; |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1640 FOR_ALL_VEHICLES(v) { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1641 if (v->owner == _local_company && v->type == type) return true; |
7086
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1642 } |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1643 |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1644 return false; |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1645 } |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1646 |
787d1ac148e4
(svn r10353) -Fix/Feature [FS#669]: disallow (in the GUI) the building of infrastructure you do not have available vehicles for. This means that the airport building button is disabled till you can actually build aircraft. The game itself will not disallow you to build the infrastructure and this "new" behaviour can be overriden with a patch setting.
rubidium <rubidium@openttd.org>
parents:
7076
diff
changeset
|
1647 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1648 /** |
16151
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1649 * Determines the #LiveryScheme for a vehicle. |
19626
017481cebabf
(svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents:
19540
diff
changeset
|
1650 * @param engine_type Engine of the vehicle. |
017481cebabf
(svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents:
19540
diff
changeset
|
1651 * @param parent_engine_type Engine of the front vehicle, #INVALID_ENGINE if vehicle is at front itself. |
017481cebabf
(svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents:
19540
diff
changeset
|
1652 * @param v the vehicle, \c NULL if in purchase list etc. |
017481cebabf
(svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents:
19540
diff
changeset
|
1653 * @return livery scheme to use. |
16151
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1654 */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1655 LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_type, const Vehicle *v) |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1656 { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1657 CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1658 const Engine *e = Engine::Get(engine_type); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1659 switch (e->type) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1660 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1661 case VEH_TRAIN: |
17185
ccebafd2a9ba
(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.
terkhen <terkhen@openttd.org>
parents:
17170
diff
changeset
|
1662 if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) { |
16151
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1663 /* Wagonoverrides use the colour scheme of the front engine. |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1664 * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1665 engine_type = parent_engine_type; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1666 e = Engine::Get(engine_type); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1667 /* Note: Luckily cargo_type is not needed for engines */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1668 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1669 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1670 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1671 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1672 if (e->u.rail.railveh_type == RAILVEH_WAGON) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1673 if (!CargoSpec::Get(cargo_type)->is_freight) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1674 if (parent_engine_type == INVALID_ENGINE) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1675 return LS_PASSENGER_WAGON_STEAM; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1676 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1677 switch (RailVehInfo(parent_engine_type)->engclass) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1678 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1679 case EC_STEAM: return LS_PASSENGER_WAGON_STEAM; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1680 case EC_DIESEL: return LS_PASSENGER_WAGON_DIESEL; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1681 case EC_ELECTRIC: return LS_PASSENGER_WAGON_ELECTRIC; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1682 case EC_MONORAIL: return LS_PASSENGER_WAGON_MONORAIL; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1683 case EC_MAGLEV: return LS_PASSENGER_WAGON_MAGLEV; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1684 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1685 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1686 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1687 return LS_FREIGHT_WAGON; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1688 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1689 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1690 bool is_mu = HasBit(e->info.misc_flags, EF_RAIL_IS_MU); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1691 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1692 switch (e->u.rail.engclass) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1693 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1694 case EC_STEAM: return LS_STEAM; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1695 case EC_DIESEL: return is_mu ? LS_DMU : LS_DIESEL; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1696 case EC_ELECTRIC: return is_mu ? LS_EMU : LS_ELECTRIC; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1697 case EC_MONORAIL: return LS_MONORAIL; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1698 case EC_MAGLEV: return LS_MAGLEV; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1699 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1700 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1701 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1702 case VEH_ROAD: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1703 /* Always use the livery of the front */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1704 if (v != NULL && parent_engine_type != INVALID_ENGINE) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1705 engine_type = parent_engine_type; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1706 e = Engine::Get(engine_type); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1707 cargo_type = v->First()->cargo_type; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1708 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1709 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1710 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1711 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1712 /* Important: Use Tram Flag of front part. Luckily engine_type refers to the front part here. */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1713 if (HasBit(e->info.misc_flags, EF_ROAD_TRAM)) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1714 /* Tram */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1715 return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1716 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1717 /* Bus or truck */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1718 return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1719 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1720 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1721 case VEH_SHIP: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1722 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1723 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1724 return IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1725 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1726 case VEH_AIRCRAFT: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1727 switch (e->u.air.subtype) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1728 case AIR_HELI: return LS_HELICOPTER; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1729 case AIR_CTOL: return LS_SMALL_PLANE; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1730 case AIR_CTOL | AIR_FAST: return LS_LARGE_PLANE; |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1731 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1732 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1733 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1734 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1735 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1736 /** |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1737 * Determines the livery for a vehicle. |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1738 * @param engine_type EngineID of the vehicle |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1739 * @param company Owner of the vehicle |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1740 * @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself. |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1741 * @param v the vehicle. NULL if in purchase list etc. |
15921
7c1f97a04d96
(svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents:
15898
diff
changeset
|
1742 * @param livery_setting The livery settings to use for acquiring the livery information. |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1743 * @return livery to use |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1744 */ |
15921
7c1f97a04d96
(svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents:
15898
diff
changeset
|
1745 const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v, byte livery_setting) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1746 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1747 const Company *c = Company::Get(company); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1748 LiveryScheme scheme = LS_DEFAULT; |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1749 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1750 /* The default livery is always available for use, but its in_use flag determines |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1751 * whether any _other_ liveries are in use. */ |
15921
7c1f97a04d96
(svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents:
15898
diff
changeset
|
1752 if (c->livery[LS_DEFAULT].in_use && (livery_setting == LIT_ALL || (livery_setting == LIT_COMPANY && company == _local_company))) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1753 /* Determine the livery scheme to use */ |
16151
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1754 scheme = GetEngineLiveryScheme(engine_type, parent_engine_type, v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1755 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1756 /* Switch back to the default scheme if the resolved scheme is not in use */ |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1757 if (!c->livery[scheme].in_use) scheme = LS_DEFAULT; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1758 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1759 |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1760 return &c->livery[scheme]; |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1761 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1762 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1763 |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1764 static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, EngineID parent_engine_type, const Vehicle *v) |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1765 { |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1766 PaletteID map = (v != NULL) ? v->colourmap : PAL_NONE; |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1767 |
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1768 /* Return cached value if any */ |
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1769 if (map != PAL_NONE) return map; |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1770 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1771 const Engine *e = Engine::Get(engine_type); |
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1772 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1773 /* Check if we should use the colour map callback */ |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1774 if (HasBit(e->info.callback_mask, CBM_VEHICLE_COLOUR_REMAP)) { |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1775 uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); |
16331
ebf6e0aec7f5
(svn r21039) -Fix/Cleanup: Remove an unneeded and even wrong test, which is never reached anyway though.
frosch <frosch@openttd.org>
parents:
16151
diff
changeset
|
1776 /* Failure means "use the default two-colour" */ |
ebf6e0aec7f5
(svn r21039) -Fix/Cleanup: Remove an unneeded and even wrong test, which is never reached anyway though.
frosch <frosch@openttd.org>
parents:
16151
diff
changeset
|
1777 if (callback != CALLBACK_FAILED) { |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19948
diff
changeset
|
1778 assert_compile(PAL_NONE == 0); // Returning 0x4000 (resp. 0xC000) coincidences with default value (PAL_NONE) |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1779 map = GB(callback, 0, 14); |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1780 /* If bit 14 is set, then the company colours are applied to the |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1781 * map else it's returned as-is. */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1782 if (!HasBit(callback, 14)) { |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1783 /* Update cache */ |
12016
d45475f68f60
(svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
1784 if (v != NULL) const_cast<Vehicle *>(v)->colourmap = map; |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1785 return map; |
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1786 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1787 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1788 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1789 |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13186
diff
changeset
|
1790 bool twocc = HasBit(e->info.misc_flags, EF_USES_2CC); |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1791 |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1792 if (map == PAL_NONE) map = twocc ? (PaletteID)SPR_2CCMAP_BASE : (PaletteID)PALETTE_RECOLOUR_START; |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1793 |
12044
904073386a13
(svn r16451) -Fix (r16449): crash when a spectator (or dedicated server) received news about new engine
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1794 /* Spectator has news shown too, but has invalid company ID - as well as dedicated server */ |
904073386a13
(svn r16451) -Fix (r16449): crash when a spectator (or dedicated server) received news about new engine
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1795 if (!Company::IsValidID(company)) return map; |
904073386a13
(svn r16451) -Fix (r16449): crash when a spectator (or dedicated server) received news about new engine
smatz <smatz@openttd.org>
parents:
12032
diff
changeset
|
1796 |
15921
7c1f97a04d96
(svn r20605) -Fix [FS#4063]: let NewGRFs var43 var (information about liveries) for vehicles not be influenced by the local setting determining whether to show liveries or not.
rubidium <rubidium@openttd.org>
parents:
15898
diff
changeset
|
1797 const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v, _settings_client.gui.liveries); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1798 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1799 map += livery->colour1; |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1800 if (twocc) map += livery->colour2 * 16; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1801 |
7802
bb4e6370dfdf
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
glx <glx@openttd.org>
parents:
7765
diff
changeset
|
1802 /* Update cache */ |
12016
d45475f68f60
(svn r16422) -Codechange: use const_cast for removing const and warn when const is (accidentally?) removed using C-style casts.
rubidium <rubidium@openttd.org>
parents:
12015
diff
changeset
|
1803 if (v != NULL) const_cast<Vehicle *>(v)->colourmap = map; |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
1804 return map; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1805 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1806 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1807 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1808 * Get the colour map for an engine. This used for unbuilt engines in the user interface. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1809 * @param engine_type ID of engine |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1810 * @param company ID of company |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1811 * @return A ready-to-use palette modifier |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1812 */ |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1813 PaletteID GetEnginePalette(EngineID engine_type, CompanyID company) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1814 { |
10207
c54d140df948
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents:
10193
diff
changeset
|
1815 return GetEngineColourMap(engine_type, company, INVALID_ENGINE, NULL); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1816 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1817 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1818 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1819 * Get the colour map for a vehicle. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1820 * @param v Vehicle to get colour map for |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1821 * @return A ready-to-use palette modifier |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
1822 */ |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1823 PaletteID GetVehiclePalette(const Vehicle *v) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1824 { |
16788
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16786
diff
changeset
|
1825 if (v->IsGroundVehicle()) { |
efb0333e5aad
(svn r21521) -Codechange: Unify some cached values that were present in both road vehicles and trains.
terkhen <terkhen@openttd.org>
parents:
16786
diff
changeset
|
1826 return GetEngineColourMap(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1827 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1828 |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1829 return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1830 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1831 |
13388
96253b319c10
(svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
1832 /** |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1833 * Delete all implicit orders which were not reached. |
17070
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1834 */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1835 void Vehicle::DeleteUnreachedImplicitOrders() |
17070
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1836 { |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1837 if (this->IsGroundVehicle()) { |
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1838 uint16 &gv_flags = this->GetGroundVehicleFlags(); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1839 if (HasBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS)) { |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1840 /* Do not delete orders, only skip them */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1841 ClrBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1842 this->cur_implicit_order_index = this->cur_real_order_index; |
17564
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1843 InvalidateVehicleOrder(this, 0); |
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1844 return; |
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1845 } |
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1846 } |
d5ff867052a5
(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.
frosch <frosch@openttd.org>
parents:
17563
diff
changeset
|
1847 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1848 const Order *order = this->GetOrder(this->cur_implicit_order_index); |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1849 while (order != NULL) { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1850 if (this->cur_implicit_order_index == this->cur_real_order_index) break; |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1851 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1852 if (order->IsType(OT_IMPLICIT)) { |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1853 /* Delete order effectively deletes order, so get the next before deleting it. */ |
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1854 order = order->next; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1855 DeleteOrder(this, this->cur_implicit_order_index); |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1856 } else { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1857 /* Skip non-implicit orders, e.g. service-orders */ |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1858 order = order->next; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1859 this->cur_implicit_order_index++; |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1860 } |
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1861 |
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1862 /* Wrap around */ |
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1863 if (order == NULL) { |
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1864 order = this->GetOrder(0); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1865 this->cur_implicit_order_index = 0; |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1866 } |
17070
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1867 } |
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1868 } |
5651
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1869 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1870 /** |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1871 * Prepare everything to begin the loading when arriving at a station. |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1872 * @pre IsTileType(this->tile, MP_STATION) || this->type == VEH_SHIP. |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1873 */ |
5651
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1874 void Vehicle::BeginLoading() |
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1875 { |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1876 assert(IsTileType(this->tile, MP_STATION) || this->type == VEH_SHIP); |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1877 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1878 if (this->current_order.IsType(OT_GOTO_STATION) && |
8840
c3d2f0eb69a1
(svn r12588) -Codechange: do not access the destination of an order directly.
rubidium <rubidium@openttd.org>
parents:
8838
diff
changeset
|
1879 this->current_order.GetDestination() == this->last_station_visited) { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1880 this->DeleteUnreachedImplicitOrders(); |
16907
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
16864
diff
changeset
|
1881 |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
1882 /* Now both order indices point to the destination station, and we can start loading */ |
17002
9f83d76a6f12
(svn r21738) -Fix (r21642)[FS#4384]: Start loading when cur_order_index points to the destination station, i.e. after deleting not-reached automatic orders.
frosch <frosch@openttd.org>
parents:
16944
diff
changeset
|
1883 this->current_order.MakeLoading(true); |
9f83d76a6f12
(svn r21738) -Fix (r21642)[FS#4384]: Start loading when cur_order_index points to the destination station, i.e. after deleting not-reached automatic orders.
frosch <frosch@openttd.org>
parents:
16944
diff
changeset
|
1884 UpdateVehicleTimetable(this, true); |
9f83d76a6f12
(svn r21738) -Fix (r21642)[FS#4384]: Start loading when cur_order_index points to the destination station, i.e. after deleting not-reached automatic orders.
frosch <frosch@openttd.org>
parents:
16944
diff
changeset
|
1885 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1886 /* Furthermore add the Non Stop flag to mark that this station |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1887 * is the actual destination of the vehicle, which is (for example) |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1888 * necessary to be known for HandleTrainLoading to determine |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1889 * whether the train is lost or not; not marking a train lost |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1890 * that arrives at random stations is bad. */ |
8848
066a8010467f
(svn r12600) -Codechange: make GetNonStopType return a more augmented type; not is there a non-stop order but the kind of non-stop order, so one doesn't need to check _patches.new_nonstop type everywhere.
rubidium <rubidium@openttd.org>
parents:
8847
diff
changeset
|
1891 this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION); |
8843
1f412a20da48
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents:
8840
diff
changeset
|
1892 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1893 } else { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1894 /* We weren't scheduled to stop here. Insert an implicit order |
17071
cef968e48b30
(svn r21808) -Fix: don't create automatic orders when there are no manual orders (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17070
diff
changeset
|
1895 * to show that we are stopping here, but only do that if the order |
17712
04160ffe763d
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
frosch <frosch@openttd.org>
parents:
17702
diff
changeset
|
1896 * list isn't empty. |
04160ffe763d
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
frosch <frosch@openttd.org>
parents:
17702
diff
changeset
|
1897 * While only groundvehicles have implicit orders, e.g. aircraft might still enter |
04160ffe763d
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
frosch <frosch@openttd.org>
parents:
17702
diff
changeset
|
1898 * the 'wrong' terminal when skipping orders etc. */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1899 Order *in_list = this->GetOrder(this->cur_implicit_order_index); |
17712
04160ffe763d
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
frosch <frosch@openttd.org>
parents:
17702
diff
changeset
|
1900 if (this->IsGroundVehicle() && in_list != NULL && |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1901 (!in_list->IsType(OT_IMPLICIT) || |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1902 in_list->GetDestination() != this->last_station_visited)) { |
17712
04160ffe763d
(svn r22492) -Fix [FS#4624] (r21642, r22328): Only try to insert implicit orders for ground vehicles. Aircraft may reach unscheduled terminals when skippnig orders etc.
frosch <frosch@openttd.org>
parents:
17702
diff
changeset
|
1903 bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1904 /* Do not create consecutive duplicates of implicit orders */ |
17748
f867dd72c41f
(svn r22532) -Fix: Do not create an implicit order if the current order is the first order in the order list and we visit the station of the last entry of the order list.
michi_cc <michi_cc@openttd.org>
parents:
17726
diff
changeset
|
1905 Order *prev_order = this->cur_implicit_order_index > 0 ? this->GetOrder(this->cur_implicit_order_index - 1) : (this->GetNumOrders() > 1 ? this->GetLastOrder() : NULL); |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1906 if (prev_order == NULL || |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1907 (!prev_order->IsType(OT_IMPLICIT) && !prev_order->IsType(OT_GOTO_STATION)) || |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1908 prev_order->GetDestination() != this->last_station_visited) { |
17567
3a23cb7f4a41
(svn r22331) -Change: When inserting an (automatic) order A in front of an order B, disable modifications of automatic orders for all vehicles currently heading for B as we do not know whether they will reach A or B first. (except for the vehicle causing the insertion of the automatic order itself)
frosch <frosch@openttd.org>
parents:
17565
diff
changeset
|
1909 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1910 /* Prefer deleting implicit orders instead of inserting new ones, |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1911 * so test whether the right order follows later */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1912 int target_index = this->cur_implicit_order_index; |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1913 bool found = false; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1914 while (target_index != this->cur_real_order_index) { |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1915 const Order *order = this->GetOrder(target_index); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1916 if (order->IsType(OT_IMPLICIT) && order->GetDestination() == this->last_station_visited) { |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1917 found = true; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1918 break; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1919 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1920 target_index++; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1921 if (target_index >= this->orders.list->GetNumOrders()) target_index = 0; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1922 assert(target_index != this->cur_implicit_order_index); // infinite loop? |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1923 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1924 |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1925 if (found) { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1926 if (suppress_implicit_orders) { |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1927 /* Skip to the found order */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1928 this->cur_implicit_order_index = target_index; |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1929 InvalidateVehicleOrder(this, 0); |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1930 } else { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1931 /* Delete all implicit orders up to the station we just reached */ |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1932 const Order *order = this->GetOrder(this->cur_implicit_order_index); |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1933 while (!order->IsType(OT_IMPLICIT) || order->GetDestination() != this->last_station_visited) { |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1934 if (order->IsType(OT_IMPLICIT)) { |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1935 /* Delete order effectively deletes order, so get the next before deleting it. */ |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1936 order = order->next; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1937 DeleteOrder(this, this->cur_implicit_order_index); |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1938 } else { |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1939 /* Skip non-implicit orders, e.g. service-orders */ |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1940 order = order->next; |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1941 this->cur_implicit_order_index++; |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1942 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1943 |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1944 /* Wrap around */ |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1945 if (order == NULL) { |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1946 order = this->GetOrder(0); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1947 this->cur_implicit_order_index = 0; |
17569
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1948 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1949 assert(order != NULL); |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1950 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1951 } |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1952 } else if (!suppress_implicit_orders && this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID && Order::CanAllocateItem()) { |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1953 /* Insert new implicit order */ |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1954 Order *implicit_order = new Order(); |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1955 implicit_order->MakeImplicit(this->last_station_visited); |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1956 InsertOrder(this, implicit_order, this->cur_implicit_order_index); |
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1957 if (this->cur_implicit_order_index > 0) --this->cur_implicit_order_index; |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1958 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1959 /* InsertOrder disabled creation of implicit orders for all vehicles with the same implicit order. |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1960 * Reenable it for this vehicle */ |
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1961 uint16 &gv_flags = this->GetGroundVehicleFlags(); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
1962 ClrBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
17568
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1963 } |
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1964 } |
16907
e2be394e4714
(svn r21642) -Feature: concept of automatic station orders; add stub orders for intermediate stations and remove them when not visiting them anymore. This allows you to see what trains visit a station without actually having to order a vehicle to stop at all stations. Based on patch by fonsinchen
rubidium <rubidium@openttd.org>
parents:
16864
diff
changeset
|
1965 } |
17002
9f83d76a6f12
(svn r21738) -Fix (r21642)[FS#4384]: Start loading when cur_order_index points to the destination station, i.e. after deleting not-reached automatic orders.
frosch <frosch@openttd.org>
parents:
16944
diff
changeset
|
1966 this->current_order.MakeLoading(false); |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1967 } |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1968 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1969 Station::Get(this->last_station_visited)->loading_vehicles.push_back(this); |
6553
733ef9947fe2
(svn r9755) -Codechange: refactor some more of the begin loading stuff.
rubidium <rubidium@openttd.org>
parents:
6552
diff
changeset
|
1970 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
1971 PrepareUnload(this); |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6562
diff
changeset
|
1972 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1973 SetWindowDirty(GetWindowClassForVehicleType(this->type), this->owner); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18678
diff
changeset
|
1974 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1975 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1976 SetWindowDirty(WC_STATION_VIEW, this->last_station_visited); |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6562
diff
changeset
|
1977 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1978 Station::Get(this->last_station_visited)->MarkTilesDirty(true); |
11694
50291ef7d6e6
(svn r16079) -Fix [FS#2824]: insanely fast trains would not stop in time for stations
rubidium <rubidium@openttd.org>
parents:
11668
diff
changeset
|
1979 this->cur_speed = 0; |
6565
547b0171c3a9
(svn r9770) -Codechange: perform the payment of cargo when loading/unloading, but when arriving at the station.
rubidium <rubidium@openttd.org>
parents:
6562
diff
changeset
|
1980 this->MarkDirty(); |
5651
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1981 } |
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1982 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1983 /** |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1984 * Perform all actions when leaving a station. |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1985 * @pre this->current_order.IsType(OT_LOADING) |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1986 */ |
5651
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1987 void Vehicle::LeaveStation() |
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
1988 { |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1989 assert(this->current_order.IsType(OT_LOADING)); |
7076
2cfd97ea12b5
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros <maedhros@openttd.org>
parents:
7070
diff
changeset
|
1990 |
12279
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
1991 delete this->cargo_payment; |
329b186db8cd
(svn r16694) -Fix [FS#2995] (rgradual loading, rnewindustries): only pay for whatever has been actually unloaded and perform the payment when unloading has finished. This fixes, amongst others:
rubidium <rubidium@openttd.org>
parents:
12228
diff
changeset
|
1992 |
7076
2cfd97ea12b5
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros <maedhros@openttd.org>
parents:
7070
diff
changeset
|
1993 /* Only update the timetable if the vehicle was supposed to stop here. */ |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1994 if (this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) UpdateVehicleTimetable(this, false); |
7076
2cfd97ea12b5
(svn r10341) -Fix (r10236): Only update the timetable when leaving stations if this is a scheduled stop.
maedhros <maedhros@openttd.org>
parents:
7070
diff
changeset
|
1995 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1996 this->current_order.MakeLeaveStation(); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1997 Station *st = Station::Get(this->last_station_visited); |
9041
7a19e805faf6
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138 <peter1138@openttd.org>
parents:
9009
diff
changeset
|
1998 st->loading_vehicles.remove(this); |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
1999 |
10176
71daf486081d
(svn r14371) -Fix [FS#2313]: loading indicator didn't stay with the front engine when turning a train in a station.
rubidium <rubidium@openttd.org>
parents:
10175
diff
changeset
|
2000 HideFillingPercent(&this->fill_percent_te_id); |
9041
7a19e805faf6
(svn r12860) -Fix [FS#1947]: Train depart animation trigger was not called in some cases.
peter1138 <peter1138@openttd.org>
parents:
9009
diff
changeset
|
2001 |
11788
c4958ccc0141
(svn r16178) -Fix [FS#2866]: don't try to reserve path for trains crashed in station
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
2002 if (this->type == VEH_TRAIN && !(this->vehstatus & VS_CRASHED)) { |
9891
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2003 /* Trigger station animation (trains only) */ |
19973
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
2004 if (IsTileType(this->tile, MP_STATION)) { |
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
2005 TriggerStationRandomisation(st, this->tile, SRT_TRAIN_DEPARTS); |
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
2006 TriggerStationAnimation(st, this->tile, SAT_TRAIN_DEPARTS); |
f8c0e108128c
(svn r24905) -Feature(ish): Implement station randomisation triggers.
peter1138 <peter1138@openttd.org>
parents:
19968
diff
changeset
|
2007 } |
9891
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2008 |
15449
f6ee1b7fde96
(svn r20098) -Fix [FS#3898]: A train reversing in a station would sometimes fail to release its reserved path.
michi_cc <michi_cc@openttd.org>
parents:
15382
diff
changeset
|
2009 SetBit(Train::From(this)->flags, VRF_LEAVING_STATION); |
9891
95fb811fb1d3
(svn r14039) -Fix [FS#2217]: reversing an overlength train at a station would try to find a route out and sometimes reset the unload counter making it wait 2.5 years before departing instead of waiting until the train would actually leave the station (michi_cc)
rubidium <rubidium@openttd.org>
parents:
9808
diff
changeset
|
2010 } |
5651
28d6c9f90f62
(svn r8110) -Codechange: direct Vehicle::current_order.type changes (to OT_LOADING and OT_LEAVESTATION) replaced by v->BeginLoading() and v->LeaveStation() calls. This should allow easy hooking of those state transitions in order to maintain vehicle loading queue.
KUDr <KUDr@openttd.org>
parents:
5609
diff
changeset
|
2011 } |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
2012 |
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
2013 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2014 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2015 * Handle the loading of the vehicle; when not it skips through dummy |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2016 * orders and does nothing in all other cases. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2017 * @param mode is the non-first call for this vehicle in this tick? |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2018 */ |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2019 void Vehicle::HandleLoading(bool mode) |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2020 { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
2021 switch (this->current_order.GetType()) { |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2022 case OT_LOADING: { |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
2023 uint wait_time = max(this->current_order.wait_time - this->lateness_counter, 0); |
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
2024 |
6616
ce5601a32593
(svn r9836) -Codechange: make non-improved loading happen FIFO-ish; generally loading/unloading will happen fifo, but there are no guarantees on the FIFO-ness. For (better) FIFO guarantees you still need to use improved loading.
rubidium <rubidium@openttd.org>
parents:
6611
diff
changeset
|
2025 /* Not the first call for this tick, or still loading */ |
17218
46deeeb7a878
(svn r21957) -Cleanup: gotodepot and timetabling settings are more or less useless; just don't use depot orders or timetabling if you don't want to use it
rubidium <rubidium@openttd.org>
parents:
17194
diff
changeset
|
2026 if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || this->current_order_time < wait_time) return; |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2027 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2028 this->PlayLeaveStationSound(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2029 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2030 this->LeaveStation(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2031 |
17560
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2032 /* Only advance to next order if we just loaded at the current one */ |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
2033 const Order *order = this->GetOrder(this->cur_implicit_order_index); |
17560
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2034 if (order == NULL || |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
2035 (!order->IsType(OT_IMPLICIT) && !order->IsType(OT_GOTO_STATION)) || |
17560
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2036 order->GetDestination() != this->last_station_visited) { |
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2037 return; |
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2038 } |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2039 break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2040 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2041 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2042 case OT_DUMMY: break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2043 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2044 default: return; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2045 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2046 |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
2047 this->IncrementImplicitOrderIndex(); |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2048 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2049 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2050 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2051 * Send this vehicle to the depot using the given command(s). |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2052 * @param flags the command flags (like execute and such). |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2053 * @param command the command to execute. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2054 * @return the cost of the depot action. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2055 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
2056 CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command) |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2057 { |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2058 CommandCost ret = CheckOwnership(this->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2059 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2060 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2061 if (this->vehstatus & VS_CRASHED) return CMD_ERROR; |
9934
26c9719c4ae0
(svn r14089) -Fix [FS#2219]: trains not being able to find a route to a depot when the front is already in the depot.
rubidium <rubidium@openttd.org>
parents:
9930
diff
changeset
|
2062 if (this->IsStoppedInDepot()) return CMD_ERROR; |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2063 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2064 if (this->current_order.IsType(OT_GOTO_DEPOT)) { |
13994
486560a72171
(svn r18536) -Fix [FS#3386]: MSVC warning. Patch by pavel1269
rubidium <rubidium@openttd.org>
parents:
13943
diff
changeset
|
2065 bool halt_in_depot = (this->current_order.GetDepotActionType() & ODATFB_HALT) != 0; |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2066 if (!!(command & DEPOT_SERVICE) == halt_in_depot) { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2067 /* We called with a different DEPOT_SERVICE setting. |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2068 * Now we change the setting to apply the new one and let the vehicle head for the same depot. |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2069 * Note: the if is (true for requesting service == true for ordered to stop in depot) */ |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2070 if (flags & DC_EXEC) { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2071 this->current_order.SetDepotOrderType(ODTF_MANUAL); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2072 this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18678
diff
changeset
|
2073 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2074 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2075 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2076 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2077 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2078 if (command & DEPOT_DONT_CANCEL) return CMD_ERROR; // Requested no cancelation of depot orders |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2079 if (flags & DC_EXEC) { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2080 /* If the orders to 'goto depot' are in the orders list (forced servicing), |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2081 * then skip to the next order; effectively cancelling this forced service */ |
17194
b590eca5d805
(svn r21933) -Codechange: Split cur_order_index into cur_auto_order_index and cur_real_order_index to keep track of the current real order in an unambiguous way.
frosch <frosch@openttd.org>
parents:
17193
diff
changeset
|
2082 if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->IncrementRealOrderIndex(); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2083 |
17565
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2084 if (this->IsGroundVehicle()) { |
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2085 uint16 &gv_flags = this->GetGroundVehicleFlags(); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
2086 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
17565
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2087 } |
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2088 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2089 this->current_order.MakeDummy(); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18678
diff
changeset
|
2090 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2091 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2092 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2093 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2094 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2095 TileIndex location; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2096 DestinationID destination; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2097 bool reverse; |
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:
11726
diff
changeset
|
2098 static const StringID no_depot[] = {STR_ERROR_UNABLE_TO_FIND_ROUTE_TO, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_UNABLE_TO_FIND_LOCAL_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR}; |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2099 if (!this->FindClosestDepot(&location, &destination, &reverse)) return_cmd_error(no_depot[this->type]); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2100 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2101 if (flags & DC_EXEC) { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2102 if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2103 |
17565
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2104 if (this->IsGroundVehicle()) { |
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2105 uint16 &gv_flags = this->GetGroundVehicleFlags(); |
17693
cdeed5a57cdb
(svn r22473) -Codechange: Automatic orders are better called implicit orders as no real order influencing path finding is added
planetmaker <planetmaker@openttd.org>
parents:
17569
diff
changeset
|
2106 SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); |
17565
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2107 } |
2ddbdf4793ab
(svn r22329) -Change: When the current orders are interrupted for non-ordered service, disable modifications to automatic orders until the next real order is completed. (train part already slipped by in r22328)
frosch <frosch@openttd.org>
parents:
17564
diff
changeset
|
2108 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2109 this->dest_tile = location; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2110 this->current_order.MakeGoToDepot(destination, ODTF_MANUAL); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2111 if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT); |
18692
90d395fc678d
(svn r23540) -Codechange: unify and document vehicle widgets
rubidium <rubidium@openttd.org>
parents:
18678
diff
changeset
|
2112 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, WID_VV_START_STOP); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2113 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2114 /* If there is no depot in front, reverse automatically (trains only) */ |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2115 if (this->type == VEH_TRAIN && reverse) DoCommand(this->tile, this->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2116 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2117 if (this->type == 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:
12112
diff
changeset
|
2118 Aircraft *a = Aircraft::From(this); |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2119 if (a->state == FLYING && a->targetairport != destination) { |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2120 /* The aircraft is now heading for a different hangar than the next in the orders */ |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2121 extern void AircraftNextAirportPos_and_Order(Aircraft *a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2122 AircraftNextAirportPos_and_Order(a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2123 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2124 } |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2125 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2126 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2127 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2128 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2129 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2130 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2131 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2132 * Update the cached visual effect. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2133 * @param allow_power_change true if the wagon-is-powered-state may change. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2134 */ |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2135 void Vehicle::UpdateVisualEffect(bool allow_power_change) |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2136 { |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2137 bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); |
18238
3141f1ed78eb
(svn r23074) -Codechange: Add Vehicle::GetEngine() to simplify code.
frosch <frosch@openttd.org>
parents:
18220
diff
changeset
|
2138 const Engine *e = this->GetEngine(); |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2139 |
16864
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2140 /* Evaluate properties */ |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2141 byte visual_effect; |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2142 switch (e->type) { |
16862
b36044db5a61
(svn r21596) -Codechange: Rename a misleading-named variable.
frosch <frosch@openttd.org>
parents:
16828
diff
changeset
|
2143 case VEH_TRAIN: visual_effect = e->u.rail.visual_effect; break; |
b36044db5a61
(svn r21596) -Codechange: Rename a misleading-named variable.
frosch <frosch@openttd.org>
parents:
16828
diff
changeset
|
2144 case VEH_ROAD: visual_effect = e->u.road.visual_effect; break; |
b36044db5a61
(svn r21596) -Codechange: Rename a misleading-named variable.
frosch <frosch@openttd.org>
parents:
16828
diff
changeset
|
2145 case VEH_SHIP: visual_effect = e->u.ship.visual_effect; break; |
16864
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2146 default: visual_effect = 1 << VE_DISABLE_EFFECT; break; |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2147 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2148 |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2149 /* Check powered wagon / visual effect callback */ |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2150 if (HasBit(e->info.callback_mask, CBM_VEHICLE_VISUAL_EFFECT)) { |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2151 uint16 callback = GetVehicleCallback(CBID_VEHICLE_VISUAL_EFFECT, 0, 0, this->engine_type, this); |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2152 |
16863
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2153 if (callback != CALLBACK_FAILED) { |
18312
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
2154 if (callback >= 0x100 && e->GetGRF()->grf_version >= 8) ErrorUnknownCallbackResult(e->GetGRFID(), CBID_VEHICLE_VISUAL_EFFECT, callback); |
1945b084b0dc
(svn r23148) -Change: [NewGRF] Check the results of various callbacks for validness.
frosch <frosch@openttd.org>
parents:
18276
diff
changeset
|
2155 |
16863
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2156 callback = GB(callback, 0, 8); |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2157 /* Avoid accidentally setting 'visual_effect' to the default value |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2158 * Since bit 6 (disable effects) is set anyways, we can safely erase some bits. */ |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2159 if (callback == VE_DEFAULT) { |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2160 assert(HasBit(callback, VE_DISABLE_EFFECT)); |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2161 SB(callback, VE_TYPE_START, VE_TYPE_COUNT, 0); |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2162 } |
16864
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2163 visual_effect = callback; |
16863
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2164 } |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2165 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2166 |
16864
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2167 /* Apply default values */ |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2168 if (visual_effect == VE_DEFAULT || |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2169 (!HasBit(visual_effect, VE_DISABLE_EFFECT) && GB(visual_effect, VE_TYPE_START, VE_TYPE_COUNT) == VE_TYPE_DEFAULT)) { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2170 /* Only train engines have default effects. |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2171 * Note: This is independent of whether the engine is a front engine or articulated part or whatever. */ |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2172 if (e->type != VEH_TRAIN || e->u.rail.railveh_type == RAILVEH_WAGON || !IsInsideMM(e->u.rail.engclass, EC_STEAM, EC_MONORAIL)) { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2173 if (visual_effect == VE_DEFAULT) { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2174 visual_effect = 1 << VE_DISABLE_EFFECT; |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2175 } else { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2176 SetBit(visual_effect, VE_DISABLE_EFFECT); |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2177 } |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2178 } else { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2179 if (visual_effect == VE_DEFAULT) { |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2180 /* Also set the offset */ |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2181 visual_effect = (VE_OFFSET_CENTRE - (e->u.rail.engclass == EC_STEAM ? 4 : 0)) << VE_OFFSET_START; |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2182 } |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2183 SB(visual_effect, VE_TYPE_START, VE_TYPE_COUNT, e->u.rail.engclass - EC_STEAM + VE_TYPE_STEAM); |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2184 } |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2185 } |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2186 |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2187 this->vcache.cached_vis_effect = visual_effect; |
d16afc89472a
(svn r21598) -Fix (r3139, r21236, r21249)[FS#4275]: The default visual effect only depends on properties of the Engine (wagon or not, tractiontype, ...), not whether it is used as articulated part, front engine or whatever in a specific consist.
frosch <frosch@openttd.org>
parents:
16863
diff
changeset
|
2188 |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2189 if (!allow_power_change && powered_before != HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER)) { |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2190 ToggleBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2191 ShowNewGrfVehicleError(this->engine_type, STR_NEWGRF_BROKEN, STR_NEWGRF_BROKEN_POWERED_WAGON, GBUG_VEH_POWERED_WAGON, false); |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2192 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2193 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2194 |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2195 static const int8 _vehicle_smoke_pos[8] = { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2196 1, 1, 1, 0, -1, -1, -1, 0 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2197 }; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2198 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2199 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2200 * Draw visual effects (smoke and/or sparks) for a vehicle chain. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2201 * @pre this->IsPrimaryVehicle() |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2202 */ |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2203 void Vehicle::ShowVisualEffect() const |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2204 { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2205 assert(this->IsPrimaryVehicle()); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2206 bool sound = false; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2207 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2208 /* Do not show any smoke when: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2209 * - vehicle smoke is disabled by the player |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2210 * - the vehicle is slowing down or stopped (by the player) |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2211 * - the vehicle is moving very slowly |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2212 */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2213 if (_settings_game.vehicle.smoke_amount == 0 || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2214 this->vehstatus & (VS_TRAIN_SLOWING | VS_STOPPED) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2215 this->cur_speed < 2) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2216 return; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2217 } |
19074
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2218 |
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2219 uint max_speed = this->vcache.cached_max_speed; |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2220 if (this->type == VEH_TRAIN) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2221 const Train *t = Train::From(this); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2222 /* For trains, do not show any smoke when: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2223 * - the train is reversing |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2224 * - is entering a station with an order to stop there and its speed is equal to maximum station entering speed |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2225 */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2226 if (HasBit(t->flags, VRF_REVERSING) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2227 (IsRailStationTile(t->tile) && t->IsFrontEngine() && t->current_order.ShouldStopAtStation(t, GetStationIndex(t->tile)) && |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2228 t->cur_speed >= t->Train::GetCurrentMaxSpeed())) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2229 return; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2230 } |
19074
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2231 |
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2232 max_speed = min(max_speed, t->gcache.cached_max_track_speed); |
19093
38652cadf0fe
(svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents:
19074
diff
changeset
|
2233 max_speed = min(max_speed, this->current_order.max_speed); |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2234 } |
19093
38652cadf0fe
(svn r23947) -Feature: Timetabled maximum travel speeds for non-flying vehicles.
michi_cc <michi_cc@openttd.org>
parents:
19074
diff
changeset
|
2235 if (this->type == VEH_ROAD || this->type == VEH_SHIP) max_speed = min(max_speed, this->current_order.max_speed * 2); |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2236 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2237 const Vehicle *v = this; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2238 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2239 do { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2240 int effect_offset = GB(v->vcache.cached_vis_effect, VE_OFFSET_START, VE_OFFSET_COUNT) - VE_OFFSET_CENTRE; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2241 byte effect_type = GB(v->vcache.cached_vis_effect, VE_TYPE_START, VE_TYPE_COUNT); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2242 bool disable_effect = HasBit(v->vcache.cached_vis_effect, VE_DISABLE_EFFECT); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2243 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2244 /* Show no smoke when: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2245 * - Smoke has been disabled for this vehicle |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2246 * - The vehicle is not visible |
17266
6f191e237da9
(svn r22006) -Fix [FS#4480]: smoke/sparks of trains would be shown under bridges, or rather through bridges
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
2247 * - The vehicle is under a bridge |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2248 * - The vehicle is on a depot tile |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2249 * - The vehicle is on a tunnel tile |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2250 * - The vehicle is a train engine that is currently unpowered */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2251 if (disable_effect || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2252 v->vehstatus & VS_HIDDEN || |
17266
6f191e237da9
(svn r22006) -Fix [FS#4480]: smoke/sparks of trains would be shown under bridges, or rather through bridges
rubidium <rubidium@openttd.org>
parents:
17218
diff
changeset
|
2253 (MayHaveBridgeAbove(v->tile) && IsBridgeAbove(v->tile)) || |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2254 IsDepotTile(v->tile) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2255 IsTunnelTile(v->tile) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2256 (v->type == VEH_TRAIN && |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2257 !HasPowerOnRail(Train::From(v)->railtype, GetTileRailType(v->tile)))) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2258 continue; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2259 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2260 |
18446
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
2261 /* The effect offset is relative to a point 4 units behind the vehicle's |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
2262 * front (which is the center of an 8/8 vehicle). Shorter vehicles need a |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
2263 * correction factor. */ |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
2264 if (v->type == VEH_TRAIN) effect_offset += (VEHICLE_LENGTH - Train::From(v)->gcache.cached_veh_length) / 2; |
83cd95a883a3
(svn r23290) -Fix [FS#2379,FS#3569]: Change the centre of train vehicles to depend on the vehicle length instead of being fixed at 4/8th of the original vehicle length to make sure shortened vehicles don't block tiles they shouldn't block.
michi_cc <michi_cc@openttd.org>
parents:
18359
diff
changeset
|
2265 |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2266 int x = _vehicle_smoke_pos[v->direction] * effect_offset; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2267 int y = _vehicle_smoke_pos[(v->direction + 2) % 8] * effect_offset; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2268 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2269 if (v->type == VEH_TRAIN && HasBit(Train::From(v)->flags, VRF_REVERSE_DIRECTION)) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2270 x = -x; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2271 y = -y; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2272 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2273 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2274 switch (effect_type) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2275 case VE_TYPE_STEAM: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2276 /* Steam smoke - amount is gradually falling until vehicle reaches its maximum speed, after that it's normal. |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2277 * Details: while vehicle's current speed is gradually increasing, steam plumes' density decreases by one third each |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2278 * third of its maximum speed spectrum. Steam emission finally normalises at very close to vehicle's maximum speed. |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2279 * REGULATION: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2280 * - instead of 1, 4 / 2^smoke_amount (max. 2) is used to provide sufficient regulation to steam puffs' amount. */ |
19074
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2281 if (GB(v->tick_counter, 0, ((4 >> _settings_game.vehicle.smoke_amount) + ((this->cur_speed * 3) / max_speed))) == 0) { |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2282 CreateEffectVehicleRel(v, x, y, 10, EV_STEAM_SMOKE); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2283 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2284 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2285 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2286 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2287 case VE_TYPE_DIESEL: { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2288 /* Diesel smoke - thicker when vehicle is starting, gradually subsiding till it reaches its maximum speed |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2289 * when smoke emission stops. |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2290 * Details: Vehicle's (max.) speed spectrum is divided into 32 parts. When max. speed is reached, chance for smoke |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2291 * emission erodes by 32 (1/4). For trains, power and weight come in handy too to either increase smoke emission in |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2292 * 6 steps (1000HP each) if the power is low or decrease smoke emission in 6 steps (512 tonnes each) if the train |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2293 * isn't overweight. Power and weight contributions are expressed in a way that neither extreme power, nor |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2294 * extreme weight can ruin the balance (e.g. FreightWagonMultiplier) in the formula. When the vehicle reaches |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2295 * maximum speed no diesel_smoke is emitted. |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2296 * REGULATION: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2297 * - up to which speed a diesel vehicle is emitting smoke (with reduced/small setting only until 1/2 of max_speed), |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2298 * - in Chance16 - the last value is 512 / 2^smoke_amount (max. smoke when 128 = smoke_amount of 2). */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2299 int power_weight_effect = 0; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2300 if (v->type == VEH_TRAIN) { |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16775
diff
changeset
|
2301 power_weight_effect = (32 >> (Train::From(this)->gcache.cached_power >> 10)) - (32 >> (Train::From(this)->gcache.cached_weight >> 9)); |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2302 } |
19074
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2303 if (this->cur_speed < (max_speed >> (2 >> _settings_game.vehicle.smoke_amount)) && |
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2304 Chance16((64 - ((this->cur_speed << 5) / max_speed) + power_weight_effect), (512 >> _settings_game.vehicle.smoke_amount))) { |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2305 CreateEffectVehicleRel(v, x, y, 10, EV_DIESEL_SMOKE); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2306 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2307 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2308 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2309 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2310 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2311 case VE_TYPE_ELECTRIC: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2312 /* Electric train's spark - more often occurs when train is departing (more load) |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2313 * Details: Electric locomotives are usually at least twice as powerful as their diesel counterparts, so spark |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2314 * emissions are kept simple. Only when starting, creating huge force are sparks more likely to happen, but when |
19968
0dba7f49118c
(svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents:
19948
diff
changeset
|
2315 * reaching its max. speed, quarter by quarter of it, chance decreases until the usual 2,22% at train's top speed. |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2316 * REGULATION: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2317 * - in Chance16 the last value is 360 / 2^smoke_amount (max. sparks when 90 = smoke_amount of 2). */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2318 if (GB(v->tick_counter, 0, 2) == 0 && |
19074
90cacf439257
(svn r23928) -Fix [FS#5053]: don't accelerate, for smoke purposes, when you reached the track's maximum speed
rubidium <rubidium@openttd.org>
parents:
18891
diff
changeset
|
2319 Chance16((6 - ((this->cur_speed << 2) / max_speed)), (360 >> _settings_game.vehicle.smoke_amount))) { |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2320 CreateEffectVehicleRel(v, x, y, 10, EV_ELECTRIC_SPARK); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2321 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2322 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2323 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2324 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2325 default: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2326 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2327 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2328 } while ((v = v->Next()) != NULL); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2329 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2330 if (sound) PlayVehicleSound(this, VSE_VISUAL_EFFECT); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2331 } |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2332 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2333 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2334 * Set the next vehicle of this vehicle. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2335 * @param next the next vehicle. NULL removes the next vehicle. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2336 */ |
7497
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2337 void Vehicle::SetNext(Vehicle *next) |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2338 { |
13936
d316a293322c
(svn r18468) -Codechange: make sure one never makes self-loops using Vehicle::SetNext
rubidium <rubidium@openttd.org>
parents:
13873
diff
changeset
|
2339 assert(this != next); |
d316a293322c
(svn r18468) -Codechange: make sure one never makes self-loops using Vehicle::SetNext
rubidium <rubidium@openttd.org>
parents:
13873
diff
changeset
|
2340 |
7497
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2341 if (this->next != NULL) { |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2342 /* We had an old next vehicle. Update the first and previous pointers */ |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2343 for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2344 v->first = this->next; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2345 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2346 this->next->previous = NULL; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2347 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2348 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2349 this->next = next; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2350 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2351 if (this->next != NULL) { |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2352 /* A new next vehicle. Update the first and previous pointers */ |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2353 if (this->next->previous != NULL) this->next->previous->next = NULL; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2354 this->next->previous = this; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2355 for (Vehicle *v = this->next; v != NULL; v = v->Next()) { |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2356 v->first = this->first; |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2357 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2358 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2359 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2360 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2361 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2362 * Adds this vehicle to a shared vehicle chain. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2363 * @param shared_chain a vehicle of the chain with shared vehicles. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2364 * @pre !this->IsOrderListShared() |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2365 */ |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2366 void Vehicle::AddToShared(Vehicle *shared_chain) |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2367 { |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2368 assert(this->previous_shared == NULL && this->next_shared == NULL); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2369 |
17282
0e5475bb2d6e
(svn r22022) -Fix [FS#4468]: verify we can allocate an order before we actually try to do so
smatz <smatz@openttd.org>
parents:
17278
diff
changeset
|
2370 if (shared_chain->orders.list == NULL) { |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2371 assert(shared_chain->previous_shared == NULL); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2372 assert(shared_chain->next_shared == NULL); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2373 this->orders.list = shared_chain->orders.list = new OrderList(NULL, shared_chain); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2374 } |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2375 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2376 this->next_shared = shared_chain->next_shared; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2377 this->previous_shared = shared_chain; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2378 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2379 shared_chain->next_shared = this; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2380 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2381 if (this->next_shared != NULL) this->next_shared->previous_shared = this; |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2382 |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2383 shared_chain->orders.list->AddVehicle(this); |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2384 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2385 |
17106
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2386 /** |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2387 * Removes the vehicle from the shared order list. |
49e51c1b1b5f
(svn r21843) -Codechange: move documentation towards the code to make it more likely to be updates [t-z].
rubidium <rubidium@openttd.org>
parents:
17089
diff
changeset
|
2388 */ |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2389 void Vehicle::RemoveFromShared() |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2390 { |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2391 /* Remember if we were first and the old window number before RemoveVehicle() |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2392 * as this changes first if needed. */ |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2393 bool were_first = (this->FirstShared() == this); |
16079
f961c962db5d
(svn r20772) -Codechange: use packed VehicleListIdentifiers as window numbers
rubidium <rubidium@openttd.org>
parents:
16060
diff
changeset
|
2394 VehicleListIdentifier vli(VL_SHARED_ORDERS, this->type, this->owner, this->FirstShared()->index); |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2395 |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2396 this->orders.list->RemoveVehicle(this); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2397 |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2398 if (!were_first) { |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2399 /* We are not the first shared one, so only relink our previous one. */ |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2400 this->previous_shared->next_shared = this->NextShared(); |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2401 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2402 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2403 if (this->next_shared != NULL) this->next_shared->previous_shared = this->previous_shared; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2404 |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2405 |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2406 if (this->orders.list->GetNumVehicles() == 1) { |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2407 /* When there is only one vehicle, remove the shared order list window. */ |
16079
f961c962db5d
(svn r20772) -Codechange: use packed VehicleListIdentifiers as window numbers
rubidium <rubidium@openttd.org>
parents:
16060
diff
changeset
|
2408 DeleteWindowById(GetWindowClassForVehicleType(this->type), vli.Pack()); |
10546
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2409 InvalidateVehicleOrder(this->FirstShared(), 0); |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2410 } else if (were_first) { |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2411 /* If we were the first one, update to the new first one. |
9ceef3c92be2
(svn r14803) -Codechange: move order list management into it's own class and remove the order count from the savegame as we can easily count that (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10528
diff
changeset
|
2412 * Note: FirstShared() is already the new first */ |
17490
78c33eb4b741
(svn r22245) -Codechange: Make vehicle lists handle command-/GUI-scope invalidations themself.
frosch <frosch@openttd.org>
parents:
17389
diff
changeset
|
2413 InvalidateWindowData(GetWindowClassForVehicleType(this->type), vli.Pack(), this->FirstShared()->index | (1U << 31)); |
9941
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2414 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2415 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2416 this->next_shared = NULL; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2417 this->previous_shared = NULL; |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2418 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2419 |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2420 void VehiclesYearlyLoop() |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2421 { |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2422 Vehicle *v; |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2423 FOR_ALL_VEHICLES(v) { |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2424 if (v->IsPrimaryVehicle()) { |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2425 /* show warning if vehicle is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */ |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10679
diff
changeset
|
2426 Money profit = v->GetDisplayProfitThisYear(); |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10679
diff
changeset
|
2427 if (v->age >= 730 && profit < 0) { |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10679
diff
changeset
|
2428 if (_settings_client.gui.vehicle_income_warn && v->owner == _local_company) { |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2429 SetDParam(0, v->index); |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2430 SetDParam(1, profit); |
19381
f37c5813696b
(svn r24282) -Codechange: Add AddVehicleAdviceNewsItem function to preemptively deduplicate code.
frosch <frosch@openttd.org>
parents:
19330
diff
changeset
|
2431 AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_IS_UNPROFITABLE, v->index); |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2432 } |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18484
diff
changeset
|
2433 AI::NewEvent(v->owner, new ScriptEventVehicleUnprofitable(v->index)); |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2434 } |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2435 |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2436 v->profit_last_year = v->profit_this_year; |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2437 v->profit_this_year = 0; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
2438 SetWindowDirty(WC_VEHICLE_DETAILS, v->index); |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2439 } |
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2440 } |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2441 GroupStatistics::UpdateProfits(); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2442 SetWindowClassesDirty(WC_TRAINS_LIST); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2443 SetWindowClassesDirty(WC_SHIPS_LIST); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2444 SetWindowClassesDirty(WC_ROADVEH_LIST); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2445 SetWindowClassesDirty(WC_AIRCRAFT_LIST); |
10577
4436af164dbd
(svn r14835) -Change: apply the 'warn if train's income is negative' setting to other vehicle types, too
smatz <smatz@openttd.org>
parents:
10574
diff
changeset
|
2446 } |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2447 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2448 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2449 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2450 * Can this station be used by the given engine type? |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2451 * @param engine_type the type of vehicles to test |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2452 * @param st the station to test for |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2453 * @return true if and only if the vehicle of the type can use this station. |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2454 * @note For road vehicles the Vehicle is needed to determine whether it can |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2455 * use the station. This function will return true for road vehicles |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2456 * when at least one of the facilities is available. |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2457 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2458 bool CanVehicleUseStation(EngineID engine_type, const Station *st) |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2459 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
2460 const Engine *e = Engine::GetIfValid(engine_type); |
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
2461 assert(e != NULL); |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2462 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2463 switch (e->type) { |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2464 case VEH_TRAIN: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2465 return (st->facilities & FACIL_TRAIN) != 0; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2466 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2467 case VEH_ROAD: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2468 /* For road vehicles we need the vehicle to know whether it can actually |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2469 * use the station, but if it doesn't have facilities for RVs it is |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2470 * certainly not possible that the station can be used. */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2471 return (st->facilities & (FACIL_BUS_STOP | FACIL_TRUCK_STOP)) != 0; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2472 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2473 case VEH_SHIP: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2474 return (st->facilities & FACIL_DOCK) != 0; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2475 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2476 case VEH_AIRCRAFT: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2477 return (st->facilities & FACIL_AIRPORT) != 0 && |
14859
304d377a82af
(svn r19455) -Codechange: split all airport information in Station to a seperate class
yexo <yexo@openttd.org>
parents:
14815
diff
changeset
|
2478 (st->airport.GetFTA()->flags & (e->u.air.subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2479 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2480 default: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2481 return false; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2482 } |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2483 } |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2484 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2485 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2486 * Can this station be used by the given vehicle? |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2487 * @param v the vehicle to test |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2488 * @param st the station to test for |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2489 * @return true if and only if the vehicle can use this station. |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2490 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2491 bool CanVehicleUseStation(const Vehicle *v, const Station *st) |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2492 { |
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:
12112
diff
changeset
|
2493 if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop(RoadVehicle::From(v)) != NULL; |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2494 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2495 return CanVehicleUseStation(v->engine_type, st); |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2496 } |
16786
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2497 |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2498 /** |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2499 * Access the ground vehicle cache of the vehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2500 * @pre The vehicle is a #GroundVehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2501 * @return #GroundVehicleCache of the vehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2502 */ |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2503 GroundVehicleCache *Vehicle::GetGroundVehicleCache() |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2504 { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2505 assert(this->IsGroundVehicle()); |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2506 if (this->type == VEH_TRAIN) { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2507 return &Train::From(this)->gcache; |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2508 } else { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2509 return &RoadVehicle::From(this)->gcache; |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2510 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2511 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2512 |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2513 /** |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2514 * Access the ground vehicle cache of the vehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2515 * @pre The vehicle is a #GroundVehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2516 * @return #GroundVehicleCache of the vehicle. |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2517 */ |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2518 const GroundVehicleCache *Vehicle::GetGroundVehicleCache() const |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2519 { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2520 assert(this->IsGroundVehicle()); |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2521 if (this->type == VEH_TRAIN) { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2522 return &Train::From(this)->gcache; |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2523 } else { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2524 return &RoadVehicle::From(this)->gcache; |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2525 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2526 } |
16827
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2527 |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2528 /** |
17563
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2529 * Access the ground vehicle flags of the vehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2530 * @pre The vehicle is a #GroundVehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2531 * @return #GroundVehicleFlags of the vehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2532 */ |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2533 uint16 &Vehicle::GetGroundVehicleFlags() |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2534 { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2535 assert(this->IsGroundVehicle()); |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2536 if (this->type == VEH_TRAIN) { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2537 return Train::From(this)->gv_flags; |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2538 } else { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2539 return RoadVehicle::From(this)->gv_flags; |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2540 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2541 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2542 |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2543 /** |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2544 * Access the ground vehicle flags of the vehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2545 * @pre The vehicle is a #GroundVehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2546 * @return #GroundVehicleFlags of the vehicle. |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2547 */ |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2548 const uint16 &Vehicle::GetGroundVehicleFlags() const |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2549 { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2550 assert(this->IsGroundVehicle()); |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2551 if (this->type == VEH_TRAIN) { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2552 return Train::From(this)->gv_flags; |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2553 } else { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2554 return RoadVehicle::From(this)->gv_flags; |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2555 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2556 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2557 |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2558 /** |
16827
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2559 * Calculates the set of vehicles that will be affected by a given selection. |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
2560 * @param set [inout] Set of affected vehicles. |
16827
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2561 * @param v First vehicle of the selection. |
17164
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2562 * @param num_vehicles Number of vehicles in the selection (not counting articulated parts). |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
2563 * @pre \a set must be empty. |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
2564 * @post \a set will contain the vehicles that will be refitted. |
16827
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2565 */ |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2566 void GetVehicleSet(VehicleSet &set, Vehicle *v, uint8 num_vehicles) |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2567 { |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2568 if (v->type == VEH_TRAIN) { |
16828
41819c032e1b
(svn r21562) -Change: Add articulated parts of vehicles in a refit selection to that selection.
terkhen <terkhen@openttd.org>
parents:
16827
diff
changeset
|
2569 Train *u = Train::From(v); |
17164
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2570 /* Only include whole vehicles, so start with the first articulated part */ |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2571 u = u->GetFirstEnginePart(); |
16828
41819c032e1b
(svn r21562) -Change: Add articulated parts of vehicles in a refit selection to that selection.
terkhen <terkhen@openttd.org>
parents:
16827
diff
changeset
|
2572 |
17164
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2573 /* Include num_vehicles vehicles, not counting articulated parts */ |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2574 for (; u != NULL && num_vehicles > 0; num_vehicles--) { |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2575 do { |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2576 /* Include current vehicle in the selection. */ |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2577 set.Include(u->index); |
16828
41819c032e1b
(svn r21562) -Change: Add articulated parts of vehicles in a refit selection to that selection.
terkhen <terkhen@openttd.org>
parents:
16827
diff
changeset
|
2578 |
17164
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2579 /* If the vehicle is multiheaded, add the other part too. */ |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2580 if (u->IsMultiheaded()) set.Include(u->other_multiheaded_part->index); |
16828
41819c032e1b
(svn r21562) -Change: Add articulated parts of vehicles in a refit selection to that selection.
terkhen <terkhen@openttd.org>
parents:
16827
diff
changeset
|
2581 |
17164
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2582 u = u->Next(); |
bfc7b87f4672
(svn r21902) -Fix: Do not count articulated parts when passing the number of vehicles to refit to the command. That may exceed 8 bits.
frosch <frosch@openttd.org>
parents:
17152
diff
changeset
|
2583 } while (u != NULL && u->IsArticulatedPart()); |
16827
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2584 } |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2585 } |
e7b5830c41b1
(svn r21561) -Change: Allow to specify the number of vehicles to refit in the refit vehicle command.
terkhen <terkhen@openttd.org>
parents:
16788
diff
changeset
|
2586 } |