Mercurial > hg > openttd
annotate src/vehicle.cpp @ 11982:9add5306a01e draft
(svn r16388) -Codechange: move u.air to Aircraft
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 22 May 2009 20:07:26 +0000 |
parents | cf1aad9b971c |
children | 6fae1efe3ae2 |
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 |
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
|
3 /** @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
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #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
|
6 #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
|
7 #include "openttd.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
|
8 #include "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
|
9 #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
|
10 #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
|
11 #include "spritecache.h" |
6453
666fc3ef3174
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros <maedhros@openttd.org>
parents:
6444
diff
changeset
|
12 #include "landscape.h" |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
13 #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
|
14 #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
|
15 #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
|
16 #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
|
17 #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
|
18 #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
|
19 #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
|
20 #include "aircraft.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
21 #include "newgrf_engine.h" |
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 "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
|
23 #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
|
24 #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
|
25 #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
|
26 #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
|
27 #include "zoom_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
|
28 #include "functions.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
29 #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
|
30 #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
|
31 #include "vehicle_func.h" |
8212
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8211
diff
changeset
|
32 #include "autoreplace_func.h" |
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8211
diff
changeset
|
33 #include "autoreplace_gui.h" |
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
|
34 #include "ai/ai.hpp" |
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
|
35 #include "core/smallmap_type.hpp" |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
36 #include "depot_func.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
37 #include "settings_type.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
|
38 #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
|
39 #include "core/pool_func.hpp" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
40 |
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
|
41 #include "table/sprites.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
|
42 #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
|
43 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 #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
|
45 |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
46 VehicleID _vehicle_id_ctr_day; |
9344
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
47 const Vehicle *_place_clicked_vehicle; |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
48 VehicleID _new_vehicle_id; |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
49 uint16 _returned_refit_capacity; |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
50 |
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
|
51 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
52 /* Initialize the vehicle-pool */ |
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
|
53 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
|
54 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
|
55 |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
56 /** 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
|
57 * @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
|
58 * @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
|
59 */ |
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
|
60 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
|
61 { |
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
|
62 /* 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
|
63 * 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
|
64 * 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
|
65 * 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
|
66 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
|
67 |
11913
f67b6243e05a
(svn r16315) -Codechange: move the autorenew settings to a new CompanySettings struct
yexo <yexo@openttd.org>
parents:
11902
diff
changeset
|
68 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
|
69 if (this->age - this->max_age < (c->settings.engine_renew_months * 30)) return false; |
8997
19392bf555ff
(svn r12792) -Codechange: [autoreplace] added a function to figure out if a replacement is needed and if so, to which EngineID
bjarni <bjarni@openttd.org>
parents:
8996
diff
changeset
|
70 if (this->age == 0) return false; // rail cars don't age and lacks a max age |
8629
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
71 |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
72 return true; |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
73 } |
8d7472e6d544
(svn r12231) -Cleanup (r12230): [autoreplace] moved Vehicle::NeedsAutorenewing() and added comments
bjarni <bjarni@openttd.org>
parents:
8582
diff
changeset
|
74 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 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
|
76 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 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
|
78 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
|
79 v->reliability = Engine::Get(v->engine_type)->reliability; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
80 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); // ensure that last service date and reliability are updated |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
83 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
|
84 { |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
85 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
|
86 |
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
|
87 if (_settings_game.order.no_servicing_if_no_breakdowns && _settings_game.difficulty.vehicle_breakdowns == 0) { |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
88 /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off. |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
89 * Note: If servicing is enabled, we postpone replacement till next service. */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
90 return EngineHasReplacementForCompany(Company::Get(this->owner), this->engine_type, this->group_id); |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
92 |
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
|
93 return _settings_game.vehicle.servint_ispercent ? |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
94 (this->reliability < Engine::Get(this->engine_type)->reliability * (100 - this->service_interval) / 100) : |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
95 (this->date_of_last_service + this->service_interval < _date); |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
96 } |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
97 |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
98 bool Vehicle::NeedsAutomaticServicing() const |
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
99 { |
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
|
100 if (_settings_game.order.gotodepot && VehicleHasDepotOrders(this)) return false; |
8862
1300bc87c872
(svn r12629) -Codechange: Split VehicleNeedsService() into Vehicle::NeedsServicing() and Vehicle::NeedsAutomaticServicing().
frosch <frosch@openttd.org>
parents:
8855
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
105 |
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
|
106 /** |
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
|
107 * 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
|
108 * @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
|
109 * @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
|
110 * @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
|
111 * @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
|
112 * @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
|
113 */ |
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
|
114 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
|
115 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
116 const Engine *e = Engine::Get(engine); |
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
|
117 uint32 grfid = e->grffile->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
|
118 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
|
119 |
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
|
120 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
|
121 SetBit(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
|
122 SetDParamStr(0, grfconfig->name); |
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
|
123 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
|
124 ShowErrorMessage(part2, part1, 0, 0); |
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
|
125 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
|
126 } |
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
|
127 |
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
|
128 /* 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
|
129 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
|
130 |
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
|
131 SetDParamStr(0, grfconfig->name); |
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
|
132 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
|
133 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
|
134 |
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
|
135 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
|
136 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
|
137 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
|
138 } |
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
|
139 |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10642
diff
changeset
|
140 StringID VehicleInTheWayErrMsg(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
|
141 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
142 switch (v->type) { |
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
|
143 case VEH_TRAIN: return STR_ERROR_TRAIN_IN_THE_WAY; |
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
|
144 case VEH_ROAD: return STR_ERROR_ROAD_VEHICLE_IN_THE_WAY; |
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
|
145 case VEH_AIRCRAFT: return STR_ERROR_AIRCRAFT_IN_THE_WAY; |
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
|
146 default: return STR_ERROR_SHIP_IN_THE_WAY; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
147 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
148 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
150 static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
151 { |
8081
97d86b93edda
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz <smatz@openttd.org>
parents:
8078
diff
changeset
|
152 byte z = *(byte*)data; |
97d86b93edda
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz <smatz@openttd.org>
parents:
8078
diff
changeset
|
153 |
97d86b93edda
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz <smatz@openttd.org>
parents:
8078
diff
changeset
|
154 if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; |
97d86b93edda
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
smatz <smatz@openttd.org>
parents:
8078
diff
changeset
|
155 if (v->z_pos > z) 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
|
156 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
157 _error_message = VehicleInTheWayErrMsg(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
158 return v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
159 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
160 |
8078
dcb1301e8c28
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz <smatz@openttd.org>
parents:
8076
diff
changeset
|
161 bool EnsureNoVehicleOnGround(TileIndex tile) |
dcb1301e8c28
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz <smatz@openttd.org>
parents:
8076
diff
changeset
|
162 { |
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
|
163 byte z = GetTileMaxZ(tile); |
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
|
164 return !HasVehicleOnPos(tile, &z, &EnsureNoVehicleProcZ); |
8078
dcb1301e8c28
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz <smatz@openttd.org>
parents:
8076
diff
changeset
|
165 } |
dcb1301e8c28
(svn r11639) -Codechange: simplify EnsureNoVehicleOnGround
smatz <smatz@openttd.org>
parents:
8076
diff
changeset
|
166 |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
167 /** Procedure called for every vehicle found in tunnel/bridge in the hash map */ |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
168 static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
169 { |
9495
9fd9426b36c9
(svn r13475) -Fix (r13464): crash on destroying aquaduct with ship on in and on company bankrupt
smatz <smatz@openttd.org>
parents:
9428
diff
changeset
|
170 if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) return NULL; |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
171 if (v == (const Vehicle *)data) return NULL; |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
172 |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
173 _error_message = VehicleInTheWayErrMsg(v); |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
174 return v; |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
175 } |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
176 |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
177 /** |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
178 * Finds vehicle in tunnel / bridge |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
179 * @param tile first end |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
180 * @param endtile second end |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
181 * @param ignore Ignore this vehicle when searching |
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
|
182 * @return true if the bridge has a vehicle |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
183 */ |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
184 bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore) |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
185 { |
10103
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
186 return HasVehicleOnPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc) || |
9a884d182149
(svn r14285) -Fix [FS#2263]: A train inside a wormhole could free the reservation of another train inside the wormhole.
michi_cc <michi_cc@openttd.org>
parents:
10083
diff
changeset
|
187 HasVehicleOnPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc); |
8072
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
188 } |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
189 |
0cba7093ca14
(svn r11633) -Codechange: merge CheckTunnelEmpty and IsVehicleOnBridge into GetVehicleTunnelBridge
smatz <smatz@openttd.org>
parents:
8071
diff
changeset
|
190 |
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
|
191 Vehicle::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
|
192 { |
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
|
193 this->type = VEH_INVALID; |
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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 this->colourmap = PAL_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
199 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
200 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
201 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 * 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
|
203 * @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
|
204 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
205 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
|
206 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
207 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
|
208 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
209 |
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
|
210 /* 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
|
211 * 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 |
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
|
218 /* 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
|
219 * 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
|
220 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
|
221 |
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
|
222 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
|
223 |
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
|
224 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
|
225 { |
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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 } |
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
|
233 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
|
234 } |
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
|
235 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
|
236 } |
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
|
237 |
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
|
238 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
|
239 } |
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
|
240 |
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
|
241 |
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
|
242 /** |
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
|
243 * 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
|
244 * @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
|
245 * @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
|
246 * @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
|
247 * @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
|
248 * @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
|
249 * @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
|
250 * 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
|
251 * @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
|
252 */ |
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
|
253 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
|
254 { |
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
|
255 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
|
256 |
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
|
257 /* 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 |
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
|
263 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
|
264 } |
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
|
265 |
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
|
266 /** |
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
|
267 * 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
|
268 * 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
|
269 * 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
|
270 * 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
|
271 * 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
|
272 * @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
|
273 * @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
|
274 * 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
|
275 * @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
|
276 * @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
|
277 * @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
|
278 * @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
|
279 */ |
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
|
280 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
|
281 { |
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 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
|
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 |
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
|
285 /** |
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
|
286 * 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
|
287 * 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
|
288 * @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
|
289 * 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
|
290 * @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
|
291 * @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
|
292 * @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
|
293 * @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
|
294 * @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
|
295 */ |
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 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
|
297 { |
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 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
|
299 } |
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 |
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 /** |
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 * 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
|
303 * @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
|
304 * @param tile The 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
|
305 * @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
|
306 * @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
|
307 * @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
|
308 * 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
|
309 * @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
|
310 */ |
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
|
311 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
|
312 { |
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
|
313 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
|
314 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
|
315 |
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
|
316 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
|
317 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
|
318 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
|
319 |
9775
c3caa51b9888
(svn r13912) -Codechange: remove some casts by returning the proper type instead of void*.
rubidium <rubidium@openttd.org>
parents:
9704
diff
changeset
|
320 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
|
321 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
|
322 } |
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
|
323 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
324 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
|
325 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
326 |
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
|
327 /** |
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 * 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
|
329 * 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
|
330 * 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
|
331 * 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
|
332 * 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
|
333 * @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
|
334 * @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
|
335 * 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
|
336 * @param tile The 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
|
337 * @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
|
338 * @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
|
339 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
340 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
|
341 { |
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 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
|
343 } |
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 |
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 /** |
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 * 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
|
347 * 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
|
348 * @note Use FindVehicleOnPos 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
|
349 * 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
|
350 * @param tile The 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
|
351 * @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
|
352 * @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
|
353 * @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
|
354 */ |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
355 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
|
356 { |
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 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
|
358 } |
4923bdc50041
(svn r14258) -Codechange: rework the way to query the vehicle hash to make sure it always results in the same irregardless of the order of the hash-linked-list.
rubidium <rubidium@openttd.org>
parents:
10056
diff
changeset
|
359 |
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 |
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
|
361 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
|
362 { |
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
|
363 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
|
364 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
|
365 |
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
|
366 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
|
367 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
|
368 } 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
|
369 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
|
370 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
|
371 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
|
372 } |
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
|
373 |
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 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
|
375 |
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
|
376 /* 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
|
377 if (old_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
|
378 Vehicle *last = 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
|
379 Vehicle *u = *old_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
|
380 while (u != 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
|
381 last = u; |
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
|
382 u = u->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
|
383 assert(u != 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
|
384 } |
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
|
385 |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
386 if (last == 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
|
387 *old_hash = 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
|
388 } else { |
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
|
389 last->next_new_hash = 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
|
390 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
391 } |
7ef94b059aec
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
peter1138 <peter1138@openttd.org>
parents:
6857
diff
changeset
|
392 |
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
|
393 /* 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
|
394 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
|
395 v->next_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
|
396 *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
|
397 assert(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
|
398 } |
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
|
399 |
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
|
400 /* 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
|
401 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
|
402 } |
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
|
403 |
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
|
404 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
|
405 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
406 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
|
407 { |
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
|
408 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
|
409 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 |
6491
696f0e1b046e
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium <rubidium@openttd.org>
parents:
6490
diff
changeset
|
414 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
|
415 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
|
416 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
417 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
|
418 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
419 /* 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
|
420 if (old_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
|
421 Vehicle *last = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
422 Vehicle *u = *old_hash; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
423 while (u != v) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
424 last = u; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
425 u = u->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
|
426 assert(u != NULL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
427 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
428 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
429 if (last == NULL) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
430 *old_hash = 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
|
431 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
432 last->next_hash = 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
|
433 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
434 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
435 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
436 /* 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
|
437 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
|
438 v->next_hash = *new_hash; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
439 *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
|
440 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
441 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
442 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
443 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
|
444 { |
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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
450 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
451 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
|
452 { |
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
|
453 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
|
454 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
|
455 } |
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
|
456 |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
457 /** |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
458 * List of vehicles that should check for autoreplace this tick. |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
459 * Mapping of vehicle -> leave depot immediatelly after autoreplace. |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
460 */ |
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
461 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
|
462 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
|
463 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
464 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
|
465 { |
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
|
466 _vehicle_pool.CleanPool(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
467 |
10571
b6779abf2e96
(svn r14828) -Codechange: move most of save/load-specific code to separate files
smatz <smatz@openttd.org>
parents:
10546
diff
changeset
|
468 _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
|
469 ResetVehiclePosHash(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
470 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
471 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
472 Vehicle *GetLastVehicleInChain(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
|
473 { |
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
|
474 while (v->Next() != NULL) v = v->Next(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
475 return v; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
476 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
477 |
9344
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
478 const Vehicle *GetLastVehicleInChain(const Vehicle *v) |
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
479 { |
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
480 while (v->Next() != NULL) v = v->Next(); |
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
481 return v; |
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
482 } |
5940dd28c40d
(svn r13240) -Codechange: More const-ness for GUI code.
peter1138 <peter1138@openttd.org>
parents:
9340
diff
changeset
|
483 |
10647
592ae9307430
(svn r14949) -Cleanup: pointer coding style
rubidium <rubidium@openttd.org>
parents:
10642
diff
changeset
|
484 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
|
485 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
486 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
|
487 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
|
488 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
|
489 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
490 |
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
|
491 /** 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
|
492 * @param *v Vehicle to test |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
493 * @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
|
494 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
495 bool IsEngineCountable(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
|
496 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
497 switch (v->type) { |
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
|
498 case VEH_AIRCRAFT: return IsNormalAircraft(v); // don't count plane shadows and helicopter rotors |
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
|
499 case 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
|
500 return !IsArticulatedPart(v) && // tenders and other articulated parts |
7526
e463f6756541
(svn r11045) -Codechange: added a function to tell if a vehicle is the rear part of a dualheaded train engine
bjarni <bjarni@openttd.org>
parents:
7512
diff
changeset
|
501 !IsRearDualheaded(v); // rear parts of multiheaded engines |
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
|
502 case VEH_ROAD: return IsRoadVehFront(v); |
0005a9ed1903
(svn r10097) -Feature: Add support for articulated road vehicles, or callbacks 11 and 17 for
maedhros <maedhros@openttd.org>
parents:
6838
diff
changeset
|
503 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
|
504 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
|
505 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
506 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
507 |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
508 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
|
509 { |
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
|
510 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
|
511 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
512 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
|
513 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
|
514 |
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
|
515 HideFillingPercent(&this->fill_percent_te_id); |
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
|
516 } |
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
|
517 |
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
|
518 if (IsEngineCountable(this)) { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
519 Company::Get(this->owner)->num_engines[this->engine_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
|
520 if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); |
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
|
521 |
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
|
522 DeleteGroupHighlightOfVehicle(this); |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
523 if (Group::IsValidID(this->group_id)) Group::Get(this->group_id)->num_engines[this->engine_type]--; |
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
|
524 if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id); |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5940
diff
changeset
|
525 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
526 |
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
|
527 if (this->type == VEH_ROAD) ClearSlot(this); |
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
|
528 if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) { |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
529 Aircraft *a = (Aircraft *)this; |
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
530 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
|
531 if (st != NULL) { |
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
|
532 const AirportFTA *layout = st->Airport()->layout; |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
533 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
|
534 } |
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
|
535 } |
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
|
536 |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
537 if (this->type != VEH_TRAIN || (this->type == VEH_TRAIN && (IsFrontEngine(this) || IsFreeWagon(this)))) { |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
538 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
|
539 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
540 |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
541 if (this->IsPrimaryVehicle()) { |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 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
|
546 DeleteWindowById(WC_VEHICLE_TIMETABLE, this->index); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
547 InvalidateWindow(WC_COMPANY, this->owner); |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
548 } |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
549 InvalidateWindowClassesData(GetWindowClassForVehicleType(this->type), 0); |
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
550 |
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
|
551 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
|
552 DeleteVehicleOrders(this); |
10493
5531e81401ee
(svn r14748) -Codechange: unduplicate window updating when deleting vehicles.
rubidium <rubidium@openttd.org>
parents:
10492
diff
changeset
|
553 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
|
554 |
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
|
555 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
|
556 StopGlobalFollowVehicle(this); |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
557 } |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
558 |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
559 Vehicle::~Vehicle() |
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
560 { |
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
|
561 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
|
562 |
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
|
563 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
|
564 |
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
|
565 /* 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
|
566 * 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
|
567 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
|
568 |
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
|
569 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
|
570 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
|
571 |
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
|
572 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
|
573 |
7412
6682e85ffa07
(svn r10798) -Fix [FS#1105]: virtual functions do not work in destructors :(.
rubidium <rubidium@openttd.org>
parents:
7400
diff
changeset
|
574 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
|
575 DeleteVehicleNews(this->index, INVALID_STRING_ID); |
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
|
576 } |
6324d82f421d
(svn r10770) -Codechange: use the pool item class as super class for the vehicle struct.
rubidium <rubidium@openttd.org>
parents:
7387
diff
changeset
|
577 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
578 /** Adds a vehicle to the list of vehicles, that visited a depot this tick |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
579 * @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
|
580 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
581 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
|
582 { |
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
|
583 /* 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
|
584 _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
|
585 |
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
|
586 /* 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
|
587 * 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
|
588 * 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
|
589 * 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
|
590 * 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
|
591 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
|
592 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
593 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6198
diff
changeset
|
594 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
|
595 { |
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
|
596 _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
|
597 |
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
|
598 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
|
599 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
|
600 |
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
|
601 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
|
602 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
|
603 /* 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
|
604 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
|
605 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
|
606 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
|
607 } |
11970
2286db6ac0bb
(svn r16376) -Codechange: Vehicle::Tick() now returns false if the vehicle was deleted
smatz <smatz@openttd.org>
parents:
11951
diff
changeset
|
608 |
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
|
609 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
|
610 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
611 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
|
612 default: break; |
c751437b3bac
(svn r9841) -Codechange: add a little more type strictness to the vehicle types.
rubidium <rubidium@openttd.org>
parents:
6616
diff
changeset
|
613 |
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
|
614 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
|
615 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
|
616 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
|
617 case VEH_SHIP: |
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
|
618 if (v->type == VEH_TRAIN && IsTrainWagon(v)) continue; |
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
|
619 if (v->type == VEH_AIRCRAFT && v->subtype != AIR_HELICOPTER) continue; |
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
|
620 if (v->type == VEH_ROAD && !IsRoadVehFront(v)) 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
|
621 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
622 v->motion_counter += (v->direction & 1) ? (v->cur_speed * 3) / 4 : v->cur_speed; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
623 /* 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
|
624 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
|
625 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
626 /* 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
|
627 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
|
628 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
629 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
630 |
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
|
631 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
|
632 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
|
633 /* Autoreplace needs the current company set as the vehicle owner */ |
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
|
634 _current_company = v->owner; |
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
|
635 |
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
|
636 /* 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
|
637 * 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
|
638 * 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
|
639 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
|
640 |
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
|
641 /* 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
|
642 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
|
643 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
|
644 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
|
645 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
646 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
|
647 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
|
648 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
|
649 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
|
650 |
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
|
651 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
|
652 |
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
|
653 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
|
654 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
|
655 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
|
656 } |
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
|
657 |
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
|
658 StringID error_message = res.GetErrorMessage(); |
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
|
659 if (error_message == STR_AUTOREPLACE_NOTHING_TO_DO || error_message == INVALID_STRING_ID) 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
|
660 |
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
|
661 if (error_message == STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY) error_message = STR_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
|
662 |
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
|
663 StringID 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
|
664 if (error_message == STR_TRAIN_TOO_LONG_AFTER_REPLACEMENT) { |
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
|
665 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
|
666 } else { |
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
|
667 message = STR_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
|
668 } |
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
|
669 |
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
|
670 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
|
671 SetDParam(1, 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
|
672 AddNewsItem(message, NS_ADVICE, v->index, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
673 } |
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
|
674 |
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
|
675 _current_company = OWNER_NONE; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
676 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
677 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
678 /** Check if a given engine type can be refitted to a given cargo |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
679 * @param engine_type Engine type to check |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
680 * @param cid_to check refit to this cargo-type |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
681 * @return true if it is possible, false otherwise |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
682 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
683 bool CanRefitTo(EngineID engine_type, CargoID cid_to) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
684 { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
685 return HasBit(EngInfo(engine_type)->refit_mask, cid_to); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
686 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
687 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
688 /** Find the first cargo type that an engine can be refitted to. |
6484
17fdaec13730
(svn r9665) -Documentation: Doxygen corrections,errors, corrections of corrections...
belugas <belugas@openttd.org>
parents:
6453
diff
changeset
|
689 * @param engine_type Which engine to find cargo for. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
690 * @return A climate dependent cargo type. CT_INVALID is returned if not refittable. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
691 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
692 CargoID FindFirstRefittableCargo(EngineID engine_type) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
694 uint32 refit_mask = EngInfo(engine_type)->refit_mask; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
695 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
696 if (refit_mask != 0) { |
6350
8132258640be
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
peter1138 <peter1138@openttd.org>
parents:
6331
diff
changeset
|
697 for (CargoID cid = 0; cid < NUM_CARGO; cid++) { |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
698 if (HasBit(refit_mask, cid)) return cid; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
699 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
700 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
701 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
702 return CT_INVALID; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
703 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
704 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
705 /** Learn the price of refitting a certain engine |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
706 * @param engine_type Which engine to refit |
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
707 * @return Price for refitting |
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11354
diff
changeset
|
708 */ |
6943
fd42cb9816c6
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium <rubidium@openttd.org>
parents:
6905
diff
changeset
|
709 CommandCost GetRefitCost(EngineID engine_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
|
710 { |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
711 Money base_cost; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
712 ExpensesType expense_type; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
713 switch (Engine::Get(engine_type)->type) { |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
714 case VEH_SHIP: |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
715 base_cost = _price.ship_base; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
716 expense_type = EXPENSES_SHIP_RUN; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
717 break; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
718 |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
719 case VEH_ROAD: |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
720 base_cost = _price.roadveh_base; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
721 expense_type = EXPENSES_ROADVEH_RUN; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
722 break; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
723 |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
724 case VEH_AIRCRAFT: |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
725 base_cost = _price.aircraft_base; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
726 expense_type = EXPENSES_AIRCRAFT_RUN; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
727 break; |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
728 |
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
|
729 case VEH_TRAIN: |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
730 base_cost = 2 * ((RailVehInfo(engine_type)->railveh_type == RAILVEH_WAGON) ? |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
731 _price.build_railwagon : _price.build_railvehicle); |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
732 expense_type = EXPENSES_TRAIN_RUN; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
733 break; |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
734 |
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
735 default: NOT_REACHED(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
736 } |
8230
5b61305fcdd4
(svn r11793) -Codechange: pass the expense type via the CommandCost instead of a global variable. Patch by Noldo (FS#1114).
rubidium <rubidium@openttd.org>
parents:
8224
diff
changeset
|
737 return CommandCost(expense_type, (EngInfo(engine_type)->refit_cost * base_cost) >> 10); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
738 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
739 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
740 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
|
741 { |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
742 SpriteID image = v->cur_image; |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
743 SpriteID pal = PAL_NONE; |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
744 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
745 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
|
746 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
747 AddSortableSpriteToDraw(image, pal, v->x_pos + v->x_offs, v->y_pos + v->y_offs, |
8793
27556e5b9388
(svn r12531) -Codechange: Rename some variables for consistency.
frosch <frosch@openttd.org>
parents:
8786
diff
changeset
|
748 v->x_extent, v->y_extent, v->z_extent, v->z_pos, (v->vehstatus & VS_SHADOW) != 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
749 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
750 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
751 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
|
752 { |
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
|
753 /* 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
|
754 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
|
755 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
|
756 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
|
757 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
|
758 |
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
|
759 /* 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
|
760 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
|
761 |
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
|
762 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
|
763 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
|
764 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
|
765 } 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
|
766 /* 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
|
767 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
|
768 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
|
769 } |
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
|
770 |
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
|
771 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
|
772 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
|
773 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
|
774 } 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
|
775 /* 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
|
776 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
|
777 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
|
778 } |
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
|
779 |
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
|
780 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
|
781 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
|
782 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
|
783 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 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
|
790 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
|
791 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
792 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
|
793 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
794 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
795 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
|
796 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
797 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
798 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
|
799 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
800 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
801 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 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
|
803 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
804 Vehicle *found = NULL, *v; |
10236
59398a628f10
(svn r14464) -Codechange: replace (uint)-1 with UINT_MAX (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10225
diff
changeset
|
805 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
|
806 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
807 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
|
808 |
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
|
809 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
|
810 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
|
811 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
812 FOR_ALL_VEHICLES(v) { |
10642
29bc871ff8d1
(svn r14944) -Cleanup: add spaces around some operators
rubidium <rubidium@openttd.org>
parents:
10634
diff
changeset
|
813 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
|
814 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
|
815 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
|
816 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 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
|
818 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
|
819 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
|
820 ); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
821 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
822 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
|
823 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
|
824 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
|
825 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
827 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
828 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
829 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
|
830 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 |
7803
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
832 void CheckVehicle32Day(Vehicle *v) |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
833 { |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
834 if ((v->day_counter & 0x1F) != 0) return; |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
835 |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
836 uint16 callback = GetVehicleCallback(CBID_VEHICLE_32DAY_CALLBACK, 0, 0, v->engine_type, v); |
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
837 if (callback == CALLBACK_FAILED) return; |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
838 if (HasBit(callback, 0)) TriggerVehicle(v, VEHICLE_TRIGGER_CALLBACK_32); // Trigger vehicle trigger 10 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
839 if (HasBit(callback, 1)) v->colourmap = PAL_NONE; // Update colourmap via callback 2D |
7803
1ad76d7d65b8
(svn r11353) -Codechange: add support for newgrf callback 32
glx <glx@openttd.org>
parents:
7802
diff
changeset
|
840 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
841 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
842 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
|
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 v->value -= v->value >> 8; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
845 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
846 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
847 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
848 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
858 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
859 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
|
860 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
861 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
|
862 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
863 /* 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
|
864 v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0); |
8980
b4160d91b7c7
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
865 if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(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
|
866 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
867 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
|
868 _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
|
869 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
|
870 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
871 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
872 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
873 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
|
874 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
875 /* increase chance of failure */ |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
876 int chance = v->breakdown_chance + 1; |
8980
b4160d91b7c7
(svn r12772) -Codechange: some vehicle.cpp coding style.
rubidium <rubidium@openttd.org>
parents:
8970
diff
changeset
|
877 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
|
878 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
|
879 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
880 /* 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
|
881 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
|
882 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
|
883 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
884 /* 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
|
885 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
|
886 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
887 /* 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
|
888 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
|
889 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
|
890 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
|
891 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
894 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
895 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
|
896 { |
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
|
897 if (v->age < 65535) v->age++; |
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
|
898 |
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
|
899 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
|
900 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
|
901 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
|
902 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
|
903 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
905 InvalidateWindow(WC_VEHICLE_DETAILS, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
906 |
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
|
907 /* 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
|
908 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
|
909 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
910 /* 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
|
911 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
|
912 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
913 StringID str; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
914 if (age == -DAYS_IN_LEAP_YEAR) { |
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
|
915 str = STR_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
|
916 } else if (age == 0) { |
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
|
917 str = STR_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
|
918 } else if (age > 0 && (age % DAYS_IN_LEAP_YEAR) == 0) { |
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
|
919 str = STR_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
|
920 } 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
|
921 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
|
922 } |
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
|
923 |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
924 SetDParam(0, v->index); |
a24b53317bd0
(svn r15318) -Fix [FS#2594](r10288): don't warn about non-primary engines getting old
smatz <smatz@openttd.org>
parents:
10960
diff
changeset
|
925 AddNewsItem(str, NS_ADVICE, v->index, 0); |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
927 |
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
|
928 /** |
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
|
929 * 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
|
930 * @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
|
931 * @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
|
932 * @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
|
933 */ |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
934 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
|
935 { |
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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 |
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
|
942 const Vehicle *u = v; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
943 const Station *st = v->last_station_visited != INVALID_STATION ? Station::Get(v->last_station_visited) : 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
|
944 |
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
|
945 /* 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 unloading += HasBit(v->vehicle_flags, VF_CARGO_UNLOADING) ? 1 : 0; |
8855
2acce887e7ec
(svn r12617) -Codechange: add type safety to the Order's load and unload types.
rubidium <rubidium@openttd.org>
parents:
8853
diff
changeset
|
951 loading |= !(u->current_order.GetUnloadType() & OUFB_UNLOAD) && 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
|
952 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
|
953 } |
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
|
954 } |
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
|
955 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
956 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
|
957 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
|
958 *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
|
959 } 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
|
960 *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
|
961 } else { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
962 *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
|
963 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
964 } |
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
|
965 |
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
|
966 /* 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
|
967 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
|
968 |
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
|
969 /* 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
|
970 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
|
971 } |
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
|
972 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
973 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
|
974 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 switch (v->type) { |
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
|
976 case 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
|
977 InvalidateWindowClasses(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
|
978 /* Clear path reservation */ |
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
|
979 SetDepotWaypointReservation(v->tile, false); |
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
|
980 if (_settings_client.gui.show_track_reservation) MarkTileDirtyByTile(v->tile); |
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
|
981 |
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
|
982 if (!IsFrontEngine(v)) v = v->First(); |
8300
ae1baac75172
(svn r11864) -Codechange: pass owner whose signals we will update instead of complex detection later
smatz <smatz@openttd.org>
parents:
8270
diff
changeset
|
983 UpdateSignalsOnSegment(v->tile, INVALID_DIAGDIR, v->owner); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
984 v->load_unload_time_rem = 0; |
8938
46aa51321117
(svn r12711) -Codechange: remove unneeded loops
glx <glx@openttd.org>
parents:
8914
diff
changeset
|
985 ClrBit(v->u.rail.flags, VRF_TOGGLE_REVERSE); |
9704
e1476334067a
(svn r13816) -Fix [FS#2150]: check for vehicle length changes outside a depot (callback 0x11) and give a warning about that
smatz <smatz@openttd.org>
parents:
9652
diff
changeset
|
986 TrainConsistChanged(v, 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
|
987 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
988 |
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
|
989 case VEH_ROAD: |
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 InvalidateWindowClasses(WC_ROADVEH_LIST); |
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
|
991 if (!IsRoadVehFront(v)) v = v->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
|
992 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
993 |
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
|
994 case VEH_SHIP: |
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 InvalidateWindowClasses(WC_SHIPS_LIST); |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
996 static_cast<Ship*>(v)->state = TRACK_BIT_DEPOT; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
997 RecalcShipStuff(v); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
998 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
999 |
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
|
1000 case VEH_AIRCRAFT: |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1001 InvalidateWindowClasses(WC_AIRCRAFT_LIST); |
11981
cf1aad9b971c
(svn r16387) -Codechange: use Aircraft instead of Vehicle where appropriate
rubidium <rubidium@openttd.org>
parents:
11976
diff
changeset
|
1002 HandleAircraftEnterHangar((Aircraft *)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
|
1003 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1004 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
|
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 |
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
|
1007 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
|
1008 /* 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
|
1009 * 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
|
1010 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
|
1011 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1012 InvalidateWindow(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
|
1013 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1014 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
|
1015 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
|
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 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
|
1018 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1019 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
|
1020 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1021 if (v->current_order.IsType(OT_GOTO_DEPOT)) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1022 InvalidateWindow(WC_VEHICLE_VIEW, v->index); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1023 |
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
|
1024 const Order *real_order = GetVehicleOrder(v, v->cur_order_index); |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1025 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
|
1026 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
|
1027 |
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
|
1028 /* 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
|
1029 * 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
|
1030 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
|
1031 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
|
1032 (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
|
1033 /* 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
|
1034 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
|
1035 } |
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
|
1036 |
8838
db9c6b0c9f07
(svn r12586) -Codechange: do not access an order's refit variables directly.
rubidium <rubidium@openttd.org>
parents:
8837
diff
changeset
|
1037 if (t.IsRefit()) { |
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
|
1038 _current_company = v->owner; |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1039 CommandCost cost = DoCommand(v->tile, v->index, t.GetRefitCargo() | t.GetRefitSubtype() << 8, DC_EXEC, GetCmdRefitVeh(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
|
1040 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1041 if (CmdFailed(cost)) { |
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
|
1042 _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
|
1043 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
|
1044 /* 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
|
1045 SetDParam(0, v->index); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9224
diff
changeset
|
1046 AddNewsItem(STR_ORDER_REFIT_FAILED, NS_ADVICE, v->index, 0); |
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 } |
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
|
1048 } else if (v->owner == _local_company && cost.GetCost() != 0) { |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6946
diff
changeset
|
1049 ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost.GetCost()); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1050 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1051 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1052 |
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
|
1053 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
|
1054 /* Part of orders */ |
7070
c856638fde6e
(svn r10335) -Fix (r10331): Increment the current order index *after* using it in UpdateVehicleTimetable.
maedhros <maedhros@openttd.org>
parents:
7038
diff
changeset
|
1055 UpdateVehicleTimetable(v, true); |
11866
1e159ef634d5
(svn r16260) -Codechange: Add Vehicle::IncrementOrderIndex() to deduplicate some code.
frosch <frosch@openttd.org>
parents:
11852
diff
changeset
|
1056 v->IncrementOrderIndex(); |
10285
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1057 } |
615db2678973
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
rubidium <rubidium@openttd.org>
parents:
10260
diff
changeset
|
1058 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
|
1059 /* 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
|
1060 _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
|
1061 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
|
1062 StringID string; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1063 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1064 switch (v->type) { |
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
|
1065 case VEH_TRAIN: string = STR_VEHICLE_STATUS_WAITING_IN_DEPOT; break; |
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
|
1066 case VEH_ROAD: string = STR_NEWS_ROAD_VEHICLE_IS_WAITING; break; |
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
|
1067 case VEH_SHIP: string = STR_NEWS_SHIP_IS_WAITING; break; |
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
|
1068 case VEH_AIRCRAFT: string = STR_NEWS_AIRCRAFT_IS_WAITING; break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1069 default: NOT_REACHED(); string = STR_EMPTY; // Set the string to something to avoid a compiler warning |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1070 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1071 |
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
|
1072 SetDParam(0, v->index); |
9234
02827bf3dc03
(svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents:
9224
diff
changeset
|
1073 AddNewsItem(string, NS_ADVICE, v->index, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1074 } |
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
|
1075 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
|
1076 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1077 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1078 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1079 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1080 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1081 /** |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1082 * Move a vehicle in the game state; that is moving it's position in |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1083 * the position hashes and marking it's location in the viewport dirty |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1084 * if requested. |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1085 * @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
|
1086 * @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
|
1087 */ |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1088 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
|
1089 { |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1090 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
|
1091 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
|
1092 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
|
1093 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1094 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
|
1095 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
|
1096 |
11326
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1097 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
|
1098 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1099 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
|
1100 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
|
1101 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
|
1102 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
|
1103 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
|
1104 |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1105 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
|
1106 MarkAllViewportsDirty( |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 ); |
557dd16a7c24
(svn r15676) -Codechange: remove the need for BeginVehicleMove and merge VehiclePositionChanged and EndVehicleMove.
rubidium <rubidium@openttd.org>
parents:
11322
diff
changeset
|
1112 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1113 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1114 |
8317
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1115 /** |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1116 * 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
|
1117 * 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
|
1118 * 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
|
1119 * @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
|
1120 * @see BeginVehicleMove() |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1121 * @see EndVehicleMove() |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1122 */ |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1123 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
|
1124 { |
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
|
1125 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
|
1126 } |
7ce2445db70c
(svn r11882) -Codechange: introduce MarkSingleVehicleDirty() and simplify the code at some places
smatz <smatz@openttd.org>
parents:
8309
diff
changeset
|
1127 |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1128 /** |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1129 * 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
|
1130 * @param v Vehicle to move |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1131 * @return Position information after the move */ |
6153 | 1132 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
|
1133 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1134 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
|
1135 -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
|
1136 -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
|
1137 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1138 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1139 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
|
1140 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
|
1141 |
6153 | 1142 GetNewVehiclePosResult gp; |
1143 gp.x = x; | |
1144 gp.y = y; | |
1145 gp.old_tile = v->tile; | |
1146 gp.new_tile = TileVirtXY(x, y); | |
1147 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
|
1148 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1149 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1150 static const Direction _new_direction_table[] = { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1151 DIR_N , DIR_NW, DIR_W , |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1152 DIR_NE, DIR_SE, DIR_SW, |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1153 DIR_E , DIR_SE, DIR_S |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1154 }; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1155 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1156 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
|
1157 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1158 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
|
1159 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1160 if (y >= v->y_pos) { |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1161 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
|
1162 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
|
1163 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1164 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1165 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
|
1166 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
|
1167 i++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1168 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1169 |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1170 Direction dir = v->direction; |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1171 |
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1172 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
|
1173 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
|
1174 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
|
1175 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1176 |
5991
1b793d99b5ba
(svn r8698) -Codechange: enumify the returns of VehicleEnterTile
rubidium <rubidium@openttd.org>
parents:
5955
diff
changeset
|
1177 /** |
10260
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1178 * 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
|
1179 * @param v Vehicle entering the tile |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1180 * @param tile Tile entered |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1181 * @param x X position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1182 * @param y Y position |
d23fed9a51e2
(svn r14491) -Documentation: updates/additions of doxygen docs (Alberth)
rubidium <rubidium@openttd.org>
parents:
10236
diff
changeset
|
1183 * @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
|
1184 * @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
|
1185 */ |
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
|
1186 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
|
1187 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1188 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
|
1189 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1190 |
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
|
1191 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
|
1192 { |
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
|
1193 /* 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
|
1194 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
|
1195 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
|
1196 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
|
1197 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
|
1198 } |
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
|
1199 } |
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
|
1200 |
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
|
1201 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
|
1202 |
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
|
1203 this->maxid++; // so there is space for last item (with v->unitnumber == maxid) |
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
|
1204 this->maxid++; // this one will always be free (well, it will fail when there are 65535 units, so this overflows) |
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
|
1205 |
11216
dc1618a3d6fa
(svn r15569) -Codechange: replace MallocT + memset( 0 ) calls by CallocT
smatz <smatz@openttd.org>
parents:
11188
diff
changeset
|
1206 this->cache = CallocT<bool>(this->maxid); |
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
|
1207 |
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
|
1208 /* 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
|
1209 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
|
1210 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
|
1211 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
|
1212 } |
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
|
1213 } |
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
|
1214 } |
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
|
1215 |
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
|
1216 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
|
1217 { |
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
|
1218 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
|
1219 |
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
|
1220 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
|
1221 |
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
|
1222 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
|
1223 } |
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
|
1224 |
6641
a988a86b0d0a
(svn r9872) -Codechange: more type strictness for vehicle types
rubidium <rubidium@openttd.org>
parents:
6638
diff
changeset
|
1225 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
|
1226 { |
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
|
1227 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
|
1228 |
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
|
1229 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
|
1230 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1231 |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1232 |
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
|
1233 /** |
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
|
1234 * 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
|
1235 * 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
|
1236 * 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
|
1237 * @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
|
1238 * @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
|
1239 * 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
|
1240 */ |
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
|
1241 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
|
1242 { |
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
|
1243 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
|
1244 |
11924
fccc9cea27a7
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
smatz <smatz@openttd.org>
parents:
11922
diff
changeset
|
1245 if (!Company::IsValidID(_local_company)) return false; |
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
|
1246 if (_settings_client.gui.always_build_infrastructure) 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
|
1247 |
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
|
1248 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
|
1249 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
|
1250 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
|
1251 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
|
1252 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
|
1253 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
|
1254 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
|
1255 } |
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
|
1256 |
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
|
1257 /* 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
|
1258 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
|
1259 /* 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
|
1260 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
|
1261 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
|
1262 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
|
1263 } |
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
|
1264 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
|
1265 } |
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
|
1266 |
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
|
1267 /* 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
|
1268 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
|
1269 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
|
1270 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
|
1271 } |
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
|
1272 |
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
|
1273 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
|
1274 } |
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
|
1275 |
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
|
1276 |
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
|
1277 const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID parent_engine_type, 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
|
1278 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1279 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
|
1280 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
|
1281 CargoID cargo_type = v == NULL ? (CargoID)CT_INVALID : v->cargo_type; |
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1282 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1283 /* 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
|
1284 * whether any _other_ liveries are 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
|
1285 if (c->livery[LS_DEFAULT].in_use && (_settings_client.gui.liveries == 2 || (_settings_client.gui.liveries == 1 && 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
|
1286 /* Determine the livery scheme to use */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1287 const Engine *e = Engine::Get(engine_type); |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1288 switch (e->type) { |
6638
5479975c4e36
(svn r9869) -Codechange: replace some bytes with VehicleType, i.e. more type strictness.
rubidium <rubidium@openttd.org>
parents:
6626
diff
changeset
|
1289 default: NOT_REACHED(); |
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
|
1290 case VEH_TRAIN: { |
5763 | 1291 const RailVehicleInfo *rvi = RailVehInfo(engine_type); |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1292 if (v != NULL && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (IsArticulatedPart(v) && rvi->railveh_type != RAILVEH_WAGON))) { |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1293 /* Wagonoverrides use the coloir scheme of the front engine. |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1294 * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1295 engine_type = parent_engine_type; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1296 e = Engine::Get(engine_type); |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1297 rvi = RailVehInfo(engine_type); |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1298 /* Note: Luckily cargo_type is not needed for engines */ |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1299 } |
5763 | 1300 |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1301 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1302 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
8309
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1303 if (rvi->railveh_type == RAILVEH_WAGON) { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1304 if (!GetCargo(cargo_type)->is_freight) { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1305 if (parent_engine_type == INVALID_ENGINE) { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1306 scheme = LS_PASSENGER_WAGON_STEAM; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1307 } else { |
8309
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1308 switch (RailVehInfo(parent_engine_type)->engclass) { |
6585
454eaee93e8a
(svn r9799) -Codechange: separate engine class and engine running cost class (mart3p).
rubidium <rubidium@openttd.org>
parents:
6581
diff
changeset
|
1309 default: NOT_REACHED(); |
8309
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1310 case EC_STEAM: scheme = LS_PASSENGER_WAGON_STEAM; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1311 case EC_DIESEL: scheme = LS_PASSENGER_WAGON_DIESEL; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1312 case EC_ELECTRIC: scheme = LS_PASSENGER_WAGON_ELECTRIC; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1313 case EC_MONORAIL: scheme = LS_PASSENGER_WAGON_MONORAIL; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1314 case EC_MAGLEV: scheme = LS_PASSENGER_WAGON_MAGLEV; break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1315 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1316 } |
8309
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1317 } else { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1318 scheme = LS_FREIGHT_WAGON; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1319 } |
8309
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1320 } else { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1321 bool is_mu = HasBit(EngInfo(engine_type)->misc_flags, EF_RAIL_IS_MU); |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1322 |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1323 switch (rvi->engclass) { |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1324 default: NOT_REACHED(); |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1325 case EC_STEAM: scheme = LS_STEAM; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1326 case EC_DIESEL: scheme = is_mu ? LS_DMU : LS_DIESEL; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1327 case EC_ELECTRIC: scheme = is_mu ? LS_EMU : LS_ELECTRIC; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1328 case EC_MONORAIL: scheme = LS_MONORAIL; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1329 case EC_MAGLEV: scheme = LS_MAGLEV; break; |
132c40a27dfb
(svn r11874) -Fix [FS#1655]: all wagons of maglev/monorail trains would get the livery colour of the engine instead of their wagon type.
rubidium <rubidium@openttd.org>
parents:
8302
diff
changeset
|
1330 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1331 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1332 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1333 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1334 |
6259
4a39d6291d58
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium <rubidium@openttd.org>
parents:
6248
diff
changeset
|
1335 case VEH_ROAD: { |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1336 /* Always use the livery of the front */ |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1337 if (v != NULL && parent_engine_type != INVALID_ENGINE) { |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1338 engine_type = parent_engine_type; |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1339 e = Engine::Get(engine_type); |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1340 cargo_type = v->First()->cargo_type; |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1341 } |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1342 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1343 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1344 |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1345 /* Important: Use Tram Flag of front part. Luckily engine_type refers to the front part here. */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1346 if (HasBit(EngInfo(engine_type)->misc_flags, EF_ROAD_TRAM)) { |
6724
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1347 /* Tram */ |
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1348 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_TRAM : LS_FREIGHT_TRAM; |
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1349 } else { |
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1350 /* Bus or truck */ |
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1351 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_BUS : LS_TRUCK; |
de30d61ce253
(svn r9956) -Codechange: Add tram livery schemes
peter1138 <peter1138@openttd.org>
parents:
6721
diff
changeset
|
1352 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1353 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1354 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1355 |
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
|
1356 case VEH_SHIP: { |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1357 if (cargo_type == CT_INVALID) cargo_type = e->GetDefaultCargoType(); |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1358 if (cargo_type == CT_INVALID) cargo_type = CT_GOODS; // The vehicle does not carry anything, let's pick some freight cargo |
6330
1838edf26c08
(svn r9302) -Codechange: Use cargo class to test for passengers when deciding on the livery scheme to use.
peter1138 <peter1138@openttd.org>
parents:
6264
diff
changeset
|
1359 scheme = IsCargoInClass(cargo_type, CC_PASSENGERS) ? LS_PASSENGER_SHIP : LS_FREIGHT_SHIP; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1360 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1361 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1362 |
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
|
1363 case VEH_AIRCRAFT: { |
11188
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11167
diff
changeset
|
1364 switch (e->u.air.subtype) { |
5855
ba456601f207
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater <Darkvater@openttd.org>
parents:
5854
diff
changeset
|
1365 case AIR_HELI: scheme = LS_HELICOPTER; break; |
ba456601f207
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater <Darkvater@openttd.org>
parents:
5854
diff
changeset
|
1366 case AIR_CTOL: scheme = LS_SMALL_PLANE; break; |
ba456601f207
(svn r8429) -Codechange: Add a name for AircraftVehicleInfo subtype helicopter and remove some magic numbers related to the subtype.
Darkvater <Darkvater@openttd.org>
parents:
5854
diff
changeset
|
1367 case AIR_CTOL | AIR_FAST: scheme = LS_LARGE_PLANE; break; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1368 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1369 break; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1370 } |
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1373 /* 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
|
1374 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
|
1375 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1376 |
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
|
1377 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
|
1378 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1379 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1380 |
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
|
1381 static SpriteID 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
|
1382 { |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1383 SpriteID 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
|
1384 |
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
|
1385 /* 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
|
1386 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
|
1387 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1388 /* Check if we should use the colour map callback */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1389 if (HasBit(EngInfo(engine_type)->callbackmask, 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
|
1390 uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v); |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1391 /* A return value of 0xC000 is stated to "use the default two-colour |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1392 * maps" which happens to be the failure action too... */ |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1393 if (callback != CALLBACK_FAILED && callback != 0xC000) { |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1394 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
|
1395 /* 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
|
1396 * 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
|
1397 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
|
1398 /* Update cache */ |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1399 if (v != NULL) ((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
|
1400 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
|
1401 } |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1402 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1403 } |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1404 |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1405 bool twocc = HasBit(EngInfo(engine_type)->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
|
1406 |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1407 if (map == PAL_NONE) map = twocc ? (SpriteID)SPR_2CCMAP_BASE : (SpriteID)PALETTE_RECOLOUR_START; |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1408 |
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
|
1409 const Livery *livery = GetEngineLivery(engine_type, company, parent_engine_type, v); |
6516
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1410 |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1411 map += livery->colour1; |
f8eb4662e1e5
(svn r9702) -Codechange: Add livery support to newgrf vehicle var 43
peter1138 <peter1138@openttd.org>
parents:
6509
diff
changeset
|
1412 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
|
1413 |
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
|
1414 /* Update cache */ |
11085
8da1855e9f14
(svn r15428) -Codechange: consistently use colour instead of having both color and colour.
rubidium <rubidium@openttd.org>
parents:
10996
diff
changeset
|
1415 if (v != NULL) ((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
|
1416 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
|
1417 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1418 |
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
|
1419 SpriteID 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
|
1420 { |
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
|
1421 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
|
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 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5651
diff
changeset
|
1424 SpriteID 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
|
1425 { |
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
|
1426 if (v->type == VEH_TRAIN) { |
11167
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1427 return GetEngineColourMap(v->engine_type, v->owner, v->u.rail.first_engine, v); |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1428 } else if (v->type == VEH_ROAD) { |
2194f431a931
(svn r15517) -Fix [FS#2642](r6455): Wagonoverrides and articulated engine parts use the colour scheme of the engine, but not its recolour callback, nor its 2CC flag. Same applies to roadvehicles.
frosch <frosch@openttd.org>
parents:
11090
diff
changeset
|
1429 return GetEngineColourMap(v->engine_type, v->owner, v->u.road.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
|
1430 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1431 |
5717
5e23e918212d
(svn r8211) -Codechange: (NewGRF) Implement callback 2D, explicit vehicle colour map
peter1138 <peter1138@openttd.org>
parents:
5693
diff
changeset
|
1432 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
|
1433 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1434 |
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
|
1435 |
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
|
1436 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
|
1437 { |
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
|
1438 assert(IsTileType(tile, MP_STATION) || type == VEH_SHIP); |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1439 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1440 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
|
1441 this->current_order.GetDestination() == this->last_station_visited) { |
8881
4fd35184e35f
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1442 current_order.MakeLoading(true); |
4fd35184e35f
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1443 UpdateVehicleTimetable(this, true); |
4fd35184e35f
(svn r12648) -Feature: allow four different non-stop types in a single game instead of two. The "TTDP compatible order" setting now only sets the default behaviour of new trains.
rubidium <rubidium@openttd.org>
parents:
8862
diff
changeset
|
1444 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1445 /* 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
|
1446 * 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
|
1447 * 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
|
1448 * 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
|
1449 * 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
|
1450 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
|
1451 |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1452 } else { |
8843
1f412a20da48
(svn r12593) -Codechange: hide Order's flags in most of the code.
rubidium <rubidium@openttd.org>
parents:
8840
diff
changeset
|
1453 current_order.MakeLoading(false); |
6550
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1454 } |
2fa52ce08b41
(svn r9752) -Codechange: remove some duplication related to BeginLoading.
rubidium <rubidium@openttd.org>
parents:
6546
diff
changeset
|
1455 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1456 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
|
1457 |
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
|
1458 VehiclePayment(this); |
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
|
1459 |
9043
9d514f6b9e04
(svn r12862) -Codechange: reduce code duplication for VehicleType -> WindowClass lookup
smatz <smatz@openttd.org>
parents:
9041
diff
changeset
|
1460 InvalidateWindow(GetWindowClassForVehicleType(this->type), this->owner); |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1461 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
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
|
1462 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
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
|
1463 InvalidateWindow(WC_STATION_VIEW, this->last_station_visited); |
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
|
1464 |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1465 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
|
1466 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
|
1467 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
|
1468 } |
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
|
1469 |
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
|
1470 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
|
1471 { |
8837
bdaf8866039c
(svn r12585) -Fix (r12584): assumption that assertions were enabled during compilation/testing was flawed.
rubidium <rubidium@openttd.org>
parents:
8836
diff
changeset
|
1472 assert(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
|
1473 |
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
|
1474 /* Only update the timetable if the vehicle was supposed to stop here. */ |
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
|
1475 if (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
|
1476 |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1477 current_order.MakeLeaveStation(); |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11913
diff
changeset
|
1478 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
|
1479 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
|
1480 |
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
|
1481 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
|
1482 |
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
|
1483 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
|
1484 /* Trigger station animation (trains only) */ |
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
|
1485 if (IsTileType(this->tile, MP_STATION)) StationAnimationTrigger(st, this->tile, STAT_ANIM_TRAIN_DEPARTS); |
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
|
1486 |
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
|
1487 /* Try to reserve a path when leaving the station as we |
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
|
1488 * might not be marked as wanting a reservation, e.g. |
9975
df1e34818bb9
(svn r14132) -Fix (r14039): Only reserve a path on leaving a station if the current block really is a PBS block. (michi_cc)
frosch <frosch@openttd.org>
parents:
9955
diff
changeset
|
1489 * when an overlength train gets turned around in a station. */ |
11976
7f11f2a71193
(svn r16382) -Codechange: make GetVehicleTrackdir a member function of Vehicle.
rubidium <rubidium@openttd.org>
parents:
11972
diff
changeset
|
1490 if (UpdateSignalsOnSegment(this->tile, TrackdirToExitdir(this->GetVehicleTrackdir()), this->owner) == SIGSEG_PBS || _settings_game.pf.reserve_paths) { |
9975
df1e34818bb9
(svn r14132) -Fix (r14039): Only reserve a path on leaving a station if the current block really is a PBS block. (michi_cc)
frosch <frosch@openttd.org>
parents:
9955
diff
changeset
|
1491 TryPathReserve(this, true, true); |
df1e34818bb9
(svn r14132) -Fix (r14039): Only reserve a path on leaving a station if the current block really is a PBS block. (michi_cc)
frosch <frosch@openttd.org>
parents:
9955
diff
changeset
|
1492 } |
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
|
1493 } |
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
|
1494 } |
6558
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
1495 |
2fc024ee8217
(svn r9760) -Codechange: remove the need for saving some vehicle variables.
rubidium <rubidium@openttd.org>
parents:
6553
diff
changeset
|
1496 |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1497 void Vehicle::HandleLoading(bool mode) |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1498 { |
8836
890a77315801
(svn r12584) -Codechange: do not access the order type directly.
rubidium <rubidium@openttd.org>
parents:
8793
diff
changeset
|
1499 switch (this->current_order.GetType()) { |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1500 case OT_LOADING: { |
6980
cb6b3e277df0
(svn r10236) -Feature: Introduce a form of timetabling for vehicles.
maedhros <maedhros@openttd.org>
parents:
6955
diff
changeset
|
1501 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
|
1502 |
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
|
1503 /* Not the first call for this tick, or still loading */ |
7928
4e8dfd103163
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13 <skidd13@openttd.org>
parents:
7923
diff
changeset
|
1504 if (mode || !HasBit(this->vehicle_flags, VF_LOADING_FINISHED) || |
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
|
1505 (_settings_game.order.timetabling && 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
|
1506 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1507 this->PlayLeaveStationSound(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1508 |
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
|
1509 bool at_destination_station = this->current_order.GetNonStopType() != ONSF_STOP_EVERYWHERE; |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1510 this->LeaveStation(); |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1511 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1512 /* If this was not the final order, don't remove it from the list. */ |
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
|
1513 if (!at_destination_station) return; |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1514 break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1515 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1516 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1517 case OT_DUMMY: break; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1518 |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1519 default: return; |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1520 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1521 |
11866
1e159ef634d5
(svn r16260) -Codechange: Add Vehicle::IncrementOrderIndex() to deduplicate some code.
frosch <frosch@openttd.org>
parents:
11852
diff
changeset
|
1522 this->IncrementOrderIndex(); |
6594
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1523 } |
7535dcf42683
(svn r9808) -Codechange: unify the Handle<VehicleType>Loading functions.
rubidium <rubidium@openttd.org>
parents:
6585
diff
changeset
|
1524 |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11085
diff
changeset
|
1525 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
|
1526 { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1527 if (!CheckOwnership(this->owner)) return CMD_ERROR; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1528 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
|
1529 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
|
1530 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1531 if (this->current_order.IsType(OT_GOTO_DEPOT)) { |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1532 bool halt_in_depot = this->current_order.GetDepotActionType() & ODATFB_HALT; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1533 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
|
1534 /* 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
|
1535 * 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
|
1536 * 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
|
1537 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
|
1538 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
|
1539 this->current_order.SetDepotActionType(halt_in_depot ? ODATF_SERVICE_ONLY : ODATFB_HALT); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1540 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1541 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1542 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1543 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1544 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1545 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
|
1546 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
|
1547 /* 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
|
1548 * then skip to the next order; effectively cancelling this forced service */ |
11866
1e159ef634d5
(svn r16260) -Codechange: Add Vehicle::IncrementOrderIndex() to deduplicate some code.
frosch <frosch@openttd.org>
parents:
11852
diff
changeset
|
1549 if (this->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) this->IncrementOrderIndex(); |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1550 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1551 this->current_order.MakeDummy(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1552 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1553 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1554 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1555 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1556 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1557 TileIndex location; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1558 DestinationID destination; |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1559 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
|
1560 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
|
1561 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
|
1562 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1563 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
|
1564 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
|
1565 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1566 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
|
1567 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
|
1568 if (!(command & DEPOT_SERVICE)) this->current_order.SetDepotActionType(ODATFB_HALT); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1569 InvalidateWindowWidget(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1570 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1571 /* 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
|
1572 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
|
1573 |
11982
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1574 if (this->type == VEH_AIRCRAFT) { |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1575 Aircraft *a = (Aircraft *)this; |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1576 if (a->state == FLYING && a->targetairport != destination) { |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1577 /* 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
|
1578 extern void AircraftNextAirportPos_and_Order(Aircraft *a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1579 AircraftNextAirportPos_and_Order(a); |
9add5306a01e
(svn r16388) -Codechange: move u.air to Aircraft
rubidium <rubidium@openttd.org>
parents:
11981
diff
changeset
|
1580 } |
8892
bb542150b318
(svn r12659) -Cleanup: some style cleanups in vehicle.cpp.
rubidium <rubidium@openttd.org>
parents:
8891
diff
changeset
|
1581 } |
8891
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1582 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1583 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1584 return CommandCost(); |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1585 |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1586 } |
384f81a7ba31
(svn r12658) -Codechange: unify a vast portion of the CmdSend<VehicleType>ToDepot commands.
rubidium <rubidium@openttd.org>
parents:
8881
diff
changeset
|
1587 |
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
|
1588 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
|
1589 { |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1590 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
|
1591 /* 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
|
1592 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
|
1593 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
|
1594 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1595 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
|
1596 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1597 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1598 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
|
1599 |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1600 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
|
1601 /* 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
|
1602 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
|
1603 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
|
1604 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
|
1605 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
|
1606 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1607 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1608 } |
797ff0b0e0a5
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
rubidium <rubidium@openttd.org>
parents:
7493
diff
changeset
|
1609 |
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
|
1610 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
|
1611 { |
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
|
1612 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
|
1613 |
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
|
1614 if (!shared_chain->orders.list) { |
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
|
1615 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
|
1616 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
|
1617 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
|
1618 } |
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
|
1619 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1620 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
|
1621 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
|
1622 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1623 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
|
1624 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1625 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
|
1626 |
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
|
1627 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
|
1628 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1629 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1630 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
|
1631 { |
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
|
1632 /* 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
|
1633 * 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
|
1634 bool were_first = (this->FirstShared() == 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
|
1635 uint32 old_window_number = (this->FirstShared()->index << 16) | (this->type << 11) | VLW_SHARED_ORDERS | this->owner; |
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
|
1636 |
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
|
1637 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
|
1638 |
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
|
1639 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
|
1640 /* 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
|
1641 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
|
1642 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1643 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1644 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
|
1645 |
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
|
1646 |
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
|
1647 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
|
1648 /* When there is only one vehicle, remove the shared order list window. */ |
9942
5885cda280e8
(svn r14097) -Fix [FS#2085]: one couldn't get a list of vehicles sharing an order when the number of orders was 0; you could see that the vehicles had a shared order though.
rubidium <rubidium@openttd.org>
parents:
9941
diff
changeset
|
1649 DeleteWindowById(GetWindowClassForVehicleType(this->type), old_window_number); |
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
|
1650 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
|
1651 } 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
|
1652 /* 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
|
1653 * Note: FirstShared() is already the new 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
|
1654 InvalidateWindowData(GetWindowClassForVehicleType(this->type), old_window_number, (this->FirstShared()->index << 16) | (1 << 15)); |
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
|
1655 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1656 |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1657 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
|
1658 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
|
1659 } |
53ba5561b1c2
(svn r14096) -Codechange: merge the shared order's vehicle list management to a single location.
rubidium <rubidium@openttd.org>
parents:
9940
diff
changeset
|
1660 |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1661 void StopAllVehicles() |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1662 { |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1663 Vehicle *v; |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1664 FOR_ALL_VEHICLES(v) { |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1665 /* Code ripped from CmdStartStopTrain. Can't call it, because of |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1666 * ownership problems, so we'll duplicate some code, for now */ |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1667 v->vehstatus |= VS_STOPPED; |
8350
8cde0dcc6818
(svn r11916) -Codechange: use enums from VehicleViewWindowWidgets instead of constants
smatz <smatz@openttd.org>
parents:
8317
diff
changeset
|
1668 InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); |
8144
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1669 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1670 } |
d18c8a0bb638
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
1671 } |
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
|
1672 |
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
|
1673 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
|
1674 { |
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
|
1675 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
|
1676 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
|
1677 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
|
1678 /* 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
|
1679 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
|
1680 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
|
1681 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
|
1682 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
|
1683 SetDParam(1, profit); |
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
|
1684 AddNewsItem( |
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
|
1685 STR_VEHICLE_IS_UNPROFITABLE, |
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
|
1686 NS_ADVICE, |
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
|
1687 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
|
1688 0); |
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
|
1689 } |
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
|
1690 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
|
1691 } |
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
|
1692 |
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
|
1693 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
|
1694 v->profit_this_year = 0; |
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
|
1695 InvalidateWindow(WC_VEHICLE_DETAILS, 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
|
1696 } |
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
|
1697 } |
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
|
1698 } |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1699 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1700 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1701 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1702 * 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
|
1703 * @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
|
1704 * @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
|
1705 * @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
|
1706 * @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
|
1707 * 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
|
1708 * 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
|
1709 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1710 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
|
1711 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11924
diff
changeset
|
1712 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
|
1713 assert(e != NULL); |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1714 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1715 switch (e->type) { |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1716 case VEH_TRAIN: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1717 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
|
1718 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1719 case VEH_ROAD: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1720 /* 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
|
1721 * 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
|
1722 * 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
|
1723 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
|
1724 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1725 case VEH_SHIP: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1726 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
|
1727 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1728 case VEH_AIRCRAFT: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1729 return (st->facilities & FACIL_AIRPORT) != 0 && |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1730 (st->Airport()->flags & (e->u.air.subtype & AIR_CTOL ? AirportFTAClass::AIRPLANES : AirportFTAClass::HELICOPTERS)) != 0; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1731 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1732 default: |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1733 return false; |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1734 } |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1735 } |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1736 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1737 /** |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1738 * 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
|
1739 * @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
|
1740 * @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
|
1741 * @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
|
1742 */ |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1743 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
|
1744 { |
10679
da30046c7acf
(svn r14990) -Codechange: handle articulated RVs and trams more strictly in GetStationTileForVehicle and CanVehicleUseStation (based on idea by Swallow)
rubidium <rubidium@openttd.org>
parents:
10656
diff
changeset
|
1745 if (v->type == VEH_ROAD) return st->GetPrimaryRoadStop(v) != NULL; |
10650
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1746 |
92ff04e7b1d9
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
rubidium <rubidium@openttd.org>
parents:
10647
diff
changeset
|
1747 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
|
1748 } |