Mercurial > hg > openttd
annotate src/engine.cpp @ 18767:50f4f95caf36 draft
(svn r23615) -Add: more API functions exposed to NoGo (part 2)
author | truebrain <truebrain@openttd.org> |
---|---|
date | Mon, 19 Dec 2011 20:57:34 +0000 |
parents | 5604c42fa1ce |
children | 88567087417f |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
12778
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
3 /* |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
4 * This file is part of OpenTTD. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
8 */ |
bc7926153e19
(svn r17248) -Fix: add GPL license notice where appropriate
rubidium <rubidium@openttd.org>
parents:
12743
diff
changeset
|
9 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
9070
diff
changeset
|
10 /** @file engine.cpp Base for all engine handling. */ |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
11 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "stdafx.h" |
10208
39cf8eebfda5
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents:
10207
diff
changeset
|
13 #include "company_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
|
14 #include "command_func.h" |
8763
d6e363672edb
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium <rubidium@openttd.org>
parents:
8633
diff
changeset
|
15 #include "news_func.h" |
5854
b52317eb405c
(svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater <Darkvater@openttd.org>
parents:
5840
diff
changeset
|
16 #include "aircraft.h" |
12232
b5e93af93fc2
(svn r16647) -Codechange: remove newgrf.h include from newgrf_engine.h to prevent unnecessary inclusion newgrf.h anyway
yexo <yexo@openttd.org>
parents:
12170
diff
changeset
|
17 #include "newgrf.h" |
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:
9036
diff
changeset
|
18 #include "newgrf_engine.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:
6606
diff
changeset
|
19 #include "group.h" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
7931
diff
changeset
|
20 #include "strings_func.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10927
diff
changeset
|
21 #include "core/random_func.hpp" |
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:
8121
diff
changeset
|
22 #include "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
23 #include "date_func.h" |
8212
11263ebe590a
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents:
8144
diff
changeset
|
24 #include "autoreplace_gui.h" |
8214
6385dffc0b37
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium <rubidium@openttd.org>
parents:
8212
diff
changeset
|
25 #include "string_func.h" |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10656
diff
changeset
|
26 #include "ai/ai.hpp" |
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:
11951
diff
changeset
|
27 #include "core/pool_func.hpp" |
12837
a6a46b1b7ad9
(svn r17327) -Codechange: Allow external use of GetEngineCategoryName().
alberth <alberth@openttd.org>
parents:
12808
diff
changeset
|
28 #include "engine_gui.h" |
14258
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
13804
diff
changeset
|
29 #include "engine_func.h" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
13804
diff
changeset
|
30 #include "engine_base.h" |
a899d4e5ee1a
(svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents:
13804
diff
changeset
|
31 #include "company_base.h" |
17235
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
32 #include "vehicle_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
|
33 |
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
|
34 #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
|
35 #include "table/engines.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
|
36 |
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:
11951
diff
changeset
|
37 EnginePool _engine_pool("Engine"); |
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:
11951
diff
changeset
|
38 INSTANTIATE_POOL_METHODS(Engine) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
39 |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
40 EngineOverrideManager _engine_mngr; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
41 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
42 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
43 * Year that engine aging stops. Engines will not reduce in reliability |
15623
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
44 * and no more engines will be introduced |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
45 */ |
13508
f7e05f44c9be
(svn r18027) -Codechange: make some unneededly global variables static and remove some unused variables
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
46 static Year _year_engine_aging_stops; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
47 |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
48 /** |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
49 * The railtypes that have been or never will be introduced, or |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
50 * an inverse bitmap of rail types that have to be introduced. */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
51 static uint16 _introduced_railtypes; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
52 |
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:
9036
diff
changeset
|
53 /** Number of engines of each vehicle type in original engine data */ |
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:
9036
diff
changeset
|
54 const uint8 _engine_counts[4] = { |
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:
9036
diff
changeset
|
55 lengthof(_orig_rail_vehicle_info), |
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:
9036
diff
changeset
|
56 lengthof(_orig_road_vehicle_info), |
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:
9036
diff
changeset
|
57 lengthof(_orig_ship_vehicle_info), |
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:
9036
diff
changeset
|
58 lengthof(_orig_aircraft_vehicle_info), |
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:
9036
diff
changeset
|
59 }; |
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:
9036
diff
changeset
|
60 |
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:
9036
diff
changeset
|
61 /** Offset of the first engine of each vehicle type in original engine data */ |
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:
9036
diff
changeset
|
62 const uint8 _engine_offsets[4] = { |
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:
9036
diff
changeset
|
63 0, |
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:
9036
diff
changeset
|
64 lengthof(_orig_rail_vehicle_info), |
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:
9036
diff
changeset
|
65 lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info), |
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:
9036
diff
changeset
|
66 lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info), |
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:
9036
diff
changeset
|
67 }; |
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:
9036
diff
changeset
|
68 |
13249
f52dcc31398e
(svn r17758) -Revert (r17208): Use assert_compile() if you cannot count.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
69 assert_compile(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info)); |
f52dcc31398e
(svn r17758) -Revert (r17208): Use assert_compile() if you cannot count.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
70 |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
71 const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT]; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
72 |
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:
9036
diff
changeset
|
73 Engine::Engine() : |
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:
9036
diff
changeset
|
74 name(NULL), |
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:
9036
diff
changeset
|
75 overrides_count(0), |
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:
9036
diff
changeset
|
76 overrides(NULL) |
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:
9036
diff
changeset
|
77 { |
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:
9036
diff
changeset
|
78 } |
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:
9036
diff
changeset
|
79 |
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:
9036
diff
changeset
|
80 Engine::Engine(VehicleType type, EngineID base) |
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:
9036
diff
changeset
|
81 { |
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:
9036
diff
changeset
|
82 this->type = type; |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15653
diff
changeset
|
83 this->grf_prop.local_id = base; |
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:
9036
diff
changeset
|
84 this->list_position = base; |
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:
9036
diff
changeset
|
85 |
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:
9036
diff
changeset
|
86 /* Check if this base engine is within the original engine data range */ |
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:
9036
diff
changeset
|
87 if (base >= _engine_counts[type]) { |
10427
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
88 /* Set model life to maximum to make wagons available */ |
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
89 this->info.base_life = 0xFF; |
14772
01bc0c785114
(svn r19360) -Add: [NewGRF] When the tractive effort of a road vehicle is not set, use a default value of 4C.
terkhen <terkhen@openttd.org>
parents:
14759
diff
changeset
|
90 /* Set road vehicle tractive effort to the default value */ |
01bc0c785114
(svn r19360) -Add: [NewGRF] When the tractive effort of a road vehicle is not set, use a default value of 4C.
terkhen <terkhen@openttd.org>
parents:
14759
diff
changeset
|
91 if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C; |
17891
9728faf89121
(svn r22690) -Fix: [NewGRF] Aircrafts defined with IDs above the default aircrafts always defaulted to passenger cargo.
frosch <frosch@openttd.org>
parents:
17640
diff
changeset
|
92 /* Aircraft must have CT_INVALID as default, as there is no property */ |
9728faf89121
(svn r22690) -Fix: [NewGRF] Aircrafts defined with IDs above the default aircrafts always defaulted to passenger cargo.
frosch <frosch@openttd.org>
parents:
17640
diff
changeset
|
93 if (type == VEH_AIRCRAFT) this->info.cargo_type = CT_INVALID; |
16513
37ad611b8ce7
(svn r21239) -Codechange/Fix: [NewGRF] Use 0xFF instead of 0 as default value for visual effect. This makes setting train prop 22 to 0 actually work (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16385
diff
changeset
|
94 /* Set visual effect to the default value */ |
16514
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
95 switch (type) { |
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
96 case VEH_TRAIN: this->u.rail.visual_effect = VE_DEFAULT; break; |
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
97 case VEH_ROAD: this->u.road.visual_effect = VE_DEFAULT; break; |
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
98 case VEH_SHIP: this->u.ship.visual_effect = VE_DEFAULT; break; |
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
99 default: break; // The aircraft, disasters and especially visual effects have no NewGRF configured visual effects |
0f4c60894d9b
(svn r21240) -Feature: [NewGRF] Implement action0 visual effect properties for ships and RVs (Hirundo)
rubidium <rubidium@openttd.org>
parents:
16513
diff
changeset
|
100 } |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17891
diff
changeset
|
101 /* Set cargo aging period to the default value. */ |
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17891
diff
changeset
|
102 this->info.cargo_age_period = CARGO_AGING_TICKS; |
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:
9036
diff
changeset
|
103 return; |
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:
9036
diff
changeset
|
104 } |
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:
9036
diff
changeset
|
105 |
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:
9036
diff
changeset
|
106 /* Copy the original engine info for this slot */ |
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:
9036
diff
changeset
|
107 this->info = _orig_engine_info[_engine_offsets[type] + base]; |
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:
9036
diff
changeset
|
108 |
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:
9036
diff
changeset
|
109 /* Copy the original engine data for this slot */ |
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:
9036
diff
changeset
|
110 switch (type) { |
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:
9036
diff
changeset
|
111 default: NOT_REACHED(); |
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:
9036
diff
changeset
|
112 |
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:
9036
diff
changeset
|
113 case VEH_TRAIN: |
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:
9036
diff
changeset
|
114 this->u.rail = _orig_rail_vehicle_info[base]; |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12082
diff
changeset
|
115 this->original_image_index = this->u.rail.image_index; |
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:
11408
diff
changeset
|
116 this->info.string_id = STR_VEHICLE_NAME_TRAIN_ENGINE_RAIL_KIRBY_PAUL_TANK_STEAM + base; |
10427
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
117 |
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
118 /* Set the default model life of original wagons to "infinite" */ |
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
119 if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF; |
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
120 |
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:
9036
diff
changeset
|
121 break; |
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:
9036
diff
changeset
|
122 |
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:
9036
diff
changeset
|
123 case VEH_ROAD: |
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:
9036
diff
changeset
|
124 this->u.road = _orig_road_vehicle_info[base]; |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12082
diff
changeset
|
125 this->original_image_index = this->u.road.image_index; |
12484
4cdaa2d25b01
(svn r16921) -Codechange: make it more clear what strings are related to road vehicles; only ROAD isn't always enough. Also unify the way of writing it.
rubidium <rubidium@openttd.org>
parents:
12384
diff
changeset
|
126 this->info.string_id = STR_VEHICLE_NAME_ROAD_VEHICLE_MPS_REGAL_BUS + base; |
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:
9036
diff
changeset
|
127 break; |
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:
9036
diff
changeset
|
128 |
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:
9036
diff
changeset
|
129 case VEH_SHIP: |
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:
9036
diff
changeset
|
130 this->u.ship = _orig_ship_vehicle_info[base]; |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12082
diff
changeset
|
131 this->original_image_index = this->u.ship.image_index; |
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:
11408
diff
changeset
|
132 this->info.string_id = STR_VEHICLE_NAME_SHIP_MPS_OIL_TANKER + base; |
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:
9036
diff
changeset
|
133 break; |
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:
9036
diff
changeset
|
134 |
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:
9036
diff
changeset
|
135 case VEH_AIRCRAFT: |
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:
9036
diff
changeset
|
136 this->u.air = _orig_aircraft_vehicle_info[base]; |
12164
d1a94177c6ec
(svn r16580) -Codechange: rename Engine::image_index to original_image_index to not confuse it with image_index from *VehInfo.
rubidium <rubidium@openttd.org>
parents:
12082
diff
changeset
|
137 this->original_image_index = this->u.air.image_index; |
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:
11408
diff
changeset
|
138 this->info.string_id = STR_VEHICLE_NAME_AIRCRAFT_SAMPSON_U52 + base; |
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:
9036
diff
changeset
|
139 break; |
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:
9036
diff
changeset
|
140 } |
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:
9036
diff
changeset
|
141 } |
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:
9036
diff
changeset
|
142 |
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:
9036
diff
changeset
|
143 Engine::~Engine() |
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:
9036
diff
changeset
|
144 { |
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:
9036
diff
changeset
|
145 UnloadWagonOverrides(this); |
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:
9036
diff
changeset
|
146 free(this->name); |
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:
9036
diff
changeset
|
147 } |
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:
9036
diff
changeset
|
148 |
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:
11171
diff
changeset
|
149 /** |
17246
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
150 * Checks whether the engine spec is properly initialised. |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
151 * @return true if enabled |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
152 */ |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
153 bool Engine::IsEnabled() const |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
154 { |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
155 return this->info.string_id != STR_NEWGRF_INVALID_ENGINE; |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
156 } |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
157 |
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
158 /** |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
159 * Retrieve the GRF ID of the NewGRF the engine is tied to. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
160 * This is the GRF providing the Action 3. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
161 * @return GRF ID of the associated NewGRF. |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
162 */ |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
163 uint32 Engine::GetGRFID() const |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
164 { |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
165 const GRFFile *file = this->GetGRF(); |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
166 return file == NULL ? 0 : file->grfid; |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
167 } |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
168 |
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
169 /** |
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:
11171
diff
changeset
|
170 * Determines whether an engine can carry something. |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18656
diff
changeset
|
171 * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargoes is available in the climate. |
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:
11171
diff
changeset
|
172 * @return true if the vehicle can carry something. |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
173 */ |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
174 bool Engine::CanCarryCargo() const |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
175 { |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
176 /* For engines that can appear in a consist (i.e. rail vehicles and (articulated) road vehicles), a capacity |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
177 * of zero is a special case, to define the vehicle to not carry anything. The default cargotype is still used |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
178 * for livery selection etc. |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
179 * Note: Only the property is tested. A capacity callback returning 0 does not have the same effect. |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
180 */ |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
181 switch (this->type) { |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
182 case VEH_TRAIN: |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
183 if (this->u.rail.capacity == 0) return false; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
184 break; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
185 |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
186 case VEH_ROAD: |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
187 if (this->u.road.capacity == 0) return false; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
188 break; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
189 |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
190 case VEH_SHIP: |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
191 case VEH_AIRCRAFT: |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
192 break; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
193 |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
194 default: NOT_REACHED(); |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
195 } |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
196 return this->GetDefaultCargoType() != CT_INVALID; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
197 } |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
198 |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
199 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
200 /** |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
201 * Determines capacity of a given vehicle from scratch. |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
202 * For aircraft the main capacity is determined. Mail might be present as well. |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
203 * @param v Vehicle of interest; NULL in purchase list |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
204 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
205 * @return Capacity |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
206 */ |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
207 uint Engine::DetermineCapacity(const Vehicle *v, uint16 *mail_capacity) const |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
208 { |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
209 assert(v == NULL || this->index == v->engine_type); |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
210 if (mail_capacity != NULL) *mail_capacity = 0; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
211 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
212 if (!this->CanCarryCargo()) return 0; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
213 |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
214 CargoID default_cargo = this->GetDefaultCargoType(); |
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
215 CargoID cargo_type = (v != NULL) ? v->cargo_type : default_cargo; |
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
216 |
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
217 if (mail_capacity != NULL && this->type == VEH_AIRCRAFT && IsCargoInClass(cargo_type, CC_PASSENGERS)) { |
18338
1acd061c150f
(svn r23174) -Codechange: Deduplicate code between GetEngineProperty() and GetVehicleProperty().
frosch <frosch@openttd.org>
parents:
18337
diff
changeset
|
218 *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
219 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
220 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
221 /* Check the refit capacity callback if we are not in the default configuration. |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
222 * Note: This might change to become more consistent/flexible/sane, esp. when default cargo is first refittable. */ |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
223 if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
224 (default_cargo != cargo_type || (v != NULL && v->cargo_subtype != 0))) { |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
225 uint16 callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, this->index, v); |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
226 if (callback != CALLBACK_FAILED) return callback; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
227 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
228 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
229 /* Get capacity according to property resp. CB */ |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
230 uint capacity; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
231 switch (this->type) { |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
232 case VEH_TRAIN: |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
233 capacity = GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity, v); |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
234 |
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
235 /* In purchase list add the capacity of the second head. Always use the plain property for this. */ |
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
236 if (v == NULL && this->u.rail.railveh_type == RAILVEH_MULTIHEAD) capacity += this->u.rail.capacity; |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
237 break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
238 |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
239 case VEH_ROAD: |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
240 capacity = GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity, v); |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
241 break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
242 |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
243 case VEH_SHIP: |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
244 capacity = GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity, v); |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
245 break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
246 |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
247 case VEH_AIRCRAFT: |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
248 capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity, v); |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
249 if (!IsCargoInClass(cargo_type, CC_PASSENGERS)) { |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
250 capacity += GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
251 } |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
252 if (cargo_type == CT_MAIL) return capacity; |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
253 default_cargo = CT_PASSENGERS; // Always use 'passengers' wrt. cargo multipliers |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
254 break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
255 |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
256 default: NOT_REACHED(); |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
257 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
258 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
259 /* Apply multipliers depending on cargo- and vehicletype. |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
260 * Note: This might change to become more consistent/flexible. */ |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
261 if (this->type != VEH_SHIP && default_cargo != cargo_type) { |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
262 switch (default_cargo) { |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
263 case CT_PASSENGERS: break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
264 case CT_MAIL: |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
265 case CT_GOODS: capacity *= 2; break; |
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
266 default: capacity *= 4; break; |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
267 } |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
268 switch (cargo_type) { |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
269 case CT_PASSENGERS: break; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
270 case CT_MAIL: |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
271 case CT_GOODS: capacity /= 2; break; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
272 default: capacity /= 4; break; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
273 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
274 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
275 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
276 return capacity; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
277 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
278 |
11408
17fa6dfa4cb1
(svn r15763) -Codechange/Fix: Add Engine::GetDisplayDefaultCapacity() and use it everywhere, so CB 36 is also used everywhere.
frosch <frosch@openttd.org>
parents:
11361
diff
changeset
|
279 /** |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
280 * Return how much the running costs of this engine are. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
281 * @return Yearly running cost of the engine. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
282 */ |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
283 Money Engine::GetRunningCost() const |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
284 { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
285 Price base_price; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
286 uint cost_factor; |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
287 switch (this->type) { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
288 case VEH_ROAD: |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
289 base_price = this->u.road.running_cost_class; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
290 if (base_price == INVALID_PRICE) return 0; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
291 cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_RUNNING_COST_FACTOR, this->u.road.running_cost); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
292 break; |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
293 |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
294 case VEH_TRAIN: |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
295 base_price = this->u.rail.running_cost_class; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
296 if (base_price == INVALID_PRICE) return 0; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
297 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_RUNNING_COST_FACTOR, this->u.rail.running_cost); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
298 break; |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
299 |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
300 case VEH_SHIP: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
301 base_price = PR_RUNNING_SHIP; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
302 cost_factor = GetEngineProperty(this->index, PROP_SHIP_RUNNING_COST_FACTOR, this->u.ship.running_cost); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
303 break; |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
304 |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
305 case VEH_AIRCRAFT: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
306 base_price = PR_RUNNING_AIRCRAFT; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
307 cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_RUNNING_COST_FACTOR, this->u.air.running_cost); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
308 break; |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
309 |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
310 default: NOT_REACHED(); |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
311 } |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
312 |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
313 return GetPrice(base_price, cost_factor, this->GetGRF(), -8); |
10925
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
314 } |
2a462cb6c227
(svn r15261) -Add: added Engine::GetRunningCost() to remove some code duplication. Also stops AIs decrementing vehicle counter of first company
glx <glx@openttd.org>
parents:
10881
diff
changeset
|
315 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
316 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
317 * Return how much a new engine costs. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
318 * @return Cost of the engine. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
319 */ |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
320 Money Engine::GetCost() const |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
321 { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
322 Price base_price; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
323 uint cost_factor; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
324 switch (this->type) { |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
325 case VEH_ROAD: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
326 base_price = PR_BUILD_VEHICLE_ROAD; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
327 cost_factor = GetEngineProperty(this->index, PROP_ROADVEH_COST_FACTOR, this->u.road.cost_factor); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
328 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
329 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
330 case VEH_TRAIN: |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
331 if (this->u.rail.railveh_type == RAILVEH_WAGON) { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
332 base_price = PR_BUILD_VEHICLE_WAGON; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
333 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor); |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
334 } else { |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
335 base_price = PR_BUILD_VEHICLE_TRAIN; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
336 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor); |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
337 } |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
338 break; |
13492
eb34fcf7db5f
(svn r18011) -Feature(ette): [NewGRF] CB 36 for roadvehicle property 09 'running cost factor'.
frosch <frosch@openttd.org>
parents:
13486
diff
changeset
|
339 |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
340 case VEH_SHIP: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
341 base_price = PR_BUILD_VEHICLE_SHIP; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
342 cost_factor = GetEngineProperty(this->index, PROP_SHIP_COST_FACTOR, this->u.ship.cost_factor); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
343 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
344 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
345 case VEH_AIRCRAFT: |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
346 base_price = PR_BUILD_VEHICLE_AIRCRAFT; |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
347 cost_factor = GetEngineProperty(this->index, PROP_AIRCRAFT_COST_FACTOR, this->u.air.cost_factor); |
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
348 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
349 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
350 default: NOT_REACHED(); |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
351 } |
13741
775d368aa2b0
(svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents:
13508
diff
changeset
|
352 |
18239
e6cbcbf3780f
(svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents:
18152
diff
changeset
|
353 return GetPrice(base_price, cost_factor, this->GetGRF(), -8); |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
354 } |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
355 |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
356 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
357 * Returns max speed of the engine for display purposes |
10969
208ba3fba382
(svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents:
10967
diff
changeset
|
358 * @return max speed in km-ish/h |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
359 */ |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
360 uint Engine::GetDisplayMaxSpeed() const |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
361 { |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
362 switch (this->type) { |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
363 case VEH_TRAIN: |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13067
diff
changeset
|
364 return GetEngineProperty(this->index, PROP_TRAIN_SPEED, this->u.rail.max_speed); |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
365 |
16384
f39955ef4720
(svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents:
16347
diff
changeset
|
366 case VEH_ROAD: { |
f39955ef4720
(svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents:
16347
diff
changeset
|
367 uint max_speed = GetEngineProperty(this->index, PROP_ROADVEH_SPEED, 0); |
f39955ef4720
(svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents:
16347
diff
changeset
|
368 return (max_speed != 0) ? max_speed * 2 : this->u.road.max_speed / 2; |
f39955ef4720
(svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents:
16347
diff
changeset
|
369 } |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
370 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
371 case VEH_SHIP: |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13067
diff
changeset
|
372 return GetEngineProperty(this->index, PROP_SHIP_SPEED, this->u.ship.max_speed) / 2; |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
373 |
15043
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
374 case VEH_AIRCRAFT: { |
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
375 uint max_speed = GetEngineProperty(this->index, PROP_AIRCRAFT_SPEED, 0); |
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
376 if (max_speed != 0) { |
15511
fbbbb2791756
(svn r20164) -Fix [FS#3870]: inconsistencies w.r.t. to km/h vs km-ish/h as "base" unit for aircraft speeds
rubidium <rubidium@openttd.org>
parents:
15457
diff
changeset
|
377 return (max_speed * 128) / 10; |
15043
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
378 } |
10969
208ba3fba382
(svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents:
10967
diff
changeset
|
379 return this->u.air.max_speed; |
15043
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
380 } |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
381 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
382 default: NOT_REACHED(); |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
383 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
384 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
385 |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
386 /** |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
387 * Returns the power of the engine for display |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
388 * and sorting purposes. |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
389 * Only trains and road vehicles have power |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
390 * @return power in display units hp |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
391 */ |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
392 uint Engine::GetPower() const |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
393 { |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
394 /* Only trains and road vehicles have 'power'. */ |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
395 switch (this->type) { |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
396 case VEH_TRAIN: |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13067
diff
changeset
|
397 return GetEngineProperty(this->index, PROP_TRAIN_POWER, this->u.rail.power); |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
398 case VEH_ROAD: |
16347
8c9974e20b1c
(svn r21058) -Feature [NewGRF]: Add CB36 support for road vehicle properties 0x13 (Power), 0x14 (Weight) and 0x18 (Tractive effort).
terkhen <terkhen@openttd.org>
parents:
16160
diff
changeset
|
399 return GetEngineProperty(this->index, PROP_ROADVEH_POWER, this->u.road.power) * 10; |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
400 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
401 default: NOT_REACHED(); |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
402 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
403 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
404 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
405 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
406 * Returns the weight of the engine for display purposes. |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
407 * For dual-headed train-engines this is the weight of both heads |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
408 * @return weight in display units metric tons |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
409 */ |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
410 uint Engine::GetDisplayWeight() const |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
411 { |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
412 /* Only trains and road vehicles have 'weight'. */ |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
413 switch (this->type) { |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
414 case VEH_TRAIN: |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13067
diff
changeset
|
415 return GetEngineProperty(this->index, PROP_TRAIN_WEIGHT, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0); |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
416 case VEH_ROAD: |
16347
8c9974e20b1c
(svn r21058) -Feature [NewGRF]: Add CB36 support for road vehicle properties 0x13 (Power), 0x14 (Weight) and 0x18 (Tractive effort).
terkhen <terkhen@openttd.org>
parents:
16160
diff
changeset
|
417 return GetEngineProperty(this->index, PROP_ROADVEH_WEIGHT, this->u.road.weight) / 4; |
10967
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
418 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
419 default: NOT_REACHED(); |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
420 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
421 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
422 |
11171
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
423 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
424 * Returns the tractive effort of the engine for display purposes. |
11171
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
425 * For dual-headed train-engines this is the tractive effort of both heads |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
426 * @return tractive effort in display units kN |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
427 */ |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
428 uint Engine::GetDisplayMaxTractiveEffort() const |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
429 { |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
430 /* Only trains and road vehicles have 'tractive effort'. */ |
11171
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
431 switch (this->type) { |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
432 case VEH_TRAIN: |
13114
940252f91c5f
(svn r17616) -Codechange [FS#3222]: Enumerize properties used in callback 0x36. Based on Terkhen's work.
frosch <frosch@openttd.org>
parents:
13067
diff
changeset
|
433 return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_TRAIN_TRACTIVE_EFFORT, this->u.rail.tractive_effort)) / 256; |
14759
04bf2dc98085
(svn r19347) -Add: Vehicle GUI now shows power, weight and tractive effort for road vehicles.
terkhen <terkhen@openttd.org>
parents:
14641
diff
changeset
|
434 case VEH_ROAD: |
16347
8c9974e20b1c
(svn r21058) -Feature [NewGRF]: Add CB36 support for road vehicle properties 0x13 (Power), 0x14 (Weight) and 0x18 (Tractive effort).
terkhen <terkhen@openttd.org>
parents:
16160
diff
changeset
|
435 return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, PROP_ROADVEH_TRACTIVE_EFFORT, this->u.road.tractive_effort)) / 256; |
11171
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
436 |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
437 default: NOT_REACHED(); |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
438 } |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
439 } |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
440 |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
441 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
442 * Returns the vehicle's (not model's!) life length in days. |
12165
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
443 * @return the life length |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
444 */ |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
445 Date Engine::GetLifeLengthInDays() const |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
446 { |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
447 /* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */ |
12170
ff38719a9687
(svn r16586) -Codechange: don't store lifelength in the savegame; it can easily be calculated, it isn't used often and now changing extend_vehicle_life in game has some effect.
rubidium <rubidium@openttd.org>
parents:
12165
diff
changeset
|
448 return (this->info.lifelength + _settings_game.vehicle.extend_vehicle_life) * DAYS_IN_LEAP_YEAR; |
12165
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
449 } |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
450 |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
451 /** |
18656
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
452 * Get the range of an aircraft type. |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
453 * @return Range of the aircraft type in tiles or 0 if unlimited range. |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
454 */ |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
455 uint16 Engine::GetRange() const |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
456 { |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
457 switch (this->type) { |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
458 case VEH_AIRCRAFT: |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
459 return GetEngineProperty(this->index, PROP_AIRCRAFT_RANGE, this->u.air.max_range); |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
460 |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
461 default: NOT_REACHED(); |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
462 } |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
463 } |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
464 |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
465 /** |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
466 * Initializes the EngineOverrideManager with the default engines. |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
467 */ |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
468 void EngineOverrideManager::ResetToDefaultMapping() |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
469 { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
470 this->Clear(); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
471 for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
472 for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
473 EngineIDMapping *eid = this->Append(); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
474 eid->type = type; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
475 eid->grfid = INVALID_GRFID; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
476 eid->internal_id = internal_id; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
477 eid->substitute_id = internal_id; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
478 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
479 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
480 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
481 |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
482 /** |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
483 * Looks up an EngineID in the EngineOverrideManager |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
484 * @param type Vehicle type |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
485 * @param grf_local_id The local id in the newgrf |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
486 * @param grfid The GrfID that defines the scope of grf_local_id. |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
487 * If a newgrf overrides the engines of another newgrf, the "scope grfid" is the ID of the overridden newgrf. |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
488 * If dynnamic_engines is disabled, all newgrf share the same ID scope identified by INVALID_GRFID. |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
489 * @return The engine ID if present, or INVALID_ENGINE if not. |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
490 */ |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
491 EngineID EngineOverrideManager::GetID(VehicleType type, uint16 grf_local_id, uint32 grfid) |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
492 { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
493 const EngineIDMapping *end = this->End(); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
494 EngineID index = 0; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
495 for (const EngineIDMapping *eid = this->Begin(); eid != end; eid++, index++) { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
496 if (eid->type == type && eid->grfid == grfid && eid->internal_id == grf_local_id) { |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
497 return index; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
498 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
499 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
500 return INVALID_ENGINE; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
501 } |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
502 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
503 /** |
17235
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
504 * Tries to reset the engine mapping to match the current NewGRF configuration. |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
505 * This is only possible when there are currently no vehicles in the game. |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
506 * @return false if resetting failed due to present vehicles. |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
507 */ |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
508 bool EngineOverrideManager::ResetToCurrentNewGRFConfig() |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
509 { |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
510 const Vehicle *v; |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
511 FOR_ALL_VEHICLES(v) { |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
512 if (IsCompanyBuildableVehicleType(v)) return false; |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
513 } |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
514 |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
515 /* Reset the engines, they will get new EngineIDs */ |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
516 _engine_mngr.ResetToDefaultMapping(); |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
517 ReloadNewGRFData(); |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
518 |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
519 return true; |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
520 } |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
521 |
3f6432af5795
(svn r21975) -Add: console command to reset the engine pool. It removes the traces of engines which are no longer associated to a NewGRF, and can be used to e.g. 'fix' scenarios which were screwed up by the author. You can only use it when there are no vehicles in the game though.
frosch <frosch@openttd.org>
parents:
17105
diff
changeset
|
522 /** |
17285
be523f4fc2cb
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
smatz <smatz@openttd.org>
parents:
17247
diff
changeset
|
523 * Initialise the engine pool with the data from the original vehicles. |
be523f4fc2cb
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
smatz <smatz@openttd.org>
parents:
17247
diff
changeset
|
524 */ |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
525 void SetupEngines() |
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
526 { |
17247
5221777879f1
(svn r21987) -Fix: Make news items, engine previews and AI preview events deal with no longer existing Engine items after resetting the pool.
frosch <frosch@openttd.org>
parents:
17246
diff
changeset
|
527 DeleteWindowByClass(WC_ENGINE_PREVIEW); |
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:
11951
diff
changeset
|
528 _engine_pool.CleanPool(); |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
529 |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
530 assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
531 const EngineIDMapping *end = _engine_mngr.End(); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
532 uint index = 0; |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
533 for (const EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) { |
17285
be523f4fc2cb
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
smatz <smatz@openttd.org>
parents:
17247
diff
changeset
|
534 /* Assert is safe; there won't be more than 256 original vehicles |
be523f4fc2cb
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
smatz <smatz@openttd.org>
parents:
17247
diff
changeset
|
535 * in any case, and we just cleaned the pool. */ |
be523f4fc2cb
(svn r22025) -Fix: verify there is enough space in the pool when creating new pool items while loading old savegames
smatz <smatz@openttd.org>
parents:
17247
diff
changeset
|
536 assert(Engine::CanAllocateItem()); |
11296
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
537 const Engine *e = new Engine(eid->type, eid->internal_id); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
538 assert(e->index == index); |
1b6a11831215
(svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents:
11238
diff
changeset
|
539 } |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
540 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
541 _introduced_railtypes = 0; |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
542 } |
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
543 |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
544 /** |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
545 * Check whether the railtypes should be introduced. |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
546 */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
547 static void CheckRailIntroduction() |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
548 { |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
549 /* All railtypes have been introduced. */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
550 if (_introduced_railtypes == UINT16_MAX || Company::GetPoolSize() == 0) return; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
551 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
552 /* We need to find the railtypes that are known to all companies. */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
553 RailTypes rts = (RailTypes)UINT16_MAX; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
554 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
555 /* We are at, or past the introduction date of the rail. */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
556 Company *c; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
557 FOR_ALL_COMPANIES(c) { |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
558 c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes, _date); |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
559 rts &= c->avail_railtypes; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
560 } |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
561 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
562 _introduced_railtypes |= rts; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
563 } |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
564 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
565 void ShowEnginePreviewWindow(EngineID engine); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
567 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
568 * Determine whether an engine type is a wagon (and not a loco). |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
569 * @param index %Engine getting queried. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
570 * @return Whether the queried engine is a wagon. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
571 */ |
9468
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
572 static bool IsWagon(EngineID index) |
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
573 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
574 const Engine *e = Engine::Get(index); |
9468
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
575 return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; |
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
576 } |
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
577 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
578 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
579 * Update #reliability of engine \a e, (if needed) update the engine GUIs. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
580 * @param e %Engine to update. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
581 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
582 static void CalcEngineReliability(Engine *e) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
583 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
584 uint age = e->age; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 |
6606
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
586 /* Check for early retirement */ |
10427
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
587 if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) { |
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:
9036
diff
changeset
|
588 int retire_early = e->info.retire_early; |
8509
721797d63deb
(svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch <frosch@openttd.org>
parents:
8479
diff
changeset
|
589 uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); |
721797d63deb
(svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch <frosch@openttd.org>
parents:
8479
diff
changeset
|
590 if (retire_early != 0 && age >= retire_early_max_age) { |
6606
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
591 /* Early retirement is enabled and we're past the date... */ |
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:
10148
diff
changeset
|
592 e->company_avail = 0; |
6606
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
593 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
594 } |
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
595 } |
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
596 |
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 if (age < e->duration_phase_1) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 uint start = e->reliability_start; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
599 e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
10427
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
600 } else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
601 /* We are at the peak of this engines life. It will have max reliability. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
602 * This is also true if the engines never expire. They will not go bad over time */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
603 e->reliability = e->reliability_max; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
604 } else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
605 uint max = e->reliability_max; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
606 e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
607 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
608 /* time's up for this engine. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
609 * We will now completely retire this design */ |
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:
10148
diff
changeset
|
610 e->company_avail = 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
|
611 e->reliability = e->reliability_final; |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5868
diff
changeset
|
612 /* Kick this engine out of the lists */ |
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5868
diff
changeset
|
613 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->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
|
614 } |
13034
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12837
diff
changeset
|
615 SetWindowClassesDirty(WC_BUILD_VEHICLE); // Update to show the new reliability |
6eb3f749890a
(svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents:
12837
diff
changeset
|
616 SetWindowClassesDirty(WC_REPLACE_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
|
617 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
618 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
619 /** Compute the value for #_year_engine_aging_stops. */ |
10631
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
620 void SetYearEngineAgingStops() |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
621 { |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
622 /* Determine last engine aging year, default to 2050 as previously. */ |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
623 _year_engine_aging_stops = 2050; |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
624 |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
625 const Engine *e; |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
626 FOR_ALL_ENGINES(e) { |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
627 const EngineInfo *ei = &e->info; |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
628 |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
629 /* Exclude certain engines */ |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
630 if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) continue; |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
631 if (e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON) continue; |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
632 |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
633 /* Base year ending date on half the model life */ |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
634 YearMonthDay ymd; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
635 ConvertDateToYMD(ei->base_intro + (ei->lifelength * DAYS_IN_LEAP_YEAR) / 2, &ymd); |
10631
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
636 |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
637 _year_engine_aging_stops = max(_year_engine_aging_stops, ymd.year); |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
638 } |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
639 } |
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
640 |
17640
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
641 /** |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
642 * Start/initialise one engine. |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
643 * @param e The engine to initialise. |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
644 * @param aging_date The date used for age calculations. |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
645 */ |
10881
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
646 void StartupOneEngine(Engine *e, Date aging_date) |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
647 { |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
648 const EngineInfo *ei = &e->info; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
649 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
650 e->age = 0; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
651 e->flags = 0; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
652 e->company_avail = 0; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
653 |
12492
3fbb8c75e370
(svn r16929) -Change: There is no point in not randomising engine introduction-date before 1922. Instead disable the randomisation for the first two years after game-start, so you do not have to wait for the first engine.
frosch <frosch@openttd.org>
parents:
12484
diff
changeset
|
654 /* Don't randomise the start-date in the first two years after gamestart to ensure availability |
3fbb8c75e370
(svn r16929) -Change: There is no point in not randomising engine introduction-date before 1922. Instead disable the randomisation for the first two years after game-start, so you do not have to wait for the first engine.
frosch <frosch@openttd.org>
parents:
12484
diff
changeset
|
655 * of engines in early starting games. |
3fbb8c75e370
(svn r16929) -Change: There is no point in not randomising engine introduction-date before 1922. Instead disable the randomisation for the first two years after game-start, so you do not have to wait for the first engine.
frosch <frosch@openttd.org>
parents:
12484
diff
changeset
|
656 * Note: TTDP uses fixed 1922 */ |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
657 uint32 r = Random(); |
12492
3fbb8c75e370
(svn r16929) -Change: There is no point in not randomising engine introduction-date before 1922. Instead disable the randomisation for the first two years after game-start, so you do not have to wait for the first engine.
frosch <frosch@openttd.org>
parents:
12484
diff
changeset
|
658 e->intro_date = ei->base_intro <= ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; |
10881
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
659 if (e->intro_date <= _date) { |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
660 e->age = (aging_date - e->intro_date) >> 5; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
661 e->company_avail = (CompanyMask)-1; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
662 e->flags |= ENGINE_AVAILABLE; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
663 } |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
664 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
665 e->reliability_start = GB(r, 16, 14) + 0x7AE0; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
666 r = Random(); |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
667 e->reliability_max = GB(r, 0, 14) + 0xBFFF; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
668 e->reliability_final = GB(r, 16, 14) + 0x3FFF; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
669 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
670 r = Random(); |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
671 e->duration_phase_1 = GB(r, 0, 5) + 7; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
672 e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
673 e->duration_phase_3 = GB(r, 9, 7) + 120; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
674 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
675 e->reliability_spd_dec = ei->decay_speed << 2; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
676 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
677 CalcEngineReliability(e); |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
678 |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
679 /* prevent certain engines from ever appearing. */ |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
680 if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
681 e->flags |= ENGINE_AVAILABLE; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
682 e->company_avail = 0; |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
683 } |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
684 } |
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
685 |
18247
973050b62813
(svn r23083) -Fix: run StartupEngines() if NewGRFs changed during loading a savegame, just like it's running when NewGRFs are changed during a game
yexo <yexo@openttd.org>
parents:
18239
diff
changeset
|
686 /** |
973050b62813
(svn r23083) -Fix: run StartupEngines() if NewGRFs changed during loading a savegame, just like it's running when NewGRFs are changed during a game
yexo <yexo@openttd.org>
parents:
18239
diff
changeset
|
687 * Start/initialise all our engines. Must be called whenever there are changes |
973050b62813
(svn r23083) -Fix: run StartupEngines() if NewGRFs changed during loading a savegame, just like it's running when NewGRFs are changed during a game
yexo <yexo@openttd.org>
parents:
18239
diff
changeset
|
688 * to the NewGRF config. |
973050b62813
(svn r23083) -Fix: run StartupEngines() if NewGRFs changed during loading a savegame, just like it's running when NewGRFs are changed during a game
yexo <yexo@openttd.org>
parents:
18239
diff
changeset
|
689 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6209
diff
changeset
|
690 void StartupEngines() |
5584
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 Engine *e; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 /* Aging of vehicles stops, so account for that when starting late */ |
10631
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
694 const Date aging_date = min(_date, ConvertYMDToDate(_year_engine_aging_stops, 0, 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
|
695 |
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:
9036
diff
changeset
|
696 FOR_ALL_ENGINES(e) { |
10881
8e9bff1a3e56
(svn r15216) -Feature: native support for Transport Tycoon (Original) savegames. Based on SVXConverter's source code and documentation by Roman Vetter
smatz <smatz@openttd.org>
parents:
10744
diff
changeset
|
697 StartupOneEngine(e, aging_date); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
698 } |
10023
d8894068dd04
(svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138 <peter1138@openttd.org>
parents:
9914
diff
changeset
|
699 |
d8894068dd04
(svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138 <peter1138@openttd.org>
parents:
9914
diff
changeset
|
700 /* Update the bitmasks for the vehicle lists */ |
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:
10148
diff
changeset
|
701 Company *c; |
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:
10148
diff
changeset
|
702 FOR_ALL_COMPANIES(c) { |
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:
10148
diff
changeset
|
703 c->avail_railtypes = GetCompanyRailtypes(c->index); |
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:
10148
diff
changeset
|
704 c->avail_roadtypes = GetCompanyRoadtypes(c->index); |
10023
d8894068dd04
(svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138 <peter1138@openttd.org>
parents:
9914
diff
changeset
|
705 } |
16643
bb429a529a4a
(svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents:
16514
diff
changeset
|
706 |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
707 /* Rail types that are invalid or never introduced are marked as |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
708 * being introduced upon start. That way we can easily check whether |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
709 * there is any date related introduction that is still going to |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
710 * happen somewhere in the future. */ |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
711 for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) { |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
712 const RailtypeInfo *rti = GetRailTypeInfo(rt); |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
713 if (rti->label != 0 && IsInsideMM(rti->introduction_date, 0, MAX_DAY)) continue; |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
714 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
715 SetBit(_introduced_railtypes, rt); |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
716 } |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
717 |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
718 CheckRailIntroduction(); |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
719 |
16643
bb429a529a4a
(svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents:
16514
diff
changeset
|
720 /* Invalidate any open purchase lists */ |
bb429a529a4a
(svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents:
16514
diff
changeset
|
721 InvalidateWindowClassesData(WC_BUILD_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
|
722 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
723 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
724 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
725 * Company \a company accepts engine \a eid for preview. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
726 * @param eid Engine being accepted (is under preview). |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
727 * @param company Current company previewing the engine. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
728 */ |
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:
10148
diff
changeset
|
729 static void AcceptEnginePreview(EngineID eid, 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
|
730 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
731 Engine *e = Engine::Get(eid); |
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
732 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
|
733 |
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:
10148
diff
changeset
|
734 SetBit(e->company_avail, company); |
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:
6247
diff
changeset
|
735 if (e->type == VEH_TRAIN) { |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13193
diff
changeset
|
736 assert(e->u.rail.railtype < RAILTYPE_END); |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
737 c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date); |
6685
91a7c42b133c
(svn r9917) -Codechange: prepare some more areas for more road types.
rubidium <rubidium@openttd.org>
parents:
6643
diff
changeset
|
738 } else if (e->type == VEH_ROAD) { |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13193
diff
changeset
|
739 SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
5823 | 740 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
741 |
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:
10148
diff
changeset
|
742 e->preview_company_rank = 0xFF; |
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:
10148
diff
changeset
|
743 if (company == _local_company) { |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5868
diff
changeset
|
744 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->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
|
745 } |
16160
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
746 |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
747 /* Update the toolbar. */ |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
748 if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD); |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
749 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER); |
5584
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 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
752 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
753 * Get the N-th best company. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
754 * @param pp Value N, 1 means best, 2 means second best, etc. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
755 * @return N-th best company if it exists, #INVALID_COMPANY otherwise. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
756 */ |
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:
10148
diff
changeset
|
757 static CompanyID GetBestCompany(uint8 pp) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
758 { |
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:
10148
diff
changeset
|
759 CompanyID best_company; |
10477
20da0dd3f897
(svn r14732) -Codechange: replace some magic number with less magic constants and use the proper type for a few variables.
rubidium <rubidium@openttd.org>
parents:
10430
diff
changeset
|
760 CompanyMask mask = 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
|
761 |
8572
8a95003be848
(svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz <smatz@openttd.org>
parents:
8565
diff
changeset
|
762 do { |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
763 int32 best_hist = -1; |
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:
10148
diff
changeset
|
764 best_company = INVALID_COMPANY; |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
765 |
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
766 const Company *c; |
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:
10148
diff
changeset
|
767 FOR_ALL_COMPANIES(c) { |
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:
10148
diff
changeset
|
768 if (c->block_preview == 0 && !HasBit(mask, c->index) && |
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:
10148
diff
changeset
|
769 c->old_economy[0].performance_history > best_hist) { |
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:
10148
diff
changeset
|
770 best_hist = c->old_economy[0].performance_history; |
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:
10148
diff
changeset
|
771 best_company = c->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
|
772 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
773 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
774 |
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:
10148
diff
changeset
|
775 if (best_company == INVALID_COMPANY) return INVALID_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
|
776 |
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:
10148
diff
changeset
|
777 SetBit(mask, best_company); |
8633
3c2144e0e2c2
(svn r12244) -Fix (r12150): typo resulting in no players are given the engine preview offer
smatz <smatz@openttd.org>
parents:
8572
diff
changeset
|
778 } while (--pp != 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
|
779 |
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:
10148
diff
changeset
|
780 return best_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
|
781 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
782 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
783 /** Daily check to offer an exclusive engine preview to the companies. */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6209
diff
changeset
|
784 void EnginesDailyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
785 { |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
786 CheckRailIntroduction(); |
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
787 |
10631
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
788 if (_cur_year >= _year_engine_aging_stops) 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
|
789 |
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:
9036
diff
changeset
|
790 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:
9036
diff
changeset
|
791 FOR_ALL_ENGINES(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:
9036
diff
changeset
|
792 EngineID i = e->index; |
6174
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
793 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
794 if (e->flags & ENGINE_OFFER_WINDOW_OPEN) { |
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:
10148
diff
changeset
|
795 if (e->preview_company_rank != 0xFF && !--e->preview_wait) { |
6174
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
796 e->flags &= ~ENGINE_OFFER_WINDOW_OPEN; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
797 DeleteWindowById(WC_ENGINE_PREVIEW, i); |
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:
10148
diff
changeset
|
798 e->preview_company_rank++; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
799 } |
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:
10148
diff
changeset
|
800 } else if (e->preview_company_rank != 0xFF) { |
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:
10148
diff
changeset
|
801 CompanyID best_company = GetBestCompany(e->preview_company_rank); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
802 |
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:
10148
diff
changeset
|
803 if (best_company == INVALID_COMPANY) { |
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:
10148
diff
changeset
|
804 e->preview_company_rank = 0xFF; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
805 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
806 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
807 |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10656
diff
changeset
|
808 e->flags |= ENGINE_OFFER_WINDOW_OPEN; |
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10656
diff
changeset
|
809 e->preview_wait = 20; |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18340
diff
changeset
|
810 AI::NewEvent(best_company, new ScriptEventEnginePreview(i)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10656
diff
changeset
|
811 if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
812 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
813 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
814 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
815 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
816 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
817 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
818 * Accept an engine prototype. XXX - it is possible that the top-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
|
819 * changes while you are waiting to accept the offer? Then it becomes invalid |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
820 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
821 * @param flags operation to perfom |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
822 * @param p1 engine-prototype offered |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
823 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
824 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
825 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
826 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11071
diff
changeset
|
827 CommandCost CmdWantEnginePreview(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
828 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
829 Engine *e = Engine::GetIfValid(p1); |
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
830 if (e == NULL || GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
831 |
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:
10148
diff
changeset
|
832 if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_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
|
833 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
834 return CommandCost(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
835 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
836 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
837 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
838 * An engine has become available for general use. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
839 * Also handle the exclusive engine preview contract. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
840 * @param e Engine generally available as of now. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
841 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
842 static void NewVehicleAvailable(Engine *e) |
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 Vehicle *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:
10148
diff
changeset
|
845 Company *c; |
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:
9036
diff
changeset
|
846 EngineID index = e->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
|
847 |
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:
10148
diff
changeset
|
848 /* In case the company didn't build the vehicle during the intro period, |
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:
10148
diff
changeset
|
849 * prevent that company from getting future intro periods for a while. */ |
6174
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
850 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
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:
10148
diff
changeset
|
851 FOR_ALL_COMPANIES(c) { |
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:
10148
diff
changeset
|
852 uint block_preview = c->block_preview; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
853 |
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:
10148
diff
changeset
|
854 if (!HasBit(e->company_avail, c->index)) 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
|
855 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
856 /* We assume the user did NOT build it.. prove me wrong ;) */ |
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:
10148
diff
changeset
|
857 c->block_preview = 20; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
858 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
859 FOR_ALL_VEHICLES(v) { |
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:
6247
diff
changeset
|
860 if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || |
12384
d4b73a406cf3
(svn r16814) -Codechange: make IsNormalAircraft() member of Aircraft
smatz <smatz@openttd.org>
parents:
12383
diff
changeset
|
861 (v->type == VEH_AIRCRAFT && Aircraft::From(v)->IsNormalAircraft())) { |
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:
10148
diff
changeset
|
862 if (v->owner == c->index && v->engine_type == 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
|
863 /* The user did prove me wrong, so restore old value */ |
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:
10148
diff
changeset
|
864 c->block_preview = block_preview; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
865 break; |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
868 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
869 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
870 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
871 |
6174
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
872 e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; |
5944
ca95cde4d1b4
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents:
5868
diff
changeset
|
873 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->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
|
874 |
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:
10148
diff
changeset
|
875 /* Now available for all companies */ |
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:
10148
diff
changeset
|
876 e->company_avail = (CompanyMask)-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
|
877 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
878 /* Do not introduce new rail wagons */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
879 if (IsWagon(index)) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
880 |
8220
01778382728c
(svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents:
8214
diff
changeset
|
881 if (e->type == VEH_TRAIN) { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
882 /* maybe make another rail type available */ |
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:
9036
diff
changeset
|
883 RailType railtype = e->u.rail.railtype; |
5823 | 884 assert(railtype < RAILTYPE_END); |
17105
a804b91f3a3e
(svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents:
17104
diff
changeset
|
885 FOR_ALL_COMPANIES(c) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date); |
8220
01778382728c
(svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents:
8214
diff
changeset
|
886 } else if (e->type == VEH_ROAD) { |
6686
68e6a459baf1
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium <rubidium@openttd.org>
parents:
6685
diff
changeset
|
887 /* maybe make another road type available */ |
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:
10148
diff
changeset
|
888 FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
6686
68e6a459baf1
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium <rubidium@openttd.org>
parents:
6685
diff
changeset
|
889 } |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9135
diff
changeset
|
890 |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18340
diff
changeset
|
891 AI::BroadcastNewEvent(new ScriptEventEngineAvailable(index)); |
10696
7edccbb67398
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents:
10656
diff
changeset
|
892 |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9135
diff
changeset
|
893 SetDParam(0, GetEngineCategoryName(index)); |
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9135
diff
changeset
|
894 SetDParam(1, index); |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12492
diff
changeset
|
895 AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, NR_ENGINE, index); |
16160
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
896 |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
897 /* Update the toolbar. */ |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
898 if (e->type == VEH_ROAD) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_ROAD); |
c638d1941c58
(svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents:
15763
diff
changeset
|
899 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
900 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
901 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6209
diff
changeset
|
902 void EnginesMonthlyLoop() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
903 { |
10631
85cfd6fe68e1
(svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents:
10571
diff
changeset
|
904 if (_cur_year < _year_engine_aging_stops) { |
8401
980fb697eb0a
(svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138 <peter1138@openttd.org>
parents:
8400
diff
changeset
|
905 Engine *e; |
980fb697eb0a
(svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138 <peter1138@openttd.org>
parents:
8400
diff
changeset
|
906 FOR_ALL_ENGINES(e) { |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
907 /* Age the vehicle */ |
15457
a4ca05c4772a
(svn r20106) -Fix (r5999): Engine and vehicle age were clamped at 0xFFFF, though there are 32bit available.
frosch <frosch@openttd.org>
parents:
15244
diff
changeset
|
908 if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
909 e->age++; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
910 CalcEngineReliability(e); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
911 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
912 |
17247
5221777879f1
(svn r21987) -Fix: Make news items, engine previews and AI preview events deal with no longer existing Engine items after resetting the pool.
frosch <frosch@openttd.org>
parents:
17246
diff
changeset
|
913 /* Do not introduce invalid engines */ |
5221777879f1
(svn r21987) -Fix: Make news items, engine previews and AI preview events deal with no longer existing Engine items after resetting the pool.
frosch <frosch@openttd.org>
parents:
17246
diff
changeset
|
914 if (!e->IsEnabled()) continue; |
5221777879f1
(svn r21987) -Fix: Make news items, engine previews and AI preview events deal with no longer existing Engine items after resetting the pool.
frosch <frosch@openttd.org>
parents:
17246
diff
changeset
|
915 |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
916 if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) { |
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:
10148
diff
changeset
|
917 /* Introduce it to all companies */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
918 NewVehicleAvailable(e); |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11296
diff
changeset
|
919 } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) { |
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:
10148
diff
changeset
|
920 /* Introduction date has passed.. show introducing dialog to one companies. */ |
6174
c9f5e97572a4
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents:
6125
diff
changeset
|
921 e->flags |= ENGINE_EXCLUSIVE_PREVIEW; |
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 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
923 /* Do not introduce new rail wagons */ |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
924 if (!IsWagon(e->index)) { |
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:
10148
diff
changeset
|
925 e->preview_company_rank = 1; // Give to the company with the highest rating. |
15552
683f2dbe75bb
(svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents:
15511
diff
changeset
|
926 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
927 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
928 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
929 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
930 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
931 |
7097
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
932 static bool IsUniqueEngineName(const char *name) |
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
933 { |
10656
39feee39693a
(svn r14958) -Codechange [FS#1923]: when checking for unique names, compare only with manually set names
smatz <smatz@openttd.org>
parents:
10631
diff
changeset
|
934 const Engine *e; |
7097
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
935 |
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:
9036
diff
changeset
|
936 FOR_ALL_ENGINES(e) { |
10656
39feee39693a
(svn r14958) -Codechange [FS#1923]: when checking for unique names, compare only with manually set names
smatz <smatz@openttd.org>
parents:
10631
diff
changeset
|
937 if (e->name != NULL && strcmp(e->name, name) == 0) return false; |
7097
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
938 } |
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
939 |
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
940 return true; |
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
941 } |
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
942 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
943 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
944 * Rename an engine. |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
945 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
946 * @param flags operation to perfom |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
947 * @param p1 engine ID to rename |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
948 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
949 * @param text the new name or an empty string when resetting to the default |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
950 * @return the cost of this operation or an error |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
951 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11071
diff
changeset
|
952 CommandCost CmdRenameEngine(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
953 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
954 Engine *e = Engine::GetIfValid(p1); |
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
955 if (e == NULL) return CMD_ERROR; |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
956 |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10480
diff
changeset
|
957 bool reset = StrEmpty(text); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
958 |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
959 if (!reset) { |
16679
07ae81d6312a
(svn r21410) -Codechange: limit engine name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16643
diff
changeset
|
960 if (Utf8StringLength(text) >= MAX_LENGTH_ENGINE_NAME_CHARS) return CMD_ERROR; |
12632
e41943276802
(svn r17075) -Codechange: rename ~750 strings to be more uniform with their relatives
rubidium <rubidium@openttd.org>
parents:
12619
diff
changeset
|
961 if (!IsUniqueEngineName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE); |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
962 } |
7097
5c2889ace3ac
(svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138 <peter1138@openttd.org>
parents:
6950
diff
changeset
|
963 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
964 if (flags & DC_EXEC) { |
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
|
965 free(e->name); |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
966 |
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
967 if (reset) { |
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
968 e->name = NULL; |
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
969 } else { |
10499
45ca88a8de7d
(svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents:
10480
diff
changeset
|
970 e->name = strdup(text); |
10148
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
diff
changeset
|
971 } |
81642658c8be
(svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz <smatz@openttd.org>
parents:
10127
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 MarkWholeScreenDirty(); |
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 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
976 return CommandCost(); |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
978 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
979 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
980 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
981 * Check if an engine is buildable. |
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:
10148
diff
changeset
|
982 * @param engine index of the engine to check. |
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:
10148
diff
changeset
|
983 * @param type the type the engine should be. |
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:
10148
diff
changeset
|
984 * @param company index of the company. |
8479
689d2708728a
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138 <peter1138@openttd.org>
parents:
8401
diff
changeset
|
985 * @return True if an engine is valid, of the specified type, and buildable by |
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:
10148
diff
changeset
|
986 * the given 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
|
987 */ |
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:
10148
diff
changeset
|
988 bool IsEngineBuildable(EngineID engine, VehicleType 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
|
989 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
990 const Engine *e = Engine::GetIfValid(engine); |
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
991 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
992 /* check if it's an engine that is in the engine array */ |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
993 if (e == NULL) 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
|
994 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
995 /* check if it's an engine of specified 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
|
996 if (e->type != type) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
997 |
6125
46d001ebacf6
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5971
diff
changeset
|
998 /* check if it's available */ |
18767
50f4f95caf36
(svn r23615) -Add: more API functions exposed to NoGo (part 2)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
999 if (company != OWNER_DEITY && !HasBit(e->company_avail, company)) 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
|
1000 |
17246
f98b40bd4ccb
(svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents:
17235
diff
changeset
|
1001 if (!e->IsEnabled()) return false; |
15244
e72aea2333da
(svn r19879) -Codechange: Also hide invalid engines from purchase lists.
frosch <frosch@openttd.org>
parents:
15043
diff
changeset
|
1002 |
18767
50f4f95caf36
(svn r23615) -Add: more API functions exposed to NoGo (part 2)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
1003 if (type == VEH_TRAIN && company != OWNER_DEITY) { |
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:
10148
diff
changeset
|
1004 /* Check if the rail type is available to this company */ |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
1005 const Company *c = Company::Get(company); |
13218
03a409fa4c29
(svn r17725) -Codechange: Reduce usage of EngInfo and XxxVehInfo, esp. when a Engine * is already present.
frosch <frosch@openttd.org>
parents:
13193
diff
changeset
|
1006 if (((GetRailTypeInfo(e->u.rail.railtype))->compatible_railtypes & c->avail_railtypes) == 0) return false; |
6530
01978c632f97
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138 <peter1138@openttd.org>
parents:
6505
diff
changeset
|
1007 } |
01978c632f97
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138 <peter1138@openttd.org>
parents:
6505
diff
changeset
|
1008 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1009 return true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1010 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1011 |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1012 /** |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1013 * Check if an engine is refittable. |
11238
06dac7488367
(svn r15592) -Fix: Refit-info in purchase list did only check the first articulated part.
frosch <frosch@openttd.org>
parents:
11188
diff
changeset
|
1014 * Note: Likely you want to use IsArticulatedVehicleRefittable(). |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1015 * @param engine index of the engine to check. |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1016 * @return true if the engine is refittable. |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1017 */ |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1018 bool IsEngineRefittable(EngineID engine) |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1019 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
1020 const Engine *e = Engine::GetIfValid(engine); |
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
1021 |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1022 /* check if it's an engine that is in the engine array */ |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
1023 if (e == NULL) return false; |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1024 |
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:
11171
diff
changeset
|
1025 if (!e->CanCarryCargo()) return false; |
9e451d497d94
(svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents:
11171
diff
changeset
|
1026 |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1027 const EngineInfo *ei = &e->info; |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1028 if (ei->refit_mask == 0) return false; |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1029 |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1030 /* Are there suffixes? |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1031 * Note: This does not mean the suffixes are actually available for every consist at any time. */ |
13036
8e2a0e8fa275
(svn r17534) -Codechange: unify the naming of callback masks/flags
rubidium <rubidium@openttd.org>
parents:
13034
diff
changeset
|
1032 if (HasBit(ei->callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) return true; |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1033 |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1034 /* Is there any cargo except the default cargo? */ |
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:
11171
diff
changeset
|
1035 CargoID default_cargo = e->GetDefaultCargoType(); |
10430
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1036 return default_cargo != CT_INVALID && ei->refit_mask != 1U << default_cargo; |
399a56984e58
(svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium <rubidium@openttd.org>
parents:
10427
diff
changeset
|
1037 } |