Mercurial > hg > openttd
annotate src/vehicle.cpp @ 18159:de0749262352 draft
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
author | frosch <frosch@openttd.org> |
---|---|
date | Mon, 03 Oct 2011 17:25:44 +0000 |
parents | f20ba7062226 |
children | 9fd018e89254 |
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" |
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
|
13 #include "gui.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 "vehicle_gui.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 "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
|
24 #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
|
25 #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
|
26 #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
|
27 #include "newgrf_station.h" |
6643
18d58b36b9b3
(svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents:
6641
diff
changeset
|
28 #include "group.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
|
29 #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
|
30 #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
|
31 #include "zoom_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
32 #include "date_func.h" |
8131
e300ac8001ae
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents:
8130
diff
changeset
|
33 #include "window_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
|
34 #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
|
35 #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
|
36 #include "autoreplace_gui.h" |
12228
240adc64d01a
(svn r16643) -Codechange: replace GetStationByTile() by Station::GetByTile()
smatz <smatz@openttd.org>
parents:
12128
diff
changeset
|
37 #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
|
38 #include "ai/ai.hpp" |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
39 #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
|
40 #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
|
41 #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
|
42 #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
|
43 #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
|
44 #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
|
45 #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
|
46 #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
|
47 #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
|
48 #include "sound_func.h" |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
49 #include "effectvehicle_func.h" |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
50 #include "effectvehicle_base.h" |
16079
f961c962db5d
(svn r20772) -Codechange: use packed VehicleListIdentifiers as window numbers
rubidium <rubidium@openttd.org>
parents:
16060
diff
changeset
|
51 #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
|
52 #include "bridge_map.h" |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
53 #include "tunnel_map.h" |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
54 #include "depot_map.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
|
55 |
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
|
56 #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
|
57 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 #define GEN_HASH(x, y) ((GB((y), 6, 6) << 6) + GB((x), 7, 6)) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
59 |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 |
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
|
64 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
65 /** 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
|
66 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
|
67 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
|
68 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
69 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
70 * 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
|
71 * @param *c The vehicle owner |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
72 * @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
|
73 */ |
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
|
74 bool Vehicle::NeedsAutorenewing(const Company *c) const |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
75 { |
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
|
76 /* 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
|
77 * 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
|
78 * 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
|
79 * 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
|
80 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
|
81 |
11913
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
82 if (!c->settings.engine_renew) return false; |
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
83 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
|
84 |
9d7cd831df9b
(svn r22847) -Fix (r22816): Wagons shall not be processed by autorenew.
frosch <frosch@openttd.org>
parents:
18007
diff
changeset
|
85 /* Only engines need renewing */ |
9d7cd831df9b
(svn r22847) -Fix (r22816): Wagons shall not be processed by autorenew.
frosch <frosch@openttd.org>
parents:
18007
diff
changeset
|
86 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
|
87 |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
88 return true; |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
89 } |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
90 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
91 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
|
92 { |
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->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
|
94 v->breakdowns_since_last_service = 0; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
95 v->reliability = Engine::Get(v->engine_type)->reliability; |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
96 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
|
97 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 |
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
|
99 /** |
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 * 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
|
101 * |
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 * @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
|
103 * @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
|
104 */ |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
105 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
|
106 { |
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
|
107 /* 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
|
108 * 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
|
109 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
|
110 |
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
|
111 /* 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
|
112 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
|
113 if (c->settings.vehicle.servint_ispercent ? |
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
|
114 (this->reliability >= Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) : |
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
|
115 (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
|
116 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
|
117 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
118 |
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
|
119 /* 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
|
120 * 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
|
121 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
|
122 _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
|
123 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
|
124 } |
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 |
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
|
126 /* 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
|
127 * 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
|
128 * 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
|
129 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
|
130 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
|
131 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
|
132 |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
133 for (const Vehicle *v = this; v != NULL; v = (v->type == VEH_TRAIN) ? Train::From(v)->GetNextUnit() : NULL) { |
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
|
134 EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id); |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
135 |
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
|
136 /* Check engine availability */ |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
137 if (new_engine == INVALID_ENGINE || !HasBit(Engine::Get(new_engine)->company_avail, v->owner)) continue; |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
138 |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
139 /* 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
|
140 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
|
141 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
|
142 /* 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
|
143 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
|
144 CargoID cargo_type; |
15820
59fd8293b2ee
(svn r20499) -Doc: Spelling fixes, and one doxygen comment addition.
alberth <alberth@openttd.org>
parents:
15763
diff
changeset
|
145 /* We cannot refit to mixed cargoes in an automated way */ |
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
|
146 if (IsArticulatedVehicleCarryingDifferentCargos(v, &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
|
147 |
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 /* 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
|
149 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
|
150 /* 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
|
151 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
|
152 } |
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 } |
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
|
154 |
14026
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
155 /* Check money. |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
156 * 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
|
157 pending_replace = true; |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
158 needed_money += 2 * Engine::Get(new_engine)->GetCost(); |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
159 if (needed_money > c->money) return false; |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
160 } |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
161 |
a9016ea549f9
(svn r18568) -Codechange: Bail out early.
frosch <frosch@openttd.org>
parents:
14009
diff
changeset
|
162 return pending_replace; |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
163 } |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
164 |
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
|
165 /** |
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
|
166 * Checks if the current order should be interupted for a service-in-depot-order. |
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
|
167 * @see NeedsServicing() |
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
|
168 * @return true if the current order should be interupted. |
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 */ |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
170 bool Vehicle::NeedsAutomaticServicing() const |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
171 { |
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
|
172 if (this->HasDepotOrder()) return false; |
16733
4b988ed6473a
(svn r21466) -Codechange: make VehicleHasDepotOrders a function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
16523
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
177 |
13873
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
178 uint Vehicle::Crash(bool flooded) |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
179 { |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
180 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
|
181 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
|
182 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
183 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
|
184 /* Stop the vehicle. */ |
ff08f0eb701d
(svn r19963) -Add: Stop a vehicle after it crashes or is destroyed.
terkhen <terkhen@openttd.org>
parents:
15292
diff
changeset
|
185 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
|
186 /* 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
|
187 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
|
188 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
|
189 v->vehstatus |= VS_CRASHED; |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
190 MarkSingleVehicleDirty(v); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
191 } |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
192 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
193 /* Dirty some windows */ |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
194 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
195 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
196 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
|
197 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
|
198 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
199 return pass; |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
200 } |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
201 |
85b3d1a4faff
(svn r18402) -Codechange: unify/centralise the code for crashing vehicles
rubidium <rubidium@openttd.org>
parents:
13856
diff
changeset
|
202 |
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
|
203 /** |
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
|
204 * 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
|
205 * @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
|
206 * @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
|
207 * @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
|
208 * @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
|
209 * @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
|
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 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
|
212 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
213 const Engine *e = Engine::Get(engine); |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15724
diff
changeset
|
214 uint32 grfid = e->grf_prop.grffile->grfid; |
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
|
215 GRFConfig *grfconfig = GetGRFConfig(grfid); |
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 |
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 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
|
218 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
|
219 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
|
220 SetDParam(1, engine); |
14645
b7a22979b84e
(svn r19224) -Codechange: change parameters passed to ShowErrorMessage() a bit
smatz <smatz@openttd.org>
parents:
14641
diff
changeset
|
221 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
|
222 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
|
223 } |
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 |
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
|
225 /* 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
|
226 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
|
227 |
14711
74b0a8a64ff5
(svn r19295) -Codechange: introduce wrapper functions for GRFConfig::name/info
yexo <yexo@openttd.org>
parents:
14707
diff
changeset
|
228 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
|
229 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
|
230 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
|
231 |
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 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
|
233 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
|
234 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
|
235 } |
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 |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
237 /** |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
238 * Vehicle constructor. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
239 * @param type Type of the new vehicle. |
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
240 */ |
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
|
241 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
|
242 { |
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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
253 * 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
|
254 * @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
|
255 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
256 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
|
257 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 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
|
259 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 |
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
|
261 /* 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
|
262 * 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 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
|
268 |
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
|
269 /* 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
|
270 * 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
|
271 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
|
272 |
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
|
273 static Vehicle *_new_vehicle_position_hash[TOTAL_HASH_SIZE]; |
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
|
274 |
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
|
275 static Vehicle *VehicleFromHash(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
|
276 { |
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
|
277 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
|
278 for (int x = xl; ; x = (x + 1) & HASH_MASK) { |
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
|
279 Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
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
|
280 for (; v != NULL; v = v->next_new_hash) { |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
281 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
|
282 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
|
283 } |
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 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
|
285 } |
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 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
|
287 } |
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 |
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 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
|
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 |
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 |
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
|
293 /** |
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
|
294 * 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
|
295 * @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
|
296 * @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
|
297 * @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
|
298 * @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
|
299 * @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
|
300 * @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
|
301 * 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
|
302 * @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
|
303 */ |
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 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
|
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 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
|
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 /* 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 |
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
|
314 return VehicleFromHash(xl, yl, xu, yu, data, proc, 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
|
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 |
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 /** |
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 * 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
|
319 * 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
|
320 * 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
|
321 * 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
|
322 * 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
|
323 * @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
|
324 * @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
|
325 * 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
|
326 * @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
|
327 * @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
|
328 * @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
|
329 * @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
|
330 */ |
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
|
331 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
|
332 { |
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
|
333 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
|
334 } |
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 |
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
|
336 /** |
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 * 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
|
338 * 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
|
339 * @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
|
340 * 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
|
341 * @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
|
342 * @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
|
343 * @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
|
344 * @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
|
345 * @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
|
346 */ |
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 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
|
348 { |
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 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
|
350 } |
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 |
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 * 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
|
354 * @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
|
355 * @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
|
356 * @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
|
357 * @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
|
358 * @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
|
359 * 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
|
360 * @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
|
361 */ |
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 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
|
363 { |
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
|
364 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
|
365 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
|
366 |
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
|
367 Vehicle *v = _new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
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
|
368 for (; v != NULL; v = v->next_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
|
369 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
|
370 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
371 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
|
372 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
|
373 } |
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
|
374 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
375 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
|
376 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
377 |
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
|
378 /** |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
379 * 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
|
380 * 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
|
381 * 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
|
382 * 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
|
383 * 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
|
384 * @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
|
385 * @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
|
386 * 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
|
387 * @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
|
388 * @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
|
389 * @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
|
390 */ |
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
|
391 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
|
392 { |
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
|
393 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
|
394 } |
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
|
395 |
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
|
396 /** |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
397 * 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
|
398 * vehicles until it returns non-NULL. |
14699
1873a17a5236
(svn r19282) -Doc: Add some doxygen doc markup.
alberth <alberth@openttd.org>
parents:
14645
diff
changeset
|
399 * @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
|
400 * 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
|
401 * @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
|
402 * @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
|
403 * @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
|
404 * @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
|
405 */ |
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
|
406 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
|
407 { |
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 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
|
409 } |
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
|
410 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
411 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
412 * Callback that returns 'real' vehicles lower or at height \c *(byte*)data . |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
413 * @param v Vehicle to examine. |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
414 * @param data Pointer to height data. |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
415 * @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
|
416 */ |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
417 static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
418 { |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
419 byte z = *(byte*)data; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
420 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
421 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
|
422 if (v->z_pos > z) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
423 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
424 return v; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
425 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
426 |
15382
8e0d118d93ce
(svn r20025) -Doc: Fix/add comments to let Doxygen know about the documentation.
alberth <alberth@openttd.org>
parents:
15362
diff
changeset
|
427 /** |
8e0d118d93ce
(svn r20025) -Doc: Fix/add comments to let Doxygen know about the documentation.
alberth <alberth@openttd.org>
parents:
15362
diff
changeset
|
428 * 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
|
429 * @param tile Position to examine. |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
430 * @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
|
431 */ |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
432 CommandCost EnsureNoVehicleOnGround(TileIndex tile) |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
433 { |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
434 byte z = GetTileMaxZ(tile); |
14705
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
435 |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
436 /* 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
|
437 * 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
|
438 * 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
|
439 */ |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
440 Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true); |
14731
9d61b2f8f104
(svn r19319) -Codechange: EnsureNoVehicleOnGround() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14711
diff
changeset
|
441 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
|
442 return CommandCost(); |
14704
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
443 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
444 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
445 /** 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
|
446 static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
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 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
|
449 if (v == (const Vehicle *)data) return NULL; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
450 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
451 return v; |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
452 } |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
453 |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
454 /** |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
455 * Finds vehicle in tunnel / bridge |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
456 * @param tile first end |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
457 * @param endtile second end |
db0194d98616
(svn r19288) -Codechange: Move EnsureNoVehicleOnGround() and HasVehicleOnTunnelBridge() functions.
alberth <alberth@openttd.org>
parents:
14699
diff
changeset
|
458 * @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
|
459 * @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
|
460 */ |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
461 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
|
462 { |
14705
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
463 /* 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
|
464 * 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
|
465 * 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
|
466 */ |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
467 Vehicle *v = VehicleFromPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc, true); |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
468 if (v == NULL) v = VehicleFromPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc, true); |
76afd62955e1
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
alberth <alberth@openttd.org>
parents:
14704
diff
changeset
|
469 |
14707
ed6ca7f84893
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
alberth <alberth@openttd.org>
parents:
14705
diff
changeset
|
470 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
|
471 return CommandCost(); |
14704
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 |
14777
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
474 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
|
475 { |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
476 TrackBits rail_bits = *(TrackBits *)data; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
477 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
478 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
|
479 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
480 Train *t = Train::From(v); |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
481 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
|
482 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
483 return v; |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
484 } |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
485 |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
486 /** |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
487 * 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
|
488 * 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
|
489 * |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
490 * @param tile The tile. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
491 * @param track_bits The track bits. |
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
492 * @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
|
493 */ |
14781
7550a3af1a05
(svn r19369) -Codechange: EnsureNoTrainOnTrackBits() returns a CommandCost now.
alberth <alberth@openttd.org>
parents:
14778
diff
changeset
|
494 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
|
495 { |
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
|
496 /* 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
|
497 * 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
|
498 * 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
|
499 */ |
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
|
500 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
|
501 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
|
502 return CommandCost(); |
14777
a8eb10828cec
(svn r19365) -Codechange: Move EnsureNoTrainOnTrackProc() to src/vehicle.cpp.
alberth <alberth@openttd.org>
parents:
14731
diff
changeset
|
503 } |
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
|
504 |
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
|
505 static void UpdateNewVehiclePosHash(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
|
506 { |
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
|
507 Vehicle **old_hash = v->old_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
|
508 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
|
509 |
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
|
510 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
|
511 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
|
512 } 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
|
513 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
|
514 int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS; |
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
|
515 new_hash = &_new_vehicle_position_hash[(x + y) & TOTAL_HASH_MASK]; |
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
|
516 } |
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
|
517 |
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
|
518 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
|
519 |
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
|
520 /* 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
|
521 if (old_hash != NULL) { |
12128
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
522 if (v->next_new_hash != NULL) v->next_new_hash->prev_new_hash = v->prev_new_hash; |
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
523 *v->prev_new_hash = v->next_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
|
524 } |
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
|
525 |
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
|
526 /* 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
|
527 if (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
|
528 v->next_new_hash = *new_hash; |
12128
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
529 if (v->next_new_hash != NULL) v->next_new_hash->prev_new_hash = &v->next_new_hash; |
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
530 v->prev_new_hash = 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
|
531 *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
|
532 } |
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 |
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 /* Remember current hash position */ |
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
|
535 v->old_new_hash = 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
|
536 } |
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
|
537 |
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 static Vehicle *_vehicle_position_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
|
539 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
540 static void UpdateVehiclePosHash(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
|
541 { |
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
|
542 UpdateNewVehiclePosHash(v, x == INVALID_COORD); |
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
|
543 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6490
diff
changeset
|
548 new_hash = (x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(x, 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
|
549 old_hash = (old_x == INVALID_COORD) ? NULL : &_vehicle_position_hash[GEN_HASH(old_x, old_y)]; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
550 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
551 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
|
552 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
553 /* 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
|
554 if (old_hash != NULL) { |
12128
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
555 if (v->next_hash != NULL) v->next_hash->prev_hash = v->prev_hash; |
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
556 *v->prev_hash = v->next_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
|
557 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
558 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
559 /* 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
|
560 if (new_hash != NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
561 v->next_hash = *new_hash; |
12128
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
562 if (v->next_hash != NULL) v->next_hash->prev_hash = &v->next_hash; |
6e43d1f1af83
(svn r16544) -Codechange: use double-linked list for vehicle position caches in order to improve performance (~5% with many vehicles)
smatz <smatz@openttd.org>
parents:
12114
diff
changeset
|
563 v->prev_hash = 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
|
564 *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
|
565 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
567 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
568 void ResetVehiclePosHash() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
569 { |
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
|
570 Vehicle *v; |
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
|
571 FOR_ALL_VEHICLES(v) { v->old_new_hash = 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
|
572 memset(_vehicle_position_hash, 0, sizeof(_vehicle_position_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
|
573 memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_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
|
574 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
575 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
576 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
|
577 { |
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
|
578 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
|
579 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
|
580 } |
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
|
581 |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
582 /** |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
583 * 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
|
584 * 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
|
585 */ |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
586 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
|
587 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
|
588 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
589 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
|
590 { |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
591 _vehicles_to_autoreplace.Reset(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
592 ResetVehiclePosHash(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
594 |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10642
diff
changeset
|
595 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
|
596 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
601 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
602 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
603 * 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
|
604 * @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
|
605 */ |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
606 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
|
607 { |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
608 switch (this->type) { |
12384
d4b73a406cf3
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents:
12383
diff
changeset
|
609 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
|
610 case VEH_TRAIN: |
17185
ccebafd2a9ba
(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.
terkhen <terkhen@openttd.org>
parents:
17170
diff
changeset
|
611 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
|
612 !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
|
613 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
|
614 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
|
615 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
618 |
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
|
619 /** |
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
|
620 * 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
|
621 * @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
|
622 */ |
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
|
623 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
|
624 { |
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
|
625 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
|
626 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 } |
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
|
632 } |
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
|
633 |
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
|
634 /** |
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
|
635 * 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
|
636 * 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
|
637 * 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
|
638 * 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
|
639 * @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
|
640 */ |
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
|
641 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
|
642 { |
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
|
643 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
|
644 /* 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
|
645 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
|
646 |
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
|
647 /* 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
|
648 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
|
649 /* 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
|
650 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
|
651 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
|
652 } |
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
|
653 |
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
|
654 /* 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
|
655 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
|
656 |
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
|
657 /* 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
|
658 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
|
659 /* Notify user about the event. */ |
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
|
660 AI::NewEvent(this->owner, new AIEventVehicleLost(this->index)); |
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
|
661 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
|
662 SetDParam(0, this->index); |
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
|
663 AddVehicleNewsItem(STR_NEWS_VEHICLE_IS_LOST, NS_ADVICE, this->index); |
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
|
664 } |
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
|
665 } |
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
|
666 |
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
|
667 /** 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
|
668 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
|
669 { |
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
|
670 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
|
671 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
672 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
|
673 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
|
674 |
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
|
675 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
|
676 |
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
|
677 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
|
678 } |
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
|
679 |
12383
3c7e93b91c73
(svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents:
12376
diff
changeset
|
680 if (this->IsEngineCountable()) { |
18154
ebcb3f30bd4a
(svn r22979) -Codechange: Add GroupStatistics::CountEngine().
frosch <frosch@openttd.org>
parents:
18153
diff
changeset
|
681 GroupStatistics::CountEngine(this, -1); |
18153
ca071969f8d7
(svn r22978) -Codechange: Replace IncreaseGroupNumVehicle() and DecreaseGroupNumVehicle() with GroupStatistics::CountVehicle().
frosch <frosch@openttd.org>
parents:
18151
diff
changeset
|
682 if (this->IsPrimaryVehicle()) GroupStatistics::CountVehicle(this, -1); |
18155
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
18154
diff
changeset
|
683 |
a7b36ae3de21
(svn r22980) -Add: GroupStatistics for DEFAULT_GROUP.
frosch <frosch@openttd.org>
parents:
18154
diff
changeset
|
684 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
|
685 DeleteGroupHighlightOfVehicle(this); |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5940
diff
changeset
|
686 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 |
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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 } |
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
|
695 } |
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
|
696 |
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
|
697 |
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
|
698 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
|
699 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
|
700 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
|
701 /* 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
|
702 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
|
703 } |
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
|
704 } |
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
|
705 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
706 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
|
707 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
|
708 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
709 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
710 if (this->IsPrimaryVehicle()) { |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
711 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
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 OrderBackup::ClearVehicle(this); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
718 } |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
719 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
720 |
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
|
721 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
|
722 DeleteVehicleOrders(this); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
723 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
|
724 |
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
|
725 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
|
726 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
|
727 |
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
|
728 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
|
729 } |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
730 |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
731 Vehicle::~Vehicle() |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
732 { |
8258
6017c5ebeb7e
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138 <peter1138@openttd.org>
parents:
8254
diff
changeset
|
733 free(this->name); |
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
|
734 |
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
|
735 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
|
736 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
|
737 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
|
738 } |
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
|
739 |
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
|
740 /* 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
|
741 * 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
|
742 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
|
743 |
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
|
744 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
|
745 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
|
746 |
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
|
747 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
|
748 |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
749 UpdateVehiclePosHash(this, INVALID_COORD, 0); |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
750 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
|
751 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
|
752 } |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
753 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15574
diff
changeset
|
754 /** |
16349
b1fc0cfd2943
(svn r21060) -Doc: Improved wording of comments (mostly by __ln__)
alberth <alberth@openttd.org>
parents:
16331
diff
changeset
|
755 * 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
|
756 * @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
|
757 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
758 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
|
759 { |
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
|
760 /* 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
|
761 _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
|
762 |
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
|
763 /* 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
|
764 * 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
|
765 * 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
|
766 * 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
|
767 * 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
|
768 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
|
769 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
770 |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
771 /** |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
772 * 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
|
773 * 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
|
774 * 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
|
775 */ |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
776 static void RunVehicleDayProc() |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
777 { |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
778 if (_game_mode != GM_NORMAL) return; |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
779 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
780 /* 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
|
781 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
|
782 Vehicle *v = Vehicle::Get(i); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
783 if (v == NULL) continue; |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
784 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
785 /* 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
|
786 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
|
787 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
|
788 if (callback != CALLBACK_FAILED) { |
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
789 if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 |
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
790 if (HasBit(callback, 1)) v->colourmap = PAL_NONE; |
dd1bb89ce304
(svn r17091) -Fix (r17089)(r17090): regression test was right
smatz <smatz@openttd.org>
parents:
12638
diff
changeset
|
791 } |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
792 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
793 |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
794 /* 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
|
795 v->OnNewDay(); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
796 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
797 } |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
798 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
799 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
|
800 { |
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
|
801 _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
|
802 |
12638
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
803 RunVehicleDayProc(); |
116c481c1fb5
(svn r17089) -Codechange: move RunVehicleDayProc() to vehicle.cpp
smatz <smatz@openttd.org>
parents:
12635
diff
changeset
|
804 |
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
|
805 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
|
806 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
|
807 |
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
|
808 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
|
809 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
|
810 /* 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
|
811 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
|
812 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
|
813 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
|
814 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11951
diff
changeset
|
815 |
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
|
816 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
|
817 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
818 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
|
819 default: break; |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
820 |
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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 v->cargo.AgeCargo(); |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
829 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
|
830 } |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17787
diff
changeset
|
831 } |
12635
8f1d500da613
(svn r17085) -Codechange: unify the place where vehicle's cargo ages
smatz <smatz@openttd.org>
parents:
12634
diff
changeset
|
832 |
12302
fc8e41f34b8c
(svn r16719) -Codechange: make IsArticulatedPart(), IsTrainEngine(), IsTrainWagon(), IsMultiheaded(), EngineHasArticPart() and IsRearDualheaded() members of Train
smatz <smatz@openttd.org>
parents:
12300
diff
changeset
|
833 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
|
834 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
|
835 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
|
836 |
13943
1473565220a3
(svn r18479) -Fix (r6532): Direction is accounted for long before motion counter is updated
peter1138 <peter1138@openttd.org>
parents:
13936
diff
changeset
|
837 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
|
838 /* 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
|
839 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
|
840 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
841 /* Play an alterate running sound every 16 ticks */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
842 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
|
843 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
844 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
845 |
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
|
846 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
|
847 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
|
848 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
|
849 /* 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
|
850 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
|
851 |
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
|
852 /* 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
|
853 * 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
|
854 * 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
|
855 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
|
856 |
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 /* 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
|
858 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
|
859 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
|
860 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
|
861 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
862 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
|
863 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
|
864 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
|
865 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
|
866 |
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
|
867 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
|
868 |
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
|
869 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
|
870 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
|
871 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
|
872 } |
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
|
873 |
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
|
874 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
|
875 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
|
876 |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
877 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
|
878 |
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
|
879 StringID message; |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
880 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
|
881 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
|
882 } else { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
883 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
|
884 } |
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
|
885 |
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
|
886 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
|
887 SetDParam(1, error_message); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
888 AddVehicleNewsItem(message, NS_ADVICE, 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
|
889 } |
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
|
890 |
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
|
891 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
|
892 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
893 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
894 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
895 * 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
|
896 * @param v Vehicle to draw. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
897 */ |
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 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
|
899 { |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
900 SpriteID image = v->cur_image; |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
901 PaletteID pal = PAL_NONE; |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
902 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
903 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
|
904 |
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
|
905 /* 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
|
906 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
|
907 |
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
|
908 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
|
909 /* 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
|
910 * 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
|
911 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
|
912 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
|
913 } |
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
|
914 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
915 AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
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
|
916 v->x_extent, v->y_extent, v->z_extent, v->z_pos, shadowed); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
917 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
918 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
919 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
920 * 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
|
921 * @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
|
922 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
923 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
|
924 { |
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
|
925 /* 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 |
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
|
931 /* 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
|
932 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
|
933 |
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
|
934 if (dpi->width + 70 < (1 << (7 + 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
|
935 xl = GB(l - 70, 7, 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
|
936 xu = GB(r, 7, 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
|
937 } 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
|
938 /* 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
|
939 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
|
940 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
|
941 } |
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
|
942 |
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
|
943 if (dpi->height + 70 < (1 << (6 + 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
|
944 yl = GB(t - 70, 6, 6) << 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
|
945 yu = GB(b, 6, 6) << 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
|
946 } 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
|
947 /* 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
|
948 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
|
949 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
|
950 } |
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
|
951 |
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
|
952 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
|
953 for (int x = xl;; x = (x + 1) & 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
|
954 const Vehicle *v = _vehicle_position_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
|
955 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
964 v = v->next_hash; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
965 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
966 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
967 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
|
968 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
969 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
970 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
|
971 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
972 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
973 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
974 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
975 * 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
|
976 * @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
|
977 * @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
|
978 * @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
|
979 * @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
|
980 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
981 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
|
982 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
983 Vehicle *found = NULL, *v; |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10225
diff
changeset
|
984 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
|
985 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
986 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
|
987 |
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
|
988 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
|
989 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
|
990 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
991 FOR_ALL_VEHICLES(v) { |
10642
29bc871ff8d1
(svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents:
10634
diff
changeset
|
992 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
|
993 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
|
994 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
|
995 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1000 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1001 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
|
1002 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
|
1003 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
|
1004 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1005 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1006 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1007 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1008 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
|
1009 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1010 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1011 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1012 * 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
|
1013 * @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
|
1014 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1015 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
|
1016 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1017 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
|
1018 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
|
1019 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1020 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1021 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
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1031 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1032 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
|
1033 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1034 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
|
1035 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1036 /* 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
|
1037 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
|
1038 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
|
1039 |
12082
d092f17a921d
(svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents:
12070
diff
changeset
|
1040 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
|
1041 _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
|
1042 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
|
1043 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1044 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1045 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1046 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
|
1047 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1048 /* increase chance of failure */ |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1049 int chance = v->breakdown_chance + 1; |
8980
b4160d91b7c7
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
1050 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
|
1051 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
|
1052 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1053 /* 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
|
1054 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
|
1055 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
|
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 /* 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
|
1058 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
|
1059 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1060 /* 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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1067 |
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
|
1068 /** |
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
|
1069 * 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
|
1070 * 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
|
1071 * @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
|
1072 * @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
|
1073 */ |
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
|
1074 bool Vehicle::HandleBreakdown() |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1075 { |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1076 /* 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
|
1077 * 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
|
1078 * 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
|
1079 * 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
|
1080 * >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
|
1081 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
|
1082 case 0: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1083 return false; |
15956
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1084 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1085 case 2: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1086 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
|
1087 |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1088 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
|
1089 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
|
1090 } |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1091 |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1092 this->MarkDirty(); |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1093 SetWindowDirty(WC_VEHICLE_VIEW, this->index); |
15958
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1094 SetWindowDirty(WC_VEHICLE_DETAILS, this->index); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1095 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1096 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
|
1097 /* 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
|
1098 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
|
1099 } else { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1100 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
|
1101 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1102 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
|
1103 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
|
1104 (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
|
1105 (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
|
1106 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1107 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1108 if (!(this->vehstatus & VS_HIDDEN)) { |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1109 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
|
1110 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
|
1111 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1112 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1113 /* FALL THROUGH */ |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1114 case 1: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1115 /* 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
|
1116 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
|
1117 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1118 /* 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
|
1119 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
|
1120 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
|
1121 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
|
1122 this->MarkDirty(); |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1123 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
|
1124 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1125 } |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1126 return true; |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1127 |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1128 default: |
c3b5855fd386
(svn r20646) -Codechange: make the code flow of breakdown handling a bit clearer
rubidium <rubidium@openttd.org>
parents:
15957
diff
changeset
|
1129 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
|
1130 return false; |
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 } |
cc4575d99aa1
(svn r20644) -Codechange [FS#4086]: unify the vehicle breakdown code (Hirundo)
rubidium <rubidium@openttd.org>
parents:
15944
diff
changeset
|
1133 |
16372
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1134 /** |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1135 * Update age of a vehicle. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1136 * @param v Vehicle to update. |
ea86953aa185
(svn r21088) -Doc: Additions/corrections of doxygen comments.
alberth <alberth@openttd.org>
parents:
16349
diff
changeset
|
1137 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1138 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
|
1139 { |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1140 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
|
1141 v->age++; |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
1142 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
|
1143 } |
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
|
1144 |
18007
c7a5373f1a03
(svn r22816) -Feature(ette): [NewGRF] Also age wagons and articulated parts.
frosch <frosch@openttd.org>
parents:
17909
diff
changeset
|
1145 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
|
1146 |
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
|
1147 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
|
1148 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
|
1149 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
|
1150 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
|
1151 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1152 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1153 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
|
1154 |
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
|
1155 /* 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
|
1156 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
|
1157 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1158 /* Don't warn if a renew is active */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1159 if (Company::Get(v->owner)->settings.engine_renew && Engine::Get(v->engine_type)->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
|
1160 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1161 StringID str; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
1162 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
|
1163 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
|
1164 } else if (age == 0) { |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
1165 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
|
1166 } 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
|
1167 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
|
1168 } 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
|
1169 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
|
1170 } |
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
|
1171 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
1172 SetDParam(0, v->index); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
1173 AddVehicleNewsItem(str, NS_ADVICE, 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
|
1174 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1175 |
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
|
1176 /** |
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
|
1177 * Calculates how full a 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
|
1178 * @param v The Vehicle to check. For trains, use the first engine. |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1179 * @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
|
1180 * @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
|
1181 */ |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1182 uint8 CalcPercentVehicleFilled(const Vehicle *v, 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
|
1183 { |
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
|
1184 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
|
1185 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
|
1186 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
|
1187 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
|
1188 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
|
1189 |
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
|
1190 const Vehicle *u = v; |
15898
cfe6456564b2
(svn r20581) -Codechange: simplify getting the station in CalcPercentVehicleFilled
rubidium <rubidium@openttd.org>
parents:
15859
diff
changeset
|
1191 /* The station may be NULL when the (colour) string does not need to be set. */ |
cfe6456564b2
(svn r20581) -Codechange: simplify getting the station in CalcPercentVehicleFilled
rubidium <rubidium@openttd.org>
parents:
15859
diff
changeset
|
1192 const Station *st = Station::GetIfValid(v->last_station_visited); |
cfe6456564b2
(svn r20581) -Codechange: simplify getting the station in CalcPercentVehicleFilled
rubidium <rubidium@openttd.org>
parents:
15859
diff
changeset
|
1193 assert(colour == NULL || st != NULL); |
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
|
1194 |
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
|
1195 /* Count up max and used */ |
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
|
1196 for (; 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
|
1197 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
|
1198 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
|
1199 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
|
1200 unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
12070
e3bc07685bc9
(svn r16477) -Fix [FS#2936] (r12650): loading indicator when 'unload' in and 'no loading' is off was pointing to the wrong direction.
rubidium <rubidium@openttd.org>
parents:
12065
diff
changeset
|
1201 loading |= !(u->current_order.GetLoadType() & OLFB_NO_LOAD) && st->goods[v->cargo_type].days_since_pickup != 255; |
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
|
1202 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
|
1203 } |
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
|
1204 } |
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
|
1205 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1206 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
|
1207 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
|
1208 *colour = STR_PERCENT_UP; |
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
|
1209 } 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
|
1210 *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
|
1211 } else { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1212 *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
|
1213 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1214 } |
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
|
1215 |
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
|
1216 /* 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
|
1217 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
|
1218 |
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
|
1219 /* 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
|
1220 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
|
1221 } |
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
|
1222 |
17186
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1223 /** |
f178a71a6670
(svn r21925) -Doc: Doxygen additions and markup corrections to vehicle-related functions.
alberth <alberth@openttd.org>
parents:
17185
diff
changeset
|
1224 * 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
|
1225 * @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
|
1226 */ |
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 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
|
1228 { |
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
|
1229 /* 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
|
1230 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
|
1231 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1232 switch (v->type) { |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1233 case VEH_TRAIN: { |
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1234 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
|
1235 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
|
1236 /* Clear path reservation */ |
12471
c0587ce9da72
(svn r16908) -Codechange: s/DepotWaypointReservation/DepotReservation/
rubidium <rubidium@openttd.org>
parents:
12460
diff
changeset
|
1237 SetDepotReservation(t->tile, false); |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1238 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
|
1239 |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1240 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
|
1241 t->wait_counter = 0; |
15362
834b4f9842c2
(svn r20005) -Codechange: Enumify force_proceed.
frosch <frosch@openttd.org>
parents:
15351
diff
changeset
|
1242 t->force_proceed = TFP_NONE; |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1243 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
|
1244 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
|
1245 break; |
12300
7ec79afe8c18
(svn r16717) -Codechange: make IsFrontEngine() member of Train
smatz <smatz@openttd.org>
parents:
12279
diff
changeset
|
1246 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1247 |
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
|
1248 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
|
1249 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
|
1250 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1251 |
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
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 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
|
1257 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
|
1258 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
|
1259 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
|
1260 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1261 |
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
|
1262 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
|
1263 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
|
1264 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
|
1265 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1266 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
|
1267 } |
15351
6adf1d7d80cd
(svn r19992) -Fix [FS#3878]: Clear force_proceed when entering depots and when loading.
frosch <frosch@openttd.org>
parents:
15322
diff
changeset
|
1268 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
|
1269 |
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
|
1270 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
|
1271 /* 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
|
1272 * 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
|
1273 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
|
1274 } |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1275 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
|
1276 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1277 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
|
1278 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
|
1279 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1280 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
|
1281 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1282 TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1283 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1284 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
|
1285 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
|
1286 |
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
|
1287 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
|
1288 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
|
1289 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
|
1290 |
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
|
1291 /* 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
|
1292 * 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
|
1293 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
|
1294 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
|
1295 (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
|
1296 /* 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
|
1297 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
|
1298 } |
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
|
1299 |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8837
diff
changeset
|
1300 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
|
1301 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
|
1302 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
|
1303 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
|
1304 |
14314
60d313b887b8
(svn r18866) -Codechange: remove the CmdFailed(ret)/CmdSucceeded(ret) wrapper functions
rubidium <rubidium@openttd.org>
parents:
14261
diff
changeset
|
1305 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
|
1306 _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
|
1307 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
|
1308 /* 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
|
1309 SetDParam(0, v->index); |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
1310 AddVehicleNewsItem(STR_NEWS_ORDER_REFIT_FAILED, NS_ADVICE, 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
|
1311 } |
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
|
1312 } 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
|
1313 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
|
1314 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
|
1315 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
|
1316 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1317 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1318 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1319 |
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
|
1320 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
|
1321 /* 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
|
1322 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
|
1323 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
|
1324 v->IncrementImplicitOrderIndex(); |
10285
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1325 } |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1326 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
|
1327 /* 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
|
1328 _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
|
1329 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
|
1330 SetDParam(0, v->index); |
12483
84df0c285bc4
(svn r16920) -Codechange: shuffle some strings around to simplify looking up vehicle type specific strings for a specific message
rubidium <rubidium@openttd.org>
parents:
12482
diff
changeset
|
1331 AddVehicleNewsItem(STR_NEWS_TRAIN_IS_WAITING + v->type, NS_ADVICE, 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
|
1332 } |
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
|
1333 AI::NewEvent(v->owner, new AIEventVehicleWaitingInDepot(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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1335 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1336 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1337 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1338 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1339 /** |
15002
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
1340 * Move a vehicle in the game state; that is moving its position in |
baf0e12ad2b4
(svn r19614) -Codechange: "it's" => "its" where appropriate
smatz <smatz@openttd.org>
parents:
14898
diff
changeset
|
1341 * the position hashes and marking its location in the viewport dirty |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1342 * if requested. |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1343 * @param v vehicle to move |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1344 * @param update_viewport whether to dirty the viewport |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1345 */ |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1346 void VehicleMove(Vehicle *v, bool update_viewport) |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1347 { |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1348 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
|
1349 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
|
1350 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
|
1351 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1352 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
|
1353 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
|
1354 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1355 UpdateVehiclePosHash(v, pt.x, pt.y); |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1356 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1357 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
|
1358 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
|
1359 v->coord.top = pt.y; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1360 v->coord.right = pt.x + spr->width + 2; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1361 v->coord.bottom = pt.y + spr->height + 2; |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1362 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1363 if (update_viewport) { |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1364 MarkAllViewportsDirty( |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1365 min(old_coord.left, v->coord.left), |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1366 min(old_coord.top, v->coord.top), |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1367 max(old_coord.right, v->coord.right) + 1, |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1368 max(old_coord.bottom, v->coord.bottom) + 1 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1369 ); |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1370 } |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1372 |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1373 /** |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1374 * Marks viewports dirty where the vehicle's image is |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1375 * In fact, it equals |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1376 * BeginVehicleMove(v); EndVehicleMove(v); |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1377 * @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
|
1378 * @see BeginVehicleMove() |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1379 * @see EndVehicleMove() |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1380 */ |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1381 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
|
1382 { |
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
|
1383 MarkAllViewportsDirty(v->coord.left, v->coord.top, v->coord.right + 1, v->coord.bottom + 1); |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1384 } |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1385 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1386 /** |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1387 * 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
|
1388 * @param v Vehicle to move |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1389 * @return Position information after the move |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
1390 */ |
6153 | 1391 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
|
1392 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1393 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
|
1394 -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
|
1395 -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
|
1396 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1397 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1398 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
|
1399 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
|
1400 |
6153 | 1401 GetNewVehiclePosResult gp; |
1402 gp.x = x; | |
1403 gp.y = y; | |
1404 gp.old_tile = v->tile; | |
1405 gp.new_tile = TileVirtXY(x, y); | |
1406 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
|
1407 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1408 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1409 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
|
1410 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
|
1411 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
|
1412 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
|
1413 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1414 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1415 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
|
1416 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1417 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
|
1418 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1419 if (y >= v->y_pos) { |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1420 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
|
1421 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
|
1422 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1423 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1424 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
|
1425 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
|
1426 i++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1427 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1428 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1429 Direction dir = v->direction; |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1430 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1431 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
|
1432 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
|
1433 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
|
1434 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1435 |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5955
diff
changeset
|
1436 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1437 * 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
|
1438 * @param v Vehicle entering the tile |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1439 * @param tile Tile entered |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1440 * @param x X position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1441 * @param y Y position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1442 * @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
|
1443 * @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
|
1444 */ |
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
|
1445 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
|
1446 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1447 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
|
1448 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1449 |
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
|
1450 /** |
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
|
1451 * 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
|
1452 * 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
|
1453 * 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
|
1454 * @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
|
1455 * @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
|
1456 */ |
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
|
1457 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
|
1458 { |
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
|
1459 /* 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
|
1460 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
|
1461 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
|
1462 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
|
1463 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
|
1464 } |
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
|
1465 } |
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
|
1466 |
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
|
1467 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
|
1468 |
14421
d8710fbbbacd
(svn r18978) -Fix [FS#3584](r14753): possible invalid memory access when merging companies
smatz <smatz@openttd.org>
parents:
14319
diff
changeset
|
1469 /* 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
|
1470 * - 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
|
1471 * - 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
|
1472 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
|
1473 |
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
|
1474 /* 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
|
1475 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
|
1476 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
|
1477 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
|
1478 } |
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
|
1479 } |
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
|
1480 } |
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
|
1481 |
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
|
1482 /** 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
|
1483 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
|
1484 { |
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
|
1485 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
|
1486 |
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
|
1487 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
|
1488 |
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
|
1489 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
|
1490 } |
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
|
1491 |
15724
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1492 /** |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1493 * 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
|
1494 * @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
|
1495 * @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
|
1496 */ |
6641
a988a86b0d0a
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium <rubidium@openttd.org>
parents:
6638
diff
changeset
|
1497 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
|
1498 { |
15724
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1499 /* 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
|
1500 uint max_veh; |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1501 switch (type) { |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1502 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
|
1503 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
|
1504 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
|
1505 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
|
1506 default: NOT_REACHED(); |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1507 } |
db6f7934da37
(svn r20391) -Fix [FS#3993]: Prevent buying more vehicles than allowed.
alberth <alberth@openttd.org>
parents:
15723
diff
changeset
|
1508 |
18157
f20ba7062226
(svn r22982) -Cleanup: Remove CountCompanyVehicles() and use ALL_GROUP statistics instead.
frosch <frosch@openttd.org>
parents:
18156
diff
changeset
|
1509 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
|
1510 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
|
1511 |
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
|
1512 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
|
1513 |
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
|
1514 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
|
1515 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1516 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1517 |
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
|
1518 /** |
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
|
1519 * 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
|
1520 * 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
|
1521 * 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
|
1522 * @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
|
1523 * @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
|
1524 * 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
|
1525 */ |
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
|
1526 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
|
1527 { |
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
|
1528 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
|
1529 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
1530 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
|
1531 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
|
1532 |
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
|
1533 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
|
1534 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
|
1535 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
|
1536 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
|
1537 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
|
1538 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
|
1539 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
|
1540 } |
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
|
1541 |
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
|
1542 /* 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
|
1543 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
|
1544 /* 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
|
1545 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
|
1546 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
|
1547 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
|
1548 } |
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
|
1549 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
|
1550 } |
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
|
1551 |
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
|
1552 /* 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
|
1553 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
|
1554 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
|
1555 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
|
1556 } |
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
|
1557 |
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
|
1558 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
|
1559 } |
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
|
1560 |
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
|
1561 |
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
|
1562 /** |
16151
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1563 * Determines the #LiveryScheme for a vehicle. |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1564 * @param engine_type EngineID of the vehicle |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1565 * @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself. |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1566 * @param v the vehicle. NULL if in purchase list etc. |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1567 * @return livery scheme to use |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1568 */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1569 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
|
1570 { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1571 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
|
1572 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
|
1573 switch (e->type) { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1574 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1575 case VEH_TRAIN: |
17185
ccebafd2a9ba
(svn r21924) -Codechange: Unify some parts of the articulated vehicle code.
terkhen <terkhen@openttd.org>
parents:
17170
diff
changeset
|
1576 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
|
1577 /* 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
|
1578 * 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
|
1579 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
|
1580 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
|
1581 /* 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
|
1582 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1583 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1584 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
|
1585 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
|
1586 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
|
1587 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
|
1588 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
|
1589 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
|
1590 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1591 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
|
1592 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1593 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
|
1594 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
|
1595 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
|
1596 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
|
1597 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
|
1598 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1599 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1600 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1601 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
|
1602 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1603 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1604 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
|
1605 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1606 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
|
1607 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1608 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
|
1609 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
|
1610 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
|
1611 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
|
1612 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
|
1613 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1614 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1615 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1616 case VEH_ROAD: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1617 /* 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
|
1618 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
|
1619 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
|
1620 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
|
1621 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
|
1622 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1623 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
|
1624 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
|
1625 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1626 /* 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
|
1627 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
|
1628 /* Tram */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1629 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
|
1630 } else { |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1631 /* Bus or truck */ |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1632 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
|
1633 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1634 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1635 case VEH_SHIP: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1636 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
|
1637 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
|
1638 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
|
1639 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1640 case VEH_AIRCRAFT: |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1641 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
|
1642 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
|
1643 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
|
1644 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
|
1645 default: NOT_REACHED(); |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1646 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1647 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1648 } |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1649 |
97bc1bfb8161
(svn r20847) -Codechange: Split most of GetEngineLivery() into a separate GetEngineLiveryScheme() function.
frosch <frosch@openttd.org>
parents:
16079
diff
changeset
|
1650 /** |
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
|
1651 * 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
|
1652 * @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
|
1653 * @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
|
1654 * @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
|
1655 * @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
|
1656 * @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
|
1657 * @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
|
1658 */ |
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
|
1659 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
|
1660 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1661 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
|
1662 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
|
1663 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1664 /* 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
|
1665 * 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
|
1666 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
|
1667 /* 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
|
1668 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
|
1669 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1670 /* 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
|
1671 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
|
1672 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1673 |
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
|
1674 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
|
1675 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1676 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1677 |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1678 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
|
1679 { |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1680 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
|
1681 |
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
|
1682 /* 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
|
1683 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
|
1684 |
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
|
1685 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
|
1686 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1687 /* 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
|
1688 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
|
1689 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
|
1690 /* 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
|
1691 if (callback != CALLBACK_FAILED) { |
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
|
1692 assert_compile(PAL_NONE == 0); // Returning 0x4000 (resp. 0xC000) conincidences 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
|
1693 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
|
1694 /* 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
|
1695 * 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
|
1696 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
|
1697 /* 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
|
1698 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
|
1699 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
|
1700 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1701 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1702 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1703 |
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
|
1704 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
|
1705 |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1706 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
|
1707 |
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
|
1708 /* 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
|
1709 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
|
1710 |
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
|
1711 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
|
1712 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1713 map += livery->colour1; |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1714 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
|
1715 |
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
|
1716 /* 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
|
1717 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
|
1718 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
|
1719 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1720 |
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
|
1721 /** |
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
|
1722 * 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
|
1723 * @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
|
1724 * @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
|
1725 * @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
|
1726 */ |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1727 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
|
1728 { |
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
|
1729 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
|
1730 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1731 |
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
|
1732 /** |
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
|
1733 * 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
|
1734 * @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
|
1735 * @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
|
1736 */ |
14319
72cb3c72d619
(svn r18872) -Codechange: introduce PaletteID and use it
rubidium <rubidium@openttd.org>
parents:
14314
diff
changeset
|
1737 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
|
1738 { |
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
|
1739 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
|
1740 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
|
1741 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1742 |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1743 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
|
1744 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1745 |
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
|
1746 /** |
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
|
1747 * Determines capacity of a given vehicle from scratch. |
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
|
1748 * For aircraft the main capacity is determined. Mail might be present as well. |
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
|
1749 * @note Keep this function consistent with Engine::GetDisplayDefaultCapacity(). |
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
|
1750 * @param v Vehicle of interest |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
1751 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft |
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
|
1752 * @return Capacity |
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
|
1753 */ |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
1754 uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity) |
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
|
1755 { |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
1756 if (mail_capacity != NULL) *mail_capacity = 0; |
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
|
1757 const Engine *e = Engine::Get(v->engine_type); |
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
|
1758 |
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
|
1759 if (!e->CanCarryCargo()) return 0; |
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
|
1760 |
13421
296f2bac97a9
(svn r17930) -Fix (r17926): Aircraft were not carrying mail anymore, when CB15 was in use.
frosch <frosch@openttd.org>
parents:
13419
diff
changeset
|
1761 if (mail_capacity != NULL && e->type == VEH_AIRCRAFT && IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
14641
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1762 *mail_capacity = GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, e->u.air.mail_capacity); |
13421
296f2bac97a9
(svn r17930) -Fix (r17926): Aircraft were not carrying mail anymore, when CB15 was in use.
frosch <frosch@openttd.org>
parents:
13419
diff
changeset
|
1763 } |
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
|
1764 CargoID default_cargo = e->GetDefaultCargoType(); |
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
|
1765 |
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
|
1766 /* Check the refit capacity callback if we are not in the default configuration. |
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
|
1767 * Note: This might change to become more consistent/flexible/sane, esp. when default cargo is first refittable. */ |
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
|
1768 if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && |
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
|
1769 (default_cargo != v->cargo_type || v->cargo_subtype != 0)) { |
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
|
1770 uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v); |
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
|
1771 if (callback != CALLBACK_FAILED) return callback; |
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
|
1772 } |
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
|
1773 |
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
|
1774 /* Get capacity according to property resp. CB */ |
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
|
1775 uint capacity; |
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
|
1776 switch (e->type) { |
14641
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1777 case VEH_TRAIN: capacity = GetVehicleProperty(v, PROP_TRAIN_CARGO_CAPACITY, e->u.rail.capacity); break; |
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1778 case VEH_ROAD: capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, e->u.road.capacity); break; |
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1779 case VEH_SHIP: capacity = GetVehicleProperty(v, PROP_SHIP_CARGO_CAPACITY, e->u.ship.capacity); break; |
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1780 case VEH_AIRCRAFT: capacity = GetVehicleProperty(v, PROP_AIRCRAFT_PASSENGER_CAPACITY, e->u.air.passenger_capacity); break; |
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
|
1781 default: NOT_REACHED(); |
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
|
1782 } |
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
|
1783 |
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
|
1784 /* Apply multipliers depending on cargo- and vehicletype. |
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
|
1785 * Note: This might change to become more consistent/flexible. */ |
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
|
1786 if (e->type != VEH_SHIP) { |
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
|
1787 if (e->type == VEH_AIRCRAFT) { |
13464
674c5ea7a2a6
(svn r17974) -Fix (r17926)[FS#3300]: C != T
frosch <frosch@openttd.org>
parents:
13421
diff
changeset
|
1788 if (!IsCargoInClass(v->cargo_type, CC_PASSENGERS)) { |
14641
9fdd19faf2ff
(svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents:
14421
diff
changeset
|
1789 capacity += GetVehicleProperty(v, PROP_AIRCRAFT_MAIL_CAPACITY, e->u.air.mail_capacity); |
13417
216dfd60fb2f
(svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents:
13390
diff
changeset
|
1790 } |
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
|
1791 if (v->cargo_type == CT_MAIL) return capacity; |
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
|
1792 } else { |
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
|
1793 switch (default_cargo) { |
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
|
1794 case CT_PASSENGERS: break; |
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
|
1795 case CT_MAIL: |
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
|
1796 case CT_GOODS: capacity *= 2; break; |
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
|
1797 default: capacity *= 4; break; |
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
|
1798 } |
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
|
1799 } |
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
|
1800 switch (v->cargo_type) { |
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
|
1801 case CT_PASSENGERS: break; |
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
|
1802 case CT_MAIL: |
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
|
1803 case CT_GOODS: capacity /= 2; break; |
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
|
1804 default: capacity /= 4; break; |
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
|
1805 } |
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
|
1806 } |
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
|
1807 |
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
|
1808 return capacity; |
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
|
1809 } |
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
|
1810 |
17070
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1811 /** |
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
|
1812 * 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
|
1813 */ |
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
|
1814 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
|
1815 { |
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
|
1816 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
|
1817 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
|
1818 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
|
1819 /* 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
|
1820 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
|
1821 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
|
1822 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
|
1823 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
|
1824 } |
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
|
1825 } |
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
|
1826 |
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
|
1827 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
|
1828 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
|
1829 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
|
1830 |
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
|
1831 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
|
1832 /* 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
|
1833 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
|
1834 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
|
1835 } 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
|
1836 /* 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
|
1837 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
|
1838 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
|
1839 } |
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
|
1840 |
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
|
1841 /* 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
|
1842 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
|
1843 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
|
1844 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
|
1845 } |
17070
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1846 } |
38c723434782
(svn r21807) -Codechange: split automatic order removal into a separate function (fonsinchen)
rubidium <rubidium@openttd.org>
parents:
17067
diff
changeset
|
1847 } |
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
|
1848 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1849 /** |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1850 * 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
|
1851 * @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
|
1852 */ |
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
|
1853 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
|
1854 { |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1855 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
|
1856 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1857 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
|
1858 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
|
1859 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
|
1860 |
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
|
1861 /* 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
|
1862 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
|
1863 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
|
1864 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1865 /* 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
|
1866 * 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
|
1867 * 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
|
1868 * 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
|
1869 * 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
|
1870 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
|
1871 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1872 } 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
|
1873 /* 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
|
1874 * 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
|
1875 * 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
|
1876 * 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
|
1877 * 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
|
1878 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
|
1879 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
|
1880 (!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
|
1881 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
|
1882 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
|
1883 /* 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
|
1884 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
|
1885 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
|
1886 (!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
|
1887 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
|
1888 |
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
|
1889 /* 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
|
1890 * 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
|
1891 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
|
1892 bool found = false; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1893 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
|
1894 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
|
1895 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
|
1896 found = true; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1897 break; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1898 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1899 target_index++; |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1900 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
|
1901 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
|
1902 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1903 |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1904 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
|
1905 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
|
1906 /* 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
|
1907 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
|
1908 InvalidateVehicleOrder(this, 0); |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1909 } 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
|
1910 /* 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
|
1911 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
|
1912 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
|
1913 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
|
1914 /* 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
|
1915 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
|
1916 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
|
1917 } 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
|
1918 /* 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
|
1919 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
|
1920 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
|
1921 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1922 |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1923 /* Wrap around */ |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1924 if (order == NULL) { |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1925 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
|
1926 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
|
1927 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1928 assert(order != NULL); |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1929 } |
180462eff3ee
(svn r22333) -Change: Prefer deleting automatic orders instead of inserting new ones.
frosch <frosch@openttd.org>
parents:
17568
diff
changeset
|
1930 } |
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 } 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
|
1932 /* 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
|
1933 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
|
1934 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
|
1935 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
|
1936 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
|
1937 |
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
|
1938 /* 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
|
1939 * 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
|
1940 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
|
1941 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
|
1942 } |
cf44305677e8
(svn r22332) -Fix: When inserting automatic orders, do not create consecutive duplicate orders.
frosch <frosch@openttd.org>
parents:
17567
diff
changeset
|
1943 } |
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
|
1944 } |
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
|
1945 this->current_order.MakeLoading(false); |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1946 } |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1947 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1948 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
|
1949 |
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
|
1950 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
|
1951 |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1952 SetWindowDirty(GetWindowClassForVehicleType(this->type), this->owner); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1953 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
1954 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
|
1955 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
|
1956 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1957 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
|
1958 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
|
1959 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
|
1960 } |
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
|
1961 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1962 /** |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1963 * Perform all actions when leaving a station. |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1964 * @pre this->current_order.IsType(OT_LOADING) |
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1965 */ |
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
|
1966 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
|
1967 { |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1968 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
|
1969 |
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
|
1970 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
|
1971 |
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
|
1972 /* 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
|
1973 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
|
1974 |
17193
f84b0a9115e7
(svn r21932) -Document: some tidbits related to vehicles
rubidium <rubidium@openttd.org>
parents:
17186
diff
changeset
|
1975 this->current_order.MakeLeaveStation(); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1976 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
|
1977 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
|
1978 |
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
|
1979 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
|
1980 |
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
|
1981 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
|
1982 /* Trigger station animation (trains only) */ |
15935
a4fa352275f4
(svn r20623) -Codechange: unify the storing of animation related information
rubidium <rubidium@openttd.org>
parents:
15921
diff
changeset
|
1983 if (IsTileType(this->tile, MP_STATION)) TriggerStationAnimation(st, this->tile, SAT_TRAIN_DEPARTS); |
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
|
1984 |
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
|
1985 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
|
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 } |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
1988 |
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
1989 |
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
|
1990 /** |
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
|
1991 * 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
|
1992 * 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
|
1993 * @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
|
1994 */ |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1995 void Vehicle::HandleLoading(bool mode) |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1996 { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1997 switch (this->current_order.GetType()) { |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1998 case OT_LOADING: { |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
1999 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
|
2000 |
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
|
2001 /* 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
|
2002 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
|
2003 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2004 this->PlayLeaveStationSound(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2005 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2006 this->LeaveStation(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2007 |
17560
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2008 /* 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
|
2009 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
|
2010 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
|
2011 (!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
|
2012 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
|
2013 return; |
dc669fc9641d
(svn r22324) -Fix: Vehicles skipped orders when inserting automatic orders failed.
frosch <frosch@openttd.org>
parents:
17490
diff
changeset
|
2014 } |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2015 break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2016 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2017 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2018 case OT_DUMMY: break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2019 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2020 default: return; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2021 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2022 |
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
|
2023 this->IncrementImplicitOrderIndex(); |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2024 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
2025 |
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
|
2026 /** |
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
|
2027 * 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
|
2028 * @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
|
2029 * @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
|
2030 * @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
|
2031 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
2032 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
|
2033 { |
14815
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2034 CommandCost ret = CheckOwnership(this->owner); |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2035 if (ret.Failed()) return ret; |
ad5c3430b2b2
(svn r19405) -Codechange: CheckOwnership() returns a CommandCost.
alberth <alberth@openttd.org>
parents:
14781
diff
changeset
|
2036 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2037 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
|
2038 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
|
2039 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2040 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
|
2041 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
|
2042 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
|
2043 /* 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
|
2044 * 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
|
2045 * 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
|
2046 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
|
2047 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
|
2048 this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
2049 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2050 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2051 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2052 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2053 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2054 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
|
2055 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
|
2056 /* 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
|
2057 * 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
|
2058 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
|
2059 |
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
|
2060 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
|
2061 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
|
2062 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
|
2063 } |
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
|
2064 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2065 this->current_order.MakeDummy(); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
2066 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2067 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2068 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2069 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2070 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2071 TileIndex location; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2072 DestinationID destination; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2073 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
|
2074 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
|
2075 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
|
2076 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2077 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
|
2078 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
|
2079 |
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
|
2080 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
|
2081 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
|
2082 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
|
2083 } |
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 |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2085 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
|
2086 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
|
2087 if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT); |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12871
diff
changeset
|
2088 SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2089 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2090 /* 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
|
2091 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
|
2092 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2093 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
|
2094 Aircraft *a = Aircraft::From(this); |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2095 if (a->state == FLYING && a->targetairport != destination) { |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2096 /* 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
|
2097 extern void AircraftNextAirportPos_and_Order(Aircraft *a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2098 AircraftNextAirportPos_and_Order(a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
2099 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
2100 } |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2101 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2102 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2103 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2104 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2105 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
2106 |
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
|
2107 /** |
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
|
2108 * 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
|
2109 * @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
|
2110 */ |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2111 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
|
2112 { |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2113 bool powered_before = HasBit(this->vcache.cached_vis_effect, VE_DISABLE_WAGON_POWER); |
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
|
2114 const Engine *e = Engine::Get(this->engine_type); |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2115 |
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
|
2116 /* 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
|
2117 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
|
2118 switch (e->type) { |
16862
b36044db5a61
(svn r21596) -Codechange: Rename a misleading-named variable.
frosch <frosch@openttd.org>
parents:
16828
diff
changeset
|
2119 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
|
2120 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
|
2121 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
|
2122 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
|
2123 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2124 |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2125 /* 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
|
2126 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
|
2127 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
|
2128 |
16863
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2129 if (callback != CALLBACK_FAILED) { |
d71ff96cc22c
(svn r21597) -Fix (r21239): Also catch the case when callback 10 returns VE_DEFAULT.
frosch <frosch@openttd.org>
parents:
16862
diff
changeset
|
2130 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
|
2131 /* 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
|
2132 * 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
|
2133 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
|
2134 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
|
2135 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
|
2136 } |
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
|
2137 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
|
2138 } |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2139 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2140 |
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
|
2141 /* 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
|
2142 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
|
2143 (!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
|
2144 /* 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
|
2145 * 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
|
2146 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
|
2147 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
|
2148 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
|
2149 } 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
|
2150 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
|
2151 } |
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
|
2152 } 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
|
2153 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
|
2154 /* 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
|
2155 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
|
2156 } |
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
|
2157 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
|
2158 } |
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
|
2159 } |
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
|
2160 |
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
|
2161 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
|
2162 |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2163 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
|
2164 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
|
2165 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
|
2166 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2167 } |
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2168 |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2169 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
|
2170 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
|
2171 }; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2172 |
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
|
2173 /** |
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
|
2174 * 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
|
2175 * @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
|
2176 */ |
16511
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2177 void Vehicle::ShowVisualEffect() const |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2178 { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2179 assert(this->IsPrimaryVehicle()); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2180 bool sound = false; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2181 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2182 /* Do not show any smoke when: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2183 * - 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
|
2184 * - 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
|
2185 * - the vehicle is moving very slowly |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2186 */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2187 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
|
2188 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
|
2189 this->cur_speed < 2) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2190 return; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2191 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2192 if (this->type == VEH_TRAIN) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2193 const Train *t = Train::From(this); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2194 /* 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
|
2195 * - the train is reversing |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2196 * - 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
|
2197 */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2198 if (HasBit(t->flags, VRF_REVERSING) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2199 (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
|
2200 t->cur_speed >= t->Train::GetCurrentMaxSpeed())) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2201 return; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2202 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2203 } |
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 const Vehicle *v = this; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2206 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2207 do { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2208 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
|
2209 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
|
2210 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
|
2211 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2212 /* Show no smoke when: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2213 * - 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
|
2214 * - 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
|
2215 * - 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
|
2216 * - 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
|
2217 * - 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
|
2218 * - 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
|
2219 if (disable_effect || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2220 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
|
2221 (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
|
2222 IsDepotTile(v->tile) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2223 IsTunnelTile(v->tile) || |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2224 (v->type == VEH_TRAIN && |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2225 !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
|
2226 continue; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2227 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2228 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2229 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
|
2230 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
|
2231 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2232 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
|
2233 x = -x; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2234 y = -y; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2235 } |
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 switch (effect_type) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2238 case VE_TYPE_STEAM: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2239 /* 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
|
2240 * 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
|
2241 * 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
|
2242 * REGULATION: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2243 * - instead of 1, 4 / 2^smoke_amount (max. 2) is used to provide sufficient regulation to steam puffs' amount. */ |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2244 if (GB(v->tick_counter, 0, ((4 >> _settings_game.vehicle.smoke_amount) + ((this->cur_speed * 3) / this->vcache.cached_max_speed))) == 0) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2245 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
|
2246 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2247 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2248 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2249 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2250 case VE_TYPE_DIESEL: { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2251 /* 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
|
2252 * when smoke emission stops. |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2253 * 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
|
2254 * 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
|
2255 * 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
|
2256 * 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
|
2257 * 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
|
2258 * 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
|
2259 * REGULATION: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2260 * - 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
|
2261 * - 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
|
2262 int power_weight_effect = 0; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2263 if (v->type == VEH_TRAIN) { |
16785
775f357828e3
(svn r21518) -Codechange: Rename AccelerationCache to GroundVehicleCache.
terkhen <terkhen@openttd.org>
parents:
16775
diff
changeset
|
2264 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
|
2265 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2266 if (this->cur_speed < (this->vcache.cached_max_speed >> (2 >> _settings_game.vehicle.smoke_amount)) && |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2267 Chance16((64 - ((this->cur_speed << 5) / this->vcache.cached_max_speed) + power_weight_effect), (512 >> _settings_game.vehicle.smoke_amount))) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2268 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
|
2269 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2270 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2271 break; |
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 case VE_TYPE_ELECTRIC: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2275 /* 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
|
2276 * 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
|
2277 * emissions are kept simple. Only when starting, creating huge force are sparks more likely to happen, but when |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2278 * reaching its max. speed, quarter by quarter of it, chance decreases untill the usuall 2,22% at train's top 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 * - 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
|
2281 if (GB(v->tick_counter, 0, 2) == 0 && |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2282 Chance16((6 - ((this->cur_speed << 2) / this->vcache.cached_max_speed)), (360 >> _settings_game.vehicle.smoke_amount))) { |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2283 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
|
2284 sound = true; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2285 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2286 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2287 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2288 default: |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2289 break; |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2290 } |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2291 } while ((v = v->Next()) != NULL); |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2292 |
b9db78828e3d
(svn r21237) -Codechange: Move HandleLocomotiveSmokeCloud to Vehicle::ShowVisualEffect (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16509
diff
changeset
|
2293 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
|
2294 } |
16509
25f8b420bbe2
(svn r21235) -Codechange: Move Train::UpdateVisualEffect to the Vehicle class (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16489
diff
changeset
|
2295 |
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
|
2296 /** |
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
|
2297 * 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
|
2298 * @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
|
2299 */ |
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
|
2300 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
|
2301 { |
13936
d316a293322c
(svn r18468) -Codechange: make sure one never makes self-loops using Vehicle::SetNext
rubidium <rubidium@openttd.org>
parents:
13873
diff
changeset
|
2302 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
|
2303 |
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
|
2304 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
|
2305 /* 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
|
2306 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
|
2307 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
|
2308 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2309 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
|
2310 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2311 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2312 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
|
2313 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2314 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
|
2315 /* 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
|
2316 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
|
2317 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
|
2318 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
|
2319 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
|
2320 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2321 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2322 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
2323 |
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
|
2324 /** |
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
|
2325 * 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
|
2326 * @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
|
2327 * @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
|
2328 */ |
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
|
2329 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
|
2330 { |
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
|
2331 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
|
2332 |
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
|
2333 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
|
2334 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
|
2335 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
|
2336 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
|
2337 } |
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
|
2338 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2339 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
|
2340 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
|
2341 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2342 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
|
2343 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2344 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
|
2345 |
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
|
2346 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
|
2347 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2348 |
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
|
2349 /** |
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
|
2350 * 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
|
2351 */ |
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
|
2352 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
|
2353 { |
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
|
2354 /* 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
|
2355 * 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
|
2356 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
|
2357 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
|
2358 |
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
|
2359 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
|
2360 |
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
|
2361 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
|
2362 /* 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
|
2363 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
|
2364 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2365 |
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 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
|
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 |
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 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
|
2370 /* 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
|
2371 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
|
2372 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
|
2373 } 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
|
2374 /* 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
|
2375 * 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
|
2376 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
|
2377 } |
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 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
|
2380 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
|
2381 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
2382 |
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
|
2383 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
|
2384 { |
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
|
2385 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
|
2386 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
|
2387 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
|
2388 /* 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
|
2389 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
|
2390 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
|
2391 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
|
2392 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
|
2393 SetDParam(1, profit); |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2394 AddVehicleNewsItem( |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12483
diff
changeset
|
2395 STR_NEWS_VEHICLE_IS_UNPROFITABLE, |
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
|
2396 NS_ADVICE, |
12010
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2397 v->index |
d0bf08a7c260
(svn r16416) -Fix [FS#2912]: Rework deleting of news when referenced vehicles/stations/industries are deleted.
frosch <frosch@openttd.org>
parents:
12008
diff
changeset
|
2398 ); |
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
|
2399 } |
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
|
2400 AI::NewEvent(v->owner, new AIEventVehicleUnprofitable(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
|
2401 } |
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
|
2402 |
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
|
2403 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
|
2404 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
|
2405 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
|
2406 } |
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
|
2407 } |
18159
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2408 GroupStatistics::UpdateProfits(); |
de0749262352
(svn r22984) -Feature: Display profit icons for groups in the group GUI.
frosch <frosch@openttd.org>
parents:
18157
diff
changeset
|
2409 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
|
2410 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
|
2411 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
|
2412 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
|
2413 } |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2414 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2415 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2416 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2417 * 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
|
2418 * @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
|
2419 * @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
|
2420 * @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
|
2421 * @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
|
2422 * 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
|
2423 * 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
|
2424 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2425 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
|
2426 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
2427 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
|
2428 assert(e != NULL); |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2429 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2430 switch (e->type) { |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2431 case VEH_TRAIN: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2432 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
|
2433 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2434 case VEH_ROAD: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2435 /* 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
|
2436 * 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
|
2437 * 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
|
2438 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
|
2439 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2440 case VEH_SHIP: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2441 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
|
2442 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2443 case VEH_AIRCRAFT: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2444 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
|
2445 (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
|
2446 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2447 default: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2448 return false; |
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 } |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2451 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2452 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2453 * 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
|
2454 * @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
|
2455 * @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
|
2456 * @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
|
2457 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2458 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
|
2459 { |
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
|
2460 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
|
2461 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
2462 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
|
2463 } |
16786
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2464 |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2465 /** |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2466 * 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
|
2467 * @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
|
2468 * @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
|
2469 */ |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2470 GroundVehicleCache *Vehicle::GetGroundVehicleCache() |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2471 { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2472 assert(this->IsGroundVehicle()); |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2473 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
|
2474 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
|
2475 } else { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2476 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
|
2477 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2478 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2479 |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2480 /** |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2481 * 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
|
2482 * @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
|
2483 * @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
|
2484 */ |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2485 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
|
2486 { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2487 assert(this->IsGroundVehicle()); |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2488 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
|
2489 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
|
2490 } else { |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2491 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
|
2492 } |
e69d11fd38e7
(svn r21519) -Codechange: Allow direct access to the GroundVehicleCache from a Vehicle.
terkhen <terkhen@openttd.org>
parents:
16785
diff
changeset
|
2493 } |
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
|
2494 |
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
|
2495 /** |
17563
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2496 * 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
|
2497 * @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
|
2498 * @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
|
2499 */ |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2500 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
|
2501 { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2502 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
|
2503 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
|
2504 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
|
2505 } else { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2506 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
|
2507 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2508 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2509 |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2510 /** |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2511 * 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
|
2512 * @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
|
2513 * @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
|
2514 */ |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2515 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
|
2516 { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2517 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
|
2518 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
|
2519 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
|
2520 } else { |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2521 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
|
2522 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2523 } |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2524 |
acf9e2d5558d
(svn r22327) -Add: Vehicle::GetGroundVehicleFlags() for accessing GroundVehicle<>::gv_flags through a Vehicle struct.
frosch <frosch@openttd.org>
parents:
17560
diff
changeset
|
2525 /** |
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
|
2526 * 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
|
2527 * @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
|
2528 * @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
|
2529 * @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
|
2530 * @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
|
2531 * @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
|
2532 */ |
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
|
2533 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
|
2534 { |
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
|
2535 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
|
2536 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
|
2537 /* 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
|
2538 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
|
2539 |
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
|
2540 /* 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
|
2541 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
|
2542 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
|
2543 /* 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
|
2544 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
|
2545 |
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
|
2546 /* 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
|
2547 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
|
2548 |
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
|
2549 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
|
2550 } 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
|
2551 } |
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
|
2552 } |
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
|
2553 } |