Mercurial > hg > openttd
annotate src/engine.cpp @ 19005:aa8cbaa8b7ce draft
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
author | frosch <frosch@openttd.org> |
---|---|
date | Sat, 28 Jan 2012 12:11:23 +0000 |
parents | 50f5f856455b |
children | 8f157dbe02b6 |
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" |
8114
2d6af5d7a142
(svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents:
7931
diff
changeset
|
19 #include "strings_func.h" |
10960
a4e5b5d2837c
(svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents:
10927
diff
changeset
|
20 #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
|
21 #include "window_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8131
diff
changeset
|
22 #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
|
23 #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
|
24 #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
|
25 #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
|
26 #include "core/pool_func.hpp" |
12837
a6a46b1b7ad9
(svn r17327) -Codechange: Allow external use of GetEngineCategoryName().
alberth <alberth@openttd.org>
parents:
12808
diff
changeset
|
27 #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
|
28 #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
|
29 #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
|
30 #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
|
31 #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
|
32 |
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
|
33 #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
|
34 #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
|
35 |
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
|
36 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
|
37 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
|
38 |
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
|
39 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
|
40 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
41 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
42 * 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
|
43 * and no more engines will be introduced |
c62577640878
(svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents:
15620
diff
changeset
|
44 */ |
13508
f7e05f44c9be
(svn r18027) -Codechange: make some unneededly global variables static and remove some unused variables
rubidium <rubidium@openttd.org>
parents:
13492
diff
changeset
|
45 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
|
46 |
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
|
47 /** |
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 * 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
|
49 * 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
|
50 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
|
51 |
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
|
52 /** 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 }; |
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 /** 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 }; |
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 |
13249
f52dcc31398e
(svn r17758) -Revert (r17208): Use assert_compile() if you cannot count.
frosch <frosch@openttd.org>
parents:
13218
diff
changeset
|
68 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
|
69 |
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
|
70 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
|
71 |
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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 { |
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 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
|
80 { |
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 this->type = type; |
15763
a60a50f29f64
(svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents:
15653
diff
changeset
|
82 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
|
83 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
|
84 |
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 /* 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
|
86 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
|
87 /* 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
|
88 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
|
89 /* 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
|
90 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
|
91 /* 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
|
92 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
|
93 /* 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 } |
17909
4d6b4b6d6069
(svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents:
17891
diff
changeset
|
100 /* 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
|
101 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
|
102 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
|
103 } |
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 /* 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
|
106 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
|
107 |
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 /* 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
|
109 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
|
110 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
|
111 |
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 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
|
113 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
|
114 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
|
115 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
|
116 |
4b216e04a76c
(svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents:
10208
diff
changeset
|
117 /* 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
|
118 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
|
119 |
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
|
120 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
|
121 |
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 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 |
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 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 |
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 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 } |
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 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
|
143 { |
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 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
|
145 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
|
146 } |
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 |
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
|
148 /** |
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
|
149 * 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
|
150 * @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
|
151 */ |
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 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
|
153 { |
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 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
|
155 } |
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 /** |
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
|
158 * 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
|
159 * 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
|
160 * @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
|
161 */ |
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 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
|
163 { |
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 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
|
165 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
|
166 } |
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 /** |
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
|
169 * Determines whether an engine can carry something. |
18678
5604c42fa1ce
(svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents:
18656
diff
changeset
|
170 * 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
|
171 * @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
|
172 */ |
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 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
|
174 { |
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 /* 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
|
176 * 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
|
177 * 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
|
178 * 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
|
179 */ |
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 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
|
181 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
|
182 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
|
183 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
|
184 |
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 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
|
186 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
|
187 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
|
188 |
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 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
|
190 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
|
191 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
|
192 |
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 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
|
194 } |
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 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
|
196 } |
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 |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
198 |
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 * 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
|
201 * 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
|
202 * @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
|
203 * @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
|
204 * @return Capacity |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
205 */ |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
206 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
|
207 { |
18340
72d57cf141f5
(svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents:
18339
diff
changeset
|
208 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
|
209 if (mail_capacity != NULL) *mail_capacity = 0; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
210 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
211 if (!this->CanCarryCargo()) return 0; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
212 |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
213 bool new_multipliers = HasBit(this->info.misc_flags, EF_NO_DEFAULT_CARGO_MULTIPLIER); |
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 |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
221 /* Check the refit capacity callback if we are not in the default configuration, or if we are using the new multiplier algorithm. */ |
18337
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
222 if (HasBit(this->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY) && |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
223 (new_multipliers || 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
|
224 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
|
225 if (callback != CALLBACK_FAILED) return callback; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
226 } |
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 /* Get capacity according to property resp. CB */ |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
229 uint capacity; |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
230 uint extra_mail_cap = 0; |
18337
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)) { |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
250 extra_mail_cap = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity, v); |
18339
4675de035ab1
(svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18338
diff
changeset
|
251 } |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
252 if (!new_multipliers && cargo_type == CT_MAIL) return capacity + extra_mail_cap; |
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 |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
259 if (!new_multipliers) { |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
260 /* Use the passenger multiplier for mail as well */ |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
261 capacity += extra_mail_cap; |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
262 extra_mail_cap = 0; |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
263 } |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
264 |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
265 /* Apply multipliers depending on cargo- and vehicletype. */ |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
266 if (new_multipliers || (this->type != VEH_SHIP && default_cargo != cargo_type)) { |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
267 uint16 default_multiplier = new_multipliers ? 0x100 : CargoSpec::Get(default_cargo)->multiplier; |
19004
50f5f856455b
(svn r23860) -Feature: [NewGRF] Add cargo property 1D to set the capacity multipliers when refitting vehicles, which do not use callback 15.
frosch <frosch@openttd.org>
parents:
18891
diff
changeset
|
268 uint16 cargo_multiplier = CargoSpec::Get(cargo_type)->multiplier; |
19005
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
269 capacity *= cargo_multiplier; |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
270 if (extra_mail_cap > 0) { |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
271 uint mail_multiplier = CargoSpec::Get(CT_MAIL)->multiplier; |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
272 capacity += (default_multiplier * extra_mail_cap * cargo_multiplier + mail_multiplier / 2) / mail_multiplier; |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
273 } |
aa8cbaa8b7ce
(svn r23861) -Feature: [NewGRF] New algorithm (activated via an engine flag) to determine the capacity of vehicles. This allows vehicles to better control the capacity for cargotypes which they know; and let cargo NewGRFs influence the capacity for cargos the vehicle NewGRF does not know, but which the vehicle is refittable to due to cargo classes.
frosch <frosch@openttd.org>
parents:
19004
diff
changeset
|
274 capacity = (capacity + default_multiplier / 2) / default_multiplier; |
18337
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 |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
277 return capacity; |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
278 } |
f3ce001bc1d1
(svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents:
18247
diff
changeset
|
279 |
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
|
280 /** |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
281 * Return how much the running costs of this engine are. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
282 * @return Yearly running cost of the engine. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
283 */ |
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
|
284 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
|
285 { |
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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 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
|
292 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
|
293 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
|
294 |
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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 |
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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 |
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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 |
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 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
|
312 } |
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
|
313 |
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
|
314 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
|
315 } |
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
|
316 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
317 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
318 * Return how much a new engine costs. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
319 * @return Cost of the engine. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
320 */ |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
321 Money Engine::GetCost() const |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
322 { |
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
|
323 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
|
324 uint cost_factor; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
325 switch (this->type) { |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
330 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
331 case VEH_TRAIN: |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 } 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
|
336 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
|
337 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
|
338 } |
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
|
339 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
|
340 |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
341 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
|
342 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
|
343 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
|
344 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
345 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
346 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
|
347 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
|
348 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
|
349 break; |
10927
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
350 |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
351 default: NOT_REACHED(); |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
352 } |
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
|
353 |
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
|
354 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
|
355 } |
68230070e59b
(svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents:
10925
diff
changeset
|
356 |
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
|
357 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
358 * 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
|
359 * @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
|
360 */ |
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 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
|
362 { |
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 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
|
364 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
|
365 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
|
366 |
16384
f39955ef4720
(svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents:
16347
diff
changeset
|
367 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
|
368 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
|
369 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
|
370 } |
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
|
371 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
372 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
|
373 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
|
374 |
15043
2120f331b2be
(svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents:
14772
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 } |
10969
208ba3fba382
(svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents:
10967
diff
changeset
|
380 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
|
381 } |
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
|
382 |
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 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
|
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 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
386 |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
387 /** |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
388 * 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
|
389 * and sorting purposes. |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
390 * 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
|
391 * @return power in display units hp |
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
392 */ |
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
|
393 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
|
394 { |
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
|
395 /* 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 |
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 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
|
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 |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
406 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
407 * 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
|
408 * 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
|
409 * @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
|
410 */ |
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 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
|
412 { |
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
|
413 /* 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 |
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 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
|
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 } |
57269a8c0b6d
(svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents:
10960
diff
changeset
|
423 |
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
|
424 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
425 * 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
|
426 * 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
|
427 * @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
|
428 */ |
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 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
|
430 { |
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
|
431 /* 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 |
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 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
|
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 } |
631c89cee615
(svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents:
11090
diff
changeset
|
441 |
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
|
442 /** |
16385
4a60a952126d
(svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents:
16384
diff
changeset
|
443 * 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
|
444 * @return the life length |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
445 */ |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
446 Date Engine::GetLifeLengthInDays() const |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
447 { |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
448 /* 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
|
449 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
|
450 } |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
451 |
299a364a2abc
(svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents:
12164
diff
changeset
|
452 /** |
18656
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
453 * Get the range of an aircraft type. |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
454 * @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
|
455 */ |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
456 uint16 Engine::GetRange() const |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
457 { |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
458 switch (this->type) { |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
459 case VEH_AIRCRAFT: |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
460 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
|
461 |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
462 default: NOT_REACHED(); |
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 |
c107e4bb6187
(svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents:
18511
diff
changeset
|
466 /** |
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
|
467 * 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
|
468 */ |
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 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
|
470 { |
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 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
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 /** |
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 * 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
|
485 * @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
|
486 * @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
|
487 * @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
|
488 * 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
|
489 * 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
|
490 * @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
|
491 */ |
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 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
|
493 { |
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 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
|
495 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
|
496 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
|
497 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
|
498 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
|
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 } |
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 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
|
502 } |
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
|
503 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
504 /** |
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
|
505 * 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
|
506 * 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
|
507 * @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
|
508 */ |
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 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
|
510 { |
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 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
|
512 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
|
513 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
|
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 |
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 /* 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
|
517 _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
|
518 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
|
519 |
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 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
|
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 |
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
|
523 /** |
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
|
524 * 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
|
525 */ |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
526 void SetupEngines() |
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
527 { |
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
|
528 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
|
529 _engine_pool.CleanPool(); |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
530 |
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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 /* 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
|
536 * 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
|
537 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
|
538 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
|
539 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
|
540 } |
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
|
541 |
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
|
542 _introduced_railtypes = 0; |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
543 } |
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
544 |
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
|
545 /** |
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 * 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
|
547 */ |
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 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
|
549 { |
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 /* 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
|
551 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
|
552 |
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 /* 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
|
554 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
|
555 |
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 /* 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
|
557 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
|
558 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
|
559 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
|
560 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
|
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 |
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 _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
|
564 } |
8221
188d5ea22361
(svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents:
8220
diff
changeset
|
565 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
566 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
|
567 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
568 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
569 * 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
|
570 * @param index %Engine getting queried. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
571 * @return Whether the queried engine is a wagon. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
572 */ |
9468
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
573 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
|
574 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
575 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
|
576 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
|
577 } |
07d40eb8252e
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents:
9417
diff
changeset
|
578 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
579 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
580 * 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
|
581 * @param e %Engine to update. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
582 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
583 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
|
584 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
585 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
|
586 |
6606
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
587 /* 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 /* 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
|
593 e->company_avail = 0; |
6606
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
594 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
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 } |
a06a7d24392b
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents:
6530
diff
changeset
|
597 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
598 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
|
599 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
|
600 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
|
601 } 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
|
602 /* 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
|
603 * 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
|
604 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
|
605 } 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
|
606 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
|
607 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
|
608 } else { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
609 /* 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
|
610 * 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
|
611 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
|
612 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
|
613 /* 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
|
614 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
|
615 } |
13034
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_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
|
617 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
|
618 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
619 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
620 /** 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
|
621 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
|
622 { |
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 /* 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
|
624 _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
|
625 |
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 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
|
627 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
|
628 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
|
629 |
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 /* 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
|
631 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
|
632 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
|
633 |
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 /* 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
|
635 YearMonthDay ymd; |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
636 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
|
637 |
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 _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
|
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 } |
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
|
641 |
17640
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
642 /** |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
643 * Start/initialise one engine. |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
644 * @param e The engine to initialise. |
99d6211b8c36
(svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents:
17495
diff
changeset
|
645 * @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
|
646 */ |
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
|
647 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
|
648 { |
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 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
|
650 |
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->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
|
652 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
|
653 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
|
654 |
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
|
655 /* 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
|
656 * 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
|
657 * 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
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 |
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 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
|
667 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
|
668 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
|
669 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
|
670 |
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 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
|
672 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
|
673 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
|
674 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
|
675 |
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 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
|
677 |
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 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
|
679 |
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 /* 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
|
681 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
|
682 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
|
683 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
|
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 } |
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
|
686 |
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
|
687 /** |
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 * 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
|
689 * 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
|
690 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6209
diff
changeset
|
691 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
|
692 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
693 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
|
694 /* 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
|
695 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
|
696 |
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
|
697 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
|
698 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
|
699 } |
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
|
700 |
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
|
701 /* 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 } |
16643
bb429a529a4a
(svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents:
16514
diff
changeset
|
707 |
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
|
708 /* 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
|
709 * 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
|
710 * 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
|
711 * 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
|
712 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
|
713 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
|
714 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
|
715 |
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 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
|
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 |
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 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
|
720 |
16643
bb429a529a4a
(svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents:
16514
diff
changeset
|
721 /* 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
|
722 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
|
723 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
724 |
17484
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
725 /** |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
726 * 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
|
727 * @param eid Engine being accepted (is under preview). |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
728 * @param company Current company previewing the engine. |
d0d74ae900fb
(svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents:
17285
diff
changeset
|
729 */ |
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
|
730 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
|
731 { |
11922
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
732 Engine *e = Engine::Get(eid); |
0a4b63f3f3c3
(svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents:
11730
diff
changeset
|
733 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
|
734 |
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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 } 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
|
740 SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
5823 | 741 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
742 |
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
|
743 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
|
744 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
|
745 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
|
746 } |
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
|
747 |
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 /* 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
|
749 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
|
750 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
|
751 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
752 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
753 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
754 * Get the N-th best company. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
755 * @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
|
756 * @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
|
757 */ |
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
|
758 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
|
759 { |
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
|
760 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
|
761 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
|
762 |
8572
8a95003be848
(svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz <smatz@openttd.org>
parents:
8565
diff
changeset
|
763 do { |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
764 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
|
765 best_company = INVALID_COMPANY; |
15652
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
766 |
354307d245e5
(svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents:
15623
diff
changeset
|
767 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
|
768 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
|
769 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
|
770 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
|
771 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
|
772 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
775 |
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
|
776 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
|
777 |
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
|
778 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
|
779 } 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
|
780 |
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
|
781 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
|
782 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
783 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
784 /** 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
|
785 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
|
786 { |
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
|
787 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
|
788 |
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
|
789 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
|
790 |
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
|
791 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
|
792 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
|
793 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
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 } |
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
|
801 } 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
|
802 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
|
803 |
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
|
804 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
|
805 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
|
806 continue; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
807 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
808 |
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
|
809 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
|
810 e->preview_wait = 20; |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18340
diff
changeset
|
811 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
|
812 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
|
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
817 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
818 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
819 * 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
|
820 * 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
|
821 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
822 * @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
|
823 * @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
|
824 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
825 * @param text unused |
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
826 * @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
|
827 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11071
diff
changeset
|
828 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
|
829 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
830 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
|
831 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
|
832 |
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
|
833 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
|
834 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
835 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
|
836 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
837 |
15653
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
838 /** |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
839 * An engine has become available for general use. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
840 * Also handle the exclusive engine preview contract. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
841 * @param e Engine generally available as of now. |
930fc2895ced
(svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents:
15652
diff
changeset
|
842 */ |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
843 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
|
844 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
845 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
|
846 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
|
847 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
|
848 |
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
|
849 /* 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
|
850 * 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
|
851 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
|
852 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
|
853 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
|
854 |
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
|
855 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
|
856 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
857 /* 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
|
858 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
|
859 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
860 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
|
861 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
|
862 (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
|
863 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
|
864 /* 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
|
865 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
|
866 break; |
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
872 |
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
|
873 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
|
874 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
|
875 |
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
|
876 /* 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
|
877 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
|
878 |
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
|
879 /* 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
|
880 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
|
881 |
8220
01778382728c
(svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents:
8214
diff
changeset
|
882 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
|
883 /* 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
|
884 RailType railtype = e->u.rail.railtype; |
5823 | 885 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
|
886 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
|
887 } 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
|
888 /* 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
|
889 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
|
890 } |
9199
dbe675dc54c4
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents:
9135
diff
changeset
|
891 |
18511
f1214da4c397
(svn r23355) -Codechange: rename all AI* to Script* (Rubidium)
truebrain <truebrain@openttd.org>
parents:
18340
diff
changeset
|
892 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
|
893 |
9199
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(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
|
895 SetDParam(1, index); |
12619
2f530108f787
(svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents:
12492
diff
changeset
|
896 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
|
897 |
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 /* 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
|
899 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
|
900 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
|
901 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
902 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6209
diff
changeset
|
903 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
|
904 { |
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
|
905 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
|
906 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
|
907 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
|
908 /* 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
|
909 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
|
910 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
|
911 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
|
912 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
913 |
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
|
914 /* 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
|
915 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
|
916 |
10744
0118ca646690
(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents:
10696
diff
changeset
|
917 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
|
918 /* 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
|
919 NewVehicleAvailable(e); |
11361
02313cc6114e
(svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents:
11296
diff
changeset
|
920 } 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
|
921 /* 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
|
922 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
|
923 |
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
|
924 /* 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
|
925 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
|
926 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
|
927 } |
5584
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 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
932 |
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
|
933 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
|
934 { |
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
|
935 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
|
936 |
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
|
937 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
|
938 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
|
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 |
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 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
|
942 } |
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
|
943 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
944 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
945 * 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
|
946 * @param tile unused |
6481
85a1a79387a2
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents:
6259
diff
changeset
|
947 * @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
|
948 * @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
|
949 * @param p2 unused |
13067
082cdb4504ac
(svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents:
13036
diff
changeset
|
950 * @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
|
951 * @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
|
952 */ |
11090
df23c4e04638
(svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents:
11071
diff
changeset
|
953 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
|
954 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
955 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
|
956 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
|
957 |
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
|
958 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
|
959 |
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
|
960 if (!reset) { |
16679
07ae81d6312a
(svn r21410) -Codechange: limit engine name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents:
16643
diff
changeset
|
961 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
|
962 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
|
963 } |
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
|
964 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
965 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
|
966 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
|
967 |
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 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
|
969 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
|
970 } 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
|
971 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
|
972 } |
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
|
973 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
974 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
975 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
976 |
6950
d2846442a133
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents:
6943
diff
changeset
|
977 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
|
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 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
980 |
15620
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
981 /** |
f8e9a3f0c140
(svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents:
15552
diff
changeset
|
982 * 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
|
983 * @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
|
984 * @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
|
985 * @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
|
986 * @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
|
987 * 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
|
988 */ |
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
|
989 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
|
990 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
991 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
|
992 |
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
|
993 /* 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
|
994 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
|
995 |
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
|
996 /* 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
|
997 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
|
998 |
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
|
999 /* 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
|
1000 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
|
1001 |
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
|
1002 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
|
1003 |
18767
50f4f95caf36
(svn r23615) -Add: more API functions exposed to NoGo (part 2)
truebrain <truebrain@openttd.org>
parents:
18678
diff
changeset
|
1004 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
|
1005 /* 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
|
1006 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
|
1007 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
|
1008 } |
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
|
1009 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1010 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
|
1011 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1012 |
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
|
1013 /** |
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
|
1014 * 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
|
1015 * 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
|
1016 * @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
|
1017 * @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
|
1018 */ |
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 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
|
1020 { |
11951
8bbe44fa53e2
(svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents:
11923
diff
changeset
|
1021 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
|
1022 |
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
|
1023 /* 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
|
1024 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
|
1025 |
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
|
1026 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
|
1027 |
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
|
1028 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
|
1029 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
|
1030 |
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 /* 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
|
1032 * 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
|
1033 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
|
1034 |
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
|
1035 /* 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
|
1036 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
|
1037 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
|
1038 } |