annotate src/engine.cpp @ 20725:fec842671605 draft

(svn r25639) -Codechange: Rename both 'STR_ERROR_NO_VEHICLES_AVAILABLE*' strings.
author alberth <alberth@openttd.org>
date Wed, 31 Jul 2013 07:25:58 +0000
parents 35dad1cb63ac
children 648c12a70f7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
19880
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
32 #include "articulated_vehicles.h"
20609
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
33 #include "error.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34
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
35 #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
36 #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
37
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
38 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
39 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
40
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
41 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
42
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
43 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
44 * 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
45 * and no more engines will be introduced
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
46 */
13508
f7e05f44c9be (svn r18027) -Codechange: make some unneededly global variables static and remove some unused variables
rubidium <rubidium@openttd.org>
parents: 13492
diff changeset
47 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
48
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
49 /**
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 * 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
51 * 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
52 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
53
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
54 /** 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
55 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
56 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
57 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
58 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
59 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
60 };
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
61
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 /** 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
63 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
64 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
65 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
66 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
67 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
68 };
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
69
13249
f52dcc31398e (svn r17758) -Revert (r17208): Use assert_compile() if you cannot count.
frosch <frosch@openttd.org>
parents: 13218
diff changeset
70 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
71
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
72 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
73
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
74 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
75 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
76 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
77 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
78 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
79 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
80
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 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
82 {
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->type = type;
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15653
diff changeset
84 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
85 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
86
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
87 /* 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
88 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
89 /* 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
90 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
91 /* 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
92 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
93 /* 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
94 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
95 /* 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
96 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
97 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
98 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
99 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
100 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
101 }
17909
4d6b4b6d6069 (svn r22713) -Feature: [NewGRF] Per vehicle custom cargo ageing period.
michi_cc <michi_cc@openttd.org>
parents: 17891
diff changeset
102 /* 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
103 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
104 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
105 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
106
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 /* 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
108 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
109
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 /* 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
111 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
112 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
113
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
114 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
115 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
116 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
117 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
118
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
119 /* 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
120 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
121
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
122 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
123
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
124 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
125 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
126 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
127 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
128 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
129
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
130 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
131 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
132 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
133 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
134 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
135
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
136 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
137 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
138 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
139 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
140 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
141 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
142 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
143
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 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
145 {
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 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
147 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
148 }
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
149
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
150 /**
19583
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
151 * Checks whether the engine is a valid (non-articulated part of an) engine.
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
152 * @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
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 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
155 {
19583
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
156 return this->info.string_id != STR_NEWGRF_INVALID_ENGINE && HasBit(this->info.climates, _settings_game.game_creation.landscape);
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
157 }
f98b40bd4ccb (svn r21986) -Codechange: Add helper function to test whether an engine is still associated to a GRF.
frosch <frosch@openttd.org>
parents: 17235
diff changeset
158
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
159 /**
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
160 * 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
161 * 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
162 * @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
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 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
165 {
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 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
167 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
168 }
e6cbcbf3780f (svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents: 18152
diff changeset
169
e6cbcbf3780f (svn r23075) -Codechange: Add GetGRF() and GetGRFID() methods to Engine and Vehicle to simplify code.
frosch <frosch@openttd.org>
parents: 18152
diff changeset
170 /**
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 * Determines whether an engine can carry something.
18678
5604c42fa1ce (svn r23526) -Codechange: unify cargos vs cargoes
rubidium <rubidium@openttd.org>
parents: 18656
diff changeset
172 * 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
173 * @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
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 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
176 {
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 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
178 * 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
179 * 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
180 * 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
181 */
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 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
183 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
184 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
185 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
186
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 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
188 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
189 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
190
9e451d497d94 (svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents: 11171
diff changeset
191 case VEH_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
192 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
193 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
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 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
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 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
198 }
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
199
18337
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
200
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
201 /**
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
202 * 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
203 * 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
204 * @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
205 * @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
206 * @return Capacity
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
207 */
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
208 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
209 {
18340
72d57cf141f5 (svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents: 18339
diff changeset
210 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
211 if (mail_capacity != NULL) *mail_capacity = 0;
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
212
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
213 if (!this->CanCarryCargo()) return 0;
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
214
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
215 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
216 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
217 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
218
72d57cf141f5 (svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents: 18339
diff changeset
219 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
220 *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
221 }
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
222
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 /* 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
224 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
225 (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
226 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
227 if (callback != CALLBACK_FAILED) return callback;
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
228 }
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
229
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
230 /* Get capacity according to property resp. CB */
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
231 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
232 uint extra_mail_cap = 0;
18337
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
233 switch (this->type) {
18339
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
234 case VEH_TRAIN:
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
235 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
236
72d57cf141f5 (svn r23176) -Codechange: Deduplicate code between Engine::DetermineCapacity() and Engine::GetDisplayDefaultCapacity().
frosch <frosch@openttd.org>
parents: 18339
diff changeset
237 /* 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
238 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
239 break;
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
240
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
241 case VEH_ROAD:
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
242 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
243 break;
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
244
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
245 case VEH_SHIP:
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
246 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
247 break;
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
248
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
249 case VEH_AIRCRAFT:
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
250 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
251 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
252 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
253 }
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
254 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
255 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
256 break;
4675de035ab1 (svn r23175) -Codechange: Refactor Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18338
diff changeset
257
18337
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
258 default: NOT_REACHED();
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
259 }
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
260
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
261 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
262 /* 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
263 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
264 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
265 }
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
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 /* 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
268 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
269 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
270 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
271 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
272 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
273 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
274 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
275 }
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
276 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
277 }
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 return capacity;
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
280 }
f3ce001bc1d1 (svn r23173) -Codechange: Rename GetVehicleCapacity() to Engine::DetermineCapacity().
frosch <frosch@openttd.org>
parents: 18247
diff changeset
281
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
282 /**
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
283 * Return how much the running costs of this engine are.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
284 * @return Yearly running cost of the engine.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
285 */
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
286 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
287 {
13741
775d368aa2b0 (svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents: 13508
diff changeset
288 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
289 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
290 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
291 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
292 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
293 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
294 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
295 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
296
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
297 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
298 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
299 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
300 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
301 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
302
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
303 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
304 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
305 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
306 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
307
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
308 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
309 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
310 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
311 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
312
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
313 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
314 }
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
315
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
316 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
317 }
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
318
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
319 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
320 * Return how much a new engine costs.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
321 * @return Cost of the engine.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
322 */
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
323 Money Engine::GetCost() const
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
324 {
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
325 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
326 uint cost_factor;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
327 switch (this->type) {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
328 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
329 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
330 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
331 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
332
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
333 case VEH_TRAIN:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
334 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
335 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
336 cost_factor = GetEngineProperty(this->index, PROP_TRAIN_COST_FACTOR, this->u.rail.cost_factor);
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
337 } 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
338 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
339 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
340 }
13741
775d368aa2b0 (svn r18266) -Codechange: Add a function to compute prices from price base and cost factor and use it consistently for vehicle purchase, running cost, and refit cost.
frosch <frosch@openttd.org>
parents: 13508
diff changeset
341 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
342
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
343 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
344 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
345 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
346 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
347
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
348 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
349 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
350 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
351 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
352
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
353 default: NOT_REACHED();
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
354 }
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
355
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
356 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
357 }
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
358
10967
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
359 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
360 * 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
361 * @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
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 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
364 {
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
365 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
366 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
367 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
368
16384
f39955ef4720 (svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents: 16347
diff changeset
369 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
370 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
371 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
372 }
10967
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
373
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 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
375 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
376
15043
2120f331b2be (svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents: 14772
diff changeset
377 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
378 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
379 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
380 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
381 }
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
382 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
383 }
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
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 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
386 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
387 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
388
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
389 /**
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
390 * 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
391 * and sorting purposes.
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
392 * 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
393 * @return power in display units hp
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
394 */
10967
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
395 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
396 {
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
397 /* 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
398 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
399 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
400 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
401 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
402 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
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 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
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 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
407
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 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
409 * 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
410 * 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
411 * @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
412 */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
413 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
414 {
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
415 /* 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
416 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
417 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
418 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
419 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
420 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
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 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
423 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
424 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
425
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 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
427 * 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
428 * 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
429 * @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
430 */
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
431 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
432 {
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
433 /* 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
434 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
435 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
436 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
437 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
438 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
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 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
441 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
442 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
443
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
444 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
445 * 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
446 * @return the life length
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 Date Engine::GetLifeLengthInDays() const
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
449 {
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
450 /* 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
451 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
452 }
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
453
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
454 /**
18656
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
455 * Get the range of an aircraft type.
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
456 * @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
457 */
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
458 uint16 Engine::GetRange() const
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
459 {
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
460 switch (this->type) {
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
461 case VEH_AIRCRAFT:
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
462 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
463
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
464 default: NOT_REACHED();
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 }
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
467
c107e4bb6187 (svn r23504) -Feature: Aircraft range.
michi_cc <michi_cc@openttd.org>
parents: 18511
diff changeset
468 /**
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
469 * 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
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 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
472 {
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 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
474 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
475 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
476 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
477 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
478 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
479 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
480 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
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
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 /**
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 * 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
487 * @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
488 * @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
489 * @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
490 * 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
491 * 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
492 * @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
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 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
495 {
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 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
497 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
498 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
499 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
500 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
501 }
1b6a11831215 (svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents: 11238
diff changeset
502 }
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 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
504 }
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
505
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
506 /**
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
507 * 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
508 * 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
509 * @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
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 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
512 {
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 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
514 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
515 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
516 }
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
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 /* 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
519 _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
520 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
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 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
523 }
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
524
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
525 /**
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
526 * 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
527 */
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
528 void SetupEngines()
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
529 {
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
530 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
531 _engine_pool.CleanPool();
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
532
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
533 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
534 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
535 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
536 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
537 /* 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
538 * 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
539 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
540 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
541 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
542 }
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
543
a804b91f3a3e (svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents: 17104
diff changeset
544 _introduced_railtypes = 0;
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
545 }
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
546
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
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 * 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
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 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
551 {
a804b91f3a3e (svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents: 17104
diff changeset
552 /* 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
553 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
554
a804b91f3a3e (svn r21842) -Feature [FS#4393]: [NewGRF] Introduction dates/required types for rail types; e.g. introduce a particular rail type in 1960 (or when a vehicle using it is introduced), but also allow limiting its introduction to only happen when the required railtypes are available
rubidium <rubidium@openttd.org>
parents: 17104
diff changeset
555 /* We 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
556 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
557
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 /* 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
559 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
560 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
561 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
562 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
563 }
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
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
565 _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
566 }
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
567
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
568 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
569
17484
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
570 /**
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
571 * 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
572 * @param index %Engine getting queried.
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
573 * @return Whether the queried engine is a wagon.
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
574 */
9468
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
575 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
576 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
577 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
578 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
579 }
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
580
17484
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
581 /**
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
582 * 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
583 * @param e %Engine to update.
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
584 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
585 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
586 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
587 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
588
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
589 /* 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
590 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
591 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
592 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
593 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
594 /* 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
595 e->company_avail = 0;
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
596 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
597 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
598 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
599
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
600 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
601 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
602 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
603 } 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
604 /* 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
605 * 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
606 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
607 } 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
608 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
609 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
610 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
611 /* 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
612 * 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
613 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
614 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
615 /* 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
616 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
617 }
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12837
diff changeset
618 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
619 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
620 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
621
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
622 /** 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
623 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
624 {
85cfd6fe68e1 (svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents: 10571
diff changeset
625 /* 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
626 _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
627
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 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
629 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
630 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
631
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 /* 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
633 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
634 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
635
85cfd6fe68e1 (svn r14926) -Feature: Automatically set last engine ageing year to the last 'introduction year plus half model life', to allow engines later than 2050 to appear.
peter1138 <peter1138@openttd.org>
parents: 10571
diff changeset
636 /* 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
637 YearMonthDay ymd;
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
638 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
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 _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
641 }
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
642 }
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
643
17640
99d6211b8c36 (svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents: 17495
diff changeset
644 /**
99d6211b8c36 (svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents: 17495
diff changeset
645 * Start/initialise one engine.
99d6211b8c36 (svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents: 17495
diff changeset
646 * @param e The engine to initialise.
99d6211b8c36 (svn r22411) -Document: another bunch of bits
rubidium <rubidium@openttd.org>
parents: 17495
diff changeset
647 * @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
648 */
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
649 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
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 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
652
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->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
654 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
655 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
656
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
657 /* 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
658 * 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
659 * 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
660 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
661 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
662 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
663 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
664 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
665 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
666 }
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
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_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
669 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
670 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
671 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
672
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 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
674 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
675 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
676 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
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 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
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 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
681
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 /* 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
683 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
684 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
685 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
686 }
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
687 }
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
688
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
689 /**
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 * 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
691 * 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
692 */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
693 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
694 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
695 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
696 /* 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
697 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
698
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
699 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
700 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
701 }
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
702
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
703 /* 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
704 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
705 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
706 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
707 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
708 }
16643
bb429a529a4a (svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents: 16514
diff changeset
709
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
710 /* 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
711 * 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
712 * 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
713 * 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
714 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
715 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
716 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
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 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
719 }
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
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
721 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
722
16643
bb429a529a4a (svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents: 16514
diff changeset
723 /* 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
724 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
725 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
726
17484
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
727 /**
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
728 * 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
729 * @param eid Engine being accepted (is under preview).
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
730 * @param company Current company previewing the engine.
d0d74ae900fb (svn r22239) -Doc: Further engine doxyment additions.
alberth <alberth@openttd.org>
parents: 17285
diff changeset
731 */
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
732 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
733 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
734 Engine *e = Engine::Get(eid);
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
735 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
736
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
737 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
738 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
739 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
740 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
741 } 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
742 SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
743 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
745 e->preview_company = INVALID_COMPANY;
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
746 e->preview_asked = (CompanyMask)-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
747 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
748 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
749 }
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
750
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
751 /* 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
752 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
753 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
19878
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
754
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
755 /* Notify preview window, that it might want to close.
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
756 * Note: We cannot directly close the window.
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
757 * In singleplayer this function is called from the preview window, so
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
758 * we have to use the GUI-scope scheduling of InvalidateWindowData.
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
759 */
547bdf50d651 (svn r24811) -Add: Close engine preview window when another client accepts it.
frosch <frosch@openttd.org>
parents: 19877
diff changeset
760 InvalidateWindowData(WC_ENGINE_PREVIEW, eid);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
761 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
762
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
763 /**
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
764 * Get the best company for an engine preview.
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
765 * @param e Engine to preview.
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
766 * @return Best company if it exists, #INVALID_COMPANY otherwise.
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
767 */
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
768 static CompanyID GetPreviewCompany(Engine *e)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
769 {
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
770 CompanyID best_company = INVALID_COMPANY;
15652
354307d245e5 (svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents: 15623
diff changeset
771
19880
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
772 /* For trains the cargomask has no useful meaning, since you can attach other wagons */
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
773 uint32 cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : (uint32)-1;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
774
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
775 int32 best_hist = -1;
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
776 const Company *c;
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
777 FOR_ALL_COMPANIES(c) {
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
778 if (c->block_preview == 0 && !HasBit(e->preview_asked, c->index) &&
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
779 c->old_economy[0].performance_history > best_hist) {
19880
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
780
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
781 /* Check whether the company uses similar vehicles */
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
782 Vehicle *v;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
783 FOR_ALL_VEHICLES(v) {
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
784 if (v->owner != c->index || v->type != e->type) continue;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
785 if (!v->GetEngine()->CanCarryCargo() || !HasBit(cargomask, v->cargo_type)) continue;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
786
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
787 best_hist = c->old_economy[0].performance_history;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
788 best_company = c->index;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
789 break;
2168a584b026 (svn r24813) -Change: Offer engine previews only to companies which actually use the particular vehicle-type/cargo-type combination.
frosch <frosch@openttd.org>
parents: 19879
diff changeset
790 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
791 }
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
792 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
793
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
794 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
795 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
796
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
797 /**
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
798 * Checks if a vehicle type is disabled for all/ai companies.
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
799 * @param type The vehicle type which shall be checked.
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
800 * @param ai If true, check if the type is disabled for AI companies, otherwise check if
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
801 * the vehicle type is disabled for human companies.
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
802 * @return Whether or not a vehicle type is disabled.
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
803 */
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
804 static bool IsVehicleTypeDisabled(VehicleType type, bool ai)
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
805 {
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
806 switch (type) {
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
807 case VEH_TRAIN: return _settings_game.vehicle.max_trains == 0 || (ai && _settings_game.ai.ai_disable_veh_train);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
808 case VEH_ROAD: return _settings_game.vehicle.max_roadveh == 0 || (ai && _settings_game.ai.ai_disable_veh_roadveh);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
809 case VEH_SHIP: return _settings_game.vehicle.max_ships == 0 || (ai && _settings_game.ai.ai_disable_veh_ship);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
810 case VEH_AIRCRAFT: return _settings_game.vehicle.max_aircraft == 0 || (ai && _settings_game.ai.ai_disable_veh_aircraft);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
811
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
812 default: NOT_REACHED();
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
813 }
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
814 }
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
815
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
816 /** 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
817 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
818 {
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
819 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
820
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
821 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
822
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
823 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
824 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
825 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
826 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
827 if (e->preview_company != INVALID_COMPANY) {
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
828 if (!--e->preview_wait) {
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 DeleteWindowById(WC_ENGINE_PREVIEW, i);
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
830 e->preview_company = 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
831 }
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
832 } else if (CountBits(e->preview_asked) < MAX_COMPANIES) {
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
833 e->preview_company = GetPreviewCompany(e);
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
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
835 if (e->preview_company == INVALID_COMPANY) {
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
836 e->preview_asked = (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
837 continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
838 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
839
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
840 SetBit(e->preview_asked, e->preview_company);
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
841 e->preview_wait = 20;
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
842 /* AIs are intentionally not skipped for preview even if they cannot build a certain
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
843 * vehicle type. This is done to not give poor performing human companies an "unfair"
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
844 * boost that they wouldn't have gotten against other human companies. The check on
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
845 * the line below is just to make AIs not notice that they have a preview if they
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
846 * cannot build the vehicle. */
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
847 if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
848 if (IsInteractiveCompany(e->preview_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
849 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
850 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
851 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
852 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
853
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
854 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
855 * 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
856 * 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
857 * @param tile unused
19968
0dba7f49118c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents: 19880
diff changeset
858 * @param flags operation to perform
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 * @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
860 * @param p2 unused
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
861 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
862 * @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
863 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
864 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
865 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
866 Engine *e = Engine::GetIfValid(p1);
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
867 if (e == NULL || e->preview_company != _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
868
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
869 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
870
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
871 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
872 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
873
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
874 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
875 * An engine has become available for general use.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
876 * Also handle the exclusive engine preview contract.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
877 * @param e Engine generally available as of now.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
878 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
879 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
880 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
881 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
882 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
883 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
884
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
885 /* 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
886 * 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
887 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
888 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
889 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
890
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
891 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
892
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
893 /* 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
894 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
895
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
896 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
897 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
898 (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
899 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
900 /* 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
901 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
902 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
903 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
904 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
905 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
906 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
907 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
908
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
909 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
910 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
911
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
912 /* 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
913 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
914
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
915 /* 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
916 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
917
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
918 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
919 /* 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
920 RailType railtype = e->u.rail.railtype;
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
921 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
922 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
923 } 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
924 /* 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
925 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
926 }
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
927
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
928 /* Only broadcast event if AIs are able to build this vehicle type. */
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
929 if (!IsVehicleTypeDisabled(e->type, true)) 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
930
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
931 /* Only provide the "New Vehicle available" news paper entry, if engine can be built. */
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
932 if (!IsVehicleTypeDisabled(e->type, false)) {
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
933 SetDParam(0, GetEngineCategoryName(index));
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
934 SetDParam(1, index);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
935 AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NT_NEW_VEHICLES, NF_VEHICLE, NR_ENGINE, index);
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
936 }
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
937
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
938 /* 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
939 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
940 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
19879
fc6003f86e35 (svn r24812) -Fix: Close pending preview windows when the engine is introduced to everyone.
frosch <frosch@openttd.org>
parents: 19878
diff changeset
941
fc6003f86e35 (svn r24812) -Fix: Close pending preview windows when the engine is introduced to everyone.
frosch <frosch@openttd.org>
parents: 19878
diff changeset
942 /* Close pending preview windows */
fc6003f86e35 (svn r24812) -Fix: Close pending preview windows when the engine is introduced to everyone.
frosch <frosch@openttd.org>
parents: 19878
diff changeset
943 DeleteWindowById(WC_ENGINE_PREVIEW, 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
944 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
945
19626
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
946 /** Monthly update of the availability, reliability, and preview offers of the engines. */
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
947 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
948 {
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
949 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
950 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
951 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
952 /* 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
953 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
954 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
955 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
956 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
957
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
958 /* 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
959 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
960
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
961 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
962 /* 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
963 NewVehicleAvailable(e);
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11296
diff changeset
964 } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
965 /* Introduction date has passed...
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
966 * Check if it is allowed to build this vehicle type at all
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
967 * based on the current game settings. If not, it does not
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
968 * make sense to show the preview dialog to any company. */
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
969 if (IsVehicleTypeDisabled(e->type, false)) continue;
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
970
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
971 /* Do not introduce new rail wagons */
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
972 if (IsWagon(e->index)) continue;
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
973
19727
a80d140bf769 (svn r24660) -Feature: do not display the preview window for disabled vehicle types (Eagle_rainbow)
yexo <yexo@openttd.org>
parents: 19626
diff changeset
974 /* Show preview dialog to one of the 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
975 e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
19877
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
976 e->preview_company = INVALID_COMPANY;
784e2ae3c6ba (svn r24810) -Fix: Make engine preview offers more robust wrt. changes in the company ranking.
frosch <frosch@openttd.org>
parents: 19727
diff changeset
977 e->preview_asked = 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
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 }
19311
8f157dbe02b6 (svn r24200) -Fix [FS#5149]: Invalidate build vehicle windows every month, in case they need resorting due to changed reliabilities.
frosch <frosch@openttd.org>
parents: 19005
diff changeset
980
8f157dbe02b6 (svn r24200) -Fix [FS#5149]: Invalidate build vehicle windows every month, in case they need resorting due to changed reliabilities.
frosch <frosch@openttd.org>
parents: 19005
diff changeset
981 InvalidateWindowClassesData(WC_BUILD_VEHICLE); // rebuild the purchase list (esp. when sorted by reliability)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
982 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
983 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
984
19626
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
985 /**
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
986 * Is \a name still free as name for an engine?
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
987 * @param name New name of an engine.
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
988 * @return \c false if the name is being used already, else \c true.
017481cebabf (svn r24535) -Doc: Two additions, lots of small spelling fixes, and some Doxygen improvements.
alberth <alberth@openttd.org>
parents: 19583
diff changeset
989 */
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
990 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
991 {
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
992 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
993
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
994 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
995 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
996 }
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
997
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
998 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
999 }
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
1000
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
1001 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
1002 * 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
1003 * @param tile unused
19968
0dba7f49118c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow)
planetmaker <planetmaker@openttd.org>
parents: 19880
diff changeset
1004 * @param flags operation to perform
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1005 * @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
1006 * @param p2 unused
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
1007 * @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
1008 * @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
1009 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
1010 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
1011 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
1012 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
1013 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
1014
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
1015 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
1016
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
1017 if (!reset) {
16679
07ae81d6312a (svn r21410) -Codechange: limit engine name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents: 16643
diff changeset
1018 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
1019 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
1020 }
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
1021
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1022 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
1023 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
1024
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
1025 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
1026 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
1027 } 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
1028 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
1029 }
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
1030
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1031 MarkWholeScreenDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1032 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1033
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
1034 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
1035 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1036
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1037
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
1038 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
1039 * 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
1040 * @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
1041 * @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
1042 * @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
1043 * @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
1044 * 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
1045 */
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
1046 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
1047 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
1048 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
1049
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
1050 /* 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
1051 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
1052
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
1053 /* 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
1054 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
1055
19583
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1056 /* check if it's available ... */
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1057 if (company == OWNER_DEITY) {
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1058 /* ... for any company (preview does not count) */
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1059 if (!(e->flags & ENGINE_AVAILABLE) || e->company_avail == 0) return false;
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1060 } else {
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1061 /* ... for this company */
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1062 if (!HasBit(e->company_avail, company)) return false;
d07ed718e6e6 (svn r24492) -Add: [NoGo] Useful behaviour for GSEngine::IsValidEngine and GSEngine::IsBuildable when outside GSCompanyMode scope.
frosch <frosch@openttd.org>
parents: 19383
diff changeset
1063 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1064
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
1065 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
1066
18767
50f4f95caf36 (svn r23615) -Add: more API functions exposed to NoGo (part 2)
truebrain <truebrain@openttd.org>
parents: 18678
diff changeset
1067 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
1068 /* 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
1069 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
1070 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
1071 }
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
1072
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1073 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
1074 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
1075
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
1076 /**
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
1077 * 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
1078 * 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
1079 * @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
1080 * @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
1081 */
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
1082 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
1083 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
1084 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
1085
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
1086 /* 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
1087 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
1088
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
1089 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
1090
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
1091 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
1092 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
1093
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
1094 /* 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
1095 * 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
1096 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
1097
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
1098 /* 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
1099 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
1100 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
1101 }
20609
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1102
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1103 /**
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1104 * Check for engines that have an appropriate availability.
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1105 */
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1106 void CheckEngines()
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1107 {
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1108 const Engine *e;
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1109 Date min_date = INT32_MAX;
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1110
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1111 FOR_ALL_ENGINES(e) {
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1112 if (!e->IsEnabled()) continue;
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1113
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1114 /* We have an available engine... yay! */
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1115 if (e->flags & ENGINE_AVAILABLE && e->company_avail != 0) return;
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1116
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1117 /* Okay, try to find the earliest date. */
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1118 min_date = min(min_date, e->info.base_intro);
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1119 }
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1120
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1121 SetDParam(0, min_date);
20725
fec842671605 (svn r25639) -Codechange: Rename both 'STR_ERROR_NO_VEHICLES_AVAILABLE*' strings.
alberth <alberth@openttd.org>
parents: 20609
diff changeset
1122 ShowErrorMessage(STR_ERROR_NO_VEHICLES_AVAILABLE_YET, STR_ERROR_NO_VEHICLES_AVAILABLE_YET_EXPLANATION, WL_WARNING);
20609
35dad1cb63ac (svn r25553) -Fix [FS#5530]: provide a warning when no vehicles are available, and tell what to do in that case
rubidium <rubidium@openttd.org>
parents: 19968
diff changeset
1123 }