annotate src/engine.cpp @ 17104:f081bf6f0633 draft

(svn r21841) -Feature: [NewGRF] Allow to define other railtypes that should be introduced if a particular rail type is introduced, e.g. to make sure slow rail is introduced when fast rail gets introduced
author rubidium <rubidium@openttd.org>
date Tue, 18 Jan 2011 21:28:07 +0000
parents 7b207547041b
children a804b91f3a3e
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"
6643
18d58b36b9b3 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium <rubidium@openttd.org>
parents: 6606
diff changeset
19 #include "group.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 7931
diff changeset
20 #include "strings_func.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10927
diff changeset
21 #include "core/random_func.hpp"
8131
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
22 #include "window_func.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
23 #include "date_func.h"
8212
11263ebe590a (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
24 #include "autoreplace_gui.h"
8214
6385dffc0b37 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium <rubidium@openttd.org>
parents: 8212
diff changeset
25 #include "string_func.h"
10696
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10656
diff changeset
26 #include "ai/ai.hpp"
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
27 #include "core/pool_func.hpp"
12837
a6a46b1b7ad9 (svn r17327) -Codechange: Allow external use of GetEngineCategoryName().
alberth <alberth@openttd.org>
parents: 12808
diff changeset
28 #include "engine_gui.h"
14258
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 13804
diff changeset
29 #include "engine_func.h"
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 13804
diff changeset
30 #include "engine_base.h"
a899d4e5ee1a (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header
rubidium <rubidium@openttd.org>
parents: 13804
diff changeset
31 #include "company_base.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
32
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
33 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
34 #include "table/engines.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
35
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
36 EnginePool _engine_pool("Engine");
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
37 INSTANTIATE_POOL_METHODS(Engine)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
38
11296
1b6a11831215 (svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents: 11238
diff changeset
39 EngineOverrideManager _engine_mngr;
1b6a11831215 (svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents: 11238
diff changeset
40
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
41 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
42 * Year that engine aging stops. Engines will not reduce in reliability
15623
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
43 * and no more engines will be introduced
c62577640878 (svn r20286) -Codechange: Unify end of doxygen comments.
frosch <frosch@openttd.org>
parents: 15620
diff changeset
44 */
13508
f7e05f44c9be (svn r18027) -Codechange: make some unneededly global variables static and remove some unused variables
rubidium <rubidium@openttd.org>
parents: 13492
diff changeset
45 static Year _year_engine_aging_stops;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
46
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
47 /** 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
48 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
49 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
50 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
51 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
52 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
53 };
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
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 /** 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
56 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
57 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
58 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
59 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
60 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
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
13249
f52dcc31398e (svn r17758) -Revert (r17208): Use assert_compile() if you cannot count.
frosch <frosch@openttd.org>
parents: 13218
diff changeset
63 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
64
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
65 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
66
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
67 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
68 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
69 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
70 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
71 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
72 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
73
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(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
75 {
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 this->type = type;
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15653
diff changeset
77 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
78 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
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 /* 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
81 if (base >= _engine_counts[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
82 /* Mark engine as valid anyway */
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->info.climates = 0x80;
10427
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
84 /* 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
85 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
86 /* 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
87 if (type == VEH_ROAD) this->u.road.tractive_effort = 0x4C;
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
88 /* 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
89 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
90 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
91 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
92 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
93 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
94 }
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
95 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
96 }
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
97
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
98 /* 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
99 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
100
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
101 /* 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
102 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
103 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
104
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
105 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
106 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
107 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
108 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
109
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
110 /* 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
111 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
112
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
113 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
114
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 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
116 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
117 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
118 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
119 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
120
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
121 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
122 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
123 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
124 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
125 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
126
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
127 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
128 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
129 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
130 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
131 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
132 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
133 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
134
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 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
136 {
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 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
138 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
139 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
140
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
141 /**
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
142 * Determines whether an engine 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
143 * A vehicle cannot carry anything if its capacity is zero, or none of the possible cargos is available in the climate.
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
144 * @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
145 */
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
146 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
147 {
9e451d497d94 (svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents: 11171
diff changeset
148 /* 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
149 * 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
150 * 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
151 * 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
152 */
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
153 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
154 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
155 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
156 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
157
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
158 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
159 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
160 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
161
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
162 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
163 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
164 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
165
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
166 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
167 }
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
168 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
169 }
9e451d497d94 (svn r15541) -Revert (r15399): 'v->cargo_type' is also used in other places, which cannot accept CT_INVALID.
frosch <frosch@openttd.org>
parents: 11171
diff changeset
170
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
171 /**
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
172 * Determines the default cargo capacity of an engine for display purposes.
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
173 *
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
174 * For planes carrying both passenger and mail this is the passenger capacity.
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
175 * For multiheaded engines this is the capacity of both heads.
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
176 * For articulated engines use GetCapacityOfArticulatedParts
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
177 *
13388
96253b319c10 (svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.
frosch <frosch@openttd.org>
parents: 13249
diff changeset
178 * @note Keep this function consistent with GetVehicleCapacity().
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
179 * @param mail_capacity returns secondary cargo (mail) capacity of aircraft
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
180 * @return The default capacity
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
181 * @see GetDefaultCargoType
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
182 */
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
183 uint Engine::GetDisplayDefaultCapacity(uint16 *mail_capacity) const
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
184 {
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
185 if (mail_capacity != NULL) *mail_capacity = 0;
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
186 if (!this->CanCarryCargo()) return 0;
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
187 switch (type) {
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
188 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
189 return GetEngineProperty(this->index, PROP_TRAIN_CARGO_CAPACITY, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 0);
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
190
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
191 case VEH_ROAD:
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
192 return GetEngineProperty(this->index, PROP_ROADVEH_CARGO_CAPACITY, this->u.road.capacity);
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
193
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
194 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
195 return GetEngineProperty(this->index, PROP_SHIP_CARGO_CAPACITY, this->u.ship.capacity);
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
196
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
197 case VEH_AIRCRAFT: {
16917
7b207547041b (svn r21652) -Cleanup: one semicolon is enough
smatz <smatz@openttd.org>
parents: 16679
diff changeset
198 uint capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_PASSENGER_CAPACITY, this->u.air.passenger_capacity);
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
199 CargoID cargo = this->GetDefaultCargoType();
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
200 if (IsCargoInClass(cargo, CC_PASSENGERS)) {
14641
9fdd19faf2ff (svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents: 14258
diff changeset
201 if (mail_capacity != NULL) *mail_capacity = GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity);
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
202 } else {
14641
9fdd19faf2ff (svn r19218) -Feature: [NewGRF] Add CB36 support for aircraft properties 0F and 11. (Eddi)
frosch <frosch@openttd.org>
parents: 14258
diff changeset
203 capacity += GetEngineProperty(this->index, PROP_AIRCRAFT_MAIL_CAPACITY, this->u.air.mail_capacity);
13388
96253b319c10 (svn r17897) -Fix [FS#3255]: CB15 and CB36 (capacity) were not always called when they should.
frosch <frosch@openttd.org>
parents: 13249
diff changeset
204 }
13417
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
205 switch (cargo) {
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
206 case CT_PASSENGERS:
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
207 case CT_MAIL: return capacity;
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
208 case CT_GOODS: return capacity / 2;
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
209 default: return capacity / 4;
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
210 }
216dfd60fb2f (svn r17926) -Fix (r9352): Make the decision whether aircraft carry mail consistent. Now always the cargo class decides.
frosch <frosch@openttd.org>
parents: 13388
diff changeset
211 }
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
212
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
213 default: NOT_REACHED();
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
214 }
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
215 }
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
216
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
217 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
218 * Return how much the running costs of this engine are.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
219 * @return Yearly running cost of the engine.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
220 */
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
221 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
222 {
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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231
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
232 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
233 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
234 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
235 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
236 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
237
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
238 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
239 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
240 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
241 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
242
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
243 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
244 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
245 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
246 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
247
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
248 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
249 }
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
250
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15653
diff changeset
251 return GetPrice(base_price, cost_factor, this->grf_prop.grffile, -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
252 }
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
253
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
254 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
255 * Return how much a new engine costs.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
256 * @return Cost of the engine.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
257 */
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
258 Money Engine::GetCost() const
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
259 {
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
260 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
261 uint cost_factor;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
262 switch (this->type) {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
263 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
264 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
265 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
266 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
267
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
268 case VEH_TRAIN:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
269 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
270 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
271 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
272 } 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
273 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
274 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
275 }
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
276 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
277
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
278 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
279 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
280 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
281 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
282
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
283 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
284 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
285 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
286 break;
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
287
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
288 default: NOT_REACHED();
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
289 }
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
290
15763
a60a50f29f64 (svn r20437) -Codechange: lets Engines use GRFFilePropsBase as well
rubidium <rubidium@openttd.org>
parents: 15653
diff changeset
291 return GetPrice(base_price, cost_factor, this->grf_prop.grffile, -8);
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
292 }
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
293
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
294 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
295 * 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
296 * @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
297 */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
298 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
299 {
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
300 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
301 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
302 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
303
16384
f39955ef4720 (svn r21100) -Feature [NewGRF]: Add CB36 support for road vehicle property 0x15 (Speed).
terkhen <terkhen@openttd.org>
parents: 16347
diff changeset
304 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
305 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
306 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
307 }
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
308
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
309 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
310 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
311
15043
2120f331b2be (svn r19660) -Feature: [NewGRF] support cb36 for aircraft speed also in the build menu
yexo <yexo@openttd.org>
parents: 14772
diff changeset
312 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
313 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
314 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
315 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
316 }
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
317 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
318 }
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
319
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
320 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
321 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
322 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
323
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
324 /**
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
325 * 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
326 * and sorting purposes.
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
327 * 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
328 * @return power in display units hp
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
329 */
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
330 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
331 {
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
332 /* 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
333 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
334 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
335 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
336 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
337 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
338
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
339 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
340 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
341 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
342
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
343 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
344 * 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
345 * 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
346 * @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
347 */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
348 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
349 {
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
350 /* 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
351 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
352 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
353 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
354 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
355 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
356
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
357 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
358 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
359 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
360
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
361 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
362 * 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
363 * 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
364 * @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
365 */
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
366 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
367 {
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
368 /* 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
369 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
370 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
371 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
372 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
373 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
374
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
375 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
376 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
377 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
378
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
379 /**
16385
4a60a952126d (svn r21101) -Doc: Additions and clarifications of doxygen comments
planetmaker <planetmaker@openttd.org>
parents: 16384
diff changeset
380 * 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
381 * @return the life length
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
382 */
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
383 Date Engine::GetLifeLengthInDays() const
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
384 {
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
385 /* 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
386 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
387 }
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
388
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
389 /**
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
390 * 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
391 */
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
392 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
393 {
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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402 }
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
403 }
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
404 }
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
405
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
406 /**
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
407 * 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
408 * @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
409 * @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
410 * @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
411 * 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
412 * 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
413 * @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
414 */
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
415 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
416 {
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
417 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
418 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
419 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
420 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
421 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
422 }
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
423 }
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
424 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
425 }
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
426
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
427 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
428 * Sets cached values in Company::num_vehicles and Group::num_vehicles
9220
baa148485404 (svn r13086) -Fix: do not crash badly after loading a newgrf with engines in-game that often
smatz <smatz@openttd.org>
parents: 9211
diff changeset
429 */
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
430 void SetCachedEngineCounts()
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
431 {
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
432 size_t engines = Engine::GetPoolSize();
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
433
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
434 /* Set up the engine count 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
435 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
436 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
437 free(c->num_engines);
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
438 c->num_engines = CallocT<EngineID>(engines);
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
439 }
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
440
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
441 /* Recalculate */
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
442 Group *g;
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
443 FOR_ALL_GROUPS(g) {
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
444 free(g->num_engines);
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
445 g->num_engines = CallocT<EngineID>(engines);
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
446 }
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
447
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
448 const Vehicle *v;
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
449 FOR_ALL_VEHICLES(v) {
12383
3c7e93b91c73 (svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents: 12232
diff changeset
450 if (!v->IsEngineCountable()) continue;
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
451
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
452 assert(v->engine_type < engines);
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
453
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
454 Company::Get(v->owner)->num_engines[v->engine_type]++;
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
455
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
456 if (v->group_id == DEFAULT_GROUP) continue;
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
457
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
458 g = Group::Get(v->group_id);
9211
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
459 assert(v->type == g->vehicle_type);
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
460 assert(v->owner == g->owner);
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
461
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
462 g->num_engines[v->engine_type]++;
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
463 }
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
464 }
30076ddd1741 (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz <smatz@openttd.org>
parents: 9206
diff changeset
465
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
466 void SetupEngines()
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
467 {
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
468 _engine_pool.CleanPool();
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
469
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
470 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
471 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
472 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
473 for (const EngineIDMapping *eid = _engine_mngr.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
474 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
475 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
476 }
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
477 }
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
478
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
479
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
480 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
481
9468
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
482 /* Determine if an engine type is a wagon (and not a loco) */
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
483 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
484 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
485 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
486 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
487 }
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
488
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
489 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
490 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
491 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
492
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
493 /* 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
494 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
495 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
496 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
497 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
498 /* 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
499 e->company_avail = 0;
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
500 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
501 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
502 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
503
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
504 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
505 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
506 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
507 } 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
508 /* 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
509 * 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
510 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
511 } 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
512 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
513 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
514 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
515 /* 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
516 * 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
517 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
518 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
519 /* 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
520 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
521 }
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12837
diff changeset
522 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
523 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
524 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
525
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
526 /** 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
527 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
528 {
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
529 /* 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
530 _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
531
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
532 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
533 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
534 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
535
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
536 /* 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
537 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
538 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
539
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
540 /* 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
541 YearMonthDay ymd;
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
542 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
543
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
544 _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
545 }
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
546 }
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
547
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
548 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
549 {
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
550 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
551
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
552 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
553 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
554 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
555
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
556 /* 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
557 * 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
558 * 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
559 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
560 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
561 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
562 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
563 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
564 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
565 }
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
566
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
567 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
568 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
569 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
570 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
571
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
572 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
573 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
574 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
575 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
576
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
577 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
578
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
579 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
580
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
581 /* 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
582 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
583 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
584 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
585 }
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
586 }
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
587
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
588 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
589 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
590 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
591 /* 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
592 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
593
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
594 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
595 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
596 }
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
597
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
598 /* 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
599 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
600 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
601 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
602 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
603 }
16643
bb429a529a4a (svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents: 16514
diff changeset
604
bb429a529a4a (svn r21374) -Fix: Purchases lists were not invalidated when using 'resetengines'
planetmaker <planetmaker@openttd.org>
parents: 16514
diff changeset
605 /* 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
606 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
607 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
608
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
609 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
610 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
611 Engine *e = Engine::Get(eid);
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
612 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
613
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
614 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
615 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
616 assert(e->u.rail.railtype < RAILTYPE_END);
17104
f081bf6f0633 (svn r21841) -Feature: [NewGRF] Allow to define other railtypes that should be introduced if a particular rail type is introduced, e.g. to make sure slow rail is introduced when fast rail gets introduced
rubidium <rubidium@openttd.org>
parents: 16917
diff changeset
617 c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
6685
91a7c42b133c (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium <rubidium@openttd.org>
parents: 6643
diff changeset
618 } 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
619 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
620 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
621
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
622 e->preview_company_rank = 0xFF;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
623 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
624 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
625 }
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
626
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
627 /* 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
628 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
629 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
630 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
631
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
632 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
633 * Get the N-th best company.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
634 * @param pp Value N, 1 means best, 2 means second best, etc.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
635 * @return N-th best company if it exists, #INVALID_COMPANY otherwise.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
636 */
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
637 static CompanyID GetBestCompany(uint8 pp)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
638 {
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
639 CompanyID best_company;
10477
20da0dd3f897 (svn r14732) -Codechange: replace some magic number with less magic constants and use the proper type for a few variables.
rubidium <rubidium@openttd.org>
parents: 10430
diff changeset
640 CompanyMask mask = 0;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
641
8572
8a95003be848 (svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz <smatz@openttd.org>
parents: 8565
diff changeset
642 do {
15652
354307d245e5 (svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents: 15623
diff changeset
643 int32 best_hist = -1;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
644 best_company = INVALID_COMPANY;
15652
354307d245e5 (svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents: 15623
diff changeset
645
354307d245e5 (svn r20317) -Codechange: Move variable declaration to their first use.
alberth <alberth@openttd.org>
parents: 15623
diff changeset
646 const Company *c;
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
647 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
648 if (c->block_preview == 0 && !HasBit(mask, c->index) &&
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
649 c->old_economy[0].performance_history > best_hist) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
650 best_hist = c->old_economy[0].performance_history;
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
651 best_company = c->index;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
652 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
653 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
654
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
655 if (best_company == INVALID_COMPANY) return INVALID_COMPANY;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
656
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
657 SetBit(mask, best_company);
8633
3c2144e0e2c2 (svn r12244) -Fix (r12150): typo resulting in no players are given the engine preview offer
smatz <smatz@openttd.org>
parents: 8572
diff changeset
658 } while (--pp != 0);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
659
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
660 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
661 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
662
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
663 /** 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
664 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
665 {
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
666 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
667
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
668 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
669 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
670 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
671 if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
c9f5e97572a4 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents: 6125
diff changeset
672 if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
673 if (e->preview_company_rank != 0xFF && !--e->preview_wait) {
6174
c9f5e97572a4 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents: 6125
diff changeset
674 e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
675 DeleteWindowById(WC_ENGINE_PREVIEW, i);
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
676 e->preview_company_rank++;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
677 }
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
678 } else if (e->preview_company_rank != 0xFF) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
679 CompanyID best_company = GetBestCompany(e->preview_company_rank);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
680
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
681 if (best_company == INVALID_COMPANY) {
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
682 e->preview_company_rank = 0xFF;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
683 continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
684 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
685
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
686 e->flags |= ENGINE_OFFER_WINDOW_OPEN;
7edccbb67398 (svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
truebrain <truebrain@openttd.org>
parents: 10656
diff changeset
687 e->preview_wait = 20;
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
688 AI::NewEvent(best_company, new AIEventEnginePreview(i));
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
689 if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
690 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
691 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
692 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
693 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
694
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
695 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
696 * 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
697 * 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
698 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
699 * @param flags operation to perfom
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
700 * @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
701 * @param p2 unused
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
702 * @param text unused
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
703 * @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
704 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
705 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
706 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
707 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
708 if (e == NULL || GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
709
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
710 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
711
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
712 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
713 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
714
15653
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
715 /**
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
716 * An engine has become available for general use.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
717 * Also handle the exclusive engine preview contract.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
718 * @param e Engine generally available as of now.
930fc2895ced (svn r20318) -Doc: Doxygen additions.
alberth <alberth@openttd.org>
parents: 15652
diff changeset
719 */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
720 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
721 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
722 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
723 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
724 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
725
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
726 /* 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
727 * 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
728 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
729 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
730 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
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 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
733
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
734 /* 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
735 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
736
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
737 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
738 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
739 (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
740 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
741 /* 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
742 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
743 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
745 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
746 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
747 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
748 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
749
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
750 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
751 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
752
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
753 /* 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
754 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
755
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
756 /* 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
757 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
758
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
759 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
760 /* 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
761 RailType railtype = e->u.rail.railtype;
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
762 assert(railtype < RAILTYPE_END);
17104
f081bf6f0633 (svn r21841) -Feature: [NewGRF] Allow to define other railtypes that should be introduced if a particular rail type is introduced, e.g. to make sure slow rail is introduced when fast rail gets introduced
rubidium <rubidium@openttd.org>
parents: 16917
diff changeset
763 FOR_ALL_COMPANIES(c) c->avail_railtypes |= GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes;
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
764 } 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
765 /* 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
766 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
767 }
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
768
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
769 AI::BroadcastNewEvent(new AIEventEngineAvailable(index));
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
770
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
771 SetDParam(0, GetEngineCategoryName(index));
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
772 SetDParam(1, index);
12619
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12492
diff changeset
773 AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, NR_ENGINE, index);
16160
c638d1941c58 (svn r20856) -Fix [FS#4141]: Road/water toolbars did not get updated when the first vehicle of their type becomes available.
terkhen <terkhen@openttd.org>
parents: 15763
diff changeset
774
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
775 /* 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
776 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
777 if (e->type == VEH_SHIP) InvalidateWindowData(WC_BUILD_TOOLBAR, TRANSPORT_WATER);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
778 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
779
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
780 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
781 {
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
782 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
783 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
784 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
785 /* 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
786 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
787 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
788 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
789 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
790
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
791 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
792 /* 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
793 NewVehicleAvailable(e);
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11296
diff changeset
794 } else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
795 /* Introduction date has passed.. show introducing dialog to one companies. */
6174
c9f5e97572a4 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros <maedhros@openttd.org>
parents: 6125
diff changeset
796 e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
797
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
798 /* Do not introduce new rail wagons */
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15511
diff changeset
799 if (!IsWagon(e->index)) {
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
800 e->preview_company_rank = 1; // Give to the company with the highest rating.
15552
683f2dbe75bb (svn r20211) -Codechange: Indented code should have curly braces around it.
alberth <alberth@openttd.org>
parents: 15511
diff changeset
801 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
802 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
803 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
804 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
805 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
806
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
807 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
808 {
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
809 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
810
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
811 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
812 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
813 }
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
814
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
815 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
816 }
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
817
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
818 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
819 * 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
820 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
821 * @param flags operation to perfom
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
822 * @param p1 engine 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
823 * @param p2 unused
13067
082cdb4504ac (svn r17567) -Fix: some doxygen warnings
rubidium <rubidium@openttd.org>
parents: 13036
diff changeset
824 * @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
825 * @return the cost of this operation or an error
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
826 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
827 CommandCost 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
828 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
829 Engine *e = Engine::GetIfValid(p1);
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
830 if (e == NULL) 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
831
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
832 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
833
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
834 if (!reset) {
16679
07ae81d6312a (svn r21410) -Codechange: limit engine name by amount of characters, not bytes
rubidium <rubidium@openttd.org>
parents: 16643
diff changeset
835 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
836 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
837 }
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
838
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
839 if (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
840 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
841
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
842 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
843 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
844 } 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
845 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
846 }
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
847
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
848 MarkWholeScreenDirty();
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
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
851 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
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
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
854
15620
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
855 /**
f8e9a3f0c140 (svn r20283) -Codechange: Unify start of doygen comments.
frosch <frosch@openttd.org>
parents: 15552
diff changeset
856 * 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
857 * @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
858 * @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
859 * @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
860 * @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
861 * 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
862 */
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
863 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
864 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
865 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
866
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
867 /* 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
868 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
869
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
870 /* 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
871 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
872
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
873 /* check if it's 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
874 if (!HasBit(e->company_avail, company)) return false;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
875
15244
e72aea2333da (svn r19879) -Codechange: Also hide invalid engines from purchase lists.
frosch <frosch@openttd.org>
parents: 15043
diff changeset
876 if (e->info.string_id == STR_NEWGRF_INVALID_ENGINE) return false;
e72aea2333da (svn r19879) -Codechange: Also hide invalid engines from purchase lists.
frosch <frosch@openttd.org>
parents: 15043
diff changeset
877
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
878 if (type == VEH_TRAIN) {
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
879 /* 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
880 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
881 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
882 }
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
883
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 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
885 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
886
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
887 /**
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
888 * 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
889 * 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
890 * @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
891 * @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
892 */
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
893 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
894 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
895 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
896
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
897 /* 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
898 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
899
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
900 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
901
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
902 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
903 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
904
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
905 /* 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
906 * 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
907 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
908
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
909 /* 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
910 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
911 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
912 }